summaryrefslogtreecommitdiff
path: root/test/utils
diff options
context:
space:
mode:
authorAbhijeet Kasurde <akasurde@redhat.com>2017-06-30 04:41:28 +0530
committerjctanner <tanner.jc@gmail.com>2017-06-29 19:11:28 -0400
commitbc4ff8aed9265b412f57c6228998113eb25a2782 (patch)
treed9a84ebb07db237c20f74ad49012374712adc6d2 /test/utils
parenta396c18a61677257ef305fcdc10b2ca3cdeab9ce (diff)
downloadansible-bc4ff8aed9265b412f57c6228998113eb25a2782.tar.gz
Modify flask_control for vmware_host test suites (#26175)
Fix adds additional helper methods to get information about host system from vcsim Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Diffstat (limited to 'test/utils')
-rwxr-xr-xtest/utils/docker/vcenter-simulator/flask_control.py57
1 files changed, 51 insertions, 6 deletions
diff --git a/test/utils/docker/vcenter-simulator/flask_control.py b/test/utils/docker/vcenter-simulator/flask_control.py
index 9a6b45e83d..1ea8cb5b34 100755
--- a/test/utils/docker/vcenter-simulator/flask_control.py
+++ b/test/utils/docker/vcenter-simulator/flask_control.py
@@ -190,28 +190,73 @@ def get_govc_vm_info():
return jsonify(vm_output)
+@app.route('/govc_host_info')
+def get_govc_host_info():
+ """ Run govc host.info """
+ host_name = request.args.get("host_name") or None
+ host_output = {}
+ if host_name:
+ all_hosts = [host_name]
+ else:
+ all_hosts = _get_all_objs(ofilter='H')
+ for host_system in all_hosts:
+ host_info = _get_host_info(host_name=host_system)
+ name = host_info.get('Name', host_system)
+ host_output[name] = host_info
+
+ return jsonify(host_output)
+
+
+def _get_host_info(host_name=None):
+ """
+ Get all information of host from vcsim
+ :param vm_name: Name of host
+ :return: Dictionary containing information about VM,
+ where KEY represent attributes and VALUE represent attribute's value
+ """
+ cmd = '%s host.info -host=%s 2>&1' % (GOVCPATH, host_name)
+
+ host_info = {}
+ if host_name is None:
+ return host_info
+ host_info = parse_govc_info(cmd)
+
+ return host_info
+
+
def _get_vm_info(vm_name=None):
"""
Get all information of VM from vcsim
:param vm_name: Name of VM
- :return: Dictionary containing inforamtion about VM,
+ :return: Dictionary containing information about VM,
where KEY represent attributes and VALUE represent attribute's value
"""
cmd = '%s vm.info %s 2>&1' % (GOVCPATH, vm_name)
- so, se = run_cmd(cmd)
- stdout_lines = so.splitlines()
vm_info = {}
if vm_name is None:
return vm_info
+ vm_info = parse_govc_info(cmd)
+
+ return vm_info
+
+def parse_govc_info(cmd):
+ """
+ Helper function to parse output of govc info commands
+ :param cmd: command variable to run and parse output for
+ :return: Dictionary containing information about object
+ """
+ so, se = run_cmd(cmd)
+ stdout_lines = so.splitlines()
+ info = {}
for line in stdout_lines:
if ":" in line:
- key, value = line.split(":")
+ key, value = line.split(":", 1)
key = key.lstrip()
- vm_info[key] = value.strip()
+ info[key] = value.strip()
- return vm_info
+ return info
def _get_all_objs(ofilter=None):