Ravi Nori has uploaded a new change for review. Change subject: cli: show command should retrieve sdk collection.get() method's args dynamically ......................................................................
cli: show command should retrieve sdk collection.get() method's args dynamically show command should retrieve sdk collection.get() method's args dynamically, currently hardcoded id/name options being used. Change-Id: If9e0bce51f3a973049bffaa243aa1bd42e0ae25d Bug-Url: https://bugzilla.redhat.com/866448 Signed-off-by: Ravi Nori <rn...@redhat.com> --- M src/ovirtcli/command/command.py M src/ovirtcli/shell/showcmdshell.py 2 files changed, 36 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/10/24710/1 diff --git a/src/ovirtcli/command/command.py b/src/ovirtcli/command/command.py index 9b9b6dc..f720dcb 100644 --- a/src/ovirtcli/command/command.py +++ b/src/ovirtcli/command/command.py @@ -345,15 +345,16 @@ coll = getattr(base, candidate + 's') if coll is not None: if name: - return coll.get(name=name) + return self.__get_by_name(coll, name, kwargs) if kwargs and kwargs.has_key('id'): - return coll.get(id=str(kwargs['id'])) + id, kwargs = self._get_query_params(opts, query_arg='--id') + return self.__get_by_id(coll, str(id), kwargs) else: identifier = self.__produce_identifier(obj_id) if identifier: - return coll.get(id=str(obj_id)) + return self.__get_by_id(coll, str(obj_id), kwargs) else: - return coll.get(name=obj_id) + return self.__get_by_name(coll, obj_id, kwargs) else: err_str = Messages.Error.NO_SUCH_TYPE_OR_ARS_NOT_VALID if context_variants: @@ -363,6 +364,18 @@ return None + def __get_by_name(self, coll, name, kwargs): + if kwargs: + return coll.get(name=name, **kwargs) + else: + return coll.get(name=name) + + def __get_by_id(self, coll, id, kwargs): + if kwargs: + return coll.get(id=id, **kwargs) + else: + return coll.get(id=id) + def __produce_identifier(self, candidate): if type(candidate) == str: match = re.search(r'[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}', candidate) diff --git a/src/ovirtcli/shell/showcmdshell.py b/src/ovirtcli/shell/showcmdshell.py index c64d3c1..6d7cbca 100644 --- a/src/ovirtcli/shell/showcmdshell.py +++ b/src/ovirtcli/shell/showcmdshell.py @@ -18,6 +18,8 @@ from ovirtcli.shell.cmdshell import CmdShell from ovirtcli.utils.typehelper import TypeHelper from ovirtcli.utils.autocompletionhelper import AutoCompletionHelper +from ovirtsdk.infrastructure import brokers +from ovirtcli.utils.methodhelper import MethodHelper class ShowCmdShell(CmdShell): @@ -32,13 +34,29 @@ def do_show(self, args): return self.context.execute_string(ShowCmdShell.NAME + ' ' + args + '\n') + def __add_resource_specific_options(self, obj, specific_options, line, key=None): + obj_coll_type = TypeHelper.getDecoratorType(TypeHelper.to_plural(obj)) + if obj_coll_type: + if hasattr(brokers, obj_coll_type): + obj_coll = getattr(brokers, obj_coll_type) + if obj_coll and hasattr(obj_coll, ShowCmdShell.ALIAS): + method_args = MethodHelper.get_documented_arguments(method_ref=getattr(obj_coll, ShowCmdShell.ALIAS), + as_params_collection=True, + spilt_or=True) + if method_args: + specific_options[obj if key == None else key] = method_args + def complete_show(self, text, line, begidx, endidx): args = TypeHelper.get_types_by_method(False, ShowCmdShell.ALIAS, expendNestedTypes=True) + specific_options = self.get_resource_specific_options(args, + line, + callback=self.__add_resource_specific_options) return AutoCompletionHelper.complete(line=line, text=text, args=args, - common_options=ShowCmdShell.OPTIONS) + common_options=ShowCmdShell.OPTIONS, + specific_options=specific_options) def is_show_argument(self, line, key): args = TypeHelper.get_types_by_method(False, ShowCmdShell.ALIAS, expendNestedTypes=True) if key in args: -- To view, visit http://gerrit.ovirt.org/24710 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If9e0bce51f3a973049bffaa243aa1bd42e0ae25d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-cli Gerrit-Branch: master Gerrit-Owner: Ravi Nori <rn...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches