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

Source Code for Module starcluster.commands.resizevolume

 1  #!/usr/bin/env python 
 2  from starcluster import node 
 3  from starcluster import volume 
 4  from starcluster import static 
 5   
 6  from createvolume import CmdCreateVolume 
 7   
 8   
9 -class CmdResizeVolume(CmdCreateVolume):
10 """ 11 resizevolume [options] <volume_id> <volume_size> 12 13 Resize an existing EBS volume 14 15 NOTE: The EBS volume must either be unpartitioned or contain only a single 16 partition. Any other configuration will be aborted. 17 """ 18 19 names = ['resizevolume', 'res'] 20
21 - def addopts(self, parser):
22 parser.add_option( 23 "-z", "--zone", dest="dest_zone", 24 action="store", type="string", default=None, 25 help="Create the resized volume in a different zone than the " + \ 26 "original volume (must be within the same region)") 27 parser.add_option( 28 "-k", "--keypair", dest="keypair", 29 action="store", type="string", default=None, 30 help="The keypair to use when launching host instance " + \ 31 "(must be defined in the config)") 32 parser.add_option( 33 "-H", "--host-instance", dest="host_instance", 34 action="store", type="string", default=None, 35 help="Use existing instance as volume host rather than " + \ 36 "launching a new host") 37 parser.add_option( 38 "-d", "--detach-volume", dest="detach_vol", 39 action="store_true", default=False, 40 help="Detach new volume from host instance after creation") 41 parser.add_option( 42 "-s", "--shutdown-volume-host", dest="shutdown_instance", 43 action="store_true", default=False, 44 help="Shutdown host instance after creating volume") 45 parser.add_option( 46 "-i", "--image-id", dest="image_id", 47 action="store", type="string", default=None, 48 help="The AMI to use when launching volume host instance") 49 parser.add_option( 50 "-I", "--instance-type", dest="instance_type", 51 action="store", type="choice", default="m1.small", 52 choices=static.INSTANCE_TYPES.keys(), 53 help="The instance type to use when launching volume " + \ 54 "host instance") 55 parser.add_option( 56 "-r", "--resizefs-cmd", dest="resizefs_cmd", 57 action="store", type="string", default="resize2fs", 58 help="Specify alternate resizefs command to use when " + \ 59 "formatting volume (default: resize2fs)")
60
61 - def execute(self, args):
62 if len(args) != 2: 63 self.parser.error( 64 "you must specify a volume id and a size (in GB)") 65 volid, size = args 66 size = self._get_size_arg(size) 67 vol = self.ec2.get_volume(volid) 68 zone = vol.zone 69 if self.opts.dest_zone: 70 zone = self.ec2.get_zone(self.opts.dest_zone).name 71 key = self.opts.keypair 72 host_instance = None 73 if self.opts.host_instance: 74 host_instance = self.ec2.get_instance(self.opts.host_instance) 75 key = host_instance.key_name 76 keypair, key_location = self._load_keypair(key) 77 if host_instance: 78 host_instance = node.Node(host_instance, key_location, 79 alias="volumecreator_host") 80 kwargs = self.specified_options_dict 81 kwargs.update(dict(keypair=keypair, key_location=key_location, 82 host_instance=host_instance)) 83 vc = volume.VolumeCreator(self.ec2, **kwargs) 84 if host_instance: 85 vc._validate_host_instance(host_instance, zone) 86 self.catch_ctrl_c() 87 new_volid = vc.resize(vol, size, dest_zone=self.opts.dest_zone) 88 if new_volid: 89 self.log.info( 90 "Volume %s was successfully resized to %sGB" % (volid, size)) 91 self.log.info("New volume id is: %s" % new_volid) 92 else: 93 self.log.error("failed to resize volume %s" % volid)
94