#
#
-# Copyright (C) 2007, 2011 Google Inc.
+# Copyright (C) 2007, 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
import os
+from ganeti import constants
from ganeti import utils
from ganeti import serializer
from ganeti import compat
_INSTANCE_CHECK_KEY = "instance-check"
+_ENABLED_HV_KEY = "enabled-hypervisors"
cfg = None
raise qa_error.Error("Can't find instance check script '%s': %s" %
(check, err))
+ enabled_hv = frozenset(GetEnabledHypervisors())
+ if not enabled_hv:
+ raise qa_error.Error("No hypervisor is enabled")
+
+ difference = enabled_hv - constants.HYPER_TYPES
+ if difference:
+ raise qa_error.Error("Unknown hypervisor(s) enabled: %s" %
+ utils.CommaJoin(difference))
+
def get(name, default=None):
- return cfg.get(name, default)
+ return cfg.get(name, default) # pylint: disable=E1103
class Either:
_cfg = cfg
# Get settings for all tests
- cfg_tests = _cfg.get("tests", {})
+ cfg_tests = _cfg.get("tests", {}) # pylint: disable=E1103
# Get default setting
default = cfg_tests.get("default", True)
"""Returns path to instance check script or C{None}.
"""
- return cfg.get(_INSTANCE_CHECK_KEY, None)
+ return cfg.get(_INSTANCE_CHECK_KEY, None) # pylint: disable=E1103
+
+
+def GetEnabledHypervisors():
+ """Returns list of enabled hypervisors.
+
+ @rtype: list
+
+ """
+ try:
+ value = cfg[_ENABLED_HV_KEY]
+ except KeyError:
+ return [constants.DEFAULT_ENABLED_HYPERVISOR]
+ else:
+ if isinstance(value, basestring):
+ # The configuration key ("enabled-hypervisors") implies there can be
+ # multiple values. Multiple hypervisors are comma-separated on the
+ # command line option to "gnt-cluster init", so we need to handle them
+ # equally here.
+ return value.split(",")
+ else:
+ return value
+
+
+def GetDefaultHypervisor():
+ """Returns the default hypervisor to be used.
+
+ """
+ return GetEnabledHypervisors()[0]
+
+
+def GetInstanceNicMac(inst, default=None):
+ """Returns MAC address for instance's network interface.
+
+ """
+ return inst.get("nic.mac/0", default)
def GetMasterNode():