我尝试使用softlayer api来获取/删除/添加trunk。 http://sldn.softlayer.com/reference/services/SoftLayer_Network_Component
我们的裸机已经通过Softlayer票中继。我们想首先删除主干。然后添加trunk。
我们可以使用baremetal uplinkComponent ID获取NetworkVlanTrunks。
client['SoftLayer_Network_Component'].getNetworkVlanTrunks(id=networkcomponentId)
这是get trunk的输出:
[{'networkComponentId': <networkcomponentId>, 'networkVlanId': <vlanid-1>}, {'networkComponentId': <networkcomponentId>, 'networkVlanId': <vlanid-2>}]
现在,我们要删除vlanid-2的主干。
vlan = client['Network_Vlan'].getObject(id=<vlanid-2>)
client['SoftLayer_Network_Component'].removeNetworkVlanTrunks([vlan], id=networkcomponentId)
但是,当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.
有谁知道这是怎么发生的? 我们使用正确的networkComponentID进行删除吗? 有谁知道如何使用addNetworkVlanTrunks?
答案 0 :(得分:1)
要检查是否已成功添加或删除vlan,请尝试以下python脚本:
"""
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)
要从网络组件中删除vlan中继,请尝试以下操作:
"""
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)
添加网络vlan中继与删除相同的想法,无论如何这里是方法:
我希望它有所帮助。如果您对此有疑问或疑问,请与我联系。