Softlayer API: 如何获取静态子网属于哪个VSI?
Softlayer API: How to get the static subnet belongs to which VSI?
背景
我可以通过流动的 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 项目。
现在我想知道哪个VSI绑定了这个子网?还有其他面膜可以帮助吗?
或者,如何获取vsi的二级ip信息?
您可以添加子网关系 属性 以更深入地显示子网通过 属性 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 地址,请参考此 post How to get secondary ip addresses。
背景
我可以通过流动的 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 项目。
现在我想知道哪个VSI绑定了这个子网?还有其他面膜可以帮助吗?
或者,如何获取vsi的二级ip信息?
您可以添加子网关系 属性 以更深入地显示子网通过 属性 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 地址,请参考此 post How to get secondary ip addresses。