首页 文章

VLAN中继的Softlayer API

提问于
浏览
1

我试图使用softlayer api来获取/删除/添加主干 . http://sldn.softlayer.com/reference/services/SoftLayer_Network_Component

我们的baremetal已经被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的trunk .

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?

1 回答

  • 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)
    

    添加网络vlan中继与删除相同的想法,无论如何这里是方法:

    我希望它有所帮助 . 如果您对此有疑问或疑问,请与我们联系 .

相关问题