Package starcluster :: Package commands :: Module ebsimage
[hide private]
[frames] | no frames]

Source Code for Module starcluster.commands.ebsimage

 1  import time 
 2   
 3  from starcluster import exception 
 4  from starcluster.logger import log 
 5   
 6  from completers import InstanceCompleter 
 7   
 8   
9 -class CmdEbsImage(InstanceCompleter):
10 """ 11 ebsimage [options] <instance-id> <image_name> 12 13 Create a new EBS image (AMI) from a running EC2 instance 14 15 Example: 16 17 $ starcluster ebsimage i-999999 my-new-image-ebs 18 19 NOTE: It should now be safe to create an image from an instance launched by 20 StarCluster. If you have issues please submit a bug report to the mailing 21 list. 22 """ 23 names = ['ebsimage', 'eimg'] 24 25 image_name = None 26 is_ebs_backed = None 27
28 - def addopts(self, parser):
29 parser.add_option( 30 "-d", "--description", dest="description", action="store", 31 type="string", 32 default="Image created @ %s" % time.strftime("%Y%m%d%H%M"), 33 help="short description of this AMI") 34 parser.add_option( 35 "-D", "--snapshot-description", dest="snapshot_description", 36 action="store", type="string", 37 default="Snapshot created @ %s" % time.strftime("%Y%m%d%H%M"), 38 help="short description for new EBS snapshot") 39 parser.add_option( 40 "-k", "--kernel-id", dest="kernel_id", action="store", 41 type="string", default=None, 42 help="kernel id for the new AMI") 43 parser.add_option( 44 "-r", "--ramdisk-id", dest="ramdisk_id", action="store", 45 type="string", default=None, 46 help="ramdisk id for the new AMI") 47 parser.add_option( 48 "-s", "--root-volume-size", dest="root_vol_size", type="int", 49 action="callback", default=15, callback=self._positive_int, 50 help="size of root volume (only used when creating an " 51 "EBS image from an S3 instance)")
52
53 - def cancel_command(self, signum, frame):
56
57 - def execute(self, args):
58 if len(args) != 2: 59 self.parser.error( 60 'you must specify an instance-id and image name') 61 instanceid, image_name = args 62 self.image_name = image_name 63 i = self.ec2.get_instance(instanceid) 64 self.is_ebs_backed = (i.root_device_type == "ebs") 65 key_location = self.cfg.get_key(i.key_name).get('key_location') 66 self.catch_ctrl_c() 67 ami_id = self.ec2.create_ebs_image(instanceid, key_location, 68 image_name, 69 **self.specified_options_dict) 70 log.info("Your new AMI id is: %s" % ami_id)
71