试图获取有关 boto 文档的信息
trying to get info on boto docs
我是 python 的新手,正在研究 boto 以快速列出 SG。我的问题是当我查看下面列出的 boto 文档时...我怎么知道我可以使用哪些属性。例如,在下面 python 的示例输出中,我创建了一个名为 inst 的变量……首先我用它来获取实例 ID,接下来我用它来获取 SG 信息……我的问题是....我怎么知道我可以获得哪些其他属性?也许是实例类型、ami-id 等。阅读下面的文档让我有点困惑,因为我是 python 的新手...任何 help/pointers 将不胜感激...
http://boto.readthedocs.org/en/latest/ref/ec2.html#module-boto.ec2.instance
>>> reservations = conn.get_all_instances()
>>> for i in reservations:
inst = i.instances[0]
print inst
Instance:i-c8990c39
Instance:i-c7e45537
Instance:i-698047c1
>>>
>>> for i in reservations:
inst = i.instances[0].groups
print inst
[<boto.ec2.group.Group object at 0xf2c7d0>]
[<boto.ec2.group.Group object at 0xf2c350>]
[<boto.ec2.group.Group object at 0xf2c750>
<boto.ec2.group.Group object at 0x10992d0>]
还有,为什么我没有得到SG却得到了实例id??
>>> for i in reservations:
inst = i.instances
print inst
[Instance:i-c8990c39]
[Instance:i-c7e45537]
[Instance:i-698047c1]
>>>
>>> for i in reservations:
sg = i.groups
print sg
[] [] []
>>>
>>>
如果您想打印出与您的实例关联的第一个安全组 ID,您可以这样做:
>>> reservations = conn.get_all_instances()
>>>
>>> for i in reservations:
sg = i.instances[0].groups[0]
print sg.id
sg-9f1xxxxx
sg-9f1xxxxx
sg-9f1xxxxx
sg-9f1xxxxx
sg-9f1xxxxx
sg-1faxxxxx
sg-9f1xxxxx
sg-9f1xxxxx
sg-9f1xxxxx
Okay I see what is going on, but another stupid question:
How come i do not get the SG but I get the instance id??
>>> for i in reservations:
inst = i.instances
print inst
[Instance:i-c8990c39]
[Instance:i-c7e45537]
[Instance:i-698047c1]
在这种情况下,您将打印所有预订。不是实例。每个预订有一个实例。
>>>
>>> for i in reservations:
sg = i.groups
print sg
[] [] []
>>>
>>>
在这种情况下,您要打印预订的安全组。预留没有与之关联的安全组。
您向我们指出的 EC2 instance reference 是否包含属性列表,例如image_id(对于 AMI id)和 instance_type。您在寻找不同的东西吗?
此外,请理解当您 'print' 一个对象时,您不一定会看到该对象的所有属性 - 相反,您通常会看到一个简单的字符串表示形式,例如 "Instance:i-c8990c39"。
最后,准备经常使用 dir(obj) 以了解更多关于 obj 属性的信息 - Python 文档很少,如果有的话,完整的 dir(obj) 会帮助你。参见 how to use type, str, and dir for introspection。
查看 python 内置函数目录:
https://docs.python.org/2/library/functions.html#dir
>>> reservations = conn.get_all_instances()
>>> instance = reservations[0].instances[0]
>>> dir(instance)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_in_monitoring_element', '_placement', '_previous_state', '_state', '_update', 'add_tag', 'ami_launch_index', 'architecture', 'block_device_mapping', 'client_token', 'confirm_product', 'connection', 'create_image', 'dns_name', 'ebs_optimized', 'endElement', 'eventsSet', 'get_attribute', 'get_console_output', 'group_name', 'groups', 'hypervisor', 'id', 'image_id', 'instance_profile', 'instance_type', 'interfaces', 'ip_address', 'item', 'kernel', 'key_name', 'launch_time', 'modify_attribute', 'monitor', 'monitored', 'monitoring', 'monitoring_state', 'persistent', 'placement', 'placement_group', 'placement_tenancy', 'platform', 'previous_state', 'previous_state_code', 'private_dns_name', 'private_ip_address', 'product_codes', 'public_dns_name', 'ramdisk', 'reason', 'reboot', 'region', 'remove_tag', 'requester_id', 'reset_attribute', 'root_device_name', 'root_device_type', 'sourceDestCheck', 'spot_instance_request_id', 'start', 'startElement', 'state', 'state_code', 'state_reason', 'stop', 'subnet_id', 'tags', 'terminate', 'unmonitor', 'update', 'use_ip', 'virtualization_type', 'vpc_id']
我是 python 的新手,正在研究 boto 以快速列出 SG。我的问题是当我查看下面列出的 boto 文档时...我怎么知道我可以使用哪些属性。例如,在下面 python 的示例输出中,我创建了一个名为 inst 的变量……首先我用它来获取实例 ID,接下来我用它来获取 SG 信息……我的问题是....我怎么知道我可以获得哪些其他属性?也许是实例类型、ami-id 等。阅读下面的文档让我有点困惑,因为我是 python 的新手...任何 help/pointers 将不胜感激...
http://boto.readthedocs.org/en/latest/ref/ec2.html#module-boto.ec2.instance
>>> reservations = conn.get_all_instances()
>>> for i in reservations:
inst = i.instances[0]
print inst
Instance:i-c8990c39
Instance:i-c7e45537
Instance:i-698047c1
>>>
>>> for i in reservations:
inst = i.instances[0].groups
print inst
[<boto.ec2.group.Group object at 0xf2c7d0>]
[<boto.ec2.group.Group object at 0xf2c350>]
[<boto.ec2.group.Group object at 0xf2c750>
<boto.ec2.group.Group object at 0x10992d0>]
还有,为什么我没有得到SG却得到了实例id??
>>> for i in reservations:
inst = i.instances
print inst
[Instance:i-c8990c39]
[Instance:i-c7e45537]
[Instance:i-698047c1]
>>>
>>> for i in reservations:
sg = i.groups
print sg
[] [] []
>>>
>>>
如果您想打印出与您的实例关联的第一个安全组 ID,您可以这样做:
>>> reservations = conn.get_all_instances()
>>>
>>> for i in reservations:
sg = i.instances[0].groups[0]
print sg.id
sg-9f1xxxxx
sg-9f1xxxxx
sg-9f1xxxxx
sg-9f1xxxxx
sg-9f1xxxxx
sg-1faxxxxx
sg-9f1xxxxx
sg-9f1xxxxx
sg-9f1xxxxx
Okay I see what is going on, but another stupid question: How come i do not get the SG but I get the instance id??
>>> for i in reservations:
inst = i.instances
print inst
[Instance:i-c8990c39]
[Instance:i-c7e45537]
[Instance:i-698047c1]
在这种情况下,您将打印所有预订。不是实例。每个预订有一个实例。
>>>
>>> for i in reservations:
sg = i.groups
print sg
[] [] []
>>>
>>>
在这种情况下,您要打印预订的安全组。预留没有与之关联的安全组。
您向我们指出的 EC2 instance reference 是否包含属性列表,例如image_id(对于 AMI id)和 instance_type。您在寻找不同的东西吗?
此外,请理解当您 'print' 一个对象时,您不一定会看到该对象的所有属性 - 相反,您通常会看到一个简单的字符串表示形式,例如 "Instance:i-c8990c39"。
最后,准备经常使用 dir(obj) 以了解更多关于 obj 属性的信息 - Python 文档很少,如果有的话,完整的 dir(obj) 会帮助你。参见 how to use type, str, and dir for introspection。
查看 python 内置函数目录: https://docs.python.org/2/library/functions.html#dir
>>> reservations = conn.get_all_instances()
>>> instance = reservations[0].instances[0]
>>> dir(instance)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_in_monitoring_element', '_placement', '_previous_state', '_state', '_update', 'add_tag', 'ami_launch_index', 'architecture', 'block_device_mapping', 'client_token', 'confirm_product', 'connection', 'create_image', 'dns_name', 'ebs_optimized', 'endElement', 'eventsSet', 'get_attribute', 'get_console_output', 'group_name', 'groups', 'hypervisor', 'id', 'image_id', 'instance_profile', 'instance_type', 'interfaces', 'ip_address', 'item', 'kernel', 'key_name', 'launch_time', 'modify_attribute', 'monitor', 'monitored', 'monitoring', 'monitoring_state', 'persistent', 'placement', 'placement_group', 'placement_tenancy', 'platform', 'previous_state', 'previous_state_code', 'private_dns_name', 'private_ip_address', 'product_codes', 'public_dns_name', 'ramdisk', 'reason', 'reboot', 'region', 'remove_tag', 'requester_id', 'reset_attribute', 'root_device_name', 'root_device_type', 'sourceDestCheck', 'spot_instance_request_id', 'start', 'startElement', 'state', 'state_code', 'state_reason', 'stop', 'subnet_id', 'tags', 'terminate', 'unmonitor', 'update', 'use_ip', 'virtualization_type', 'vpc_id']