From 9ccacbc873b32169f72c63cfb825f3ffb57fff0c Mon Sep 17 00:00:00 2001 From: Dimitris Aragiorgis Date: Sat, 16 Feb 2013 15:19:31 +0200 Subject: [PATCH] Make network config methods take uuid as argument This will be needed in the following patches where nic.network will refer to network's uuid and not name. Signed-off-by: Dimitris Aragiorgis Reviewed-by: Helga Velroyen --- lib/config.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/lib/config.py b/lib/config.py index 4f8c36d..532a762 100644 --- a/lib/config.py +++ b/lib/config.py @@ -270,13 +270,12 @@ class ConfigWriter: """ return self._config_data.cluster.SimpleFillDP(group.diskparams) - def _UnlockedGetNetworkMACPrefix(self, net): + def _UnlockedGetNetworkMACPrefix(self, net_uuid): """Return the network mac prefix if it exists or the cluster level default. """ prefix = None - if net: - net_uuid = self._UnlockedLookupNetwork(net) + if net_uuid: nobj = self._UnlockedGetNetwork(net_uuid) if nobj.mac_prefix: prefix = nobj.mac_prefix @@ -302,14 +301,14 @@ class ConfigWriter: return GenMac @locking.ssynchronized(_config_lock, shared=1) - def GenerateMAC(self, net, ec_id): + def GenerateMAC(self, net_uuid, ec_id): """Generate a MAC for an instance. This should check the current instances for duplicates. """ existing = self._AllMACs() - prefix = self._UnlockedGetNetworkMACPrefix(net) + prefix = self._UnlockedGetNetworkMACPrefix(net_uuid) gen_mac = self._GenerateOneMAC(prefix) return self._temporary_ids.Generate(existing, gen_mac, ec_id) @@ -358,21 +357,20 @@ class ConfigWriter: (constants.RELEASE_ACTION, address, net_uuid)) @locking.ssynchronized(_config_lock, shared=1) - def ReleaseIp(self, net, address, ec_id): + def ReleaseIp(self, net_uuid, address, ec_id): """Give a specified IP address back to an IP pool. This is just a wrapper around _UnlockedReleaseIp. """ - net_uuid = self._UnlockedLookupNetwork(net) - self._UnlockedReleaseIp(net_uuid, address, ec_id) + if net_uuid: + self._UnlockedReleaseIp(net_uuid, address, ec_id) @locking.ssynchronized(_config_lock, shared=1) - def GenerateIp(self, net, ec_id): + def GenerateIp(self, net_uuid, ec_id): """Find a free IPv4 address for an instance. """ - net_uuid = self._UnlockedLookupNetwork(net) nobj = self._UnlockedGetNetwork(net_uuid) pool = network.AddressPool(nobj) @@ -404,12 +402,12 @@ class ConfigWriter: address, net_uuid)) @locking.ssynchronized(_config_lock, shared=1) - def ReserveIp(self, net, address, ec_id): + def ReserveIp(self, net_uuid, address, ec_id): """Reserve a given IPv4 address for use by an instance. """ - net_uuid = self._UnlockedLookupNetwork(net) - return self._UnlockedReserveIp(net_uuid, address, ec_id) + if net_uuid: + return self._UnlockedReserveIp(net_uuid, address, ec_id) @locking.ssynchronized(_config_lock, shared=1) def ReserveLV(self, lv_name, ec_id): @@ -2526,20 +2524,19 @@ class ConfigWriter: self._config_data.cluster.serial_no += 1 self._WriteConfig() - def _UnlockedGetGroupNetParams(self, net, node): + def _UnlockedGetGroupNetParams(self, net_uuid, node): """Get the netparams (mode, link) of a network. Get a network's netparams for a given node. - @type net: string - @param net: network name + @type net_uuid: string + @param net_uuid: network uuid @type node: string @param node: node name @rtype: dict or None @return: netparams """ - net_uuid = self._UnlockedLookupNetwork(net) node_info = self._UnlockedGetNodeInfo(node) nodegroup_info = self._UnlockedGetNodeGroup(node_info.group) netparams = nodegroup_info.networks.get(net_uuid, None) @@ -2547,11 +2544,11 @@ class ConfigWriter: return netparams @locking.ssynchronized(_config_lock, shared=1) - def GetGroupNetParams(self, net, node): + def GetGroupNetParams(self, net_uuid, node): """Locking wrapper of _UnlockedGetGroupNetParams() """ - return self._UnlockedGetGroupNetParams(net, node) + return self._UnlockedGetGroupNetParams(net_uuid, node) @locking.ssynchronized(_config_lock, shared=1) def CheckIPInNodeGroup(self, ip, node): -- 1.7.10.4