starcluster.commands.createkey

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

# Source Code for Module starcluster.commands.createkey

     1  #!/usr/bin/env python
     2
     3  from starcluster.logger import log
     4
     5  from base import CmdBase
     6
     7
     8 -class CmdCreateKey(CmdBase):
     9      """
    10      createkey [options] <name>
    11
    12      Create a new Amazon EC2 keypair
    13      """
    14      names = ['createkey', 'ck']
    15
    16 -    def addopts(self, parser):
    17          parser.add_option("-o", "--output-file", dest="output_file",
    18                            action="store", type="string", default=None,
    19                            help="Save the new keypair to a file")
    20          #parser.add_option("-a","--add-to-config", dest="add_to_config",
    21              #action="store_true", default=False,
    22              #help="add new keypair to StarCluster config")
    23
    24 -    def execute(self, args):
    25          if len(args) != 1:
    26              self.parser.error("please provide a key name")
    27          name = args[0]
    28          ofile = self.opts.output_file
    29          kp = self.ec2.create_keypair(name, output_file=ofile)
    30          log.info("Successfully created keypair: %s" % name)
    31          log.info("fingerprint: %s" % kp.fingerprint)
    32          log.info("contents: \n%s" % kp.material)
    33          if ofile:
    34              log.info("keypair written to %s" % ofile)
    35