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