Commit d8470559 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Implement {Add,Readd,Remove}Node in GanetiContext

By doing this we've a central place which coordinates what needs to be
done when adding or removing nodes. Another patch will add calls into
the job queue.

Two log messages move to config.py.

When removing a node, node_leave_cluster is now called after it has
been removed from the configuration and job manager. That way we're
sure not to access the node again after files have been removed.

Reviewed-by: iustinp
parent d2e03a33
......@@ -284,6 +284,31 @@ class GanetiContext(object):
assert self.__class__._instance is None, "Attempt to modify Ganeti Context"
object.__setattr__(self, name, value)
def AddNode(self, node):
"""Adds a node to the configuration and lock manager.
"""
# Add it to the configuration
self.cfg.AddNode(node)
# Add the new node to the Ganeti Lock Manager
self.glm.add(locking.LEVEL_NODE, node.name)
def ReaddNode(self, node):
"""Updates a node that's already in the configuration
"""
def RemoveNode(self, name):
"""Removes a node from the configuration and lock manager.
"""
# Remove node from configuration
self.cfg.RemoveNode(name)
# Remove the node from the Ganeti Lock Manager
self.glm.remove(locking.LEVEL_NODE, name)
def ParseOptions():
"""Parse the command line options.
......
......@@ -1356,15 +1356,9 @@ class LURemoveNode(LogicalUnit):
logger.Info("stopping the node daemon and removing configs from node %s" %
node.name)
rpc.call_node_leave_cluster(node.name)
logger.Info("Removing node %s from config" % node.name)
self.cfg.RemoveNode(node.name)
# Remove the node from the Ganeti Lock Manager
self.context.glm.remove(locking.LEVEL_NODE, node.name)
self.context.RemoveNode(node.name)
utils.RemoveHostFromEtcHosts(node.name)
rpc.call_node_leave_cluster(node.name)
class LUQueryNodes(NoHooksLU):
......@@ -1738,11 +1732,10 @@ class LUAddNode(LogicalUnit):
if not result[node]:
logger.Error("could not copy file %s to node %s" % (fname, node))
if not self.op.readd:
logger.Info("adding node %s to cluster.conf" % node)
self.cfg.AddNode(new_node)
# Add the new node to the Ganeti Lock Manager
self.context.glm.add(locking.LEVEL_NODE, node)
if self.op.readd:
self.context.ReaddNode(new_node)
else:
self.context.AddNode(new_node)
class LUQueryClusterInfo(NoHooksLU):
......
......@@ -34,6 +34,7 @@ much memory.
import os
import tempfile
import random
import logging
from ganeti import errors
from ganeti import locking
......@@ -461,6 +462,8 @@ class ConfigWriter:
node: an object.Node instance
"""
logging.info("Adding node %s to configuration" % node.name)
self._OpenConfig()
self._config_data.nodes[node.name] = node
self._WriteConfig()
......@@ -470,6 +473,8 @@ class ConfigWriter:
"""Remove a node from the configuration.
"""
logging.info("Removing node %s from configuration" % node_name)
self._OpenConfig()
if node_name not in self._config_data.nodes:
raise errors.ConfigurationError("Unknown node '%s'" % node_name)
......
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