If we had any errors in setup in one of the hosts, exit with non-zero
[ganeti-local] / tools / move-instance
index 05b3b24..f007431 100755 (executable)
@@ -148,18 +148,18 @@ class RapiClientFactory:
     self.src_cluster_name = src_cluster_name
     self.dest_cluster_name = dest_cluster_name
 
+    # TODO: Implement timeouts for RAPI connections
     # TODO: Support for using system default paths for verifying SSL certificate
-    # (already implemented in CertAuthorityVerify)
     logging.debug("Using '%s' as source CA", options.src_ca_file)
-    src_ssl_config = rapi.client.CertAuthorityVerify(cafile=options.src_ca_file)
+    src_curl_config = rapi.client.GenericCurlConfig(cafile=options.src_ca_file)
 
     if options.dest_ca_file:
       logging.debug("Using '%s' as destination CA", options.dest_ca_file)
-      dest_ssl_config = \
-        rapi.client.CertAuthorityVerify(cafile=options.dest_ca_file)
+      dest_curl_config = \
+        rapi.client.GenericCurlConfig(cafile=options.dest_ca_file)
     else:
       logging.debug("Using source CA for destination")
-      dest_ssl_config = src_ssl_config
+      dest_curl_config = src_curl_config
 
     logging.debug("Source RAPI server is %s:%s",
                   src_cluster_name, options.src_rapi_port)
@@ -182,7 +182,7 @@ class RapiClientFactory:
     self.GetSourceClient = lambda: \
       rapi.client.GanetiRapiClient(src_cluster_name,
                                    port=options.src_rapi_port,
-                                   config_ssl_verification=src_ssl_config,
+                                   curl_config_fn=src_curl_config,
                                    username=src_username,
                                    password=src_password)
 
@@ -212,7 +212,7 @@ class RapiClientFactory:
     self.GetDestClient = lambda: \
       rapi.client.GanetiRapiClient(dest_cluster_name,
                                    port=dest_rapi_port,
-                                   config_ssl_verification=dest_ssl_config,
+                                   curl_config_fn=dest_curl_config,
                                    username=dest_username,
                                    password=dest_password)
 
@@ -250,7 +250,7 @@ class MoveJobPollReportCb(cli.JobPollReportCbBase):
       return
 
     logging.info("[%s] %s", time.ctime(utils.MergeTime(timestamp)),
-                 utils.SafeEncode(log_msg))
+                 cli.FormatLogMessage(log_type, log_msg))
 
   def ReportNotChanged(self, job_id, status):
     """Called if a job hasn't changed in a while.
@@ -437,7 +437,7 @@ class MoveDestExecutor(object):
       mrt.dest_to_source.release()
 
   @staticmethod
-  def _CreateInstance(cl, name, snode, pnode, iallocator, instance, expinfo):
+  def _CreateInstance(cl, name, pnode, snode, iallocator, instance, expinfo):
     """Starts the instance creation in remote import mode.
 
     @type cl: L{rapi.client.GanetiRapiClient}
@@ -460,15 +460,15 @@ class MoveDestExecutor(object):
     disk_template = instance["disk_template"]
 
     disks = [{
-      "size": i["size"],
-      "mode": i["mode"],
+      constants.IDISK_SIZE: i["size"],
+      constants.IDISK_MODE: i["mode"],
       } for i in instance["disks"]]
 
     nics = [{
-      "ip": ip,
-      "mac": mac,
-      "mode": mode,
-      "link": link,
+      constants.INIC_IP: ip,
+      constants.INIC_MAC: mac,
+      constants.INIC_MODE: mode,
+      constants.INIC_LINK: link,
       } for ip, mac, mode, link in instance["nics"]]
 
     # TODO: Should this be the actual up/down status? (run_state)
@@ -490,7 +490,8 @@ class MoveDestExecutor(object):
                              source_x509_ca=expinfo["x509_ca"],
                              source_instance_name=instance["name"],
                              beparams=instance["be_instance"],
-                             hvparams=instance["hv_instance"])
+                             hvparams=instance["hv_instance"],
+                             osparams=instance["os_instance"])
 
 
 class MoveSourceExecutor(object):
@@ -771,6 +772,7 @@ def CheckOptions(parser, options, args):
   return (src_cluster_name, dest_cluster_name, instance_names)
 
 
+@rapi.client.UsesRapiClient
 def main():
   """Main routine.
 
@@ -818,7 +820,7 @@ def main():
   try:
     # Add instance moves to workerpool
     for move in moves:
-      wp.AddTask(rapi_factory, move)
+      wp.AddTask((rapi_factory, move))
 
     # Wait for all moves to finish
     wp.Quiesce()