Last active
December 14, 2015 06:59
-
-
Save siroken3/5047587 to your computer and use it in GitHub Desktop.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UserProvidedkernels.html にある AKIを取得するための botocore スクリプト
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
| def get_aki(region, architecture="x86_64", partitioned=True): | |
| import botocore.session | |
| session = botocore.session.get_session() | |
| ec2 = session.get_service('ec2') | |
| op = ec2.get_operation('DescribeImages') | |
| code, data = op.call( | |
| ec2.get_endpoint(region), | |
| filters=[ | |
| {"name":"owner-alias", "values":["amazon"]}, | |
| {"name":"image-type", "values":["kernel"]}, | |
| {"name":"architecture", "values":[architecture]} | |
| ] | |
| ) | |
| images = data['imagesSet'] | |
| suffix = '-hd00_' if partitioned else '-hd0_' | |
| last_one_location = sorted([im['imageLocation'] for im in images if im['imageLocation'].find('pv-grub{suffix}'.format(suffix=suffix)) != -1])[-1:][0] | |
| aki = [im['imageId'] for im in images if im['imageLocation'] == last_one_location][0] | |
| return aki |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment