Revision b31c8676

b/lib/cmdlib.py
1959 1959
      self.context.AddNode(new_node)
1960 1960

  
1961 1961

  
1962
class LUSetNodeParams(LogicalUnit):
1963
  """Modifies the parameters of a node.
1964

  
1965
  """
1966
  HPATH = "node-modify"
1967
  HTYPE = constants.HTYPE_NODE
1968
  _OP_REQP = ["node_name"]
1969
  REQ_BGL = False
1970

  
1971
  def CheckArguments(self):
1972
    node_name = self.cfg.ExpandNodeName(self.op.node_name)
1973
    if node_name is None:
1974
      raise errors.OpPrereqError("Invalid node name '%s'" % self.op.node_name)
1975
    self.op.node_name = node_name
1976
    if not hasattr(self.op, 'master_candidate'):
1977
      raise errors.OpPrereqError("Please pass at least one modification")
1978
    self.op.master_candidate = bool(self.op.master_candidate)
1979

  
1980
  def ExpandNames(self):
1981
    self.needed_locks = {locking.LEVEL_NODE: self.op.node_name}
1982

  
1983
  def BuildHooksEnv(self):
1984
    """Build hooks env.
1985

  
1986
    This runs on the master node.
1987

  
1988
    """
1989
    env = {
1990
      "OP_TARGET": self.op.node_name,
1991
      "MASTER_CANDIDATE": str(self.op.master_candidate),
1992
      }
1993
    nl = [self.cfg.GetMasterNode(),
1994
          self.op.node_name]
1995
    return env, nl, nl
1996

  
1997
  def CheckPrereq(self):
1998
    """Check prerequisites.
1999

  
2000
    This only checks the instance list against the existing names.
2001

  
2002
    """
2003
    force = self.force = self.op.force
2004

  
2005
    return
2006

  
2007
  def Exec(self, feedback_fn):
2008
    """Modifies a node.
2009

  
2010
    """
2011
    node = self.cfg.GetNodeInfo(self.op.node_name)
2012

  
2013
    result = []
2014

  
2015
    if self.op.master_candidate is not None:
2016
      node.master_candidate = self.op.master_candidate
2017
      result.append(("master_candidate", str(self.op.master_candidate)))
2018

  
2019
    # this will trigger configuration file update, if needed
2020
    self.cfg.Update(node)
2021
    # this will trigger job queue propagation or cleanup
2022
    self.context.ReaddNode(node)
2023

  
2024
    return result
2025

  
2026

  
1962 2027
class LUQueryClusterInfo(NoHooksLU):
1963 2028
  """Query cluster configuration.
1964 2029

  
b/lib/mcpu.py
54 54
    opcodes.OpQueryNodes: cmdlib.LUQueryNodes,
55 55
    opcodes.OpQueryNodeVolumes: cmdlib.LUQueryNodeVolumes,
56 56
    opcodes.OpRemoveNode: cmdlib.LURemoveNode,
57
    opcodes.OpSetNodeParams: cmdlib.LUSetNodeParams,
57 58
    # instance lu
58 59
    opcodes.OpCreateInstance: cmdlib.LUCreateInstance,
59 60
    opcodes.OpReinstallInstance: cmdlib.LUReinstallInstance,
b/lib/opcodes.py
312 312
  __slots__ = ["nodes", "output_fields"]
313 313

  
314 314

  
315
class OpSetNodeParams(OpCode):
316
  """Change the parameters of a node."""
317
  OP_ID = "OP_NODE_SET_PARAMS"
318
  OP_DSC_FIELD = "node_name"
319
  __slots__ = [
320
    "node_name",
321
    "force",
322
    "master_candidate",
323
    ]
324

  
315 325
# instance opcodes
316 326

  
317 327
class OpCreateInstance(OpCode):
b/scripts/gnt-node
365 365
  return 0
366 366

  
367 367

  
368
def SetNodeParams(opts, args):
369
  """Modifies a node.
370

  
371
  @param opts: the command line options selected by the user
372
  @type args: list
373
  @param args: should contain only one element, the node name
374
  @rtype: int
375
  @return: the desired exit code
376

  
377
  """
378
  if opts.master_candidate is None:
379
    ToStderr("Please give at least one of the parameters.")
380
    return 1
381

  
382
  candidate = opts.master_candidate == 'yes'
383
  op = opcodes.OpSetNodeParams(node_name=args[0],
384
                              master_candidate=candidate,
385
                              force=opts.force)
386

  
387
  # even if here we process the result, we allow submit only
388
  result = SubmitOrSend(op, opts)
389

  
390
  if result:
391
    ToStdout("Modified node %s", args[0])
392
    for param, data in result:
393
      ToStdout(" - %-5s -> %s", param, data)
394
  return 0
395

  
396

  
368 397
commands = {
369 398
  'add': (AddNode, ARGS_ONE,
370 399
          [DEBUG_OPT,
......
408 437
           " The default field list is"
409 438
           " (in order): %s." % ", ".join(_LIST_DEF_FIELDS),
410 439
           ),
440
  'modify': (SetNodeParams, ARGS_ONE,
441
             [DEBUG_OPT, FORCE_OPT,
442
              SUBMIT_OPT,
443
              make_option("-C", "--master-candidate", dest="master_candidate",
444
                          choices=('yes', 'no'), default=None,
445
                          help="Set the master_candidate flag on the node"),
446
              ],
447
             "<instance>", "Alters the parameters of an instance"),
411 448
  'remove': (RemoveNode, ARGS_ONE, [DEBUG_OPT],
412 449
             "<node_name>", "Removes a node from the cluster"),
413 450
  'volumes': (ListVolumes, ARGS_ANY,

Also available in: Unified diff