1 import sys
2 import time
3 import warnings
4
5 from starcluster import exception
6 from starcluster.logger import log
7
8 from completers import InstanceCompleter
9
10
12 """
13 s3image [options] <instance-id> <image_name> [<bucket>]
14
15 Create a new instance-store (S3) AMI from a running EC2 instance
16
17 Example:
18
19 $ starcluster s3image i-999999 my-new-image mybucket
20
21 NOTE: It should now be safe to create an image from an instance launched by
22 StarCluster. If you have issues please submit a bug report to the mailing
23 list.
24 """
25 names = ['s3image', 'simg', 'createimage']
26
27 bucket = None
28 image_name = None
29
31 parser.add_option(
32 "-d", "--description", dest="description", action="store",
33 type="string",
34 default="Image created @ %s" % time.strftime("%Y%m%d%H%M"),
35 help="short description of this AMI")
36 parser.add_option(
37 "-k", "--kernel-id", dest="kernel_id", action="store",
38 type="string", default=None,
39 help="kernel id for the new AMI")
40 parser.add_option(
41 "-R", "--ramdisk-id", dest="ramdisk_id", action="store",
42 type="string", default=None,
43 help="ramdisk id for the new AMI")
44 parser.add_option(
45 "-r", "--remove-image-files", dest="remove_image_files",
46 action="store_true", default=False,
47 help="Remove generated image files on the "
48 "instance after registering (for S3 AMIs)")
49
52
54 if "createimage" in sys.argv:
55 warnings.warn("createimage is deprecated and will go away in the "
56 "next release. please use the s3image/ebsimage "
57 "commands instead", DeprecationWarning)
58 if len(args) != 3:
59 self.parser.error(
60 'you must specify an instance-id, image name, and bucket')
61 bucket = None
62 instanceid, image_name, bucket = args
63 self.bucket = bucket
64 self.image_name = image_name
65 i = self.ec2.get_instance(instanceid)
66 key_location = self.cfg.get_key(i.key_name).get('key_location')
67 aws_user_id = self.cfg.aws.get('aws_user_id')
68 ec2_cert = self.cfg.aws.get('ec2_cert')
69 ec2_private_key = self.cfg.aws.get('ec2_private_key')
70 self.catch_ctrl_c()
71 ami_id = self.ec2.create_s3_image(instanceid, key_location,
72 aws_user_id, ec2_cert,
73 ec2_private_key, bucket,
74 image_name=image_name,
75 **self.specified_options_dict)
76 log.info("Your new AMI id is: %s" % ami_id)
77