Sort the instance names in batcher
[ganeti-local] / scripts / gnt-instance
index f1063d8..80afc41 100755 (executable)
@@ -375,13 +375,12 @@ def BatchCreate(opts, args):
   in the form::
 
     {"instance-name":{
-      "disk_size": 25,
-      "swap_size": 1024,
+      "disk_size": [20480],
       "template": "drbd",
       "backend": {
         "memory": 512,
         "vcpus": 1 },
-      "os": "etch-image",
+      "os": "debootstrap",
       "primary_node": "firstnode",
       "secondary_node": "secondnode",
       "iallocator": "dumb"}
@@ -397,8 +396,7 @@ def BatchCreate(opts, args):
   @return: the desired exit code
 
   """
-  _DEFAULT_SPECS = {"disk_size": 20 * 1024,
-                    "swap_size": 4 * 1024,
+  _DEFAULT_SPECS = {"disk_size": [20 * 1024],
                     "backend": {},
                     "iallocator": None,
                     "primary_node": None,
@@ -449,7 +447,9 @@ def BatchCreate(opts, args):
   # Iterate over the instances and do:
   #  * Populate the specs with default value
   #  * Validate the instance specs
-  for (name, specs) in instance_data.iteritems():
+  i_names = utils.NiceSort(instance_data.keys())
+  for name in i_names:
+    specs = instance_data[name]
     specs = _PopulateWithDefaults(specs)
     _Validate(specs)
 
@@ -458,19 +458,29 @@ def BatchCreate(opts, args):
     if specs['hypervisor']:
       hypervisor, hvparams = specs['hypervisor'].iteritems()
 
+    disks = []
+    for elem in specs['disk_size']:
+      try:
+        size = utils.ParseUnit(elem)
+      except ValueError, err:
+        raise errors.OpPrereqError("Invalid disk size '%s' for"
+                                   " instance %s: %s" %
+                                   (elem, name, err))
+      disks.append({"size": size})
+
+    nic0 = {'ip': specs['ip'], 'bridge': specs['bridge'], 'mac': specs['mac']}
+
     op = opcodes.OpCreateInstance(instance_name=name,
-                                  disk_size=specs['disk_size'],
-                                  swap_size=specs['swap_size'],
+                                  disks=disks,
                                   disk_template=specs['template'],
                                   mode=constants.INSTANCE_CREATE,
                                   os_type=specs['os'],
                                   pnode=specs['primary_node'],
                                   snode=specs['secondary_node'],
-                                  ip=specs['ip'], bridge=specs['bridge'],
+                                  nics=[nic0],
                                   start=specs['start'],
                                   ip_check=specs['ip_check'],
                                   wait_for_sync=True,
-                                  mac=specs['mac'],
                                   iallocator=specs['iallocator'],
                                   hypervisor=hypervisor,
                                   hvparams=hvparams,
@@ -826,11 +836,11 @@ def MigrateInstance(opts, args):
 
   The migrate is done without shutdown.
 
-  Args:
-    opts - class with options as members
-    args - list with a single element, the instance name
-  Opts used:
-    force - whether to migrate without asking questions.
+  @param opts: the command line options selected by the user
+  @type args: list
+  @param args: should contain only one element, the instance name
+  @rtype: int
+  @return: the desired exit code
 
   """
   instance_name = args[0]
@@ -1268,7 +1278,7 @@ add_opts = [
               metavar="<DIR>"),
   make_option("--file-driver", dest="file_driver", help="Driver to use"
               " for image files", default="loop", metavar="<DRIVER>"),
-  make_option("--iallocator", metavar="<NAME>",
+  make_option("-I", "--iallocator", metavar="<NAME>",
               help="Select nodes for the instance automatically using the"
               " <NAME> iallocator plugin", default=None, type="string"),
   ikv_option("-H", "--hypervisor", dest="hypervisor",