From e6ea45b2833fdd57a8011154aec5c1f6b00f44ca Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Sat, 8 Apr 2017 11:17:30 -0500 Subject: Low-level Compute v2 API: floating ip api.compute.APIv2 floating ip 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: Ic461b8d15e072e0534dcd73fff6857581d83c89b --- openstackclient/api/compute_v2.py | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'openstackclient/api') diff --git a/openstackclient/api/compute_v2.py b/openstackclient/api/compute_v2.py index 3bf3a0d8..20062a2f 100644 --- a/openstackclient/api/compute_v2.py +++ b/openstackclient/api/compute_v2.py @@ -64,6 +64,88 @@ class APIv2(api.BaseAPI): return ret + # Flaoting IPs + + def floating_ip_create( + self, + pool=None, + ): + """Create a new floating ip + + https://developer.openstack.org/api-ref/compute/#create-allocate-floating-ip-address + + :param pool: Name of floating IP pool + """ + + url = "/os-floating-ips" + + try: + return self.create( + url, + json={'pool': pool}, + )['floating_ip'] + except ( + ksa_exceptions.NotFound, + ksa_exceptions.BadRequest, + ): + msg = _("%s not found") % pool + raise exceptions.NotFound(msg) + + def floating_ip_delete( + self, + floating_ip_id=None, + ): + """Delete a floating IP + + https://developer.openstack.org/api-ref/compute/#delete-deallocate-floating-ip-address + + :param string security_group: + Floating IP ID + """ + + url = "/os-floating-ips" + + if floating_ip_id is not None: + return self.delete('/%s/%s' % (url, floating_ip_id)) + + return None + + def floating_ip_find( + self, + floating_ip=None, + ): + """Return a security group given name or ID + + https://developer.openstack.org/api-ref/compute/#list-floating-ip-addresses + + :param string floating_ip: + Floating IP address + :returns: A dict of the floating IP attributes + """ + + url = "/os-floating-ips" + + return self.find( + url, + attr='ip', + value=floating_ip, + ) + + def floating_ip_list( + self, + ): + """Get floating IPs + + https://developer.openstack.org/api-ref/compute/#show-floating-ip-address-details + + :returns: + list of security groups names + """ + + url = "/os-floating-ips" + + return self.list(url)["floating_ips"] + # Security Groups def security_group_create( -- cgit v1.2.1