Juan Hernandez has uploaded a new change for review.

Change subject: cli: Don't get by name in collections without name
......................................................................

cli: Don't get by name in collections without name

Some collections, for example the disks collection, don't support
retrieving an entity by name as the corresponding entity doesn't have a
name attribute. But we don't take that into account when trying to find
an object by identifier. As a result commands like the following:

  # show disk mydisk

Cause the following error message:

  unknown error: get() got an unexpected keyword argument 'name'

The reason is that we are calling the "get" method of the collection
passing a "name" parameter that the method doesn't actually have.

This patch changes the CLI so that it will check if the collection "get"
method has a "name" parameter. If it has it will call it as it does now,
if it doesn't have it then it will return None.

Change-Id: Ie8ba22bb4323dcab65551d1c9f96000c09460fa1
Bug-Url: https://bugzilla.redhat.com/1091725
Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com>
---
M src/ovirtcli/command/command.py
1 file changed, 12 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/00/31800/1

diff --git a/src/ovirtcli/command/command.py b/src/ovirtcli/command/command.py
index bdedc47..0eb2830 100644
--- a/src/ovirtcli/command/command.py
+++ b/src/ovirtcli/command/command.py
@@ -30,6 +30,7 @@
 import re
 import keyword
 import __builtin__
+import inspect
 
 
 class OvirtCommand(Command):
@@ -365,6 +366,17 @@
         return None
 
     def __get_by_name(self, coll, name, kwargs):
+        # Some collections, for example the disks collection, don't support
+        # retrieving an entity by name as the corresponding entity doesn't have
+        # a name attribute:
+        getter = getattr(coll, "get")
+        if getter is None:
+            return None
+        spec = inspect.getargspec(getter)
+        if not "name" in spec.args:
+            return None
+
+        # Invoke the getter:
         if kwargs:
             return coll.get(name=name, **kwargs)
         else:


-- 
To view, visit http://gerrit.ovirt.org/31800
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie8ba22bb4323dcab65551d1c9f96000c09460fa1
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-cli
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to