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