summaryrefslogtreecommitdiff
path: root/openstackclient/network
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2018-01-29 09:59:08 -0600
committerMonty Taylor <mordred@inaugust.com>2018-01-29 12:05:22 -0600
commita742e47ecf86ef514d124ec5d10df197c01b253b (patch)
treeffbaa70058663ac3d28ca601769474444413e654 /openstackclient/network
parent2ef279ab71eb56860bc0ff10e14b8a865773f83a (diff)
downloadpython-openstackclient-a742e47ecf86ef514d124ec5d10df197c01b253b.tar.gz
Use find_ip from openstacksdk
The find_ip from openstacksdk started being usable by OSC back in 0.9.15 but the local method never got replaced. Change-Id: I18a334280e5f384f8bb96198cdad79c612a02290
Diffstat (limited to 'openstackclient/network')
-rw-r--r--openstackclient/network/v2/floating_ip.py64
1 files changed, 4 insertions, 60 deletions
diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py
index 181f88c0..a6f03404 100644
--- a/openstackclient/network/v2/floating_ip.py
+++ b/openstackclient/network/v2/floating_ip.py
@@ -15,8 +15,6 @@
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
@@ -86,54 +84,6 @@ def _get_attrs(client_manager, parsed_args):
return attrs
-def _find_floating_ip(
- session,
- name_or_id,
- ignore_missing=True,
- **params
-):
- """Find a floating IP by IP or ID
-
- The SDK's find_ip() can only locate a floating IP by ID so we have
- to do this ourselves.
- """
- def _get_one_match(name_or_id):
- """Given a list of results, return the match"""
- the_result = None
- ip_list = list(_floating_ip.FloatingIP.list(session, **params))
- for maybe_result in ip_list:
- id_value = maybe_result.id
- ip_value = maybe_result.floating_ip_address
-
- if (id_value == name_or_id) or (ip_value == name_or_id):
- # Only allow one resource to be found. If we already
- # found a match, raise an exception to show it.
- if the_result is None:
- the_result = maybe_result
- else:
- msg = "More than one %s exists with the name '%s'."
- msg = (msg % (_floating_ip.FloatingIP, name_or_id))
- raise sdk_exceptions.DuplicateResource(msg)
-
- return the_result
-
- # Try to short-circuit by looking directly for a matching ID.
- try:
- match = _floating_ip.FloatingIP.existing(id=name_or_id, **params)
- return match.get(session)
- except sdk_exceptions.NotFoundException:
- pass
-
- result = _get_one_match(name_or_id)
- if result is not None:
- return result
-
- if ignore_missing:
- return None
- raise sdk_exceptions.ResourceNotFound(
- "No %s found for %s" % (_floating_ip.FloatingIP.__name__, name_or_id))
-
-
class CreateFloatingIP(common.NetworkAndComputeShowOne):
_description = _("Create floating IP")
@@ -246,8 +196,7 @@ class DeleteFloatingIP(common.NetworkAndComputeDelete):
return parser
def take_action_network(self, client, parsed_args):
- obj = _find_floating_ip(
- self.app.client_manager.sdk_connection.session,
+ obj = client.find_ip(
self.r,
ignore_missing=False,
)
@@ -487,9 +436,7 @@ class SetFloatingIP(command.Command):
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,
+ obj = client.find_ip(
parsed_args.floating_ip,
ignore_missing=False,
)
@@ -521,8 +468,7 @@ class ShowFloatingIP(common.NetworkAndComputeShowOne):
return parser
def take_action_network(self, client, parsed_args):
- obj = _find_floating_ip(
- self.app.client_manager.sdk_connection.session,
+ obj = client.find_ip(
parsed_args.floating_ip,
ignore_missing=False,
)
@@ -586,9 +532,7 @@ class UnsetFloatingIP(command.Command):
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,
+ obj = client.find_ip(
parsed_args.floating_ip,
ignore_missing=False,
)