From 763c8c5670f238920398165e670592e006213f32 Mon Sep 17 00:00:00 2001 From: Sindhu Devale Date: Thu, 6 Oct 2016 10:01:59 -0500 Subject: "floating ip set/unset port" for OSC Implements Neutron feature of floating ip associate/disassociate into OpenStack Client. Previously, network.find_ip() function only supported to search floating ip by UUID. Hence, _find_floating_ip() function is used in floating_ip.py, to search fip both by UUID and ip_address. [1] adds the ability to find fip object using both UUID and ip_address. This functionality however, won't be available until the SDK is released. Hence, we continue to use _find_floating_ip() method, which was cleaned up by [2] to remove the use of ip_cache. Once, the SDK is released, we will remove all the usage of _find_floating_ip() method and instead only use network.find_ip(). [1] https://review.openstack.org/#/c/449879/2 [2] https://review.openstack.org/#/c/447938/ Change-Id: I6c5222287c46ca42365917d2deae70bdb626347 Co-Authored-By: Reedip Co-Authored-By: RuiChen Closes-Bug: #1560297 --- openstackclient/network/v2/floating_ip.py | 76 ++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) (limited to 'openstackclient/network/v2') diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py index 3ac76aa3..9bfc7a64 100644 --- a/openstackclient/network/v2/floating_ip.py +++ b/openstackclient/network/v2/floating_ip.py @@ -17,6 +17,7 @@ import logging from openstack import exceptions as sdk_exceptions from openstack.network.v2 import floating_ip as _floating_ip +from osc_lib.command import command from osc_lib import utils from openstackclient.i18n import _ @@ -164,7 +165,7 @@ class CreateFloatingIP(common.NetworkAndComputeShowOne): ) parser.add_argument( '--fixed-ip-address', - metavar='', + metavar='', dest='fixed_ip_address', help=_("Fixed IP address mapped to the floating IP") ) @@ -446,6 +447,47 @@ class ListIPFloating(ListFloatingIP): client, parsed_args) +class SetFloatingIP(command.Command): + _description = _("Set floating IP Properties") + + def get_parser(self, prog_name): + parser = super(SetFloatingIP, self).get_parser(prog_name) + parser.add_argument( + 'floating_ip', + metavar='', + help=_("Floating IP to associate (IP address or ID)")) + parser.add_argument( + '--port', + metavar='', + required=True, + help=_("Assocaite the floating IP with port (name or ID)")), + parser.add_argument( + '--fixed-ip-address', + metavar='', + dest='fixed_ip_address', + help=_("Fixed IP of the port " + "(required only if port has multiple IPs)") + ) + return parser + + def take_action(self, parsed_args): + client = self.app.client_manager.network + attrs = {} + # TODO(sindhu) Use client.find_ip() once SDK 0.9.15 is released + obj = _find_floating_ip( + self.app.client_manager.sdk_connection.session, + parsed_args.floating_ip, + ignore_missing=False, + ) + port = client.find_port(parsed_args.port, + ignore_missing=False) + attrs['port_id'] = port.id + if parsed_args.fixed_ip_address: + attrs['fixed_ip_address'] = parsed_args.fixed_ip_address + + client.update_ip(obj, **attrs) + + class ShowFloatingIP(common.NetworkAndComputeShowOne): _description = _("Display floating IP details") @@ -499,3 +541,35 @@ class ShowIPFloating(ShowFloatingIP): 'Please use "floating ip show" instead.')) return super(ShowIPFloating, self).take_action_compute( client, parsed_args) + + +class UnsetFloatingIP(command.Command): + _description = _("Unset floating IP Properties") + + def get_parser(self, prog_name): + parser = super(UnsetFloatingIP, self).get_parser(prog_name) + parser.add_argument( + 'floating_ip', + metavar='', + help=_("Floating IP to disassociate (IP address or ID)")) + parser.add_argument( + '--port', + action='store_true', + default=False, + help=_("Disassociate any port associated with the floating IP") + ) + return parser + + def take_action(self, parsed_args): + client = self.app.client_manager.network + # TODO(sindhu) Use client.find_ip() once SDK 0.9.15 is released + obj = _find_floating_ip( + self.app.client_manager.sdk_connection.session, + parsed_args.floating_ip, + ignore_missing=False, + ) + if parsed_args.port: + attrs = { + 'port_id': None, + } + client.update_ip(obj, **attrs) -- cgit v1.2.1