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