From 5c864202ad4a9b741e231798ff04e9d46d46473e Mon Sep 17 00:00:00 2001 From: gbenhaim Date: Tue, 25 Apr 2017 02:07:05 +0300 Subject: [PATCH] Improve lago ovirt status 1. Format the output with format plugins. 2. Adding url to the web ui. 3. Adding engine's web ui username and password. 4. Auto detect all the items from api.system_service.summary (hosts, vms, sds, users) Signed-off-by: gbenhaim --- lago/plugins/output.py | 2 +- ovirtlago/cmd.py | 4 ++-- ovirtlago/virt.py | 28 ++++++++++++++++++++++------ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lago/plugins/output.py b/lago/plugins/output.py index f094a0a0..96aa24f0 100644 --- a/lago/plugins/output.py +++ b/lago/plugins/output.py @@ -150,6 +150,6 @@ def dfs(father, path, acc): acc.append(delimiter.join(path)) result = [] - dfs(info_dict['Prefix'], [], result) + dfs(info_dict.get('Prefix') or info_dict, [], result) return '\n'.join(result) diff --git a/ovirtlago/cmd.py b/ovirtlago/cmd.py index 0677139c..93ab925c 100755 --- a/ovirtlago/cmd.py +++ b/ovirtlago/cmd.py @@ -217,8 +217,8 @@ def do_ovirt_start_vms(prefix, vms_timeout, **kwargs): @cli_plugin(help='Print oVirt setup status') @in_ovirt_prefix @with_logging -def do_ovirt_status(prefix, **kwargs): - prefix.virt_env.engine_vm().status() +def do_ovirt_status(prefix, out_format, **kwargs): + print(out_format.format(prefix.virt_env.engine_vm().status())) @cli_plugin( diff --git a/ovirtlago/virt.py b/ovirtlago/virt.py index 65005ad1..a1bdf298 100644 --- a/ovirtlago/virt.py +++ b/ovirtlago/virt.py @@ -24,6 +24,7 @@ import lago.vm import logging import yaml +from collections import OrderedDict from lago.config import config as lago_config from ovirtlago import utils from utils import partial @@ -461,13 +462,28 @@ def _sds_state(dc_id): @require_sdk(version='4') def status(self): api = self.get_api_v4(check=True) - sys_service = api.system_service().get() - print("Version: %s" % sys_service.product_info.version.full_version) - print("Hosts: %d" % sys_service.summary.hosts.total) - print("SDs: %d" % sys_service.summary.storage_domains.total) - print("Users: %d" % sys_service.summary.users.total) - print("Vms: %d" % sys_service.summary.vms.total) + info = {'global': {}, 'items': {}} + + info['global']['version' + ] = sys_service.product_info.version.full_version + info['global']['web_ui'] = OrderedDict( + [ + ('url', self.ip()), ('username', constants.ENGINE_USER), + ('password', self.metadata['ovirt-engine-password']) + ] + ) + + for k, v in vars(sys_service.summary).viewitems(): + if isinstance(v, otypes.ApiSummaryItem): + info['items'][k.lstrip('_')] = OrderedDict( + [ + ('total', v.total), + ('active', v.active), + ] + ) + + return info class HostVM(lago.vm.DefaultVM):