Last active
March 6, 2019 19:43
-
-
Save thisisshi/43364475ba2ff3f206b510b27e979d34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
tests ami dergistering describe images call | |
""" | |
import boto3 | |
import placebo | |
import pprint | |
from botocore.exceptions import ClientError | |
session = boto3.Session() | |
pill = placebo.attach(session, data_path='placebo') | |
pill.playback() | |
client = session.client('ec2', 'us-east-1') | |
images = client.describe_images(Owners=['self']) | |
print('Getting images') | |
pprint.pprint(images) | |
image_to_deregister = images['Images'][0]['ImageId'] | |
resp = client.deregister_image(ImageId=image_to_deregister) | |
print('Deregistering the image that was found') | |
pprint.pprint(resp) | |
images = client.describe_images(ImageIds=[image_to_deregister], Owners=['self']) | |
print('Describing the deregistered image') | |
pprint.pprint(images) | |
already_deregistered = 'ami-0f469065fa8e02462' | |
print('Describing an older deregistered image') | |
try: | |
images = client.describe_images(ImageIds=[already_deregistered], Owners=['self']) | |
except ClientError as e: | |
pprint.pprint(e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Getting images | |
{'Images': [{'Architecture': 'x86_64', | |
'BlockDeviceMappings': [{'DeviceName': '/dev/sda1', | |
'Ebs': {'DeleteOnTermination': True, | |
'Encrypted': False, | |
'SnapshotId': 'snap-0bf9e1af959fbdddf', | |
'VolumeSize': 1, | |
'VolumeType': 'gp2'}}], | |
'CreationDate': '2019-03-06T14:16:59.000Z', | |
'Description': '', | |
'Hypervisor': 'xen', | |
'ImageId': 'ami-041151726c89bed87', | |
'ImageLocation': '644160558196/test2', | |
'ImageType': 'machine', | |
'Name': 'test2', | |
'OwnerId': '644160558196', | |
'Public': False, | |
'RootDeviceName': '/dev/sda1', | |
'RootDeviceType': 'ebs', | |
'State': 'available', | |
'VirtualizationType': 'paravirtual'}], | |
'ResponseMetadata': {'HTTPHeaders': {'content-length': '1469', | |
'content-type': 'text/xml;charset=UTF-8', | |
'date': 'Wed, 06 Mar 2019 18:50:29 GMT', | |
'server': 'AmazonEC2'}, | |
'HTTPStatusCode': 200, | |
'RequestId': 'fc317ff7-ef0b-488d-94aa-c8b5d0cfccea', | |
'RetryAttempts': 0}} | |
Deregistering the image that was found | |
{'ResponseMetadata': {'HTTPHeaders': {'content-length': '231', | |
'content-type': 'text/xml;charset=UTF-8', | |
'date': 'Wed, 06 Mar 2019 18:50:29 GMT', | |
'server': 'AmazonEC2'}, | |
'HTTPStatusCode': 200, | |
'RequestId': '4bd4e7ee-693a-4c24-8754-c4164daa7c5e', | |
'RetryAttempts': 0}} | |
Describing the deregistered image | |
{'Images': [], | |
'ResponseMetadata': {'HTTPHeaders': {'content-length': '219', | |
'content-type': 'text/xml;charset=UTF-8', | |
'date': 'Wed, 06 Mar 2019 18:50:30 GMT', | |
'server': 'AmazonEC2'}, | |
'HTTPStatusCode': 200, | |
'RequestId': '476bc5d5-62c1-4fd1-9b05-48b4818a53f4', | |
'RetryAttempts': 0}} | |
Describing an older deregistered image | |
ClientError("An error occurred (InvalidAMIID.NotFound) when calling the DescribeImages operation: The image id '[ami-0f469065fa8e02462]' does not exist") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment