首页 文章

如何在python api softlayer create_instance调用中指定private_vlan

提问于
浏览
0

我试图使用python api命令一个vsi,指定我已经使用的私有和公共vlans,但调用失败 .

>>> client = SoftLayer.Client(username=SL_USERNAME, api_key=SL_API_KEY,endpoint_url=SoftLayer.API_PUBLIC_ENDPOINT)
>>> mgr = SoftLayer.VSManager(client)
>>> vsi
{'dedicated': False, 'disks': ['100', '25'], 'hourly': True, 'domain':'vmonic.local', 'private': False, 'cpus': 1, 'private_vlan': 123, 'public_vlan':1234, 'datacenter': 'sjc03', 'ssh_keys': ['12345', '23456'], 'hostname':'ansible-server', 'os_code': 'CENTOS_LATEST', 'local_disk': True, 'memory': 1024}
>>> mgr.create_instance(**vsi)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site- packages/SoftLayer/managers/vs.py",line 534, in
create_instance
inst = self.guest.createObject(self._generate_create_dict(**kwargs))
File "/usr/local/lib/python2.7/site-packages/SoftLayer/API.py", line 373, in
call_handler
return self(name, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/API.py", line 341, in call
return self.client.call(self.name, name, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/API.py", line 237, in call
return self.transport(request)
File "/usr/local/lib/python2.7/site-packages/SoftLayer/transports.py",  line 187, in
__call__
raise _ex(ex.faultCode, ex.faultString)
SoftLayer.exceptions.SoftLayerAPIError:
SoftLayerAPIError(SoftLayer_Exception_Public): Could not obtain network VLAN with id
#123.

从上面粘贴的输出中的真值中清除vlan和ssh键ID .

我可以使用SL门户创建一个vsi,指定在api调用中失败的相同vlan . 我需要在python api中做些什么才能使它工作?

1 回答

  • 1

    我验证了你的模板工作正常,公共和私有vlans设置成功 . 根据您的例外情况,vlan“123”不存在,必须在公共和私有vlan中指定网络vlan标识符 .

    请仔细检查"123"和"1234"是 network vlan identifiers .

    以下脚本将有助于获取特定数据中心的vlan(例如sjc03)

    """
    List Vlans for specific datacenter
    """
    import SoftLayer
    
    # Your SoftLayer API username and key.
    USERNAME = 'set me'
    API_KEY = 'set me'
    
    # Declare the API client
    client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
    mgr = SoftLayer.NetworkManager(client)
    # Define Datacenter name
    dc = 'sjc03'
    
    try:
        result = mgr.list_vlans(datacenter=dc)
        print(result)
    except SoftLayer.SoftLayerAPIError as e:
        print("Error. "
              % (e.faultCode, e.faultString))
    

    更新

    """
    Get Vlan from vlanNumber
    """
    import SoftLayer
    
    # Your SoftLayer API username and key.
    USERNAME = 'set me'
    API_KEY = 'set me'
    
    # Declare the API client
    client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
    mgr = SoftLayer.NetworkManager(client)
    
    # Define Vlan number
    vlanNumber = 966
    
    try:
        result = mgr.list_vlans(vlan_number=vlanNumber)
        print(result)
    except SoftLayer.SoftLayerAPIError as e:
        print("Error. "
              % (e.faultCode, e.faultString))
    

相关问题