Revision a268af8d lib/rapi/client.py

b/lib/rapi/client.py
1371 1371
    return self._SendRequest(HTTP_DELETE,
1372 1372
                             ("/%s/nodes/%s/tags" %
1373 1373
                              (GANETI_RAPI_VERSION, node)), query, None)
1374

  
1375
  def GetGroups(self, bulk=False):
1376
    """Gets all node groups in the cluster.
1377

  
1378
    @type bulk: bool
1379
    @param bulk: whether to return all information about the groups
1380

  
1381
    @rtype: list of dict or str
1382
    @return: if bulk is true, a list of dictionaries with info about all node
1383
        groups in the cluster, else a list of names of those node groups
1384

  
1385
    """
1386
    query = []
1387
    if bulk:
1388
      query.append(("bulk", 1))
1389

  
1390
    groups = self._SendRequest(HTTP_GET, "/%s/groups" % GANETI_RAPI_VERSION,
1391
                               query, None)
1392
    if bulk:
1393
      return groups
1394
    else:
1395
      return [g["name"] for g in groups]
1396

  
1397
  def GetGroup(self, group):
1398
    """Gets information about a node group.
1399

  
1400
    @type group: str
1401
    @param group: name of the node group whose info to return
1402

  
1403
    @rtype: dict
1404
    @return: info about the node group
1405

  
1406
    """
1407
    return self._SendRequest(HTTP_GET,
1408
                             "/%s/groups/%s" % (GANETI_RAPI_VERSION, group),
1409
                             None, None)
1410

  
1411
  def CreateGroup(self, name, dry_run=False):
1412
    """Creates a new node group.
1413

  
1414
    @type name: str
1415
    @param name: the name of node group to create
1416
    @type dry_run: bool
1417
    @param dry_run: whether to peform a dry run
1418

  
1419
    @rtype: int
1420
    @return: job id
1421

  
1422
    """
1423
    query = []
1424
    if dry_run:
1425
      query.append(("dry-run", 1))
1426

  
1427
    body = {
1428
      "name": name,
1429
      }
1430

  
1431
    return self._SendRequest(HTTP_POST, "/%s/groups" % GANETI_RAPI_VERSION,
1432
                             query, body)
1433

  
1434
  def DeleteGroup(self, group, dry_run=False):
1435
    """Deletes a node group.
1436

  
1437
    @type group: str
1438
    @param group: the node group to delete
1439
    @type dry_run: bool
1440
    @param dry_run: whether to peform a dry run
1441

  
1442
    @rtype: int
1443
    @return: job id
1444

  
1445
    """
1446
    query = []
1447
    if dry_run:
1448
      query.append(("dry-run", 1))
1449

  
1450
    return self._SendRequest(HTTP_DELETE,
1451
                             ("/%s/groups/%s" %
1452
                              (GANETI_RAPI_VERSION, group)), query, None)
1453

  
1454
  def RenameGroup(self, group, new_name):
1455
    """Changes the name of a node group.
1456

  
1457
    @type group: string
1458
    @param group: Node group name
1459
    @type new_name: string
1460
    @param new_name: New node group name
1461

  
1462
    @rtype: int
1463
    @return: job id
1464

  
1465
    """
1466
    body = {
1467
      "new_name": new_name,
1468
      }
1469

  
1470
    return self._SendRequest(HTTP_PUT,
1471
                             ("/%s/groups/%s/rename" %
1472
                              (GANETI_RAPI_VERSION, group)), None, body)

Also available in: Unified diff