Fix : EC2 - Added ownerId filter for describe instances (#3149)
* Fix : EC2 - Added ownerId filter for describe instances * linting
This commit is contained in:
parent
6fb7867767
commit
552b1294df
@ -11,6 +11,7 @@ from cryptography.hazmat.primitives import serialization
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives.asymmetric import rsa
|
||||
|
||||
from moto.iam.models import ACCOUNT_ID
|
||||
|
||||
EC2_RESOURCE_TO_PREFIX = {
|
||||
"customer-gateway": "cgw",
|
||||
@ -291,7 +292,9 @@ def get_object_value(obj, attr):
|
||||
keys = attr.split(".")
|
||||
val = obj
|
||||
for key in keys:
|
||||
if hasattr(val, key):
|
||||
if key == "owner_id":
|
||||
return ACCOUNT_ID
|
||||
elif hasattr(val, key):
|
||||
val = getattr(val, key)
|
||||
elif isinstance(val, dict):
|
||||
val = val[key]
|
||||
@ -364,6 +367,7 @@ filter_dict_attribute_mapping = {
|
||||
"image-id": "image_id",
|
||||
"network-interface.private-dns-name": "private_dns",
|
||||
"private-dns-name": "private_dns",
|
||||
"owner-id": "owner_id",
|
||||
}
|
||||
|
||||
|
||||
|
@ -536,6 +536,20 @@ def test_get_instances_filtering_by_image_id():
|
||||
reservations[0]["Instances"].should.have.length_of(1)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_get_instances_filtering_by_account_id():
|
||||
image_id = "ami-1234abcd"
|
||||
client = boto3.client("ec2", region_name="us-east-1")
|
||||
conn = boto3.resource("ec2", "us-east-1")
|
||||
conn.create_instances(ImageId=image_id, MinCount=1, MaxCount=1)
|
||||
|
||||
reservations = client.describe_instances(
|
||||
Filters=[{"Name": "owner-id", "Values": ["123456789012"]}]
|
||||
)["Reservations"]
|
||||
|
||||
reservations[0]["Instances"].should.have.length_of(1)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_get_instances_filtering_by_private_dns():
|
||||
image_id = "ami-1234abcd"
|
||||
|
Loading…
x
Reference in New Issue
Block a user