python - Is it possible to list instances with no VPC using Boto get_only_instances()? -
there aws account instances in vpc , in ec2 classic. try list them separately using get_only_instances() method, seems filters doesn't work not set argument (vpc:none).
import boto import boto.ec2 conn = boto.ec2_connect_to_region('us-east-1', profile_name='qa') = conn.get_only_instances(filters={'vpc_id':'vpc-a0876691'}) # len(a) > 0, , should b = conn.get_only_instances(filters={'vpc_id':none}) # len(b) = 0, should > 0
btw. see following approach work fine:
b = [i in conn.get_only_instances() if not i.vpc_id] # len(b) > 0, , should
the call get_only_instances
ends making call describeinstances endpoint in api.
specifically, boto use filter 'vpc-id', stated in above linked documentation 'the id of vpc instance running in.'
unfortunately, haven't found way query via boto denote boolean "not" operation. i'm adding answer state don't think it's possible.
to work around this, use similar approach yours:
import boto import boto.ec2 conn = boto.ec2.connect_to_region('us-east-1') has_vpc = {'vpc-id': '*'} r_with_vpc = conn.get_only_instances(filters=instance_filters) r_all = conn.get_only_instances() instance_vpc_list = [i.id in r_with_vpc] instance_all = [i.id in r_all] instance_without_vpc = [ in instance_all if not in instance_vpc_list ]
the real difference being build intermediate list of hosts any vpc set don't need know vpc ids ahead of time.
Comments
Post a Comment