3
# Copyright 2009 Canonical Ltd. This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
15
'francis': 559320013529}
17
_image_match = re.compile(
18
r'launchpad-ec2test(\d+)/image.manifest.xml$').match
20
if __name__ == '__main__':
21
if len(sys.argv) == 1:
22
owner = os.environ['USER']
23
elif len(sys.argv) == 2:
26
raise RuntimeError('Too many arguments')
31
# Get the AWS identifier and secret identifier.
32
aws_id = os.path.join(os.environ['HOME'], '.ec2', 'aws_id')
33
if not os.path.exists(aws_id):
35
"Please put your aws access key identifier and secret access "
36
"key identifier in %s. (On two lines).\n" % (aws_id,))
37
aws_file = open(aws_id, 'r')
39
identifier = aws_file.readline().strip()
40
secret = aws_file.readline().strip()
43
# Make the EC2 connection.
44
conn = boto.connect_ec2(identifier, secret)
47
for image in conn.get_all_images(owners=owners.values()):
48
match = _image_match(image.location)
50
val = int(match.group(1))
54
images[val].append(image)
55
images = images.items()
58
last, recent = images[-2:]
59
for tmp in (last, recent):
62
'more than one image of value %d found: %r' % tmp)
65
perms = last.get_launch_permissions()
66
perms['user_ids'].extend(owners.values())
67
recent.set_launch_permissions(**perms)
69
pprint.pprint(recent.get_launch_permissions())