From 97da33fcf599efeb29d7e496d34a450c78c557f5 Mon Sep 17 00:00:00 2001
From: fujioka yuuichi <fujioka-yuuichi@zx.mxh.nes.nec.co.jp>
Date: Mon, 2 Sep 2013 11:03:50 +0900
Subject: [PATCH] Allow name argument to flavor-access-add

Administrator cannot use the flavor name in arguments of
"nova flavor-access-add" and "nova flavor-access-remove".

This patch fixes this problem.

Change-Id: I68b267dc071382f1978efc2088cd8e837455e8b4
Related-Bug: #1205298
---
 novaclient/base.py             |  7 ++++++-
 novaclient/tests/v1_1/fakes.py | 12 +++++++-----
 novaclient/utils.py            |  1 +
 novaclient/v1_1/shell.py       |  2 +-
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/novaclient/base.py b/novaclient/base.py
index b26134aa1..b80f9412f 100644
--- a/novaclient/base.py
+++ b/novaclient/base.py
@@ -212,7 +212,12 @@ class ManagerWithFind(Manager):
             list_kwargs['detailed'] = detailed
 
         if 'is_public' in list_argspec.args and 'is_public' in kwargs:
-            list_kwargs['is_public'] = kwargs['is_public']
+            is_public = kwargs['is_public']
+            list_kwargs['is_public'] = is_public
+            if is_public is None:
+                tmp_kwargs = kwargs.copy()
+                del tmp_kwargs['is_public']
+                searches = tmp_kwargs.items()
 
         listing = self.list(**list_kwargs)
 
diff --git a/novaclient/tests/v1_1/fakes.py b/novaclient/tests/v1_1/fakes.py
index 6055f1abe..7d9b88c4e 100644
--- a/novaclient/tests/v1_1/fakes.py
+++ b/novaclient/tests/v1_1/fakes.py
@@ -591,11 +591,13 @@ class FakeHTTPClient(base_client.HTTPClient):
     #
 
     def get_flavors(self, **kw):
-        return (200, {}, {'flavors': [
-            {'id': 1, 'name': '256 MB Server'},
-            {'id': 2, 'name': '512 MB Server'},
-            {'id': 'aa1', 'name': '128 MB Server'}
-        ]})
+        status, header, flavors = self.get_flavors_detail(**kw)
+        for flavor in flavors['flavors']:
+            for k in flavor.keys():
+                if k not in ['id', 'name']:
+                    del flavor[k]
+
+        return (200, {}, flavors)
 
     def get_flavors_detail(self, **kw):
         flavors = {'flavors': [
diff --git a/novaclient/utils.py b/novaclient/utils.py
index 6524605f8..ae28ca664 100644
--- a/novaclient/utils.py
+++ b/novaclient/utils.py
@@ -225,6 +225,7 @@ def find_resource(manager, name_or_id, **find_args):
             resource = getattr(manager, 'resource_class', None)
             name_attr = resource.NAME_ATTR if resource else 'name'
             kwargs = {name_attr: name_or_id}
+            kwargs.update(find_args)
             return manager.find(**kwargs)
         except exceptions.NotFound:
             msg = "No %s with a name or ID of '%s' exists." % \
diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py
index de22ada66..62194a775 100644
--- a/novaclient/v1_1/shell.py
+++ b/novaclient/v1_1/shell.py
@@ -1378,7 +1378,7 @@ def _find_image(cs, image):
 def _find_flavor_for_admin(cs, flavor):
     """Get a flavor for administrator by name, ID, or RAM size."""
     try:
-        return utils.find_resource(cs.flavors, flavor, is_public='None')
+        return utils.find_resource(cs.flavors, flavor, is_public=None)
     except exceptions.NotFound:
         return cs.flavors.find(ram=flavor)