Commit 0debfb35 authored by Guido Trotter's avatar Guido Trotter
Browse files

config.Add{Node,Instance}: get the ec id



This is ok because adding a node or instance cannot happen in a query.

We get the ec id from the LU and pass it to _EnsureUUID, which will
then for now not use it.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 73064714
......@@ -365,12 +365,12 @@ class GanetiContext(object):
assert self.__class__._instance is None, "Attempt to modify Ganeti Context"
object.__setattr__(self, name, value)
def AddNode(self, node):
def AddNode(self, node, ec_id):
"""Adds a node to the configuration and lock manager.
"""
# Add it to the configuration
self.cfg.AddNode(node)
self.cfg.AddNode(node, ec_id)
# If preseeding fails it'll not be added
self.jobqueue.AddNode(node)
......
......@@ -3037,7 +3037,7 @@ class LUAddNode(LogicalUnit):
" candidate status: %s" % msg)
else:
_RedistributeAncillaryFiles(self, additional_nodes=[node])
self.context.AddNode(new_node)
self.context.AddNode(new_node, self.proc.GetECId())
class LUSetNodeParams(LogicalUnit):
......@@ -6097,7 +6097,8 @@ class LUCreateInstance(LogicalUnit):
feedback_fn("adding instance %s to cluster config" % instance)
self.cfg.AddInstance(iobj)
self.cfg.AddInstance(iobj, self.proc.GetECId())
# Declare that we don't want to remove the instance lock anymore, as we've
# added the instance to the config
del self.remove_locks[locking.LEVEL_INSTANCE]
......
......@@ -724,7 +724,7 @@ class ConfigWriter:
return self._config_data.cluster.rsahostkeypub
@locking.ssynchronized(_config_lock)
def AddInstance(self, instance):
def AddInstance(self, instance, ec_id):
"""Add an instance to the config.
This should be used after creating a new instance.
......@@ -747,7 +747,7 @@ class ConfigWriter:
" MAC address '%s' already in use." %
(instance.name, nic.mac))
self._EnsureUUID(instance)
self._EnsureUUID(instance, ec_id)
instance.serial_no = 1
instance.ctime = instance.mtime = time.time()
......@@ -758,10 +758,11 @@ class ConfigWriter:
self._temporary_macs.discard(nic.mac)
self._WriteConfig()
def _EnsureUUID(self, item):
def _EnsureUUID(self, item, ec_id):
"""Ensures a given object has a valid UUID.
@param item: the instance or node to be checked
@param ec_id: the execution context id for the uuid reservation
"""
if not item.uuid:
......@@ -907,7 +908,7 @@ class ConfigWriter:
return my_dict
@locking.ssynchronized(_config_lock)
def AddNode(self, node):
def AddNode(self, node, ec_id):
"""Add a node to the configuration.
@type node: L{objects.Node}
......@@ -916,7 +917,7 @@ class ConfigWriter:
"""
logging.info("Adding node %s to configuration", node.name)
self._EnsureUUID(node)
self._EnsureUUID(node, ec_id)
node.serial_no = 1
node.ctime = node.mtime = time.time()
......
......@@ -148,7 +148,7 @@ class TestConfigRunner(unittest.TestCase):
self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_instance,
None)
cfg.AddInstance(inst)
cfg.AddInstance(inst, "my-job")
instance = cfg.GetInstanceInfo(cfg.GetInstanceList()[0])
# first pass, must not fail
cfg.Update(instance, None)
......
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