From abb1da7e5a4840a822b6b1fb1de649d2522fa9ad Mon Sep 17 00:00:00 2001 From: caberos Date: Thu, 13 Aug 2020 14:49:33 -0400 Subject: [PATCH 1/2] add vs list hardware and all option --- SoftLayer/CLI/virt/list.py | 50 +++++++++++++++++--------------- tests/CLI/modules/vs/vs_tests.py | 4 +++ 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/SoftLayer/CLI/virt/list.py b/SoftLayer/CLI/virt/list.py index 1a3c4d545..e80417657 100644 --- a/SoftLayer/CLI/virt/list.py +++ b/SoftLayer/CLI/virt/list.py @@ -52,6 +52,8 @@ @click.option('--hourly', is_flag=True, help='Show only hourly instances') @click.option('--monthly', is_flag=True, help='Show only monthly instances') @click.option('--transient', help='Filter by transient instances', type=click.BOOL) +@click.option('--hardware', is_flag=True, default=False, help='Show the all VSI related to hardware') +@click.option('--all', is_flag=True, default=False, help='Show the all VSI and hardware VSIs') @helpers.multi_option('--tag', help='Filter by tags') @click.option('--sortby', help='Column to sort by', @@ -69,7 +71,7 @@ show_default=True) @environment.pass_env def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network, - hourly, monthly, tag, columns, limit, transient): + hourly, monthly, tag, columns, limit, transient, all, hardware): """List virtual servers.""" vsi = SoftLayer.VSManager(env.client) @@ -88,27 +90,29 @@ def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network, table = formatting.Table(columns.columns) table.sortby = sortby - for guest in guests: - table.add_row([value or formatting.blank() - for value in columns.row(guest)]) + if not hardware or all: + for guest in guests: + table.add_row([value or formatting.blank() + for value in columns.row(guest)]) - env.fout(table) + env.fout(table) - hardware_guests = vsi.get_hardware_guests() - for hardware in hardware_guests: - if hardware['virtualHost']['guests']: - title = "Hardware(id = {hardwareId}) guests associated".format(hardwareId=hardware['id']) - table_hardware_guest = formatting.Table(['id', 'hostname', 'CPU', 'Memory', 'Start Date', 'Status', - 'powerState'], title=title) - table_hardware_guest.sortby = 'hostname' - for guest in hardware['virtualHost']['guests']: - table_hardware_guest.add_row([ - guest['id'], - guest['hostname'], - '%i %s' % (guest['maxCpu'], guest['maxCpuUnits']), - guest['maxMemory'], - utils.clean_time(guest['createDate']), - guest['status']['keyName'], - guest['powerState']['keyName'] - ]) - env.fout(table_hardware_guest) + if hardware or all: + hardware_guests = vsi.get_hardware_guests() + for hardware in hardware_guests: + if hardware['virtualHost']['guests']: + title = "Hardware(id = {hardwareId}) guests associated".format(hardwareId=hardware['id']) + table_hardware_guest = formatting.Table(['id', 'hostname', 'CPU', 'Memory', 'Start Date', 'Status', + 'powerState'], title=title) + table_hardware_guest.sortby = 'hostname' + for guest in hardware['virtualHost']['guests']: + table_hardware_guest.add_row([ + guest['id'], + guest['hostname'], + '%i %s' % (guest['maxCpu'], guest['maxCpuUnits']), + guest['maxMemory'], + utils.clean_time(guest['createDate']), + guest['status']['keyName'], + guest['powerState']['keyName'] + ]) + env.fout(table_hardware_guest) diff --git a/tests/CLI/modules/vs/vs_tests.py b/tests/CLI/modules/vs/vs_tests.py index 06d3147ac..bce887178 100644 --- a/tests/CLI/modules/vs/vs_tests.py +++ b/tests/CLI/modules/vs/vs_tests.py @@ -846,3 +846,7 @@ def test_vs_migrate_exception(self): self.assert_not_called_with('SoftLayer_Account', 'getVirtualGuests') self.assert_called_with('SoftLayer_Virtual_Guest', 'migrate', identifier=100) self.assert_not_called_with('SoftLayer_Virtual_Guest', 'migrateDedicatedHost', args=(999), identifier=100) + + def test_list_vsi(self): + result = self.run_command(['vs', 'list', '--hardware']) + self.assert_no_fail(result) From 487ae59238faf4addb1c031fd28af1ba890af355 Mon Sep 17 00:00:00 2001 From: caberos Date: Thu, 13 Aug 2020 17:22:53 -0400 Subject: [PATCH 2/2] fix tox tool --- SoftLayer/CLI/virt/list.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SoftLayer/CLI/virt/list.py b/SoftLayer/CLI/virt/list.py index e80417657..ffb9fd4a0 100644 --- a/SoftLayer/CLI/virt/list.py +++ b/SoftLayer/CLI/virt/list.py @@ -53,7 +53,7 @@ @click.option('--monthly', is_flag=True, help='Show only monthly instances') @click.option('--transient', help='Filter by transient instances', type=click.BOOL) @click.option('--hardware', is_flag=True, default=False, help='Show the all VSI related to hardware') -@click.option('--all', is_flag=True, default=False, help='Show the all VSI and hardware VSIs') +@click.option('--all-guests', is_flag=True, default=False, help='Show the all VSI and hardware VSIs') @helpers.multi_option('--tag', help='Filter by tags') @click.option('--sortby', help='Column to sort by', @@ -71,7 +71,7 @@ show_default=True) @environment.pass_env def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network, - hourly, monthly, tag, columns, limit, transient, all, hardware): + hourly, monthly, tag, columns, limit, transient, hardware, all_guests): """List virtual servers.""" vsi = SoftLayer.VSManager(env.client) @@ -90,22 +90,22 @@ def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network, table = formatting.Table(columns.columns) table.sortby = sortby - if not hardware or all: + if not hardware or all_guests: for guest in guests: table.add_row([value or formatting.blank() for value in columns.row(guest)]) env.fout(table) - if hardware or all: + if hardware or all_guests: hardware_guests = vsi.get_hardware_guests() - for hardware in hardware_guests: - if hardware['virtualHost']['guests']: - title = "Hardware(id = {hardwareId}) guests associated".format(hardwareId=hardware['id']) + for hd_guest in hardware_guests: + if hd_guest['virtualHost']['guests']: + title = "Hardware(id = {hardwareId}) guests associated".format(hardwareId=hd_guest['id']) table_hardware_guest = formatting.Table(['id', 'hostname', 'CPU', 'Memory', 'Start Date', 'Status', 'powerState'], title=title) table_hardware_guest.sortby = 'hostname' - for guest in hardware['virtualHost']['guests']: + for guest in hd_guest['virtualHost']['guests']: table_hardware_guest.add_row([ guest['id'], guest['hostname'],