Commit 1e0d3321 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Iustin Pop
Browse files

Implement LUNetworkSetParams

Support modifying all network parameters except for network (ip
range). Cannot modify gateway and reserved ips at the same time.
Signed-off-by: default avatarDimitris Aragiorgis <>
Reviewed-by: default avatarIustin Pop <>
parent 306bed0e
...@@ -15471,11 +15471,156 @@ class LUNetworkRemove(LogicalUnit): ...@@ -15471,11 +15471,156 @@ class LUNetworkRemove(LogicalUnit):
class LUNetworkSetParams(LogicalUnit): class LUNetworkSetParams(LogicalUnit):
def BuildHooksNodes(self): """Modifies the parameters of a network.
HPATH = "network-modify"
REQ_BGL = False
def CheckArguments(self):
if (self.op.gateway and
(self.op.add_reserved_ips or self.op.remove_reserved_ips)):
raise errors.OpPrereqError("Cannot modify gateway and reserved ips"
" at once", errors.ECODE_INVAL)
def ExpandNames(self):
self.network_uuid = self.cfg.LookupNetwork(self.op.network_name) = self.cfg.GetNetwork(self.network_uuid)
self.needed_locks = {
locking.LEVEL_NETWORK: [self.network_uuid],
if is None:
raise errors.OpPrereqError("Could not retrieve network '%s' (UUID: %s)" %
(self.op.network_name, self.network_uuid),
def CheckPrereq(self):
"""Check prerequisites.
self.gateway =
self.network_type =
self.mac_prefix =
self.network6 =
self.gateway6 =
self.pool = network.AddressPool(
if self.op.gateway:
if self.op.gateway == constants.VALUE_NONE:
self.gateway = None
self.gateway = self.op.gateway
if self.pool.IsReserved(self.gateway):
raise errors.OpPrereqError("%s is already reserved" %
self.gateway, errors.ECODE_INVAL)
if self.op.network_type:
if self.op.network_type == constants.VALUE_NONE:
self.network_type = None
self.network_type = self.op.network_type
if self.op.mac_prefix:
if self.op.mac_prefix == constants.VALUE_NONE:
self.mac_prefix = None
self.mac_prefix = self.op.mac_prefix
if self.op.gateway6:
if self.op.gateway6 == constants.VALUE_NONE:
self.gateway6 = None
self.gateway6 = self.op.gateway6
if self.op.network6:
if self.op.network6 == constants.VALUE_NONE:
self.network6 = None
self.network6 = self.op.network6
def BuildHooksEnv(self): def BuildHooksEnv(self):
pass """Build hooks env.
env = {
"NETWORK_NAME": self.op.network_name,
"NETWORK_GATEWAY": self.gateway,
"NETWORK_SUBNET6": self.network6,
"NETWORK_GATEWAY6": self.gateway6,
"NETWORK_MAC_PREFIX": self.mac_prefix,
"NETWORK_TYPE": self.network_type,
return env
def BuildHooksNodes(self):
"""Build hooks nodes.
mn = self.cfg.GetMasterNode()
return ([mn], [mn])
def Exec(self, feedback_fn):
"""Modifies the network.
#TODO: reserve/release via temporary reservation manager
# extend cfg.ReserveIp/ReleaseIp with the external flag
if self.op.gateway:
if self.gateway ==
self.LogWarning("Gateway is already %s" % self.gateway)
if self.gateway:
self.pool.Reserve(self.gateway, external=True)
self.pool.Release(, external=True) = self.gateway
if self.op.add_reserved_ips:
for ip in self.op.add_reserved_ips:
if self.pool.IsReserved(ip):
self.LogWarning("IP %s is already reserved" % ip)
self.pool.Reserve(ip, external=True)
except errors.AddressPoolError, e:
self.LogWarning("Cannot reserve ip %s. %s" % (ip, e))
if self.op.remove_reserved_ips:
for ip in self.op.remove_reserved_ips:
if ip ==
self.LogWarning("Cannot unreserve Gateway's IP")
if not self.pool.IsReserved(ip):
self.LogWarning("IP %s is already unreserved" % ip)
self.pool.Release(ip, external=True)
except errors.AddressPoolError, e:
self.LogWarning("Cannot release ip %s. %s" % (ip, e))
if self.op.mac_prefix: = self.mac_prefix
if self.op.network6: = self.network6
if self.op.gateway6: = self.gateway6
if self.op.network_type: = self.network_type
self.cfg.Update(, feedback_fn)
class _NetworkQuery(_QueryBase): class _NetworkQuery(_QueryBase):
...@@ -2224,6 +2224,8 @@ class ConfigWriter: ...@@ -2224,6 +2224,8 @@ class ConfigWriter:
test = target in self._config_data.instances.values() test = target in self._config_data.instances.values()
elif isinstance(target, objects.NodeGroup): elif isinstance(target, objects.NodeGroup):
test = target in self._config_data.nodegroups.values() test = target in self._config_data.nodegroups.values()
elif isinstance(target, objects.Network):
test = target in self._config_data.networks.values()
else: else:
raise errors.ProgrammerError("Invalid object type (%s) passed to" raise errors.ProgrammerError("Invalid object type (%s) passed to"
" ConfigWriter.Update" % type(target)) " ConfigWriter.Update" % type(target))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment