本文整理汇总了Python中boto.vpc.VPCConnection.get_all_network_interfaces方法的典型用法代码示例。如果您正苦于以下问题:Python VPCConnection.get_all_network_interfaces方法的具体用法?Python VPCConnection.get_all_network_interfaces怎么用?Python VPCConnection.get_all_network_interfaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto.vpc.VPCConnection
的用法示例。
在下文中一共展示了VPCConnection.get_all_network_interfaces方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect_to_region
# 需要导入模块: from boto.vpc import VPCConnection [as 别名]
# 或者: from boto.vpc.VPCConnection import get_all_network_interfaces [as 别名]
secrets = json.load(args.secrets)
conn = connect_to_region(
args.region,
aws_access_key_id=secrets['aws_access_key_id'],
aws_secret_access_key=secrets['aws_secret_access_key']
)
vpc = VPCConnection(
aws_access_key_id=secrets['aws_access_key_id'],
aws_secret_access_key=secrets['aws_secret_access_key'],
region=conn.region
)
else:
conn = connect_to_region(args.region)
vpc = VPCConnection(region=conn.region)
interfaces = vpc.get_all_network_interfaces()
used_ips = [i.private_ip_address for i in interfaces]
subnets = vpc.get_all_subnets(subnet_ids=config["subnet_ids"])
blocks = [s.cidr_block for s in subnets]
available_ips = []
for b in blocks:
# skip first 5 IPs (they are sometimes "reserved") and the last one
# (broadcast)
for ip in list(IP(b))[4:-1]:
if str(ip) not in used_ips:
available_ips.append(ip)
sample = random.sample(available_ips, args.number)
for ip in sample:
print ip