summaryrefslogtreecommitdiff
path: root/openstackclient/network/v2
diff options
context:
space:
mode:
authorSindhu Devale <sindhu.devale@intel.com>2016-10-06 10:01:59 -0500
committerDean Troyer <dtroyer@gmail.com>2017-04-05 16:12:40 +0000
commit763c8c5670f238920398165e670592e006213f32 (patch)
treec8b6c7f1dce72d35dc77389a488f5312d88d6cfa /openstackclient/network/v2
parent0e42ea3ae325cf5b168bb966e62cd6b8e9ee0159 (diff)
downloadpython-openstackclient-763c8c5670f238920398165e670592e006213f32.tar.gz
"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<reedip.banerjee@nectechnologies.in> Co-Authored-By: RuiChen<chenrui.momo@gmail.com> Closes-Bug: #1560297
Diffstat (limited to 'openstackclient/network/v2')
-rw-r--r--openstackclient/network/v2/floating_ip.py76
1 files changed, 75 insertions, 1 deletions
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='<fixed-ip-address>',
+ metavar='<ip-address>',
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='<floating-ip>',
+ help=_("Floating IP to associate (IP address or ID)"))
+ parser.add_argument(
+ '--port',
+ metavar='<port>',
+ required=True,
+ help=_("Assocaite the floating IP with port (name or ID)")),
+ parser.add_argument(
+ '--fixed-ip-address',
+ metavar='<ip-address>',
+ 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='<floating-ip>',
+ 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)