X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/3df435427de850427aeba1907827d5454f6010f0..8c72ab2bf99249079910a9f9c7c792c6f9c4f792:/lib/objects.py diff --git a/lib/objects.py b/lib/objects.py index 9cbbbee..c23068e 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2006, 2007, 2010 Google Inc. +# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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 @@ -26,20 +26,24 @@ pass to and from external parties. """ -# pylint: disable-msg=E0203,W0201 +# pylint: disable=E0203,W0201,R0902 # E0203: Access to member %r before its definition, since we use # objects.py which doesn't explicitely initialise its members # W0201: Attribute '%s' defined outside __init__ +# R0902: Allow instances of these objects to have more than 20 attributes + import ConfigParser import re import copy +import time from cStringIO import StringIO from ganeti import errors from ganeti import constants +from ganeti import netutils from socket import AF_INET @@ -92,6 +96,21 @@ def UpgradeGroupedParams(target, defaults): return target +def UpgradeBeParams(target): + """Update the be parameters dict to the new format. + + @type target: dict + @param target: "be" parameters dict + + """ + if constants.BE_MEMORY in target: + memory = target[constants.BE_MEMORY] + target[constants.BE_MAXMEM] = memory + target[constants.BE_MINMEM] = memory + #FIXME(dynmem): delete old value + #del target[constants.BE_MEMORY] + + class ConfigObject(object): """A generic config object. @@ -169,7 +188,7 @@ class ConfigObject(object): raise errors.ConfigurationError("Invalid object passed to FromDict:" " expected dict, got %s" % type(val)) val_str = dict([(str(k), v) for k, v in val.iteritems()]) - obj = cls(**val_str) # pylint: disable-msg=W0142 + obj = cls(**val_str) # pylint: disable=W0142 return obj @staticmethod @@ -314,6 +333,25 @@ class TaggableObject(ConfigObject): return obj +class MasterNetworkParameters(ConfigObject): + """Network configuration parameters for the master + + @ivar name: master name + @ivar ip: master IP + @ivar netmask: master netmask + @ivar netdev: master network device + @ivar ip_family: master IP family + + """ + __slots__ = [ + "name", + "ip", + "netmask", + "netdev", + "ip_family" + ] + + class ConfigData(ConfigObject): """Top-level config object.""" __slots__ = [ @@ -389,7 +427,7 @@ class ConfigData(ConfigObject): class NIC(ConfigObject): """Config object representing a network card.""" - __slots__ = ["mac", "ip", "bridge", "nicparams"] + __slots__ = ["mac", "ip", "nicparams"] @classmethod def CheckParameterSyntax(cls, nicparams): @@ -400,7 +438,8 @@ class NIC(ConfigObject): @raise errors.ConfigurationError: when a parameter is not valid """ - if nicparams[constants.NIC_MODE] not in constants.NIC_VALID_MODES: + if (nicparams[constants.NIC_MODE] not in constants.NIC_VALID_MODES and + nicparams[constants.NIC_MODE] != constants.VALUE_AUTO): err = "Invalid nic mode: %s" % nicparams[constants.NIC_MODE] raise errors.ConfigurationError(err) @@ -409,21 +448,6 @@ class NIC(ConfigObject): err = "Missing bridged nic link" raise errors.ConfigurationError(err) - def UpgradeConfig(self): - """Fill defaults for missing configuration values. - - """ - if self.nicparams is None: - self.nicparams = {} - if self.bridge is not None: - self.nicparams[constants.NIC_MODE] = constants.NIC_MODE_BRIDGED - self.nicparams[constants.NIC_LINK] = self.bridge - # bridge is no longer used it 2.1. The slot is left there to support - # upgrading, but can be removed once upgrades to the current version - # straight from 2.0 are deprecated. - if self.bridge is not None: - self.bridge = None - class Disk(ConfigObject): """Config object representing a block device.""" @@ -455,6 +479,8 @@ class Disk(ConfigObject): """ if self.dev_type == constants.LD_LV: return "/dev/%s/%s" % (self.logical_id[0], self.logical_id[1]) + elif self.dev_type == constants.LD_BLOCKDEV: + return self.logical_id[1] return None def ChildrenNeeded(self): @@ -497,7 +523,8 @@ class Disk(ConfigObject): devices needs to (or can) be assembled. """ - if self.dev_type in [constants.LD_LV, constants.LD_FILE]: + if self.dev_type in [constants.LD_LV, constants.LD_FILE, + constants.LD_BLOCKDEV]: result = [node] elif self.dev_type in constants.LDS_DRBD: result = [self.logical_id[0], self.logical_id[1]] @@ -542,6 +569,28 @@ class Disk(ConfigObject): # be different) return result + def ComputeGrowth(self, amount): + """Compute the per-VG growth requirements. + + This only works for VG-based disks. + + @type amount: integer + @param amount: the desired increase in (user-visible) disk space + @rtype: dict + @return: a dictionary of volume-groups and the required size + + """ + if self.dev_type == constants.LD_LV: + return {self.logical_id[0]: amount} + elif self.dev_type == constants.LD_DRBD8: + if self.children: + return self.children[0].ComputeGrowth(amount) + else: + return {} + else: + # Other disk types do not require VG space + return {} + def RecordGrow(self, amount): """Update the size of this disk after growth. @@ -550,7 +599,7 @@ class Disk(ConfigObject): actual algorithms from bdev. """ - if self.dev_type == constants.LD_LV or self.dev_type == constants.LD_FILE: + if self.dev_type in (constants.LD_LV, constants.LD_FILE): self.size += amount elif self.dev_type == constants.LD_DRBD8: if self.children: @@ -651,7 +700,7 @@ class Disk(ConfigObject): """ if self.dev_type == constants.LD_LV: - val = "