Don't restrict ids to int.

This commit is contained in:
Josh Kearney 2011-06-09 10:38:01 -05:00
parent 117e455bb6
commit d778d4278e
2 changed files with 8 additions and 3 deletions
novaclient

@ -32,12 +32,12 @@ except NameError:
def getid(obj):
"""
Abstracts the common pattern of allowing both an object or an object's ID
(integer) as a parameter when dealing with relationships.
(UUID) as a parameter when dealing with relationships.
"""
try:
return obj.id
except AttributeError:
return int(obj)
return obj
class Manager(object):

@ -27,6 +27,7 @@ import os
import prettytable
import sys
import textwrap
import uuid
# Choices for flags.
DAY_CHOICES = [getattr(novaclient, i).lower()
@ -664,7 +665,11 @@ class OpenStackShell(object):
try:
if isinstance(name_or_id, int) or name_or_id.isdigit():
return manager.get(int(name_or_id))
else:
try:
uuid.UUID(name_or_id)
return manager.get(name_or_id)
except ValueError:
return manager.find(name=name_or_id)
except novaclient.NotFound:
raise CommandError("No %s with a name or ID of '%s' exists." %