【问题标题】:Softlayer API: How to get the static subnet belongs to which VSI?Softlayer API:如何获取静态子网属于哪个 VSI?
【发布时间】:2023-03-28 10:30:01
【问题描述】:

背景

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

【问题讨论】:

    标签: python api ibm-cloud-infrastructure


    【解决方案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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-26
      • 1970-01-01
      相关资源
      最近更新 更多