@@ -83,7 +83,6 @@ def _get_attrs(client_manager, parsed_args):
8383
8484def _find_floating_ip (
8585 session ,
86- ip_cache ,
8786 name_or_id ,
8887 ignore_missing = True ,
8988 ** params
@@ -93,11 +92,11 @@ def _find_floating_ip(
9392 The SDK's find_ip() can only locate a floating IP by ID so we have
9493 to do this ourselves.
9594 """
96-
9795 def _get_one_match (name_or_id ):
9896 """Given a list of results, return the match"""
9997 the_result = None
100- for maybe_result in ip_cache :
98+ ip_list = list (_floating_ip .FloatingIP .list (session , ** params ))
99+ for maybe_result in ip_list :
101100 id_value = maybe_result .id
102101 ip_value = maybe_result .floating_ip_address
103102
@@ -116,19 +115,16 @@ def _get_one_match(name_or_id):
116115 # Try to short-circuit by looking directly for a matching ID.
117116 try :
118117 match = _floating_ip .FloatingIP .existing (id = name_or_id , ** params )
119- return ( match .get (session ), ip_cache )
118+ return match .get (session )
120119 except sdk_exceptions .NotFoundException :
121120 pass
122121
123- if len (ip_cache ) == 0 :
124- ip_cache = list (_floating_ip .FloatingIP .list (session , ** params ))
125-
126122 result = _get_one_match (name_or_id )
127123 if result is not None :
128- return ( result , ip_cache )
124+ return result
129125
130126 if ignore_missing :
131- return ( None , ip_cache )
127+ return None
132128 raise sdk_exceptions .ResourceNotFound (
133129 "No %s found for %s" % (_floating_ip .FloatingIP .__name__ , name_or_id ))
134130
@@ -240,9 +236,8 @@ def update_parser_common(self, parser):
240236 return parser
241237
242238 def take_action_network (self , client , parsed_args ):
243- ( obj , self . ip_cache ) = _find_floating_ip (
239+ obj = _find_floating_ip (
244240 self .app .client_manager .sdk_connection .session ,
245- self .ip_cache ,
246241 self .r ,
247242 ignore_missing = False ,
248243 )
@@ -255,11 +250,6 @@ def take_action_compute(self, client, parsed_args):
255250 def take_action (self , parsed_args ):
256251 """Implements a naive cache for the list of floating IPs"""
257252
258- # NOTE(dtroyer): This really only prevents multiple list()
259- # calls when performing multiple resource deletes
260- # in a single command. In an interactive session
261- # each delete command will call list().
262- self .ip_cache = []
263253 super (DeleteFloatingIP , self ).take_action (parsed_args )
264254
265255
@@ -459,9 +449,6 @@ def take_action_compute(self, client, parsed_args):
459449class ShowFloatingIP (common .NetworkAndComputeShowOne ):
460450 _description = _ ("Display floating IP details" )
461451
462- # ip_cache is unused here but is a side effect of _find_floating_ip()
463- ip_cache = []
464-
465452 def update_parser_common (self , parser ):
466453 parser .add_argument (
467454 'floating_ip' ,
@@ -471,9 +458,8 @@ def update_parser_common(self, parser):
471458 return parser
472459
473460 def take_action_network (self , client , parsed_args ):
474- ( obj , self . ip_cache ) = _find_floating_ip (
461+ obj = _find_floating_ip (
475462 self .app .client_manager .sdk_connection .session ,
476- [],
477463 parsed_args .floating_ip ,
478464 ignore_missing = False ,
479465 )
0 commit comments