如果我知道实例的区域和名称,那么获取实例的公共IP地址的最简单方法是什么?
def get_public_ip(region, instance_name):
# ???
使用gcutil:
$ gcutil listinstances --columns=external-ip
或使用python apinetworkInterfaces
结构如下所示:
u'networkInterfaces':[
{
u'accessConfigs':[
{
u'kind':u'compute#accessConfig',
u'type':u'ONE_TO_ONE_NAT',
u'name':u'External NAT',
u'natIP':u'xxx.xxx.xxx.xxx'
}
],
u'networkIP':u'10.xxx.xxx.xxx',
u'network': u'https://www.googleapis.com/compute/v1/projects/<my-project-id>/global/networks/<network-name>',
u'name':u'nic0'
}
]
因此您可以使用此“列表实例”示例执行以下操作:
for instance in instances:
print instance['networkInterfaces'][0]['accessConfigs'][0]['natIP']
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句