#!/usr/bin/python
#
-# Copyright (C) 2010 Google Inc.
+# Copyright (C) 2010, 2011, 2012 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
"""
-# pylint: disable-msg=C0103
+# pylint: disable=C0103
# C0103: Invalid name move-instance
import os
from ganeti import compat
from ganeti import rapi
-import ganeti.rapi.client # pylint: disable-msg=W0611
+import ganeti.rapi.client # pylint: disable=W0611
import ganeti.rapi.client_utils
+from ganeti.rapi.client import UsesRapiClient
SRC_RAPI_PORT_OPT = \
disks = [{
constants.IDISK_SIZE: i["size"],
constants.IDISK_MODE: i["mode"],
+ constants.IDISK_NAME: str(i.get("name")),
} for i in instance["disks"]]
nics = [{
constants.INIC_MAC: mac,
constants.INIC_MODE: mode,
constants.INIC_LINK: link,
- } for ip, mac, mode, link in instance["nics"]]
+ constants.INIC_NETWORK: network,
+ constants.INIC_NAME: nic_name
+ } for nic_name, _, ip, mac, mode, link, network, _ in instance["nics"]]
if len(override_nics) > len(nics):
raise Error("Can not create new NICs")
logging.info("Retrieving instance information from source cluster")
instinfo = self._GetInstanceInfo(src_client, mrt.PollJob,
mrt.move.src_instance_name)
+ if instinfo["disk_template"] == constants.DT_FILE:
+ raise Error("Inter-cluster move of file-based instances is not"
+ " supported.")
logging.info("Preparing export on source cluster")
expinfo = self._PrepareExport(src_client, mrt.PollJob,
class MoveSourceWorker(workerpool.BaseWorker):
- def RunTask(self, rapi_factory, move): # pylint: disable-msg=W0221
+ def RunTask(self, rapi_factory, move): # pylint: disable=W0221
"""Executes an instance move.
@type rapi_factory: L{RapiClientFactory}
(mrt.src_error_message, mrt.dest_error_message))
else:
move.error_message = None
- except Exception, err: # pylint: disable-msg=W0703
+ except Exception, err: # pylint: disable=W0703
logging.exception("Caught unhandled exception")
move.error_message = str(err)
logging.info("Destination cluster RAPI version: %s", dest_client.GetVersion())
-def SetupLogging(options):
- """Setting up logging infrastructure.
-
- @param options: Parsed command line options
-
- """
- fmt = "%(asctime)s: %(threadName)s "
- if options.debug or options.verbose:
- fmt += "%(levelname)s "
- fmt += "%(message)s"
-
- formatter = logging.Formatter(fmt)
-
- stderr_handler = logging.StreamHandler()
- stderr_handler.setFormatter(formatter)
- if options.debug:
- stderr_handler.setLevel(logging.NOTSET)
- elif options.verbose:
- stderr_handler.setLevel(logging.INFO)
- else:
- stderr_handler.setLevel(logging.ERROR)
-
- root_logger = logging.getLogger("")
- root_logger.setLevel(logging.NOTSET)
- root_logger.addHandler(stderr_handler)
-
-
def ParseOptions():
"""Parses options passed to program.
return (src_cluster_name, dest_cluster_name, instance_names)
-@rapi.client.UsesRapiClient
+@UsesRapiClient
def main():
"""Main routine.
"""
(parser, options, args) = ParseOptions()
- SetupLogging(options)
+ utils.SetupToolLogging(options.debug, options.verbose, threadname=True)
(src_cluster_name, dest_cluster_name, instance_names) = \
CheckOptions(parser, options, args)