2016-07-22 81 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

與許可或設備訪問有關。請檢查您是否已啓用**查看硬件詳細信息**權限,並且您具有適當的**訪問網絡組件所屬的硬件**設備的權限。 –