-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcopy_images_region.py
67 lines (43 loc) · 1.39 KB
/
copy_images_region.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import authenticate
import os
import time
target_region="us-east-1"
error_images=[]
trial_run=True
# list images
def list_images(ec2_client,user_id):
owner_field="OwnerId"
public_field="Public"
images_field="Images"
image_id_field="ImageId"
image_name_field="Name"
tags_field="Tags"
type_field="VirtualizationType"
required_fields = [image_id_field, image_name_field, tags_field, type_field]
images_info = []
try:
images = ec2_client.describe_images(ImageIds=[], ExecutableUsers=[],DryRun=False)
if images_field not in images:
raise Exception("Image field not found. Response is malformed")
for image in images[images_field]:
# dont care if the image is already pubic, it can be moved easily in that case
if owner_field in image and image[owner_field] == "143148225560":
image_info={}
for field in required_fields:
if field in image:
image_info[field] = image[field]
image_info["image_description"] = get_image_description(ec2_client, image_info[image_id_field])
images_info.append(image_info)
return images_info
except Exception as e:
print("Unable to list EC2 images on client\nError: " + str(e))
exit(1)
#copy image to region
def copy_image():
# copy all images
def copy_all_images():
# main method
if __name__=="__main__":
# get list of images in region
# run copy operation to new region
# once copied, need to tag them again