Implement gnt-cluster master-ping
[ganeti-local] / scripts / gnt-instance
index c0230d9..ec19602 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"
@@ -227,8 +228,9 @@ def GenericManyOps(operation, fn):
     for name in inames:
       op = fn(name, opts)
       jex.QueueJob(name, op)
-    jex.WaitOrShow(not opts.submit_only)
-    return 0
+    results = jex.WaitOrShow(not opts.submit_only)
+    rcode = compat.all(row[0] for row in results)
+    return int(not rcode)
   return realfn
 
 
@@ -257,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",
@@ -315,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"
@@ -387,6 +393,7 @@ def BatchCreate(opts, args):
                     "hypervisor": None,
                     "hvparams": {},
                     "file_storage_dir": None,
+                    "force_variant": False,
                     "file_driver": 'loop'}
 
   def _PopulateWithDefaults(spec):
@@ -478,7 +485,7 @@ def BatchCreate(opts, args):
                                   disk_template=specs['template'],
                                   mode=constants.INSTANCE_CREATE,
                                   os_type=specs['os'],
-                                  force_variant=opts.force_variant,
+                                  force_variant=specs["force_variant"],
                                   pnode=specs['primary_node'],
                                   snode=specs['secondary_node'],
                                   nics=tmp_nics,
@@ -620,10 +627,19 @@ def RenameInstance(opts, args):
   @return: the desired exit code
 
   """
+  if not opts.name_check:
+    if not AskUser("As you disabled the check of the DNS entry, please verify"
+                   " that '%s' is a FQDN. Continue?" % args[1]):
+      return 1
+
   op = opcodes.OpRenameInstance(instance_name=args[0],
                                 new_name=args[1],
-                                ignore_ip=not opts.ip_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
 
 
@@ -884,7 +900,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
@@ -1187,11 +1213,11 @@ def ShowInstanceConfig(opts, args):
     if vnc_bind_address:
       port = instance["network_port"]
       display = int(port) - constants.VNC_BASE_PORT
-      if display > 0 and vnc_bind_address == constants.BIND_ADDRESS_GLOBAL:
+      if display > 0 and vnc_bind_address == constants.IP4_ADDRESS_ANY:
         vnc_console_port = "%s:%s (display %s)" % (instance["pnode"],
                                                    port,
                                                    display)
-      elif display > 0 and utils.IsValidIP(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))
@@ -1396,7 +1422,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': (
@@ -1415,8 +1441,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,"
@@ -1439,7 +1466,7 @@ commands = {
   'rename': (
     RenameInstance,
     [ArgInstance(min=1, max=1), ArgHost(min=1, max=1)],
-    [NOIPCHECK_OPT, SUBMIT_OPT],
+    [NOIPCHECK_OPT, NONAMECHECK_OPT, SUBMIT_OPT],
     "<instance> <new_name>", "Rename the instance"),
   'replace-disks': (
     ReplaceDisks, ARGS_ONE_INSTANCE,