diff --git a/lib/backend.py b/lib/backend.py index fdb45c1eb0709a3d047a04eb63c06f020843b270..9184cf7c407a7f9323a96b9af16a425c5487c744 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -250,7 +250,7 @@ def GetNodeInfo(vgname): outputarray['vg_size'] = vginfo['vg_size'] outputarray['vg_free'] = vginfo['vg_free'] - hyper = hypervisor.GetHypervisor() + hyper = hypervisor.GetHypervisor(_GetConfig()) hyp_info = hyper.GetNodeInfo() if hyp_info is not None: outputarray.update(hyp_info) @@ -285,7 +285,7 @@ def VerifyNode(what): result = {} if 'hypervisor' in what: - result['hypervisor'] = hypervisor.GetHypervisor().Verify() + result['hypervisor'] = hypervisor.GetHypervisor(_GetConfig()).Verify() if 'filelist' in what: result['filelist'] = utils.FingerprintFiles(what['filelist']) @@ -425,7 +425,7 @@ def GetInstanceList(): """ try: - names = hypervisor.GetHypervisor().ListInstances() + names = hypervisor.GetHypervisor(_GetConfig()).ListInstances() except errors.HypervisorError, err: logging.exception("Error enumerating instances") raise @@ -449,7 +449,7 @@ def GetInstanceInfo(instance): """ output = {} - iinfo = hypervisor.GetHypervisor().GetInstanceInfo(instance) + iinfo = hypervisor.GetHypervisor(_GetConfig()).GetInstanceInfo(instance) if iinfo is not None: output['memory'] = iinfo[2] output['state'] = iinfo[4] @@ -477,7 +477,7 @@ def GetAllInstancesInfo(): """ output = {} - iinfo = hypervisor.GetHypervisor().GetAllInstancesInfo() + iinfo = hypervisor.GetHypervisor(_GetConfig()).GetAllInstancesInfo() if iinfo: for name, inst_id, memory, vcpus, state, times in iinfo: output[name] = { @@ -676,7 +676,7 @@ def StartInstance(instance, extra_args): return True block_devices = _GatherBlockDevs(instance) - hyper = hypervisor.GetHypervisor() + hyper = hypervisor.GetHypervisor(_GetConfig()) try: hyper.StartInstance(instance, block_devices, extra_args) @@ -699,7 +699,7 @@ def ShutdownInstance(instance): if instance.name not in running_instances: return True - hyper = hypervisor.GetHypervisor() + hyper = hypervisor.GetHypervisor(_GetConfig()) try: hyper.StopInstance(instance) except errors.HypervisorError, err: @@ -747,7 +747,7 @@ def RebootInstance(instance, reboot_type, extra_args): logging.error("Cannot reboot instance that is not running") return False - hyper = hypervisor.GetHypervisor() + hyper = hypervisor.GetHypervisor(_GetConfig()) if reboot_type == constants.INSTANCE_REBOOT_SOFT: try: hyper.RebootInstance(instance) @@ -772,7 +772,7 @@ def MigrateInstance(instance, target, live): """Migrates an instance to another node. """ - hyper = hypervisor.GetHypervisor() + hyper = hypervisor.GetHypervisor(_GetConfig()) try: hyper.MigrateInstance(instance, target, live) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index f9b09b9800f3cf570d2b0dc79e8c99b4ce251a52..cb57d9e1be83fb043291075d3fa783596c5b782e 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -3642,7 +3642,7 @@ class LUConnectConsole(NoHooksLU): logger.Debug("connecting to console of %s on %s" % (instance.name, node)) - hyper = hypervisor.GetHypervisor() + hyper = hypervisor.GetHypervisor(self.cfg) console_cmd = hyper.GetShellCommandForConsole(instance) # build ssh cmdline diff --git a/lib/hypervisor/__init__.py b/lib/hypervisor/__init__.py index 035ce86957c79dacbf47975419105c990bdf4030..4e0dcde30d02f852eb0a56b09bd359db54765ce8 100644 --- a/lib/hypervisor/__init__.py +++ b/lib/hypervisor/__init__.py @@ -23,7 +23,6 @@ """ -from ganeti import ssconf from ganeti import constants from ganeti import errors @@ -40,14 +39,16 @@ _HYPERVISOR_MAP = { } -def GetHypervisor(): +def GetHypervisor(cfg): """Return a Hypervisor instance. This function parses the cluster hypervisor configuration file and instantiates a class based on the value of this file. + @param cfg: Configuration object + """ - ht_kind = ssconf.SimpleStore().GetHypervisorType() + ht_kind = cfg.GetHypervisorType() if ht_kind not in _HYPERVISOR_MAP: raise errors.HypervisorError("Unknown hypervisor type '%s'" % ht_kind)