Skip to content

Commit 6336d9c

Browse files
author
Brian Flores
committed
updated command
1 parent 9f76ba2 commit 6336d9c

File tree

11 files changed

+262
-445
lines changed

11 files changed

+262
-445
lines changed

SoftLayer/CLI/dedicatedhost/list.py

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,54 @@
44
import click
55

66
import SoftLayer
7-
from SoftLayer.CLI import columns as column_helper
87
from SoftLayer.CLI import environment
98
from SoftLayer.CLI import formatting
109
from SoftLayer.CLI import helpers
1110

12-
COLUMNS = [
13-
column_helper.Column('datacenter', ('datacenter', 'name')),
14-
column_helper.Column(
15-
'created_by',
16-
('billingItem', 'orderItem', 'order', 'userRecord', 'username')),
17-
column_helper.Column(
18-
'tags',
19-
lambda server: formatting.tags(server.get('tagReferences')),
20-
mask="tagReferences.tag.name"),
21-
]
22-
23-
DEFAULT_COLUMNS = [
24-
'id',
25-
'name',
26-
'cpuCount',
27-
'diskCapacity',
28-
'memoryCapacity',
29-
'datacenter',
30-
'guestCount',
31-
]
32-
3311

3412
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
35-
@click.option('--cpu', '-c', help='Number of CPU cores', type=click.INT)
3613
@helpers.multi_option('--tag', help='Filter by tags')
3714
@click.option('--sortby', help='Column to sort by',
38-
default='name',
39-
show_default=True)
40-
@click.option('--columns',
41-
callback=column_helper.get_formatter(COLUMNS),
42-
help='Columns to display. [options: %s]'
43-
% ', '.join(column.name for column in COLUMNS),
44-
default=','.join(DEFAULT_COLUMNS),
15+
default='Name',
4516
show_default=True)
46-
@click.option('--datacenter', '-d', help='Datacenter shortname')
47-
@click.option('--name', '-H', help='Host portion of the FQDN')
48-
@click.option('--memory', '-m', help='Memory capacity in mebibytes',
49-
type=click.INT)
50-
@click.option('--disk', '-D', help='Disk capacity')
17+
@click.option('--datacenter', '-d', help='Filter by datacenter shortname')
18+
@click.option('--name', '-H', help='Filter by host portion of the FQDN')
19+
@click.option('--order', help='Filter by ID of the order which purchased this dedicated host', type=click.INT)
20+
@click.option('--owner', help='Filter by owner of the dedicated host')
5121
@environment.pass_env
52-
def cli(env, sortby, cpu, columns, datacenter, name, memory, disk, tag):
22+
def cli(env, sortby, datacenter, name, tag, order, owner):
5323
"""List dedicated host."""
5424
mgr = SoftLayer.DedicatedHostManager(env.client)
55-
hosts = mgr.list_instances(cpus=cpu,
56-
datacenter=datacenter,
57-
hostname=name,
58-
memory=memory,
59-
disk=disk,
60-
tags=tag,
61-
mask=columns.mask())
62-
63-
table = formatting.Table(columns.columns)
25+
dedicated_hosts = mgr.list_instances(datacenter=datacenter,
26+
hostname=name,
27+
tags=tag,
28+
order=order,
29+
owner=owner)
30+
31+
table = formatting.Table(["Id", "Name", "Datacenter", "Router", "CPU (allocated/total)",
32+
"Memory (allocated/total)", "Disk (allocated/total)", "Guests"])
33+
table.align['Name'] = 'l'
6434
table.sortby = sortby
6535

66-
for host in hosts:
67-
table.add_row([value or formatting.blank()
68-
for value in columns.row(host)])
69-
70-
env.fout(table)
36+
if len(dedicated_hosts) == 0:
37+
click.secho("No dedicated hosts are found.")
38+
else:
39+
for host in dedicated_hosts:
40+
cpu_allocated = host.get('allocationStatus').get('cpuAllocated')
41+
cpu_total = host.get('allocationStatus').get('cpuCount')
42+
memory_allocated = host.get('allocationStatus').get('memoryAllocated')
43+
memory_total = host.get('allocationStatus').get('memoryCapacity')
44+
disk_allocated = host.get('allocationStatus').get('diskAllocated')
45+
disk_total = host.get('allocationStatus').get('diskCapacity')
46+
table.add_row([
47+
host.get('id'),
48+
host.get('name'),
49+
host.get('datacenter').get('name'),
50+
host.get('backendRouter').get('hostname'),
51+
f"{cpu_allocated}/{cpu_total}",
52+
f"{memory_allocated}/{memory_total}",
53+
f"{disk_allocated}/{disk_total}",
54+
host.get('guestCount')
55+
])
56+
57+
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
('virtual:notifications', 'SoftLayer.CLI.virt.notifications:cli'),
5858
('virtual:notification-add', 'SoftLayer.CLI.virt.notification_add:cli'),
5959
('virtual:notification-delete', 'SoftLayer.CLI.virt.notification_delete:cli'),
60-
('virtual:host-list', 'SoftLayer.CLI.virt.host_list:cli'),
60+
('virtual:host-list', 'SoftLayer.CLI.dedicatedhost.list:cli'),
6161

6262
('dedicatedhost', 'SoftLayer.CLI.dedicatedhost'),
6363
('dedicatedhost:list', 'SoftLayer.CLI.dedicatedhost.list:cli'),

SoftLayer/CLI/virt/host_list.py

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)