2016-07-22 59 views
0

我尝试使用softlayer api来获取/删除/添加trunk。 http://sldn.softlayer.com/reference/services/SoftLayer_Network_Component用于VLAN Trunk的Softlayer API

我们的baremetal已经被软件票树干了。我们希望先移除后备箱。然后添加主干。

我们可以使用baremetal uplinkComponent ID获取NetworkNetworkVlanTrunks。 client['SoftLayer_Network_Component'].getNetworkVlanTrunks(id=networkcomponentId)

这里就是让干线的输出:

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

现在,我们要删除的VLAN-ID-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

您应该更加小心代码格式,请参阅http://stackoverflow.com/editing-help#comment-formatting –

回答

0

要检查是否添加或删除成功的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. <[email protected]> 
""" 
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. <[email protected]> 
""" 
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中继线是相同的想法比删除,无论如何这里是方法:

我希望它能帮助。如果您对此有疑问或疑问,请告知我。

+0

我已经尝试过使用您的代码。但是,删除中继线时仍然出现内部错误。 'networkcomponentId = 5253429个 networkVlans = [{ “ID”:1231207}] 尝试: removetrunk = network_component.removeNetworkVlanTrunks(networkVlans,ID = networkcomponentId) 除了SoftLayer.SoftLayerAPIError为e: 打印('错误的faultcode =%S ,faultString =%s' %(e.faultCode,e.faultString)) exit(1)' – yqdou

+0

这里是错误异常:'错误faultCode = SoftLayer_Exception_InternalError,faultString =发生内部系统错误。' – yqdou

+0

与许可或设备访问有关。请检查您是否已启用**查看硬件详细信息**权限,并且您具有适当的**访问网络组件所属的硬件**设备的权限。 –

相关问题