From b2783dc3c44f5843a25770ff749d7a0de18b8dfc Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Mon, 17 Apr 2017 17:04:43 -0500 Subject: Low-level Compute v2 API: network api.compute.APIv2 network functions. novaclient 8.0 is now released without support for the previously deprecated nova-net functions, so include a new low-level REST implementation of the removed APIs. Change-Id: If230f128e91cda44461fe93c976cac2aecec2252 --- openstackclient/api/compute_v2.py | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 'openstackclient/api') diff --git a/openstackclient/api/compute_v2.py b/openstackclient/api/compute_v2.py index 181522e4..3141728a 100644 --- a/openstackclient/api/compute_v2.py +++ b/openstackclient/api/compute_v2.py @@ -175,6 +175,100 @@ class APIv2(api.BaseAPI): return self.list(url)["floating_ips"] + # Networks + + def network_create( + self, + name=None, + subnet=None, + share_subnet=None, + ): + """Create a new network + + https://developer.openstack.org/api-ref/compute/#create-project-network + + :param string name: + Network label + :param integer subnet: + Subnet for IPv4 fixed addresses in CIDR notation + :param integer share_subnet: + Shared subnet between projects, True or False + :returns: A dict of the network attributes + """ + + url = "/os-tenant-networks" + + params = { + 'label': name, + 'cidr': subnet, + 'share_address': share_subnet, + } + + return self.create( + url, + json={'network': params}, + )['network'] + + def network_delete( + self, + network=None, + ): + """Delete a network + + https://developer.openstack.org/api-ref/compute/#delete-project-network + + :param string network: + Network name or ID + """ + + url = "/os-tenant-networks" + + network = self.find( + url, + attr='label', + value=network, + )['id'] + if network is not None: + return self.delete('/%s/%s' % (url, network)) + + return None + + def network_find( + self, + network=None, + ): + """Return a network given name or ID + + https://developer.openstack.org/api-ref/compute/#show-project-network-details + + :param string network: + Network name or ID + :returns: A dict of the network attributes + """ + + url = "/os-tenant-networks" + + return self.find( + url, + attr='label', + value=network, + ) + + def network_list( + self, + ): + """Get networks + + https://developer.openstack.org/api-ref/compute/#list-project-networks + + :returns: + list of networks + """ + + url = "/os-tenant-networks" + + return self.list(url)["networks"] + # Security Groups def security_group_create( -- cgit v1.2.1