Revision a7f860c1 lib/rapi/client.py
b/lib/rapi/client.py | ||
---|---|---|
1686 | 1686 |
("/%s/nodes/%s/tags" % |
1687 | 1687 |
(GANETI_RAPI_VERSION, node)), query, None) |
1688 | 1688 |
|
1689 |
def GetNetworks(self, bulk=False): |
|
1690 |
"""Gets all networks in the cluster. |
|
1691 |
|
|
1692 |
@type bulk: bool |
|
1693 |
@param bulk: whether to return all information about the networks |
|
1694 |
|
|
1695 |
@rtype: list of dict or str |
|
1696 |
@return: if bulk is true, a list of dictionaries with info about all |
|
1697 |
networks in the cluster, else a list of names of those networks |
|
1698 |
|
|
1699 |
""" |
|
1700 |
query = [] |
|
1701 |
_AppendIf(query, bulk, ("bulk", 1)) |
|
1702 |
|
|
1703 |
networks = self._SendRequest(HTTP_GET, "/%s/networks" % GANETI_RAPI_VERSION, |
|
1704 |
query, None) |
|
1705 |
if bulk: |
|
1706 |
return networks |
|
1707 |
else: |
|
1708 |
return [n["name"] for n in networks] |
|
1709 |
|
|
1710 |
def GetNetwork(self, network): |
|
1711 |
"""Gets information about a network. |
|
1712 |
|
|
1713 |
@type group: str |
|
1714 |
@param group: name of the network whose info to return |
|
1715 |
|
|
1716 |
@rtype: dict |
|
1717 |
@return: info about the network |
|
1718 |
|
|
1719 |
""" |
|
1720 |
return self._SendRequest(HTTP_GET, |
|
1721 |
"/%s/networks/%s" % (GANETI_RAPI_VERSION, network), |
|
1722 |
None, None) |
|
1723 |
|
|
1724 |
def CreateNetwork(self, network_name, network, gateway=None, network6=None, |
|
1725 |
gateway6=None, mac_prefix=None, network_type=None, |
|
1726 |
add_reserved_ips=None, dry_run=False): |
|
1727 |
"""Creates a new network. |
|
1728 |
|
|
1729 |
@type name: str |
|
1730 |
@param name: the name of network to create |
|
1731 |
@type dry_run: bool |
|
1732 |
@param dry_run: whether to peform a dry run |
|
1733 |
|
|
1734 |
@rtype: string |
|
1735 |
@return: job id |
|
1736 |
|
|
1737 |
""" |
|
1738 |
query = [] |
|
1739 |
_AppendDryRunIf(query, dry_run) |
|
1740 |
|
|
1741 |
body = { |
|
1742 |
"network_name": network_name, |
|
1743 |
"gateway": gateway, |
|
1744 |
"network": network, |
|
1745 |
"gateway6": gateway6, |
|
1746 |
"network6": network6, |
|
1747 |
"mac_prefix": mac_prefix, |
|
1748 |
"network_type": network_type, |
|
1749 |
"add_reserved_ips": add_reserved_ips |
|
1750 |
} |
|
1751 |
|
|
1752 |
return self._SendRequest(HTTP_POST, "/%s/networks" % GANETI_RAPI_VERSION, |
|
1753 |
query, body) |
|
1754 |
|
|
1755 |
def ConnectNetwork(self, network_name, group_name, mode, link): |
|
1756 |
"""Connects a Network to a NodeGroup with the given netparams |
|
1757 |
|
|
1758 |
""" |
|
1759 |
body = { |
|
1760 |
"group_name": group_name, |
|
1761 |
"network_mode": mode, |
|
1762 |
"network_link": link |
|
1763 |
} |
|
1764 |
|
|
1765 |
return self._SendRequest(HTTP_PUT, |
|
1766 |
("/%s/networks/%s/connect" % |
|
1767 |
(GANETI_RAPI_VERSION, network_name)), None, body) |
|
1768 |
|
|
1769 |
def DisconnectNetwork(self, network_name, group_name): |
|
1770 |
"""Connects a Network to a NodeGroup with the given netparams |
|
1771 |
|
|
1772 |
""" |
|
1773 |
body = { |
|
1774 |
"group_name": group_name |
|
1775 |
} |
|
1776 |
return self._SendRequest(HTTP_PUT, |
|
1777 |
("/%s/networks/%s/disconnect" % |
|
1778 |
(GANETI_RAPI_VERSION, network_name)), None, body) |
|
1779 |
|
|
1780 |
|
|
1781 |
def DeleteNetwork(self, network, dry_run=False): |
|
1782 |
"""Deletes a network. |
|
1783 |
|
|
1784 |
@type group: str |
|
1785 |
@param group: the network to delete |
|
1786 |
@type dry_run: bool |
|
1787 |
@param dry_run: whether to peform a dry run |
|
1788 |
|
|
1789 |
@rtype: string |
|
1790 |
@return: job id |
|
1791 |
|
|
1792 |
""" |
|
1793 |
query = [] |
|
1794 |
_AppendDryRunIf(query, dry_run) |
|
1795 |
|
|
1796 |
return self._SendRequest(HTTP_DELETE, |
|
1797 |
("/%s/networks/%s" % |
|
1798 |
(GANETI_RAPI_VERSION, network)), query, None) |
|
1799 |
|
|
1689 | 1800 |
def GetGroups(self, bulk=False): |
1690 | 1801 |
"""Gets all node groups in the cluster. |
1691 | 1802 |
|
Also available in: Unified diff