diff options
author | Simon Rettberg | 2024-04-12 14:00:15 +0200 |
---|---|---|
committer | Simon Rettberg | 2024-04-12 14:00:15 +0200 |
commit | 98dc341428e247141f120d05fac48c4e144a4c0f (patch) | |
tree | 3ebacb37927e338383ac64c2e20eb0b2f820cb85 /contrib/cloud/aws-import | |
parent | Merge branch 'master' into openslx (diff) | |
parent | Merge branch 'ipxe:master' into aqc1xx (diff) | |
download | ipxe-98dc341428e247141f120d05fac48c4e144a4c0f.tar.gz ipxe-98dc341428e247141f120d05fac48c4e144a4c0f.tar.xz ipxe-98dc341428e247141f120d05fac48c4e144a4c0f.zip |
Merge branch 'aqc1xx' into openslx
Diffstat (limited to 'contrib/cloud/aws-import')
-rwxr-xr-x | contrib/cloud/aws-import | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/contrib/cloud/aws-import b/contrib/cloud/aws-import index b9a350f6..ace00587 100755 --- a/contrib/cloud/aws-import +++ b/contrib/cloud/aws-import @@ -46,11 +46,19 @@ def create_snapshot(region, description, image): return snapshot_id -def import_image(region, name, architecture, image, public): +def import_image(region, name, architecture, image, public, overwrite): """Import an AMI image""" client = boto3.client('ec2', region_name=region) resource = boto3.resource('ec2', region_name=region) description = '%s (%s)' % (name, architecture) + images = client.describe_images(Filters=[{'Name': 'name', + 'Values': [description]}]) + if overwrite and images['Images']: + images = images['Images'][0] + image_id = images['ImageId'] + snapshot_id = images['BlockDeviceMappings'][0]['Ebs']['SnapshotId'] + resource.Image(image_id).deregister() + resource.Snapshot(snapshot_id).delete() snapshot_id = create_snapshot(region=region, description=description, image=image) client.get_waiter('snapshot_completed').wait(SnapshotIds=[snapshot_id]) @@ -88,6 +96,8 @@ parser.add_argument('--name', '-n', help="Image name") parser.add_argument('--public', '-p', action='store_true', help="Make image public") +parser.add_argument('--overwrite', action='store_true', + help="Overwrite any existing image with same name") parser.add_argument('--region', '-r', action='append', help="AWS region(s)") parser.add_argument('--wiki', '-w', metavar='FILE', @@ -115,7 +125,8 @@ with ThreadPoolExecutor(max_workers=len(imports)) as executor: name=args.name, architecture=architectures[image], image=image, - public=args.public): (region, image) + public=args.public, + overwrite=args.overwrite): (region, image) for region, image in imports} results = {futures[future]: future.result() for future in as_completed(futures)} |