Revision f629a262 lib/rapi/client.py

b/lib/rapi/client.py
1625 1625
                             ("/%s/nodes/%s/tags" %
1626 1626
                              (GANETI_RAPI_VERSION, node)), query, None)
1627 1627

  
1628
  def GetNetworks(self, bulk=False):
1629
    """Gets all networks in the cluster.
1630

  
1631
    @type bulk: bool
1632
    @param bulk: whether to return all information about the networks
1633

  
1634
    @rtype: list of dict or str
1635
    @return: if bulk is true, a list of dictionaries with info about all
1636
        networks in the cluster, else a list of names of those networks
1637

  
1638
    """
1639
    query = []
1640
    _AppendIf(query, bulk, ("bulk", 1))
1641

  
1642
    networks = self._SendRequest(HTTP_GET, "/%s/networks" % GANETI_RAPI_VERSION,
1643
                               query, None)
1644
    if bulk:
1645
      return networks
1646
    else:
1647
      return [n["name"] for n in networks]
1648

  
1649
  def GetNetwork(self, network):
1650
    """Gets information about a network.
1651

  
1652
    @type group: str
1653
    @param group: name of the network whose info to return
1654

  
1655
    @rtype: dict
1656
    @return: info about the network
1657

  
1658
    """
1659
    return self._SendRequest(HTTP_GET,
1660
                             "/%s/networks/%s" % (GANETI_RAPI_VERSION, network),
1661
                             None, None)
1662

  
1663
  def CreateNetwork(self, network_name, network, gateway=None, network6=None,
1664
                    gateway6=None, mac_prefix=None, network_type=None,
1665
                    add_reserved_ips=None, dry_run=False):
1666
    """Creates a new network.
1667

  
1668
    @type name: str
1669
    @param name: the name of network to create
1670
    @type dry_run: bool
1671
    @param dry_run: whether to peform a dry run
1672

  
1673
    @rtype: string
1674
    @return: job id
1675

  
1676
    """
1677
    query = []
1678
    _AppendDryRunIf(query, dry_run)
1679

  
1680
    body = {
1681
      "network_name": network_name,
1682
      "gateway": gateway,
1683
      "network": network,
1684
      "gateway6": gateway6,
1685
      "network6": network6,
1686
      "mac_prefix": mac_prefix,
1687
      "network_type": network_type,
1688
      "add_reserved_ips": add_reserved_ips
1689
      }
1690

  
1691
    return self._SendRequest(HTTP_POST, "/%s/networks" % GANETI_RAPI_VERSION,
1692
                             query, body)
1693

  
1694
  def ConnectNetwork(self, network_name, group_name, mode, link):
1695
    """Connects a Network to a NodeGroup with the given netparams
1696

  
1697
    """
1698
    body = {
1699
      "group_name": group_name,
1700
      "network_mode": mode,
1701
      "network_link": link
1702
      }
1703

  
1704
    return self._SendRequest(HTTP_PUT,
1705
                             ("/%s/networks/%s/connect" %
1706
                             (GANETI_RAPI_VERSION, network_name)), None, body)
1707

  
1708
  def DisconnectNetwork(self, network_name, group_name):
1709
    """Connects a Network to a NodeGroup with the given netparams
1710

  
1711
    """
1712
    body = {
1713
      "group_name": group_name
1714
      }
1715
    return self._SendRequest(HTTP_PUT,
1716
                             ("/%s/networks/%s/disconnect" %
1717
                             (GANETI_RAPI_VERSION, network_name)), None, body)
1718

  
1719

  
1720
  def DeleteNetwork(self, network, dry_run=False):
1721
    """Deletes a network.
1722

  
1723
    @type group: str
1724
    @param group: the network to delete
1725
    @type dry_run: bool
1726
    @param dry_run: whether to peform a dry run
1727

  
1728
    @rtype: string
1729
    @return: job id
1730

  
1731
    """
1732
    query = []
1733
    _AppendDryRunIf(query, dry_run)
1734

  
1735
    return self._SendRequest(HTTP_DELETE,
1736
                             ("/%s/networks/%s" %
1737
                              (GANETI_RAPI_VERSION, network)), query, None)
1738

  
1628 1739
  def GetGroups(self, bulk=False):
1629 1740
    """Gets all node groups in the cluster.
1630 1741

  

Also available in: Unified diff