1

I tried to use softlayer api to get/remove/add trunk. http://sldn.softlayer.com/reference/services/SoftLayer_Network_Component

our baremetal has already trunked by Softlayer ticket. We want to remove the trunk first. and then add trunk.

We could getNetworkVlanTrunks using baremetal uplinkComponent ID. client['SoftLayer_Network_Component'].getNetworkVlanTrunks(id=networkcomponentId)

Here is the output of get trunk:

[{'networkComponentId': <networkcomponentId>, 'networkVlanId': <vlanid-1>}, {'networkComponentId': <networkcomponentId>, 'networkVlanId': <vlanid-2>}]

Now, we want to remove trunk of vlanid-2.

vlan = client['Network_Vlan'].getObject(id=<vlanid-2>) client['SoftLayer_Network_Component'].removeNetworkVlanTrunks([vlan], id=networkcomponentId)

However, we got this error when removeNetworkVlanTrunks:

File "/usr/lib64/python2.7/site-packages/SoftLayer/transports.py", line 187, in __call__ raise _ex(ex.faultCode, ex.faultString) SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_InternalError): An internal system error has occurred.

Does anyone know about how this happen? Are we using the right networkComponentID for remove? Does anyone know how to use the addNetworkVlanTrunks?

yqdou
  • 11
  • 1
  • You should be more careful about code formatting, see http://stackoverflow.com/editing-help#comment-formatting – Nick Roz Jul 22 '16 at 11:38

1 Answers1

1

To check if the vlans were added or removed successfully, try the following python script:

"""
This script removes the network vlan trunks from network component

See below references for more details.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Component/addNetworkVlanTrunks

@License: http://sldn.softlayer.com/article/License
@Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
from pprint import pprint as pp

# Your SoftLayer username and apiKey
user = 'set me'
api = 'set me'

# Connect to SoftLayer
client = SoftLayer.create_client_from_env(username=user, api_key=api)

# Define the network component id
networkComponentId = 916616

# Define the network vlans that you wish to remove
networkVlans = [{"id": 1318157}]

try:
    result = client['SoftLayer_Network_Component'].removeNetworkVlanTrunks(networkVlans, id=networkComponentId)
    pp(result)
except SoftLayer.SoftLayerAPIError as e:
    print('Error faultCode=%s, faultString=%s'
          % (e.faultCode, e.faultString))
    exit(1)

To remove a vlan trunk from network component, try the following:

"""
This script removes the network vlan trunks from network component

See below references for more details.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Component/addNetworkVlanTrunks

@License: http://sldn.softlayer.com/article/License
@Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
from pprint import pprint as pp

# Your SoftLayer username and apiKey
user = 'set me'
api = 'set me'

# Connect to SoftLayer
client = SoftLayer.create_client_from_env(username=user, api_key=api)

# Define the network component id
networkComponentId = 916616

# Define the network vlans that you wish to remove
networkVlans = [{"id": 1318157}]

try:
    result = client['SoftLayer_Network_Component'].removeNetworkVlanTrunks(networkVlans, id=networkComponentId)
    pp(result)
except SoftLayer.SoftLayerAPIError as e:
    print('Error faultCode=%s, faultString=%s'
          % (e.faultCode, e.faultString))
    exit(1)

To add network vlan trunks is the same idea than remove, anyway here is the method:

I hope it helps. Let me know if you have an issue or doubt about it.

  • I have tried with your code. But, still get internal error when remove trunk. `networkcomponentId = 5253429 networkVlans = [{"id": 1231207}] try: removetrunk = network_component.removeNetworkVlanTrunks(networkVlans, id=networkcomponentId) except SoftLayer.SoftLayerAPIError as e: print('Error faultCode=%s, faultString=%s' % (e.faultCode, e.faultString)) exit(1)` – yqdou Jul 25 '16 at 06:01
  • Here is the error exception: `Error faultCode=SoftLayer_Exception_InternalError, faultString=An internal system error has occurred.` – yqdou Jul 25 '16 at 06:17
  • That exception is related with permission or device access. Please check that you have **View Hardware Details** permission enabled and you have the proper **access to the hardware** device, in which the network component belongs. – Ruber Cuellar Valenzuela Jul 25 '16 at 14:07
  • Yes, I have those permissions. I can view the details and access the hardware. One more thing to confirm, is the network component ID the { uplinkNetworkComponents.uplinkComponent.id }? – yqdou Jul 26 '16 at 01:52
  • The **network component id** is the **uplinkNetworkComponents** (You should use the identifiers inside of this property). This is different than **uplinkNetworkComponents.uplinkComponent.id**. – Ruber Cuellar Valenzuela Jul 26 '16 at 14:21