-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Copy tested AMI to more regions
Closes: #328
- Loading branch information
Showing
2 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/python3 | ||
# Copy an AMI to multiple regions, generating an "AMI JSON" | ||
# file matching the Container Linux schema: | ||
# https://alpha.release.core-os.net/amd64-usr/current/coreos_production_ami_all.json | ||
# Note this assumes the images are HVM. | ||
|
||
import os,sys,argparse,subprocess,io,time,re,multiprocessing | ||
import tempfile, json | ||
|
||
def fatal(msg): | ||
print('error: {}'.format(msg), file=sys.stderr) | ||
raise SystemExit(1) | ||
|
||
def csv_list(string): | ||
return string.split(',') | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--source-region", help="Source region", | ||
action='store', required=True) | ||
parser.add_argument("--source-image-id", help="Source AMI", | ||
action='store', required=True) | ||
parser.add_argument("--name", help="AMI name", | ||
action='store', required=True) | ||
parser.add_argument("--regions", help="Name", | ||
action='store', required=True, | ||
type=csv_list) | ||
parser.add_argument("--out", help="Store output in FILE", | ||
action='store', metavar='FILE', | ||
required=True) | ||
|
||
args = parser.parse_args() | ||
|
||
amis = [] | ||
|
||
for region in args.regions: | ||
print("Uploading to: {}".format(region)) | ||
res = json.loads(subprocess.check_output(['aws', '--output', 'json', 'ec2', 'copy-image', | ||
'--source-region', args.source_region, | ||
'--source-image-id', args.source_image_id, | ||
'--name', args.name, | ||
'--region', region])) | ||
iid = res['ImageId'] | ||
print("Complete, ImageId={}".format(iid)) | ||
amis.append({'name': region, | ||
'hvm': iid}) | ||
|
||
amis.sort(key=lambda x: x['name']) | ||
|
||
with open(args.out, 'w') as f: | ||
json.dump({'amis': amis}, f) |