在自动缩放组博托List实例 [英] List instances in auto scaling group with boto
问题描述
我要列出当前在一个自动缩放组运行的所有实例。可以在完成与博托?
I want to list all instances that are currently running within a auto scaling group. Can that be accomplished with boto?
必须有阿布沙耶夫集团和实例之间的一些关系,因为博托具有在 shutdown_instances
方法 boto.ec2.autoscale.group.AutoScalingGroup
类。
There must be some relation between the ASG and the instances as boto has the shutdown_instances
method within the boto.ec2.autoscale.group.AutoScalingGroup
class.
任何指针朝着正确的方向是高度AP preciated!
Any pointers in the right direction is highly appreciated!
推荐答案
这样的事情应该工作:
>>> import boto
>>> autoscale = boto.connect_autoscale()
>>> ec2 = boto.connect_ec2()
>>> group = autoscale.get_all_groups(['mygroupname'])[0]
>>> instance_ids = [i.instance_id for i in group.instances]
>>> reservations = ec2.get_all_instances(instance_ids)
>>> instances = [i for r in reservations for i in r.instances]
我们要收集实例ID的,然后调用EC2的原因是,自动定标只存储了有关情况的信息的一小部分。这将导致变量实例指向实例对象在自动缩放基mygroupname的每个实例的列表。
The reason we have to collect the Instance ID's and then call EC2 is that AutoScale only stores a small subset of information about the instances. This would result in the variable instances pointing to a list of Instance objects for each instance in the autoscaling group "mygroupname".
这篇关于在自动缩放组博托List实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!