Revision 445d7262 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
                    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
      "reserved_ips": 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
  def ConnectNetworkAll(self, network_name, mode, link):
1720
    """Connects a Network to a NodeGroup with the given netparams
1721

  
1722
    """
1723
    body = {
1724
      "network_mode": mode,
1725
      "network_link": link
1726
      }
1727

  
1728
    return self._SendRequest(HTTP_PUT,
1729
                             ("/%s/networks/%s/connectall" %
1730
                             (GANETI_RAPI_VERSION, network_name)), None, body)
1731

  
1732
  def DisconnectNetworkAll(self, network_name):
1733
    """Connects a Network to a NodeGroup with the given netparams
1734

  
1735
    """
1736
    return self._SendRequest(HTTP_PUT,
1737
                             ("/%s/networks/%s/disconnectall" %
1738
                             (GANETI_RAPI_VERSION, network_name)), None, None)
1739

  
1740
  def DeleteNetwork(self, network, dry_run=False):
1741
    """Deletes a network.
1742

  
1743
    @type group: str
1744
    @param group: the network to delete
1745
    @type dry_run: bool
1746
    @param dry_run: whether to peform a dry run
1747

  
1748
    @rtype: string
1749
    @return: job id
1750

  
1751
    """
1752
    query = []
1753
    _AppendDryRunIf(query, dry_run)
1754

  
1755
    return self._SendRequest(HTTP_DELETE,
1756
                             ("/%s/networks/%s" %
1757
                              (GANETI_RAPI_VERSION, network)), query, None)
1758

  
1628 1759
  def GetGroups(self, bulk=False):
1629 1760
    """Gets all node groups in the cluster.
1630 1761

  

Also available in: Unified diff