summaryrefslogtreecommitdiff
path: root/openstackclient/api
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2017-04-17 17:04:43 -0500
committerDean Troyer <dtroyer@gmail.com>2017-04-17 19:45:21 -0500
commitb2783dc3c44f5843a25770ff749d7a0de18b8dfc (patch)
treed8ea54d2425533d23f5771223f88a334600856ad /openstackclient/api
parent6f473be588a7d0dcd10ca189e3e1dba45a6eb2fe (diff)
downloadpython-openstackclient-b2783dc3c44f5843a25770ff749d7a0de18b8dfc.tar.gz
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
Diffstat (limited to 'openstackclient/api')
-rw-r--r--openstackclient/api/compute_v2.py94
1 files changed, 94 insertions, 0 deletions
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(