gnt-debug: Extend job queue tests
[ganeti-local] / scripts / gnt-instance
index 475514e..75ecd63 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 #
 
-# Copyright (C) 2006, 2007 Google Inc.
+# Copyright (C) 2006, 2007, 2008, 2009, 2010 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -37,6 +37,7 @@ from ganeti import constants
 from ganeti import compat
 from ganeti import utils
 from ganeti import errors
+from ganeti import netutils
 
 
 _SHUTDOWN_CLUSTER = "cluster"
@@ -258,6 +259,7 @@ def ListInstances(opts, args):
       "snodes": "Secondary_Nodes", "admin_state": "Autostart",
       "oper_state": "Running",
       "oper_ram": "Memory", "disk_template": "Disk_template",
+      "oper_vcpus": "VCPUs",
       "ip": "IP_address", "mac": "MAC_address",
       "nic_mode": "NIC_Mode", "nic_link": "NIC_Link",
       "bridge": "Bridge",
@@ -316,6 +318,9 @@ def ListInstances(opts, args):
       elif field == "oper_ram":
         if val is None:
           val = "(node down)"
+      elif field == "oper_vcpus":
+        if val is None:
+          val = "(node down)"
       elif field == "sda_size" or field == "sdb_size":
         if val is None:
           val = "N/A"
@@ -554,16 +559,17 @@ def ReinstallInstance(opts, args):
   else:
     os_name = opts.os
 
-  # third, get confirmation: multi-reinstall requires --force-multi
-  # *and* --force, single-reinstall just --force
+  # third, get confirmation: multi-reinstall requires --force-multi,
+  # single-reinstall either --force or --force-multi (--force-multi is
+  # a stronger --force)
   multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1
   if multi_on:
     warn_msg = "Note: this will remove *all* data for the below instances!\n"
-    if not ((opts.force_multi and opts.force) or
+    if not (opts.force_multi or
             _ConfirmOperation(inames, "reinstall", extra=warn_msg)):
       return 1
   else:
-    if not opts.force:
+    if not (opts.force or opts.force_multi):
       usertext = ("This will reinstall the instance %s and remove"
                   " all data. Continue?") % inames[0]
       if not AskUser(usertext):
@@ -629,9 +635,12 @@ def RenameInstance(opts, args):
 
   op = opcodes.OpRenameInstance(instance_name=args[0],
                                 new_name=args[1],
-                                ignore_ip=not opts.ip_check,
-                                check_name=opts.name_check)
-  SubmitOrSend(op, opts)
+                                ip_check=opts.ip_check,
+                                name_check=opts.name_check)
+  result = SubmitOrSend(op, opts)
+
+  ToStdout("Instance '%s' renamed to '%s'", args[0], result)
+
   return 0
 
 
@@ -892,7 +901,17 @@ def MigrateInstance(opts, args):
     if not AskUser(usertext):
       return 1
 
-  op = opcodes.OpMigrateInstance(instance_name=instance_name, live=opts.live,
+  # this should be removed once --non-live is deprecated
+  if not opts.live and opts.migration_mode is not None:
+    raise errors.OpPrereqError("Only one of the --non-live and "
+                               "--migration-mode options can be passed",
+                               errors.ECODE_INVAL)
+  if not opts.live: # --non-live passed
+    mode = constants.HT_MIGRATION_NONLIVE
+  else:
+    mode = opts.migration_mode
+
+  op = opcodes.OpMigrateInstance(instance_name=instance_name, mode=mode,
                                  cleanup=opts.cleanup)
   SubmitOpCode(op, cl=cl, opts=opts)
   return 0
@@ -1199,7 +1218,7 @@ def ShowInstanceConfig(opts, args):
         vnc_console_port = "%s:%s (display %s)" % (instance["pnode"],
                                                    port,
                                                    display)
-      elif display > 0 and utils.IsValidIP4(vnc_bind_address):
+      elif display > 0 and netutils.IsValidIP4(vnc_bind_address):
         vnc_console_port = ("%s:%s (node %s) (display %s)" %
                              (vnc_bind_address, port,
                               instance["pnode"], display))
@@ -1404,7 +1423,7 @@ commands = {
     " using the remote mirror (only for instances of type drbd)"),
   'migrate': (
     MigrateInstance, ARGS_ONE_INSTANCE,
-    [FORCE_OPT, NONLIVE_OPT, CLEANUP_OPT],
+    [FORCE_OPT, NONLIVE_OPT, MIGRATION_MODE_OPT, CLEANUP_OPT],
     "[-f] <instance>", "Migrate instance to its secondary node"
     " (only for instances of type drbd)"),
   'move': (
@@ -1423,8 +1442,9 @@ commands = {
     "[<instance>...]",
     "Lists the instances and their status. The available fields are"
     " (see the man page for details): status, oper_state, oper_ram,"
-    " name, os, pnode, snodes, admin_state, admin_ram, disk_template,"
-    " ip, mac, nic_mode, nic_link, sda_size, sdb_size, vcpus, serial_no,"
+    " oper_vcpus, name, os, pnode, snodes, admin_state, admin_ram,"
+    " disk_template, ip, mac, nic_mode, nic_link, sda_size, sdb_size,"
+    " vcpus, serial_no,"
     " nic.count, nic.mac/N, nic.ip/N, nic.mode/N, nic.link/N,"
     " nic.macs, nic.ips, nic.modes, nic.links,"
     " disk.count, disk.size/N, disk.sizes,"