Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

Commit 75fcafb

Browse files
author
Dan Wendlandt
committed
prevent floatingip-show and floatingip-delete from querying by "name"
bug 1048088 floating IPs do not have names, but the show and delete commands inherited logic that implied that they did, leading to very odd results that would result is "floating-ip show X" return a result even if X was not a valid UUID for any floating IP. Change-Id: I5939a2a28ae4abf94d44fadb75a657fe706f1295
1 parent 99d7d70 commit 75fcafb

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

quantumclient/quantum/v2_0/__init__.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,17 @@ class DeleteCommand(QuantumCommand):
307307
api = 'network'
308308
resource = None
309309
log = None
310+
allow_names = True
310311

311312
def get_parser(self, prog_name):
312313
parser = super(DeleteCommand, self).get_parser(prog_name)
314+
if self.allow_names:
315+
help_str = 'ID or name of %s to delete'
316+
else:
317+
help_str = 'ID of %s to delete'
313318
parser.add_argument(
314319
'id', metavar=self.resource,
315-
help='ID or name of %s to delete' % self.resource)
320+
help=help_str % self.resource)
316321
return parser
317322

318323
def run(self, parsed_args):
@@ -321,9 +326,11 @@ def run(self, parsed_args):
321326
quantum_client.format = parsed_args.request_format
322327
obj_deleter = getattr(quantum_client,
323328
"delete_%s" % self.resource)
324-
_id = find_resourceid_by_name_or_id(quantum_client,
325-
self.resource,
326-
parsed_args.id)
329+
if self.allow_names:
330+
_id = find_resourceid_by_name_or_id(quantum_client, self.resource,
331+
parsed_args.id)
332+
else:
333+
_id = parsed_args.id
327334
obj_deleter(_id)
328335
print >>self.app.stdout, (_('Deleted %(resource)s: %(id)s')
329336
% {'id': parsed_args.id,
@@ -396,13 +403,18 @@ class ShowCommand(QuantumCommand, show.ShowOne):
396403
api = 'network'
397404
resource = None
398405
log = None
406+
allow_names = True
399407

400408
def get_parser(self, prog_name):
401409
parser = super(ShowCommand, self).get_parser(prog_name)
402410
add_show_list_common_argument(parser)
411+
if self.allow_names:
412+
help_str = 'ID or name of %s to look up'
413+
else:
414+
help_str = 'ID of %s to look up'
403415
parser.add_argument(
404416
'id', metavar=self.resource,
405-
help='ID or name of %s to look up' % self.resource)
417+
help=help_str % self.resource)
406418
return parser
407419

408420
def get_data(self, parsed_args):
@@ -415,8 +427,12 @@ def get_data(self, parsed_args):
415427
params = {'verbose': 'True'}
416428
if parsed_args.fields:
417429
params = {'fields': parsed_args.fields}
418-
_id = find_resourceid_by_name_or_id(quantum_client, self.resource,
419-
parsed_args.id)
430+
if self.allow_names:
431+
_id = find_resourceid_by_name_or_id(quantum_client, self.resource,
432+
parsed_args.id)
433+
else:
434+
_id = parsed_args.id
435+
420436
obj_shower = getattr(quantum_client, "show_%s" % self.resource)
421437
data = obj_shower(_id, **params)
422438
if self.resource in data:

quantumclient/quantum/v2_0/floatingip.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ShowFloatingIP(ShowCommand):
3939

4040
resource = 'floatingip'
4141
log = logging.getLogger(__name__ + '.ShowFloatingIP')
42+
allow_names = False
4243

4344

4445
class CreateFloatingIP(CreateCommand):
@@ -80,6 +81,7 @@ class DeleteFloatingIP(DeleteCommand):
8081

8182
log = logging.getLogger(__name__ + '.DeleteFloatingIP')
8283
resource = 'floatingip'
84+
allow_names = False
8385

8486

8587
class AssociateFloatingIP(QuantumCommand):

0 commit comments

Comments
 (0)