Revision 4588b4bd
b/lib/rapi/client.py | ||
---|---|---|
1688 | 1688 |
("/%s/nodes/%s/tags" % |
1689 | 1689 |
(GANETI_RAPI_VERSION, node)), query, None) |
1690 | 1690 |
|
1691 |
def GetNetworks(self, bulk=False): |
|
1692 |
"""Gets all networks in the cluster. |
|
1693 |
|
|
1694 |
@type bulk: bool |
|
1695 |
@param bulk: whether to return all information about the networks |
|
1696 |
|
|
1697 |
@rtype: list of dict or str |
|
1698 |
@return: if bulk is true, a list of dictionaries with info about all |
|
1699 |
networks in the cluster, else a list of names of those networks |
|
1700 |
|
|
1701 |
""" |
|
1702 |
query = [] |
|
1703 |
_AppendIf(query, bulk, ("bulk", 1)) |
|
1704 |
|
|
1705 |
networks = self._SendRequest(HTTP_GET, "/%s/networks" % GANETI_RAPI_VERSION, |
|
1706 |
query, None) |
|
1707 |
if bulk: |
|
1708 |
return networks |
|
1709 |
else: |
|
1710 |
return [n["name"] for n in networks] |
|
1711 |
|
|
1712 |
def GetNetwork(self, network): |
|
1713 |
"""Gets information about a network. |
|
1714 |
|
|
1715 |
@type group: str |
|
1716 |
@param group: name of the network whose info to return |
|
1717 |
|
|
1718 |
@rtype: dict |
|
1719 |
@return: info about the network |
|
1720 |
|
|
1721 |
""" |
|
1722 |
return self._SendRequest(HTTP_GET, |
|
1723 |
"/%s/networks/%s" % (GANETI_RAPI_VERSION, network), |
|
1724 |
None, None) |
|
1725 |
|
|
1726 |
def CreateNetwork(self, network_name, network, gateway=None, network6=None, |
|
1727 |
gateway6=None, mac_prefix=None, network_type=None, |
|
1728 |
add_reserved_ips=None, dry_run=False): |
|
1729 |
"""Creates a new network. |
|
1730 |
|
|
1731 |
@type name: str |
|
1732 |
@param name: the name of network to create |
|
1733 |
@type dry_run: bool |
|
1734 |
@param dry_run: whether to peform a dry run |
|
1735 |
|
|
1736 |
@rtype: string |
|
1737 |
@return: job id |
|
1738 |
|
|
1739 |
""" |
|
1740 |
query = [] |
|
1741 |
_AppendDryRunIf(query, dry_run) |
|
1742 |
|
|
1743 |
body = { |
|
1744 |
"network_name": network_name, |
|
1745 |
"gateway": gateway, |
|
1746 |
"network": network, |
|
1747 |
"gateway6": gateway6, |
|
1748 |
"network6": network6, |
|
1749 |
"mac_prefix": mac_prefix, |
|
1750 |
"network_type": network_type, |
|
1751 |
"add_reserved_ips": add_reserved_ips |
|
1752 |
} |
|
1753 |
|
|
1754 |
return self._SendRequest(HTTP_POST, "/%s/networks" % GANETI_RAPI_VERSION, |
|
1755 |
query, body) |
|
1756 |
|
|
1757 |
def ConnectNetwork(self, network_name, group_name, mode, link): |
|
1758 |
"""Connects a Network to a NodeGroup with the given netparams |
|
1759 |
|
|
1760 |
""" |
|
1761 |
body = { |
|
1762 |
"group_name": group_name, |
|
1763 |
"network_mode": mode, |
|
1764 |
"network_link": link |
|
1765 |
} |
|
1766 |
|
|
1767 |
return self._SendRequest(HTTP_PUT, |
|
1768 |
("/%s/networks/%s/connect" % |
|
1769 |
(GANETI_RAPI_VERSION, network_name)), None, body) |
|
1770 |
|
|
1771 |
def DisconnectNetwork(self, network_name, group_name): |
|
1772 |
"""Connects a Network to a NodeGroup with the given netparams |
|
1773 |
|
|
1774 |
""" |
|
1775 |
body = { |
|
1776 |
"group_name": group_name |
|
1777 |
} |
|
1778 |
return self._SendRequest(HTTP_PUT, |
|
1779 |
("/%s/networks/%s/disconnect" % |
|
1780 |
(GANETI_RAPI_VERSION, network_name)), None, body) |
|
1781 |
|
|
1782 |
|
|
1783 |
def DeleteNetwork(self, network, dry_run=False): |
|
1784 |
"""Deletes a network. |
|
1785 |
|
|
1786 |
@type group: str |
|
1787 |
@param group: the network to delete |
|
1788 |
@type dry_run: bool |
|
1789 |
@param dry_run: whether to peform a dry run |
|
1790 |
|
|
1791 |
@rtype: string |
|
1792 |
@return: job id |
|
1793 |
|
|
1794 |
""" |
|
1795 |
query = [] |
|
1796 |
_AppendDryRunIf(query, dry_run) |
|
1797 |
|
|
1798 |
return self._SendRequest(HTTP_DELETE, |
|
1799 |
("/%s/networks/%s" % |
|
1800 |
(GANETI_RAPI_VERSION, network)), query, None) |
|
1801 |
|
|
1691 | 1802 |
def GetGroups(self, bulk=False): |
1692 | 1803 |
"""Gets all node groups in the cluster. |
1693 | 1804 |
|
b/lib/rapi/connector.py | ||
---|---|---|
89 | 89 |
|
90 | 90 |
|
91 | 91 |
def GetHandlers(node_name_pattern, instance_name_pattern, |
92 |
group_name_pattern, job_id_pattern, disk_pattern, |
|
92 |
group_name_pattern, network_name_pattern, |
|
93 |
job_id_pattern, disk_pattern, |
|
93 | 94 |
query_res_pattern): |
94 | 95 |
"""Returns all supported resources and their handlers. |
95 | 96 |
|
... | ... | |
167 | 168 |
re.compile(r"^/2/instances/(%s)/console$" % instance_name_pattern): |
168 | 169 |
rlib2.R_2_instances_name_console, |
169 | 170 |
|
171 |
"/2/networks": rlib2.R_2_networks, |
|
172 |
re.compile(r"^/2/networks/(%s)$" % network_name_pattern): |
|
173 |
rlib2.R_2_networks_name, |
|
174 |
re.compile(r"^/2/networks/(%s)/connect$" % network_name_pattern): |
|
175 |
rlib2.R_2_networks_name_connect, |
|
176 |
re.compile(r"^/2/networks/(%s)/disconnect$" % network_name_pattern): |
|
177 |
rlib2.R_2_networks_name_disconnect, |
|
178 |
|
|
170 | 179 |
"/2/groups": rlib2.R_2_groups, |
171 | 180 |
re.compile(r"^/2/groups/(%s)$" % group_name_pattern): |
172 | 181 |
rlib2.R_2_groups_name, |
... | ... | |
198 | 207 |
} |
199 | 208 |
|
200 | 209 |
|
201 |
CONNECTOR.update(GetHandlers(_NAME_PATTERN, _NAME_PATTERN, _NAME_PATTERN, |
|
210 |
CONNECTOR.update(GetHandlers(_NAME_PATTERN, _NAME_PATTERN, |
|
211 |
_NAME_PATTERN, _NAME_PATTERN, |
|
202 | 212 |
constants.JOB_ID_TEMPLATE, _DISK_PATTERN, |
203 | 213 |
_NAME_PATTERN)) |
b/lib/rapi/rlib2.py | ||
---|---|---|
71 | 71 |
I_FIELDS = ["name", "admin_state", "os", |
72 | 72 |
"pnode", "snodes", |
73 | 73 |
"disk_template", |
74 |
"nic.ips", "nic.macs", "nic.modes", "nic.links", "nic.bridges", |
|
74 |
"nic.ips", "nic.macs", "nic.modes", |
|
75 |
"nic.links", "nic.networks", "nic.bridges", |
|
75 | 76 |
"network_port", |
76 | 77 |
"disk.sizes", "disk_usage", |
77 | 78 |
"beparams", "hvparams", |
... | ... | |
91 | 92 |
"group.uuid", |
92 | 93 |
] + _COMMON_FIELDS |
93 | 94 |
|
95 |
NET_FIELDS = ["name", "network", "gateway", |
|
96 |
"network6", "gateway6", |
|
97 |
"mac_prefix", "network_type", |
|
98 |
"free_count", "reserved_count", |
|
99 |
"map", "group_list", "inst_list", |
|
100 |
"external_reservations", |
|
101 |
] |
|
102 |
|
|
94 | 103 |
G_FIELDS = [ |
95 | 104 |
"alloc_policy", |
96 | 105 |
"name", |
... | ... | |
643 | 652 |
}) |
644 | 653 |
|
645 | 654 |
|
655 |
class R_2_networks(baserlib.OpcodeResource): |
|
656 |
"""/2/networks resource. |
|
657 |
|
|
658 |
""" |
|
659 |
GET_OPCODE = opcodes.OpNetworkQuery |
|
660 |
POST_OPCODE = opcodes.OpNetworkAdd |
|
661 |
POST_RENAME = { |
|
662 |
"name": "network_name", |
|
663 |
} |
|
664 |
|
|
665 |
def GetPostOpInput(self): |
|
666 |
"""Create a network. |
|
667 |
|
|
668 |
""" |
|
669 |
assert not self.items |
|
670 |
return (self.request_body, { |
|
671 |
"dry_run": self.dryRun(), |
|
672 |
}) |
|
673 |
|
|
674 |
def GET(self): |
|
675 |
"""Returns a list of all networks. |
|
676 |
|
|
677 |
""" |
|
678 |
client = self.GetClient() |
|
679 |
|
|
680 |
if self.useBulk(): |
|
681 |
bulkdata = client.QueryNetworks([], NET_FIELDS, False) |
|
682 |
return baserlib.MapBulkFields(bulkdata, NET_FIELDS) |
|
683 |
else: |
|
684 |
data = client.QueryNetworks([], ["name"], False) |
|
685 |
networknames = [row[0] for row in data] |
|
686 |
return baserlib.BuildUriList(networknames, "/2/networks/%s", |
|
687 |
uri_fields=("name", "uri")) |
|
688 |
|
|
689 |
|
|
690 |
class R_2_networks_name(baserlib.OpcodeResource): |
|
691 |
"""/2/network/[network_name] resource. |
|
692 |
|
|
693 |
""" |
|
694 |
DELETE_OPCODE = opcodes.OpNetworkRemove |
|
695 |
|
|
696 |
def GET(self): |
|
697 |
"""Send information about a network. |
|
698 |
|
|
699 |
""" |
|
700 |
network_name = self.items[0] |
|
701 |
client = self.GetClient() |
|
702 |
|
|
703 |
result = baserlib.HandleItemQueryErrors(client.QueryNetworks, |
|
704 |
names=[network_name], |
|
705 |
fields=NET_FIELDS, |
|
706 |
use_locking=self.useLocking()) |
|
707 |
|
|
708 |
return baserlib.MapFields(NET_FIELDS, result[0]) |
|
709 |
|
|
710 |
def GetDeleteOpInput(self): |
|
711 |
"""Delete a network. |
|
712 |
|
|
713 |
""" |
|
714 |
assert len(self.items) == 1 |
|
715 |
return (self.request_body, { |
|
716 |
"network_name": self.items[0], |
|
717 |
"dry_run": self.dryRun(), |
|
718 |
}) |
|
719 |
|
|
720 |
class R_2_networks_name_connect(baserlib.OpcodeResource): |
|
721 |
"""/2/network/[network_name]/connect. |
|
722 |
|
|
723 |
""" |
|
724 |
PUT_OPCODE = opcodes.OpNetworkConnect |
|
725 |
|
|
726 |
def GetPutOpInput(self): |
|
727 |
"""Changes some parameters of node group. |
|
728 |
|
|
729 |
""" |
|
730 |
assert self.items |
|
731 |
return (self.request_body, { |
|
732 |
"network_name": self.items[0], |
|
733 |
}) |
|
734 |
|
|
735 |
class R_2_networks_name_disconnect(baserlib.OpcodeResource): |
|
736 |
"""/2/network/[network_name]/disconnect. |
|
737 |
|
|
738 |
""" |
|
739 |
PUT_OPCODE = opcodes.OpNetworkDisconnect |
|
740 |
|
|
741 |
def GetPutOpInput(self): |
|
742 |
"""Changes some parameters of node group. |
|
743 |
|
|
744 |
""" |
|
745 |
assert self.items |
|
746 |
return (self.request_body, { |
|
747 |
"network_name": self.items[0], |
|
748 |
}) |
|
749 |
|
|
646 | 750 |
class R_2_groups(baserlib.OpcodeResource): |
647 | 751 |
"""/2/groups resource. |
648 | 752 |
|
... | ... | |
656 | 760 |
def GetPostOpInput(self): |
657 | 761 |
"""Create a node group. |
658 | 762 |
|
763 |
|
|
659 | 764 |
""" |
660 | 765 |
assert not self.items |
661 | 766 |
return (self.request_body, { |
Also available in: Unified diff