Compare commits

...

4 Commits

7 changed files with 792 additions and 548 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -21,6 +21,33 @@
from pvc.lib.node import format_info as node_format_info
from pvc.lib.node import format_list as node_format_list
from pvc.lib.vm import format_vm_tags as vm_format_tags
from pvc.lib.vm import format_vm_vcpus as vm_format_vcpus
from pvc.lib.vm import format_vm_memory as vm_format_memory
from pvc.lib.vm import format_vm_networks as vm_format_networks
from pvc.lib.vm import format_vm_volumes as vm_format_volumes
from pvc.lib.vm import format_info as vm_format_info
from pvc.lib.vm import format_list as vm_format_list
from pvc.lib.network import format_info as network_format_info
from pvc.lib.network import format_list as network_format_list
from pvc.lib.network import format_list_dhcp as network_format_dhcp_list
from pvc.lib.network import format_list_acl as network_format_acl_list
from pvc.lib.network import format_list_sriov_pf as network_format_sriov_pf_list
from pvc.lib.network import format_info_sriov_vf as network_format_sriov_vf_info
from pvc.lib.network import format_list_sriov_vf as network_format_sriov_vf_list
from pvc.lib.storage import format_raw_output as storage_format_raw
from pvc.lib.storage import format_info_benchmark as storage_format_benchmark_info
from pvc.lib.storage import format_list_benchmark as storage_format_benchmark_list
from pvc.lib.storage import format_list_osd as storage_format_osd_list
from pvc.lib.storage import format_list_pool as storage_format_pool_list
from pvc.lib.storage import format_list_volume as storage_format_volume_list
from pvc.lib.storage import format_list_snapshot as storage_format_snapshot_list
from pvc.lib.provisioner import format_list_template as provisioner_format_template_list
from pvc.lib.provisioner import format_list_userdata as provisioner_format_userdata_list
from pvc.lib.provisioner import format_list_script as provisioner_format_script_list
from pvc.lib.provisioner import format_list_ova as provisioner_format_ova_list
from pvc.lib.provisioner import format_list_profile as provisioner_format_profile_list
from pvc.lib.provisioner import format_list_task as provisioner_format_task_status
# Define colour values for use in formatters
@@ -36,7 +63,7 @@ ansii = {
}
def cli_cluster_status_format_pretty(data):
def cli_cluster_status_format_pretty(CLI_CONFIG, data):
"""
Pretty format the full output of cli_cluster_status
"""
@@ -188,7 +215,7 @@ def cli_cluster_status_format_pretty(data):
return "\n".join(output)
def cli_cluster_status_format_short(data):
def cli_cluster_status_format_short(CLI_CONFIG, data):
"""
Pretty format the health-only output of cli_cluster_status
"""
@@ -233,7 +260,7 @@ def cli_cluster_status_format_short(data):
return "\n".join(output)
def cli_connection_list_format_pretty(data):
def cli_connection_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_connection_list
"""
@@ -305,7 +332,7 @@ def cli_connection_list_format_pretty(data):
return "\n".join(output)
def cli_connection_detail_format_pretty(data):
def cli_connection_detail_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_connection_detail
"""
@@ -425,25 +452,281 @@ def cli_connection_detail_format_pretty(data):
return "\n".join(output)
def cli_node_info_format_pretty(data):
def cli_node_info_format_pretty(CLI_CONFIG, data):
"""
Pretty format the basic output of cli_node_info
"""
return node_format_info(data, long_output=False)
return node_format_info(CLI_CONFIG, data, long_output=False)
def cli_node_info_format_long(data):
def cli_node_info_format_long(CLI_CONFIG, data):
"""
Pretty format the full output of cli_node_info
"""
return node_format_info(data, long_output=True)
return node_format_info(CLI_CONFIG, data, long_output=True)
def cli_node_list_format_pretty(data):
def cli_node_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_node_list
"""
return node_format_list(data)
return node_format_list(CLI_CONFIG, data)
def cli_vm_tag_get_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_vm_tag_get
"""
return vm_format_tags(CLI_CONFIG, data)
def cli_vm_vcpu_get_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_vm_vcpu_get
"""
return vm_format_vcpus(CLI_CONFIG, data)
def cli_vm_memory_get_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_vm_memory_get
"""
return vm_format_memory(CLI_CONFIG, data)
def cli_vm_network_get_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_vm_network_get
"""
return vm_format_networks(CLI_CONFIG, data)
def cli_vm_volume_get_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_vm_volume_get
"""
return vm_format_volumes(CLI_CONFIG, data)
def cli_vm_info_format_pretty(CLI_CONFIG, data):
"""
Pretty format the basic output of cli_vm_info
"""
return vm_format_info(CLI_CONFIG, data, long_output=False)
def cli_vm_info_format_long(CLI_CONFIG, data):
"""
Pretty format the full output of cli_vm_info
"""
return vm_format_info(CLI_CONFIG, data, long_output=True)
def cli_vm_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_vm_list
"""
return vm_format_list(CLI_CONFIG, data)
def cli_network_info_format_pretty(CLI_CONFIG, data):
"""
Pretty format the full output of cli_network_info
"""
return network_format_info(CLI_CONFIG, data, long_output=True)
def cli_network_info_format_long(CLI_CONFIG, data):
"""
Pretty format the full output of cli_network_info
"""
return network_format_info(CLI_CONFIG, data, long_output=True)
def cli_network_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_network_list
"""
return network_format_list(CLI_CONFIG, data)
def cli_network_dhcp_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_network_dhcp_list
"""
return network_format_dhcp_list(CLI_CONFIG, data)
def cli_network_acl_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_network_acl_list
"""
return network_format_acl_list(CLI_CONFIG, data)
def cli_network_sriov_pf_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_network_sriov_pf_list
"""
return network_format_sriov_pf_list(CLI_CONFIG, data)
def cli_network_sriov_vf_info_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_network_sriov_vf_info
"""
return network_format_sriov_vf_info(CLI_CONFIG, data)
def cli_network_sriov_vf_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_network_sriov_vf_list
"""
return network_format_sriov_vf_list(CLI_CONFIG, data)
def cli_storage_status_format_raw(CLI_CONFIG, data):
"""
Direct format the output of cli_storage_status
"""
return storage_format_raw(CLI_CONFIG, data)
def cli_storage_util_format_raw(CLI_CONFIG, data):
"""
Direct format the output of cli_storage_util
"""
return storage_format_raw(CLI_CONFIG, data)
def cli_storage_benchmark_info_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_storage_benchmark_info
"""
return storage_format_benchmark_info(CLI_CONFIG, data)
def cli_storage_benchmark_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_storage_benchmark_list
"""
return storage_format_benchmark_list(CLI_CONFIG, data)
def cli_storage_osd_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_storage_osd_list
"""
return storage_format_osd_list(CLI_CONFIG, data)
def cli_storage_pool_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_storage_pool_list
"""
return storage_format_pool_list(CLI_CONFIG, data)
def cli_storage_volume_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_storage_volume_list
"""
return storage_format_volume_list(CLI_CONFIG, data)
def cli_storage_snapshot_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_storage_snapshot_list
"""
return storage_format_snapshot_list(CLI_CONFIG, data)
def cli_provisioner_template_system_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_provisioner_template_system_list
"""
return provisioner_format_template_list(CLI_CONFIG, data, template_type="system")
def cli_provisioner_template_network_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_provisioner_template_network_list
"""
return provisioner_format_template_list(CLI_CONFIG, data, template_type="network")
def cli_provisioner_template_storage_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_provisioner_template_storage_list
"""
return provisioner_format_template_list(CLI_CONFIG, data, template_type="storage")
def cli_provisioner_userdata_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_provisioner_userdata_list
"""
return provisioner_format_userdata_list(CLI_CONFIG, data)
def cli_provisioner_script_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_provisioner_script_list
"""
return provisioner_format_script_list(CLI_CONFIG, data)
def cli_provisioner_ova_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_provisioner_ova_list
"""
return provisioner_format_ova_list(CLI_CONFIG, data)
def cli_provisioner_profile_list_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_provisioner_profile_list
"""
return provisioner_format_profile_list(CLI_CONFIG, data)
def cli_provisioner_status_format_pretty(CLI_CONFIG, data):
"""
Pretty format the output of cli_provisioner_status
"""
return provisioner_format_task_status(CLI_CONFIG, data)

View File

@@ -542,11 +542,16 @@ def net_sriov_vf_info(config, node, vf):
return False, "VF not found."
else:
# Return a single instance if the response is a list
data = dict()
data["node"] = node
if isinstance(response.json(), list):
return True, response.json()[0]
data = dict()
data["vf_information"] = response.json()[0]
return True, data
# This shouldn't happen, but is here just in case
else:
return True, response.json()
data["vf_information"] = response.json()
return True, data
else:
return False, response.json().get("message", "")
@@ -714,7 +719,7 @@ def format_info(config, network_information, long_output):
)
ainformation.append("")
if retcode:
firewall_rules_string = format_list_acl(firewall_rules_list)
firewall_rules_string = format_list_acl(config, firewall_rules_list)
for line in firewall_rules_string.split("\n"):
ainformation.append(line)
else:
@@ -888,7 +893,7 @@ def format_list(config, network_list):
return "\n".join(network_list_output)
def format_list_dhcp(dhcp_lease_list):
def format_list_dhcp(config, dhcp_lease_list):
dhcp_lease_list_output = []
# Determine optimal column widths
@@ -987,7 +992,7 @@ def format_list_dhcp(dhcp_lease_list):
return "\n".join(dhcp_lease_list_output)
def format_list_acl(acl_list):
def format_list_acl(config, acl_list):
# Handle when we get an empty entry
if not acl_list:
acl_list = list()
@@ -1086,7 +1091,7 @@ def format_list_acl(acl_list):
return "\n".join(acl_list_output)
def format_list_sriov_pf(pf_list):
def format_list_sriov_pf(config, pf_list):
# The maximum column width of the VFs column
max_vfs_length = 70
@@ -1206,7 +1211,7 @@ def format_list_sriov_pf(pf_list):
return "\n".join(pf_list_output)
def format_list_sriov_vf(vf_list):
def format_list_sriov_vf(config, vf_list):
# Handle when we get an empty entry
if not vf_list:
vf_list = list()
@@ -1338,10 +1343,13 @@ def format_list_sriov_vf(vf_list):
return "\n".join(vf_list_output)
def format_info_sriov_vf(config, vf_information, node):
if not vf_information:
def format_info_sriov_vf(config, data):
if not data or not data["vf_information"]:
return "No VF found"
node = data["node"]
vf_information = data["vf_information"]
# Get information on the using VM if applicable
if vf_information["usage"]["used"] == "True" and vf_information["usage"]["domain"]:
vm_information = call_api(

View File

@@ -273,7 +273,7 @@ def getOutputColours(node_information):
)
def format_info(node_information, long_output):
def format_info(config, node_information, long_output):
(
health_colour,
daemon_state_colour,
@@ -442,7 +442,7 @@ def format_info(node_information, long_output):
return "\n".join(ainformation)
def format_list(node_list):
def format_list(config, node_list):
if node_list == "Node not found.":
return node_list

View File

@@ -750,24 +750,11 @@ def task_status(config, task_id=None, is_watching=False):
if response.status_code == 200:
retvalue = True
respjson = response.json()
if is_watching:
# Just return the raw JSON to the watching process instead of formatting it
# Just return the raw JSON to the watching process instead of including value
return respjson
job_state = respjson["state"]
if job_state == "RUNNING":
retdata = "Job state: RUNNING\nStage: {}/{}\nStatus: {}".format(
respjson["current"], respjson["total"], respjson["status"]
)
elif job_state == "FAILED":
retdata = "Job state: FAILED\nStatus: {}".format(respjson["status"])
elif job_state == "COMPLETED":
retdata = "Job state: COMPLETED\nStatus: {}".format(respjson["status"])
else:
retdata = "Job state: {}\nStatus: {}".format(
respjson["state"], respjson["status"]
)
return retvalue, respjson
else:
retvalue = False
retdata = response.json().get("message", "")
@@ -814,7 +801,7 @@ def task_status(config, task_id=None, is_watching=False):
#
# Format functions
#
def format_list_template(template_data, template_type=None):
def format_list_template(config, template_data, template_type=None):
"""
Format the returned template template
@@ -1330,7 +1317,12 @@ def format_list_template_storage(template_template):
return "\n".join(template_list_output)
def format_list_userdata(userdata_data, lines=None):
def format_list_userdata(config, userdata_data):
if not config.get("long_output"):
lines = 4
else:
lines = None
if isinstance(userdata_data, dict):
userdata_data = [userdata_data]
@@ -1432,7 +1424,12 @@ def format_list_userdata(userdata_data, lines=None):
return "\n".join(userdata_list_output)
def format_list_script(script_data, lines=None):
def format_list_script(config, script_data):
if not config.get("long_output"):
lines = 4
else:
lines = None
if isinstance(script_data, dict):
script_data = [script_data]
@@ -1531,7 +1528,7 @@ def format_list_script(script_data, lines=None):
return "\n".join(script_list_output)
def format_list_ova(ova_data):
def format_list_ova(config, ova_data):
if isinstance(ova_data, dict):
ova_data = [ova_data]
@@ -1678,7 +1675,7 @@ def format_list_ova(ova_data):
return "\n".join(ova_list_output)
def format_list_profile(profile_data):
def format_list_profile(config, profile_data):
if isinstance(profile_data, dict):
profile_data = [profile_data]
@@ -1867,7 +1864,23 @@ def format_list_profile(profile_data):
return "\n".join(profile_list_output)
def format_list_task(task_data):
def format_list_task(config, task_data):
if not isinstance(task_data, list):
job_state = task_data["state"]
if job_state == "RUNNING":
retdata = "Job state: RUNNING\nStage: {}/{}\nStatus: {}".format(
task_data["current"], task_data["total"], task_data["status"]
)
elif job_state == "FAILED":
retdata = "Job state: FAILED\nStatus: {}".format(task_data["status"])
elif job_state == "COMPLETED":
retdata = "Job state: COMPLETED\nStatus: {}".format(task_data["status"])
else:
retdata = "Job state: {}\nStatus: {}".format(
task_data["state"], task_data["status"]
)
return retdata
task_list_output = []
# Determine optimal column widths

View File

@@ -21,7 +21,7 @@
import math
from json import dumps, loads
from json import loads
from requests_toolbelt.multipart.encoder import (
MultipartEncoder,
MultipartEncoderMonitor,
@@ -143,7 +143,7 @@ def ceph_util(config):
return False, response.json().get("message", "")
def format_raw_output(status_data):
def format_raw_output(config, status_data):
ainformation = list()
ainformation.append(
"{bold}Ceph cluster {stype} (primary node {end}{blue}{primary}{end}{bold}){end}\n".format(
@@ -379,7 +379,7 @@ def getOutputColoursOSD(osd_information):
return osd_up_flag, osd_up_colour, osd_in_flag, osd_in_colour
def format_list_osd(osd_list):
def format_list_osd(config, osd_list):
# Handle empty list
if not osd_list:
osd_list = list()
@@ -835,7 +835,7 @@ def ceph_pool_set_pgs(config, pool, pgs):
return retstatus, response.json().get("message", "")
def format_list_pool(pool_list):
def format_list_pool(config, pool_list):
# Handle empty list
if not pool_list:
pool_list = list()
@@ -1318,7 +1318,7 @@ def ceph_volume_clone(config, pool, volume, new_volume):
return retstatus, response.json().get("message", "")
def format_list_volume(volume_list):
def format_list_volume(config, volume_list):
# Handle empty list
if not volume_list:
volume_list = list()
@@ -1596,7 +1596,7 @@ def ceph_snapshot_modify(config, pool, volume, snapshot, new_name=None):
return retstatus, response.json().get("message", "")
def format_list_snapshot(snapshot_list):
def format_list_snapshot(config, snapshot_list):
# Handle empty list
if not snapshot_list:
snapshot_list = list()
@@ -1981,7 +1981,7 @@ def format_list_benchmark(config, benchmark_information):
return "\n".join(benchmark_list_output)
def format_info_benchmark(config, oformat, benchmark_information):
def format_info_benchmark(config, benchmark_information):
# This matrix is a list of the possible format functions for a benchmark result
# It is extensable in the future should newer formats be required.
benchmark_matrix = {
@@ -1991,11 +1991,6 @@ def format_info_benchmark(config, oformat, benchmark_information):
benchmark_version = benchmark_information[0]["test_format"]
if oformat == "json-pretty":
return dumps(benchmark_information, indent=4)
elif oformat == "json":
return dumps(benchmark_information)
else:
return benchmark_matrix[benchmark_version](config, benchmark_information[0])

View File

@@ -286,20 +286,18 @@ def vm_tag_set(config, vm, action, tag, protected=False):
return retstatus, response.json().get("message", "")
def format_vm_tags(config, name, tags):
def format_vm_tags(config, data):
"""
Format the output of a tags dictionary in a nice table
"""
tags = data.get("tags", [])
if len(tags) < 1:
return "No tags found."
output_list = []
name_length = 5
_name_length = len(name) + 1
if _name_length > name_length:
name_length = _name_length
tags_name_length = 4
tags_type_length = 5
tags_protected_length = 10
@@ -495,44 +493,38 @@ def vm_vcpus_get(config, vm):
except Exception:
return False, "ERROR: Failed to parse XML data."
vm_vcpus = int(parsed_xml.vcpu.text)
vm_sockets = parsed_xml.cpu.topology.attrib.get("sockets")
vm_cores = parsed_xml.cpu.topology.attrib.get("cores")
vm_threads = parsed_xml.cpu.topology.attrib.get("threads")
data = dict()
data["name"] = vm
data["vcpus"] = int(parsed_xml.vcpu.text)
data["sockets"] = parsed_xml.cpu.topology.attrib.get("sockets")
data["cores"] = parsed_xml.cpu.topology.attrib.get("cores")
data["threads"] = parsed_xml.cpu.topology.attrib.get("threads")
return True, (vm_vcpus, (vm_sockets, vm_cores, vm_threads))
return True, data
def format_vm_vcpus(config, name, vcpus):
def format_vm_vcpus(config, data):
"""
Format the output of a vCPU value in a nice table
"""
output_list = []
name_length = 5
_name_length = len(name) + 1
if _name_length > name_length:
name_length = _name_length
vcpus_length = 6
sockets_length = 8
cores_length = 6
threads_length = 8
output_list.append(
"{bold}{name: <{name_length}} \
{vcpus: <{vcpus_length}} \
"{bold}{vcpus: <{vcpus_length}} \
{sockets: <{sockets_length}} \
{cores: <{cores_length}} \
{threads: <{threads_length}}{end_bold}".format(
name_length=name_length,
vcpus_length=vcpus_length,
sockets_length=sockets_length,
cores_length=cores_length,
threads_length=threads_length,
bold=ansiprint.bold(),
end_bold=ansiprint.end(),
name="Name",
vcpus="vCPUs",
sockets="Sockets",
cores="Cores",
@@ -540,23 +532,20 @@ def format_vm_vcpus(config, name, vcpus):
)
)
output_list.append(
"{bold}{name: <{name_length}} \
{vcpus: <{vcpus_length}} \
"{bold}{vcpus: <{vcpus_length}} \
{sockets: <{sockets_length}} \
{cores: <{cores_length}} \
{threads: <{threads_length}}{end_bold}".format(
name_length=name_length,
vcpus_length=vcpus_length,
sockets_length=sockets_length,
cores_length=cores_length,
threads_length=threads_length,
bold="",
end_bold="",
name=name,
vcpus=vcpus[0],
sockets=vcpus[1][0],
cores=vcpus[1][1],
threads=vcpus[1][2],
vcpus=data["vcpus"],
sockets=data["sockets"],
cores=data["cores"],
threads=data["threads"],
)
)
return "\n".join(output_list)
@@ -619,44 +608,35 @@ def vm_memory_get(config, vm):
except Exception:
return False, "ERROR: Failed to parse XML data."
vm_memory = int(parsed_xml.memory.text)
data = dict()
data["name"] = vm
data["memory"] = int(parsed_xml.memory.text)
return True, vm_memory
return True, data
def format_vm_memory(config, name, memory):
def format_vm_memory(config, data):
"""
Format the output of a memory value in a nice table
"""
output_list = []
name_length = 5
_name_length = len(name) + 1
if _name_length > name_length:
name_length = _name_length
memory_length = 6
output_list.append(
"{bold}{name: <{name_length}} \
{memory: <{memory_length}}{end_bold}".format(
name_length=name_length,
"{bold}{memory: <{memory_length}}{end_bold}".format(
memory_length=memory_length,
bold=ansiprint.bold(),
end_bold=ansiprint.end(),
name="Name",
memory="RAM (M)",
)
)
output_list.append(
"{bold}{name: <{name_length}} \
{memory: <{memory_length}}{end_bold}".format(
name_length=name_length,
"{bold}{memory: <{memory_length}}{end_bold}".format(
memory_length=memory_length,
bold="",
end_bold="",
name=name,
memory=memory,
memory=data["memory"],
)
)
return "\n".join(output_list)
@@ -946,7 +926,9 @@ def vm_networks_get(config, vm):
except Exception:
return False, "ERROR: Failed to parse XML data."
network_data = list()
data = dict()
data["name"] = vm
data["networks"] = list()
for interface in parsed_xml.devices.find("interface"):
mac_address = interface.mac.attrib.get("address")
model = interface.model.attrib.get("type")
@@ -960,76 +942,65 @@ def vm_networks_get(config, vm):
elif interface_type == "hostdev":
network = "hostdev:{}".format(interface.source.attrib.get("dev"))
network_data.append((network, mac_address, model))
data["networks"].append(
{"network": network, "mac_address": mac_address, "model": model}
)
return True, network_data
return True, data
def format_vm_networks(config, name, networks):
def format_vm_networks(config, data):
"""
Format the output of a network list in a nice table
"""
output_list = []
name_length = 5
vni_length = 8
network_length = 8
macaddr_length = 12
model_length = 6
_name_length = len(name) + 1
if _name_length > name_length:
name_length = _name_length
for network in data["networks"]:
_network_length = len(network["network"]) + 1
if _network_length > network_length:
network_length = _network_length
for network in networks:
_vni_length = len(network[0]) + 1
if _vni_length > vni_length:
vni_length = _vni_length
_macaddr_length = len(network[1]) + 1
_macaddr_length = len(network["mac_address"]) + 1
if _macaddr_length > macaddr_length:
macaddr_length = _macaddr_length
_model_length = len(network[2]) + 1
_model_length = len(network["model"]) + 1
if _model_length > model_length:
model_length = _model_length
output_list.append(
"{bold}{name: <{name_length}} \
{vni: <{vni_length}} \
"{bold}{network: <{network_length}} \
{macaddr: <{macaddr_length}} \
{model: <{model_length}}{end_bold}".format(
name_length=name_length,
vni_length=vni_length,
network_length=network_length,
macaddr_length=macaddr_length,
model_length=model_length,
bold=ansiprint.bold(),
end_bold=ansiprint.end(),
name="Name",
vni="Network",
network="Network",
macaddr="MAC Address",
model="Model",
)
)
count = 0
for network in networks:
if count > 0:
name = ""
for network in data["networks"]:
count += 1
output_list.append(
"{bold}{name: <{name_length}} \
{vni: <{vni_length}} \
"{bold}{network: <{network_length}} \
{macaddr: <{macaddr_length}} \
{model: <{model_length}}{end_bold}".format(
name_length=name_length,
vni_length=vni_length,
network_length=network_length,
macaddr_length=macaddr_length,
model_length=model_length,
bold="",
end_bold="",
name=name,
vni=network[0],
macaddr=network[1],
model=network[2],
network=network["network"],
macaddr=network["mac_address"],
model=network["model"],
)
)
return "\n".join(output_list)
@@ -1270,7 +1241,9 @@ def vm_volumes_get(config, vm):
except Exception:
return False, "ERROR: Failed to parse XML data."
volume_data = list()
data = dict()
data["name"] = vm
data["volumes"] = list()
for disk in parsed_xml.devices.find("disk"):
protocol = disk.attrib.get("type")
disk_id = disk.target.attrib.get("dev")
@@ -1285,58 +1258,52 @@ def vm_volumes_get(config, vm):
protocol = "unknown"
source = "unknown"
volume_data.append((source, disk_id, protocol, bus))
data["volumes"].append(
{"volume": source, "disk_id": disk_id, "protocol": protocol, "bus": bus}
)
return True, volume_data
return True, data
def format_vm_volumes(config, name, volumes):
def format_vm_volumes(config, data):
"""
Format the output of a volume value in a nice table
"""
output_list = []
name_length = 5
volume_length = 7
disk_id_length = 4
protocol_length = 5
bus_length = 4
_name_length = len(name) + 1
if _name_length > name_length:
name_length = _name_length
for volume in volumes:
_volume_length = len(volume[0]) + 1
for volume in data["volumes"]:
_volume_length = len(volume["volume"]) + 1
if _volume_length > volume_length:
volume_length = _volume_length
_disk_id_length = len(volume[1]) + 1
_disk_id_length = len(volume["disk_id"]) + 1
if _disk_id_length > disk_id_length:
disk_id_length = _disk_id_length
_protocol_length = len(volume[2]) + 1
_protocol_length = len(volume["protocol"]) + 1
if _protocol_length > protocol_length:
protocol_length = _protocol_length
_bus_length = len(volume[3]) + 1
_bus_length = len(volume["bus"]) + 1
if _bus_length > bus_length:
bus_length = _bus_length
output_list.append(
"{bold}{name: <{name_length}} \
{volume: <{volume_length}} \
"{bold}{volume: <{volume_length}} \
{disk_id: <{disk_id_length}} \
{protocol: <{protocol_length}} \
{bus: <{bus_length}}{end_bold}".format(
name_length=name_length,
volume_length=volume_length,
disk_id_length=disk_id_length,
protocol_length=protocol_length,
bus_length=bus_length,
bold=ansiprint.bold(),
end_bold=ansiprint.end(),
name="Name",
volume="Volume",
disk_id="Dev",
protocol="Type",
@@ -1344,28 +1311,23 @@ def format_vm_volumes(config, name, volumes):
)
)
count = 0
for volume in volumes:
if count > 0:
name = ""
for volume in data["volumes"]:
count += 1
output_list.append(
"{bold}{name: <{name_length}} \
{volume: <{volume_length}} \
"{bold}{volume: <{volume_length}} \
{disk_id: <{disk_id_length}} \
{protocol: <{protocol_length}} \
{bus: <{bus_length}}{end_bold}".format(
name_length=name_length,
volume_length=volume_length,
disk_id_length=disk_id_length,
protocol_length=protocol_length,
bus_length=bus_length,
bold="",
end_bold="",
name=name,
volume=volume[0],
disk_id=volume[1],
protocol=volume[2],
bus=volume[3],
volume=volume["volume"],
disk_id=volume["disk_id"],
protocol=volume["protocol"],
bus=volume["bus"],
)
)
return "\n".join(output_list)
@@ -1869,7 +1831,7 @@ def format_info(config, domain_information, long_output):
return "\n".join(ainformation)
def format_list(config, vm_list, raw):
def format_list(config, vm_list):
# Function to strip the "br" off of nets and return a nicer list
def getNiceNetID(domain_information):
# Network list
@@ -1888,13 +1850,6 @@ def format_list(config, vm_list, raw):
tag_list.append(tag["name"])
return tag_list
# Handle raw mode since it just lists the names
if raw:
ainformation = list()
for vm in sorted(item["name"] for item in vm_list):
ainformation.append(vm)
return "\n".join(ainformation)
vm_list_output = []
# Determine optimal column widths