Softlayer API:如何让静态子网属于哪个VSI?

时间:2017-07-06 05:39:57

标签: python api ibm-cloud-infrastructure

背景

我可以通过流动的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]

结果包含:

[... '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},
             ...]
            }
            ...
            ]]

问题

STATIC_IP_ROUTED子网的结果不包含virtualGuest项。

  1. 现在我想知道哪个VSI绑定了这个子网?还有其他面具可以帮忙吗?

  2. 或者,我怎样才能获得vsi的二级ip信息?

1 个答案:

答案 0 :(得分:1)

您可以添加子网关系属性以更深入地显示通过属性 endpointIpAddress 绑定子网的VSI。

请使用前面提到的掩码尝试您的代码:

# 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]

或者您可以使用 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)

在这两种解决方案中,您都会看到VirtualGuest项目信息。

要检索VSI的辅助IP地址,请参阅此帖How to get secondary ip addresses