starcluster.commands.ebsimage

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

# Source Code for Module starcluster.commands.ebsimage

     1  #!/usr/bin/env python
     2
     3  import time
     4
     5  from starcluster import exception
     6  from starcluster.logger import log
     7
     8  from completers import InstanceCompleter
     9
    10
    11 -class CmdEbsImage(InstanceCompleter):
    12      """
    13      ebsimage [options] <instance-id> <image_name>
    14
    15      Create a new EBS image (AMI) from a running EC2 instance
    16
    17      Example:
    18
    19          $ starcluster ebsimage i-999999 my-new-image-ebs
    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 = ['ebsimage', 'eimg']
    26
    27      image_name = None
    28      is_ebs_backed = None
    29
    30 -    def addopts(self, parser):
    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              "-D", "--snapshot-description", dest="snapshot_description",
    38              action="store", type="string",
    39              default="Snapshot created @ %s" % time.strftime("%Y%m%d%H%M"),
    40              help="short description for new EBS snapshot")
    41          parser.add_option(
    42              "-k", "--kernel-id", dest="kernel_id", action="store",
    43              type="string", default=None,
    44              help="kernel id for the new AMI")
    45          parser.add_option(
    46              "-r", "--ramdisk-id", dest="ramdisk_id", action="store",
    47              type="string", default=None,
    48              help="ramdisk id for the new AMI")
    49          parser.add_option(
    50              "-s", "--root-volume-size", dest="root_vol_size", type="int",
    51              action="callback", default=15, callback=self._positive_int,
    52              help="size of root volume (only used when creating an " + \
    53              "EBS image from an S3 instance)")
    54
    55 -    def cancel_command(self, signum, frame):
    56          raise exception.CancelledEBSImageCreation(self.image_name,
    57                                                    self.is_ebs_backed)
    58
    59 -    def execute(self, args):
    60          if len(args) != 2:
    61              self.parser.error(
    62                  'you must specify an instance-id and image name')
    63          instanceid, image_name = args
    64          self.image_name = image_name
    65          i = self.ec2.get_instance(instanceid)
    66          self.is_ebs_backed = (i.root_device_type == "ebs")
    67          key_location = self.cfg.get_key(i.key_name).get('key_location')
    68          self.catch_ctrl_c()
    69          ami_id = self.ec2.create_ebs_image(instanceid, key_location,
    70                                             image_name,
    71                                             **self.specified_options_dict)
    72          log.info("Your new AMI id is: %s" % ami_id)
    73