Michael Pasternak has uploaded a new change for review. Change subject: cli: add option to retrieve system summary #854369 ......................................................................
cli: add option to retrieve system summary #854369 [oVirt shell (connected)]# summary hosts-active : 0 hosts-total : 4 storage_domains-active: 3 storage_domains-total : 4 users-active : 1 users-total : 3 vms-active : 0 vms-total : 7 https://bugzilla.redhat.com/show_bug.cgi?id=854369 Change-Id: I76bc19432b239f8394a15c7e3b37629437d38345 Signed-off-by: Michael Pasternak <[email protected]> --- A src/ovirtcli/command/summary.py M src/ovirtcli/context.py M src/ovirtcli/format/text.py M src/ovirtcli/shell/engineshell.py A src/ovirtcli/shell/summarycmdshell.py 5 files changed, 79 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/64/12964/1 diff --git a/src/ovirtcli/command/summary.py b/src/ovirtcli/command/summary.py new file mode 100644 index 0000000..fcff790 --- /dev/null +++ b/src/ovirtcli/command/summary.py @@ -0,0 +1,40 @@ +# +# Copyright (c) 2010 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +from ovirtcli.command.command import OvirtCommand + + +class SummaryCommand(OvirtCommand): + + name = 'summary' + description = 'displaying the system status' + helptext = """\ + == Usage == + + summary + + == Description == + + Displaying the system status. + """ + + def execute(self): + connection = self.check_connection() + self.context.formatter.format( + self.context, + connection.get_summary() + ) diff --git a/src/ovirtcli/context.py b/src/ovirtcli/context.py index a48e1e6..4b0cb84 100644 --- a/src/ovirtcli/context.py +++ b/src/ovirtcli/context.py @@ -26,6 +26,7 @@ import pkg_resources from ovirtcli.command.info import InfoCommand from ovirtcli.historymanager import HistoryManager +from ovirtcli.command.summary import SummaryCommand class OvirtCliExecutionContext(ExecutionContext): @@ -110,6 +111,7 @@ self.add_command(UpdateCommand) self.add_command(InfoCommand) self.add_command(HistoryCommand) + self.add_command(SummaryCommand) def __update_backend_metadata(self): """Return a dict with prompt variables.""" diff --git a/src/ovirtcli/format/text.py b/src/ovirtcli/format/text.py index 2464b49..8fd847e 100644 --- a/src/ovirtcli/format/text.py +++ b/src/ovirtcli/format/text.py @@ -23,6 +23,7 @@ from ovirtsdk.infrastructure.common import Base from ovirtsdk.infrastructure import brokers import types +from ovirtsdk.xml.params import ApiSummary class FormatMode(): @@ -223,8 +224,11 @@ stdout.write('\n') def format(self, context, result, show_all=False): + RESOURCE_EXCEPTIONS = [ApiSummary] + COLLECTION_EXCEPTIONS = [] self.context = context - if isinstance(result, params.BaseResource): + + if isinstance(result, params.BaseResource) or type(result) in RESOURCE_EXCEPTIONS: if isinstance(result, Base): context.terminal.stdout.write('\n') self._format_resource(result.superclass, show_empty=show_all) @@ -233,7 +237,7 @@ context.terminal.stdout.write('\n') self._format_resource(resource=result, show_empty=show_all) context.terminal.stdout.write('\n') - elif isinstance(result, list): + elif isinstance(result, list) or type(result) in COLLECTION_EXCEPTIONS: context.terminal.stdout.write('\n') self._format_collection(collection=result, show_empty=show_all) # context.terminal.stdout.write('\n') diff --git a/src/ovirtcli/shell/engineshell.py b/src/ovirtcli/shell/engineshell.py index 82a6552..394217d 100644 --- a/src/ovirtcli/shell/engineshell.py +++ b/src/ovirtcli/shell/engineshell.py @@ -41,13 +41,14 @@ from ovirtcli.shell.historycmdshell import HistoryCmdShell from cli.messages import Messages from ovirtcli.shell.infocmdshell import InfoCmdShell +from ovirtcli.shell.summarycmdshell import SummaryCmdShell class EngineShell(cmd.Cmd, ConnectCmdShell, ActionCmdShell, \ ShowCmdShell, ListCmdShell, UpdateCmdShell, \ RemoveCmdShell, AddCmdShell, DisconnectCmdShell, \ ConsoleCmdShell, PingCmdShell, StatusCmdShell, \ ClearCmdShell, FileCmdShell, HistoryCmdShell, \ - InfoCmdShell): + InfoCmdShell, SummaryCmdShell): OFF_LINE_CONTENT = [ConnectCmdShell.NAME, HelpCommand.name, 'exit', "EOF"] ############################# INIT ################################# def __init__(self, context, parser, completekey='tab', stdin=None, stdout=None): @@ -67,6 +68,7 @@ FileCmdShell.__init__(self, context, parser) HistoryCmdShell.__init__(self, context, parser) InfoCmdShell.__init__(self, context, parser) + SummaryCmdShell.__init__(self, context, parser) self.last_output = '' self.__input_buffer = '' diff --git a/src/ovirtcli/shell/summarycmdshell.py b/src/ovirtcli/shell/summarycmdshell.py new file mode 100644 index 0000000..a22b5c5 --- /dev/null +++ b/src/ovirtcli/shell/summarycmdshell.py @@ -0,0 +1,28 @@ +# +# Copyright (c) 2010 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +from ovirtcli.shell.cmdshell import CmdShell + + +class SummaryCmdShell(CmdShell): + NAME = 'summary' + + def __init__(self, context, parser): + CmdShell.__init__(self, context, parser) + + def do_summary(self, args): + return self.context.execute_string(SummaryCmdShell.NAME + ' ' + args + '\n') -- To view, visit http://gerrit.ovirt.org/12964 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I76bc19432b239f8394a15c7e3b37629437d38345 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-cli Gerrit-Branch: master Gerrit-Owner: Michael Pasternak <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
