Commit fd3d37b6 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add the master/vm_capable flags in node add


Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 77bad5b2
......@@ -213,7 +213,9 @@ def AddNode(opts, args):
bootstrap.SetupNodeDaemon(cluster_name, node, opts.ssh_key_check)
op = opcodes.OpAddNode(node_name=args[0], secondary_ip=sip,
readd=opts.readd, group=opts.nodegroup)
readd=opts.readd, group=opts.nodegroup,
vm_capable=opts.vm_capable,
master_capable=opts.master_capable)
SubmitOpCode(op, opts=opts)
......@@ -678,7 +680,8 @@ commands = {
'add': (
AddNode, [ArgHost(min=1, max=1)],
[SECONDARY_IP_OPT, READD_OPT, NOSSH_KEYCHECK_OPT, NONODE_SETUP_OPT,
VERBOSE_OPT, NODEGROUP_OPT, PRIORITY_OPT],
VERBOSE_OPT, NODEGROUP_OPT, PRIORITY_OPT, CAPAB_MASTER_OPT,
CAPAB_VM_OPT],
"[-s ip] [--readd] [--no-ssh-key-check] [--no-node-setup] [--verbose] "
" <node_name>",
"Add a node to the cluster"),
......
......@@ -3681,8 +3681,11 @@ class LUAddNode(LogicalUnit):
("primary_ip", None, ht.NoType),
("secondary_ip", None, ht.TMaybeString),
("readd", False, ht.TBool),
("group", None, ht.TMaybeString)
("group", None, ht.TMaybeString),
("master_capable", None, ht.TMaybeBool),
("vm_capable", None, ht.TMaybeBool),
]
_NFLAGS = ["master_capable", "vm_capable"]
def CheckArguments(self):
self.primary_ip_family = self.cfg.GetPrimaryIPFamily()
......@@ -3705,6 +3708,8 @@ class LUAddNode(LogicalUnit):
"NODE_NAME": self.op.node_name,
"NODE_PIP": self.op.primary_ip,
"NODE_SIP": self.op.secondary_ip,
"MASTER_CAPABLE": str(self.op.master_capable),
"VM_CAPABLE": str(self.op.vm_capable),
}
nodes_0 = self.cfg.GetNodeList()
nodes_1 = nodes_0 + [self.op.node_name, ]
......@@ -3768,6 +3773,27 @@ class LUAddNode(LogicalUnit):
" existing node %s" % existing_node.name,
errors.ECODE_NOTUNIQUE)
# After this 'if' block, None is no longer a valid value for the
# _capable op attributes
if self.op.readd:
old_node = self.cfg.GetNodeInfo(node)
assert old_node is not None, "Can't retrieve locked node %s" % node
for attr in self._NFLAGS:
if getattr(self.op, attr) is None:
setattr(self.op, attr, getattr(old_node, attr))
else:
for attr in self._NFLAGS:
if getattr(self.op, attr) is None:
setattr(self.op, attr, True)
if self.op.readd and not self.op.vm_capable:
pri, sec = cfg.GetNodeInstances(node)
if pri or sec:
raise errors.OpPrereqError("Node %s being re-added with vm_capable"
" flag set to false, but it already holds"
" instances" % node,
errors.ECODE_STATE)
# check that the type of the node (single versus dual homed) is the
# same as for the master
myself = cfg.GetNodeInfo(self.cfg.GetMasterNode())
......@@ -3801,19 +3827,19 @@ class LUAddNode(LogicalUnit):
else:
exceptions = []
self.master_candidate = _DecideSelfPromotion(self, exceptions=exceptions)
if self.op.master_capable:
self.master_candidate = _DecideSelfPromotion(self, exceptions=exceptions)
else:
self.master_candidate = False
if self.op.readd:
self.new_node = self.cfg.GetNodeInfo(node)
assert self.new_node is not None, "Can't retrieve locked node %s" % node
self.new_node = old_node
else:
node_group = cfg.LookupNodeGroup(self.op.group)
self.new_node = objects.Node(name=node,
primary_ip=primary_ip,
secondary_ip=secondary_ip,
master_candidate=self.master_candidate,
master_capable=True,
vm_capable=True,
offline=False, drained=False,
group=node_group)
......@@ -3836,6 +3862,10 @@ class LUAddNode(LogicalUnit):
if self.changed_primary_ip:
new_node.primary_ip = self.op.primary_ip
# copy the master/vm_capable flags
for attr in self._NFLAGS:
setattr(new_node, attr, getattr(self.op, attr))
# notify the user about any possible mc promotion
if new_node.master_candidate:
self.LogInfo("Node will be a master candidate")
......@@ -3901,7 +3931,8 @@ class LUAddNode(LogicalUnit):
self.LogWarning("Node failed to demote itself from master"
" candidate status: %s" % msg)
else:
_RedistributeAncillaryFiles(self, additional_nodes=[node])
_RedistributeAncillaryFiles(self, additional_nodes=[node],
additional_vm=self.op.vm_capable)
self.context.AddNode(new_node, self.proc.GetECId())
......
......@@ -366,11 +366,16 @@ class OpAddNode(OpCode):
without removal from the cluster.
@type group: C{str}
@ivar group: The node group to which this node will belong.
@type vm_capable: C{bool}
@ivar vm_capable: The vm_capable node attribute
@type master_capable: C{bool}
@ivar master_capable: The master_capable node attribute
"""
OP_ID = "OP_NODE_ADD"
OP_DSC_FIELD = "node_name"
__slots__ = ["node_name", "primary_ip", "secondary_ip", "readd", "group"]
__slots__ = ["node_name", "primary_ip", "secondary_ip", "readd", "group",
"vm_capable", "master_capable"]
class OpQueryNodes(OpCode):
......
......@@ -65,6 +65,8 @@
<arg>--readd</arg>
<arg>-s <replaceable>secondary_ip</replaceable></arg>
<arg>-g <replaceable>nodegroup</replaceable></arg>
<arg>--master-capable=<option>yes|no</option></arg>
<arg>--vm-capable=<option>yes|no</option></arg>
<arg choice="req"><replaceable>nodename</replaceable></arg>
</cmdsynopsis>
......@@ -110,6 +112,13 @@
you can skip this option, otherwise it's mandatory.
</para>
<para>
The <option>vm_capable</option>
and <option>master_capable</option> options are described
in <citerefentry><refentrytitle>ganeti</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
and are used to set the properties of the new node.
</para>
<para>
Example:
<screen>
......
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