X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/b459a848dc62e314e61e8ae14edd3ff6cc2b2822..5ae4945a5852c99082eb78284cf0bef8c1244a8d:/lib/hypervisor/hv_base.py diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py index 7c4b1b5..bb0da91 100644 --- a/lib/hypervisor/hv_base.py +++ b/lib/hypervisor/hv_base.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2006, 2007, 2008, 2009, 2010 Google Inc. +# Copyright (C) 2006, 2007, 2008, 2009, 2010, 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 @@ -48,6 +48,12 @@ from ganeti import constants def _IsCpuMaskWellFormed(cpu_mask): + """Verifies if the given single CPU mask is valid + + The single CPU mask should be in the form "a,b,c,d", where each + letter is a positive number or range. + + """ try: cpu_list = utils.ParseCpuMask(cpu_mask) except errors.ParseError, _: @@ -55,16 +61,31 @@ def _IsCpuMaskWellFormed(cpu_mask): return isinstance(cpu_list, list) and len(cpu_list) > 0 +def _IsMultiCpuMaskWellFormed(cpu_mask): + """Verifies if the given multiple CPU mask is valid + + A valid multiple CPU mask is in the form "a:b:c:d", where each + letter is a single CPU mask. + + """ + try: + utils.ParseMultiCpuMask(cpu_mask) + except errors.ParseError, _: + return False + + return True + + # Read the BaseHypervisor.PARAMETERS docstring for the syntax of the # _CHECK values # must be afile _FILE_CHECK = (utils.IsNormAbsPath, "must be an absolute normalized path", - os.path.isfile, "not found or not a file") + os.path.isfile, "not found or not a file") # must be a directory _DIR_CHECK = (utils.IsNormAbsPath, "must be an absolute normalized path", - os.path.isdir, "not found or not a directory") + os.path.isdir, "not found or not a directory") # CPU mask must be well-formed # TODO: implement node level check for the CPU mask @@ -72,6 +93,11 @@ _CPU_MASK_CHECK = (_IsCpuMaskWellFormed, "CPU mask definition is not well-formed", None, None) +# Multiple CPU mask must be well-formed +_MULTI_CPU_MASK_CHECK = (_IsMultiCpuMaskWellFormed, + "Multiple CPU mask definition is not well-formed", + None, None) + # Check for validity of port number _NET_PORT_CHECK = (lambda x: 0 < x < 65535, "invalid port number", None, None) @@ -85,6 +111,8 @@ REQ_NET_PORT_CHECK = (True, ) + _NET_PORT_CHECK OPT_NET_PORT_CHECK = (False, ) + _NET_PORT_CHECK REQ_CPU_MASK_CHECK = (True, ) + _CPU_MASK_CHECK OPT_CPU_MASK_CHECK = (False, ) + _CPU_MASK_CHECK +REQ_MULTI_CPU_MASK_CHECK = (True, ) + _MULTI_CPU_MASK_CHECK +OPT_MULTI_CPU_MASK_CHECK = (False, ) + _MULTI_CPU_MASK_CHECK # no checks at all NO_CHECK = (False, None, None, None, None) @@ -133,6 +161,7 @@ class BaseHypervisor(object): """ PARAMETERS = {} ANCILLARY_FILES = [] + ANCILLARY_FILES_OPT = [] CAN_MIGRATE = False def __init__(self): @@ -221,13 +250,16 @@ class BaseHypervisor(object): """Return a list of ancillary files to be copied to all nodes as ancillary configuration files. - @rtype: list of strings - @return: list of absolute paths of files to ship cluster-wide + @rtype: (list of absolute paths, list of absolute paths) + @return: (all files, optional files) """ # By default we return a member variable, so that if an hypervisor has just # a static list of files it doesn't have to override this function. - return cls.ANCILLARY_FILES + assert set(cls.ANCILLARY_FILES).issuperset(cls.ANCILLARY_FILES_OPT), \ + "Optional ancillary files must be a subset of ancillary files" + + return (cls.ANCILLARY_FILES, cls.ANCILLARY_FILES_OPT) def Verify(self): """Verify the hypervisor. @@ -263,8 +295,19 @@ class BaseHypervisor(object): """ pass - def FinalizeMigration(self, instance, info, success): - """Finalized an instance migration. + def BalloonInstanceMemory(self, instance, mem): + """Balloon an instance memory to a certain value. + + @type instance: L{objects.Instance} + @param instance: instance to be accepted + @type mem: int + @param mem: actual memory size to use for instance runtime + + """ + raise NotImplementedError + + def FinalizeMigrationDst(self, instance, info, success): + """Finalize the instance migration on the target node. Should finalize or revert any preparation done to accept the instance. Since by default we do no preparation, we also don't have anything to do @@ -292,6 +335,50 @@ class BaseHypervisor(object): """ raise NotImplementedError + def FinalizeMigrationSource(self, instance, success, live): + """Finalize the instance migration on the source node. + + @type instance: L{objects.Instance} + @param instance: the instance that was migrated + @type success: bool + @param success: whether the migration succeeded or not + @type live: bool + @param live: whether the user requested a live migration or not + + """ + pass + + def GetMigrationStatus(self, instance): + """Get the migration status + + @type instance: L{objects.Instance} + @param instance: the instance that is being migrated + @rtype: L{objects.MigrationStatus} + @return: the status of the current migration (one of + L{constants.HV_MIGRATION_VALID_STATUSES}), plus any additional + progress info that can be retrieved from the hypervisor + + """ + raise NotImplementedError + + def _InstanceStartupMemory(self, instance): + """Get the correct startup memory for an instance + + This function calculates how much memory an instance should be started + with, making sure it's a value between the minimum and the maximum memory, + but also trying to use no more than the current free memory on the node. + + @type instance: L{objects.Instance} + @param instance: the instance that is being started + @rtype: integer + @return: memory the instance should be started with + + """ + free_memory = self.GetNodeInfo()["memory_free"] + max_start_mem = min(instance.beparams[constants.BE_MAXMEM], free_memory) + start_mem = max(instance.beparams[constants.BE_MINMEM], max_start_mem) + return start_mem + @classmethod def CheckParameterSyntax(cls, hvparams): """Check the given parameters for validity.