Python Softlayer API:如何获取静态子网属于哪个VSI? 出身背景

Python Softlayer API:如何获取静态子网属于哪个VSI? 出身背景,python,api,ibm-cloud-infrastructure,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[

我可以通过流动的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},
             ...]
            }
            ...
            ]]
问题 静态IP路由子网的结果不包含virtualGuest项

  • 现在我想知道哪个VSI绑定了这个子网?其他面膜有帮助吗

  • 或者,如何获取vsi的辅助ip信息


  • 您可以添加subnets relational属性,以更深入地显示通过属性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地址,请参阅本文