【问题标题】:Get volume information associated with Instance获取与 Instance 关联的卷信息
【发布时间】:2016-12-25 13:58:53
【问题描述】:

我正在尝试检索与实例关联的所有卷。

if volume.attachment_state() == 'attached':

        volumesinstance = ec2_connection.get_all_instances()

        ids = [z for k in volumesinstance for z in k.instances]

        for s in ids:

            try:
                tags = s.tags
                instance_name = tags["Name"]
                print (instance_name)
            except Exception as e:
                print e

但是,它没有按预期工作。

【问题讨论】:

    标签: boto boto3


    【解决方案1】:

    您可以在 get_all_instances 方法中添加过滤器

    像这样:

    filter = {'block-device-mapping.volume-id': volume.id}
            volumesinstance = ec2_connection.get_all_instances(filters=filter)
    
    ids = [z for k in volumesinstance for z in k.instances]
    
    for s in ids:
    
       try:
           tags = s.tags
           instance_name = tags["Name"]
           print (instance_name)
       except Exception as e:
           print e
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      • 2021-08-19
      相关资源
      最近更新 更多