Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions SoftLayer/CLI/virt/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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-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',
Expand All @@ -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, hardware, all_guests):
"""List virtual servers."""

vsi = SoftLayer.VSManager(env.client)
Expand All @@ -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_guests:
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_guests:
hardware_guests = vsi.get_hardware_guests()
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 hd_guest['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)
4 changes: 4 additions & 0 deletions tests/CLI/modules/vs/vs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)