Revision 64dae8fc

b/doc/rapi.rst
464 464
      ...
465 465
    ]
466 466

  
467
``/2/nodes/[node_name]/role``
468
+++++++++++++++++++++++++++++
469

  
470
Manages node role.
471

  
472
It supports the following commands: ``GET``, ``PUT``.
473

  
474
The role is always one of the following:
475

  
476
  - drained
477
  - master
478
  - master-candidate
479
  - offline
480
  - regular
481

  
482
``GET``
483
~~~~~~~
484

  
485
Returns the current node role.
486

  
487
Example::
488

  
489
    "master-candidate"
490

  
491
``PUT``
492
~~~~~~~
493

  
494
Change the node role.
495

  
496
The request is a string which should be PUT to this URI. The result will be a
497
job id.
498

  
499
It supports the ``force`` argument.
500

  
467 501
``/2/nodes/[node_name]/tags``
468 502
+++++++++++++++++++++++++++++
469 503

  
b/lib/rapi/connector.py
154 154
  "/2/nodes": rlib2.R_2_nodes,
155 155
  re.compile(r'^/2/nodes/([\w\._-]+)$'): rlib2.R_2_nodes_name,
156 156
  re.compile(r'^/2/nodes/([\w\._-]+)/tags$'): rlib2.R_2_nodes_name_tags,
157
  re.compile(r'^/2/nodes/([\w\._-]+)/role$'): rlib2.R_2_nodes_name_role,
157 158
  "/2/instances": rlib2.R_2_instances,
158 159
  re.compile(r'^/2/instances/([\w\._-]+)$'): rlib2.R_2_instances_name,
159 160
  re.compile(r'^/2/instances/([\w\._-]+)/tags$'): rlib2.R_2_instances_name_tags,
b/lib/rapi/rlib2.py
30 30
from ganeti.rapi import baserlib
31 31

  
32 32

  
33

  
34 33
I_FIELDS = ["name", "admin_state", "os",
35 34
            "pnode", "snodes",
36 35
            "disk_template",
......
48 47
            "ctotal", "cnodes", "csockets",
49 48
            ]
50 49

  
50
_NR_DRAINED = "drained"
51
_NR_MASTER_CANDIATE = "master-candidate"
52
_NR_MASTER = "master"
53
_NR_OFFLINE = "offline"
54
_NR_REGULAR = "regular"
55

  
56
_NR_MAP = {
57
  "M": _NR_MASTER,
58
  "C": _NR_MASTER_CANDIATE,
59
  "D": _NR_DRAINED,
60
  "O": _NR_OFFLINE,
61
  "R": _NR_REGULAR,
62
  }
63

  
51 64

  
52 65
class R_version(baserlib.R_Generic):
53 66
  """/version resource.
......
190 203
    return baserlib.MapFields(N_FIELDS, result[0])
191 204

  
192 205

  
206
class R_2_nodes_name_role(baserlib.R_Generic):
207
  """ /2/nodes/[node_name]/role resource.
208

  
209
  """
210
  def GET(self):
211
    """Returns the current node role.
212

  
213
    @return: Node role
214

  
215
    """
216
    node_name = self.items[0]
217
    client = baserlib.GetClient()
218
    result = client.QueryNodes(names=[node_name], fields=["role"],
219
                               use_locking=self.useLocking())
220

  
221
    return _NR_MAP[result[0][0]]
222

  
223
  def PUT(self):
224
    """Sets the node role.
225

  
226
    @return: a job id
227

  
228
    """
229
    if not isinstance(self.req.request_body, basestring):
230
      raise http.HttpBadRequest("Invalid body contents, not a string")
231

  
232
    node_name = self.items[0]
233
    role = self.req.request_body
234

  
235
    if role == _NR_REGULAR:
236
      candidate = False
237
      offline = False
238
      drained = False
239

  
240
    elif role == _NR_MASTER_CANDIATE:
241
      candidate = True
242
      offline = drained = None
243

  
244
    elif role == _NR_DRAINED:
245
      drained = True
246
      candidate = offline = None
247

  
248
    elif role == _NR_OFFLINE:
249
      offline = True
250
      candidate = drained = None
251

  
252
    else:
253
      raise http.HttpBadRequest("Can't set '%s' role" % role)
254

  
255
    op = opcodes.OpSetNodeParams(node_name=node_name,
256
                                 master_candidate=candidate,
257
                                 offline=offline,
258
                                 drained=drained,
259
                                 force=bool(self.useForce()))
260

  
261
    return baserlib.SubmitJob([op])
262

  
263

  
193 264
class R_2_instances(baserlib.R_Generic):
194 265
  """/2/instances resource.
195 266

  

Also available in: Unified diff