简体   繁体   English

Softlayer API:如何获取属于哪个VSI的静态子网?

[英]Softlayer API: How to get the static subnet belongs to which VSI?

background 背景

I can get a vlan's subnet info by the flowing python script: 我可以通过流动的python脚本获取vlan的子网信息:

# Declare an Object Mask to get additional information
    object_mask = 'mask[primaryRouter,subnets[id,billingItem,cidr,version,addressSpace,subnetType,networkIdentifier,totalIpAddresses,usableIpAddressCount,ipAddresses[ipAddress, isReserved, virtualGuest, hardware]]]'
    # Declare an Object Filter to get information from specific vlan
    filter = {'networkVlans': {'id': {'operation': vlan_id}}}
    return self.sl_account.getNetworkVlans(mask=object_mask, filter=filter)[0]

And the result contains: 结果包含:

[... 'subnets': [{'cidr': 28,
              'id': 986245,
              'billingItem': {'allowCancellationFlag': 1,}
              orderItemId': 223126909,
              'ipAddresses': [{'ipAddress': '169.38.73.xxx', ...
               'subnetType': 'STATIC_IP_ROUTED',
             'totalIpAddresses': '8',
             'usableIpAddressCount': '5',
             'version': 4},
             ...]
            }
            ...
            ]]

question

The result of STATIC_IP_ROUTED subnet do not contain the virtualGuest item. STATIC_IP_ROUTED子网的结果不包含virtualGuest项目。

  1. Now I want to know which VSI has bind this subnet? 现在我想知道哪个VSI绑定了该子网? Does any other mask can helps? 是否有其他口罩可以帮助您?

  2. Or, How can I get the secondary ip info of a vsi? 或者,如何获取vsi的辅助IP信息?

You may add the subnets relational property to go deeper and display the VSI on which the subnet is binded through the property endpointIpAddress . 您可以添加子网关系属性,使其更深入,并通过属性EndpointIpAddress显示绑定了子网的VSI。

Please try your code with the mask previously mentioned: 请使用前面提到的掩码尝试您的代码:

# Declare an Object Mask to get additional information
object_mask = 'mask[primaryRouter,subnets[id,billingItem,cidr,version,addressSpace,subnetType,networkIdentifier,totalIpAddresses,usableIpAddressCount,ipAddresses[id, ipAddress, virtualGuest[id], hardware[id]]], subnets[endPointIpAddress[id,ipAddress,subnet[id, datacenter[longName,name]],hardware[id,fullyQualifiedDomainName],virtualGuest[id,fullyQualifiedDomainName]]]]'

# Declare an Object Filter to get information from specific vlan
filter = {'networkVlans': {'id': {'operation': vlan_id}}}

return self.sl_account.getNetworkVlans(mask=object_mask, filter=filter)[0]

Or you may use the SoftLayer_Account::getSubnets method. 或者,您可以使用SoftLayer_Account :: getSubnets方法。

# Declare an Object Mask to get additional subnet information
object_mask = 'mask[id, networkIdentifier, subnetType, totalIpAddresses, datacenter[longName, name], networkVlan[id, vlanNumber], endPointIpAddress[id,ipAddress,subnet[id, datacenter[longName,name]],hardware[id,fullyQualifiedDomainName],virtualGuest[id,fullyQualifiedDomainName]]]'

# Declare an Object Filter to get information from specific Subnet.
filter = {"subnets":{"id":{"operation":subnet_id}}}

subnetsResult = client ['Account'].getSubnets(filter = filter, mask = object_mask)

print(subnetsResult)

On both solutions you will see the VirtualGuest item information. 在这两种解决方案上,您将看到VirtualGuest项目信息。

In order to retrieve the secondary ip Addresses of a VSI please refer to this post How to get secondary ip addresses . 为了检索VSI的辅助IP地址,请参阅此文章如何获取辅助IP地址

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM