starcluster.commands.s3image

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

# Source Code for Module starcluster.commands.s3image

     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 CmdS3Image(InstanceCompleter):
    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
    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              "-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
    50 -    def cancel_command(self, signum, frame):
    51          raise exception.CancelledS3ImageCreation(self.bucket, self.image_name)
    52
    53 -    def execute(self, args):
    54          if len(args) != 3:
    55              self.parser.error(
    56                  'you must specify an instance-id, image name, and bucket')
    57          bucket = None
    58          instanceid, image_name, bucket = args
    59          self.bucket = bucket
    60          self.image_name = image_name
    61          i = self.ec2.get_instance(instanceid)
    62          key_location = self.cfg.get_key(i.key_name).get('key_location')
    63          aws_user_id = self.cfg.aws.get('aws_user_id')
    64          ec2_cert = self.cfg.aws.get('ec2_cert')
    65          ec2_private_key = self.cfg.aws.get('ec2_private_key')
    66          self.catch_ctrl_c()
    67          ami_id = self.ec2.create_s3_image(instanceid, key_location,
    68                                            aws_user_id, ec2_cert,
    69                                            ec2_private_key, bucket,
    70                                            image_name=image_name,
    71                                            **self.specified_options_dict)
    72          log.info("Your new AMI id is: %s" % ami_id)
    73