Add list support to filters (#1083)
* initial pass with TODOs * add list support to get_object_value * fix group-id filters * add tests for sg name and id filters
This commit is contained in:
parent
8e57dc92f4
commit
1f6b1b8c4a
@ -335,6 +335,11 @@ def get_object_value(obj, attr):
|
|||||||
val = getattr(val, key)
|
val = getattr(val, key)
|
||||||
elif isinstance(val, dict):
|
elif isinstance(val, dict):
|
||||||
val = val[key]
|
val = val[key]
|
||||||
|
elif isinstance(val, list):
|
||||||
|
for item in val:
|
||||||
|
item_val = get_object_value(item, key)
|
||||||
|
if item_val:
|
||||||
|
return item_val
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
return val
|
return val
|
||||||
@ -385,8 +390,9 @@ filter_dict_attribute_mapping = {
|
|||||||
'state-reason-code': '_state_reason.code',
|
'state-reason-code': '_state_reason.code',
|
||||||
'source-dest-check': 'source_dest_check',
|
'source-dest-check': 'source_dest_check',
|
||||||
'vpc-id': 'vpc_id',
|
'vpc-id': 'vpc_id',
|
||||||
'group-id': 'security_groups',
|
'group-id': 'security_groups.id',
|
||||||
'instance.group-id': 'security_groups',
|
'instance.group-id': 'security_groups.id',
|
||||||
|
'instance.group-name': 'security_groups.name',
|
||||||
'instance-type': 'instance_type',
|
'instance-type': 'instance_type',
|
||||||
'private-ip-address': 'private_ip',
|
'private-ip-address': 'private_ip',
|
||||||
'ip-address': 'public_ip',
|
'ip-address': 'public_ip',
|
||||||
|
@ -437,6 +437,41 @@ def test_get_instances_filtering_by_ni_private_dns():
|
|||||||
])['Reservations']
|
])['Reservations']
|
||||||
reservations[0]['Instances'].should.have.length_of(1)
|
reservations[0]['Instances'].should.have.length_of(1)
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_get_instances_filtering_by_instance_group_name():
|
||||||
|
image_id = 'ami-1234abcd'
|
||||||
|
client = boto3.client('ec2', region_name='us-east-1')
|
||||||
|
client.create_security_group(
|
||||||
|
Description='test',
|
||||||
|
GroupName='test_sg'
|
||||||
|
)
|
||||||
|
client.run_instances(ImageId=image_id,
|
||||||
|
MinCount=1,
|
||||||
|
MaxCount=1,
|
||||||
|
SecurityGroups=['test_sg'])
|
||||||
|
reservations = client.describe_instances(Filters=[
|
||||||
|
{'Name': 'instance.group-name', 'Values': ['test_sg']}
|
||||||
|
])['Reservations']
|
||||||
|
reservations[0]['Instances'].should.have.length_of(1)
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_get_instances_filtering_by_instance_group_id():
|
||||||
|
image_id = 'ami-1234abcd'
|
||||||
|
client = boto3.client('ec2', region_name='us-east-1')
|
||||||
|
create_sg = client.create_security_group(
|
||||||
|
Description='test',
|
||||||
|
GroupName='test_sg'
|
||||||
|
)
|
||||||
|
group_id = create_sg['GroupId']
|
||||||
|
client.run_instances(ImageId=image_id,
|
||||||
|
MinCount=1,
|
||||||
|
MaxCount=1,
|
||||||
|
SecurityGroups=['test_sg'])
|
||||||
|
reservations = client.describe_instances(Filters=[
|
||||||
|
{'Name': 'instance.group-id', 'Values': [group_id]}
|
||||||
|
])['Reservations']
|
||||||
|
reservations[0]['Instances'].should.have.length_of(1)
|
||||||
|
|
||||||
@mock_ec2_deprecated
|
@mock_ec2_deprecated
|
||||||
def test_get_instances_filtering_by_tag():
|
def test_get_instances_filtering_by_tag():
|
||||||
conn = boto.connect_ec2()
|
conn = boto.connect_ec2()
|
||||||
|
Loading…
Reference in New Issue
Block a user