Skip to content

Commit e63d10a

Browse files
Merge pull request #1835 from BrianSantivanez/issue1829
New Command: `slcli virtual host-list`
2 parents 1c9d0a6 + f24827a commit e63d10a

File tree

20 files changed

+298
-137
lines changed

20 files changed

+298
-137
lines changed

SoftLayer/CLI/core.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ def get_latest_version():
5252
return latest
5353

5454

55-
CONTEXT_SETTINGS = dict(
56-
help_option_names=['--help', '-h'],
57-
auto_envvar_prefix='SLCLI',
58-
max_content_width=999
59-
)
55+
CONTEXT_SETTINGS = {
56+
"help_option_names": ['--help', '-h'],
57+
"auto_envvar_prefix": 'SLCLI',
58+
"max_content_width": 999
59+
}
6060

6161

6262
def get_version_message(ctx, param, value):

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+
for host in dedicated_hosts:
38+
cpu_allocated = host.get('allocationStatus').get('cpuAllocated')
39+
cpu_total = host.get('allocationStatus').get('cpuCount')
40+
memory_allocated = host.get('allocationStatus').get('memoryAllocated')
41+
memory_total = host.get('allocationStatus').get('memoryCapacity')
42+
disk_allocated = host.get('allocationStatus').get('diskAllocated')
43+
disk_total = host.get('allocationStatus').get('diskCapacity')
44+
table.add_row([
45+
host.get('id'),
46+
host.get('name'),
47+
host.get('datacenter').get('name'),
48+
host.get('backendRouter').get('hostname'),
49+
f"{cpu_allocated}/{cpu_total}",
50+
f"{memory_allocated}/{memory_total}",
51+
f"{disk_allocated}/{disk_total}",
52+
host.get('guestCount')
53+
])
54+
55+
env.fout(table)
56+
else:
57+
click.secho("No dedicated hosts are found.")

SoftLayer/CLI/hardware/reload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1414
@click.argument('identifier')
1515
@click.option('--postinstall', '-i',
16-
help=("Post-install script to download (Only HTTPS executes, HTTP leaves file in /root"))
16+
help="Post-install script to download (Only HTTPS executes, HTTP leaves file in /root")
1717
@helpers.multi_option('--key', '-k', help="SSH keys to add to the root user")
1818
@click.option('--lvm', '-l', is_flag=True, default=False, show_default=True,
1919
help="A flag indicating that the provision should use LVM for all logical drives.")

SoftLayer/CLI/order/place.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
@click.option('--billing', type=click.Choice(['hourly', 'monthly']), default='hourly', show_default=True,
2929
help="Billing rate")
3030
@click.option('--complex-type',
31-
help=("The complex type of the order. Starts with 'SoftLayer_Container_Product_Order'."))
31+
help="The complex type of the order. Starts with 'SoftLayer_Container_Product_Order'.")
3232
@click.option('--extras',
3333
help="JSON string denoting extra data that needs to be sent with the order")
3434
@click.argument('order_items', nargs=-1)

SoftLayer/CLI/order/quote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _parse_create_args(client, args):
7575
@click.option('--quantity', type=int, default=None,
7676
help="The quantity of the item being ordered if different from quoted value")
7777
@click.option('--complex-type', default='SoftLayer_Container_Product_Order_Hardware_Server', show_default=True,
78-
help=("The complex type of the order. Starts with 'SoftLayer_Container_Product_Order'."))
78+
help="The complex type of the order. Starts with 'SoftLayer_Container_Product_Order'.")
7979
@click.option('--userdata', '-u', help="User defined metadata string")
8080
@click.option('--userfile', '-F', type=click.Path(exists=True, readable=True, resolve_path=True),
8181
help="Read userdata from file")

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +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.dedicatedhost.list:cli'),
6061

6162
('dedicatedhost', 'SoftLayer.CLI.dedicatedhost'),
6263
('dedicatedhost:list', 'SoftLayer.CLI.dedicatedhost.list:cli'),

SoftLayer/CLI/storage_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _format_name(obj):
6565

6666
return name
6767
else:
68-
raise Exception('Unknown type %s' % obj['type'])
68+
raise ValueError('Unknown type %s' % obj['type'])
6969

7070

7171
COLUMNS = [

SoftLayer/CLI/virt/create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ def _parse_create_args(client, args):
199199
@click.option('--router-private', type=click.INT,
200200
help="The ID of the private ROUTER on which you want the virtual server placed")
201201
@helpers.multi_option('--public-security-group', '-S',
202-
help=('Security group ID to associate with the public interface'))
202+
help='Security group ID to associate with the public interface')
203203
@helpers.multi_option('--private-security-group', '-s',
204-
help=('Security group ID to associate with the private interface'))
204+
help='Security group ID to associate with the private interface')
205205
@click.option('--wait', type=click.INT,
206206
help="Wait until VS is finished provisioning for up to X seconds before returning")
207207
@click.option('--placementgroup',

SoftLayer/fixtures/SoftLayer_Account.py

Lines changed: 186 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -704,17 +704,192 @@
704704
'metricTrackingObjectId': 10,
705705
}]
706706

707-
getDedicatedHosts = [{
708-
'datacenter': {
709-
'name': 'dal05'
710-
},
711-
'memoryCapacity': 242,
712-
'name': 'test-dedicated',
713-
'diskCapacity': 1200,
714-
'guestCount': 1,
715-
'cpuCount': 56,
716-
'id': 12345
717-
}]
707+
getDedicatedHosts = [
708+
{
709+
"cpuCount": 56,
710+
"createDate": "2021-11-18T15:13:57-06:00",
711+
"diskCapacity": 1200,
712+
"id": 656700,
713+
"memoryCapacity": 242,
714+
"name": "dedicatedhost01",
715+
"guestCount": 0,
716+
"allocationStatus": {
717+
"cpuAllocated": 0,
718+
"cpuAvailable": 56,
719+
"cpuCount": 56,
720+
"diskAllocated": 0,
721+
"diskAvailable": 1200,
722+
"diskCapacity": 1200,
723+
"guestCount": 0,
724+
"memoryAllocated": 0,
725+
"memoryAvailable": 242,
726+
"memoryCapacity": 242
727+
},
728+
"backendRouter": {
729+
"accountId": 1,
730+
"bareMetalInstanceFlag": 0,
731+
"domain": "softlayer.com",
732+
"fullyQualifiedDomainName": "bcr01a.dal13.softlayer.com",
733+
"hardwareStatusId": 5,
734+
"hostname": "bcr01a.dal13",
735+
"id": 1883692,
736+
"notes": "",
737+
"provisionDate": None,
738+
"serviceProviderId": 1,
739+
"serviceProviderResourceId": None
740+
},
741+
"billingItem": {
742+
"allowCancellationFlag": 1,
743+
"cancellationDate": None,
744+
"categoryCode": "dedicated_virtual_hosts",
745+
"createDate": "2021-11-18T15:13:59-06:00",
746+
"currentHourlyCharge": "0",
747+
"cycleStartDate": "2023-01-04T00:07:36-06:00",
748+
"description": "56 Cores X 242 RAM X 1.2 TB",
749+
"hostName": "dedicatedhost01",
750+
"hourlyRecurringFee": "0",
751+
"hoursUsed": "465",
752+
"id": 910104016,
753+
"laborFee": "0",
754+
"laborFeeTaxRate": "0",
755+
"lastBillDate": "2023-01-04T00:07:36-06:00",
756+
"modifyDate": "2023-01-04T00:07:36-06:00",
757+
"nextBillDate": "2023-02-04T00:00:00-06:00",
758+
"oneTimeFee": "0",
759+
"oneTimeFeeTaxRate": "0",
760+
"orderItemId": 874370304,
761+
"parentId": None,
762+
"recurringFee": "0",
763+
"recurringFeeTaxRate": "0",
764+
"recurringMonths": 1,
765+
"serviceProviderId": 1,
766+
"setupFee": "0",
767+
"setupFeeTaxRate": "0",
768+
"orderItem": {
769+
"categoryCode": "dedicated_virtual_hosts",
770+
"description": "56 Cores X 242 RAM X 1.2 TB",
771+
"hostName": "dedicatedhost01",
772+
"hourlyRecurringFee": "0",
773+
"id": 874370304,
774+
"itemId": 10195,
775+
"itemPriceId": "200269",
776+
"laborAfterTaxAmount": "0",
777+
"laborFee": "0",
778+
"laborFeeTaxRate": "0",
779+
"laborTaxAmount": "0",
780+
"oneTimeAfterTaxAmount": "0",
781+
"oneTimeFee": "0",
782+
"oneTimeFeeTaxRate": "0",
783+
"oneTimeTaxAmount": "0",
784+
"parentId": None,
785+
"presetId": None,
786+
"promoCodeId": None,
787+
"quantity": None,
788+
"recurringAfterTaxAmount": "0",
789+
"recurringFee": "0",
790+
"recurringTaxAmount": "0",
791+
"setupAfterTaxAmount": "0",
792+
"setupFee": "0",
793+
"setupFeeDeferralMonths": None,
794+
"setupFeeTaxRate": "0",
795+
"setupTaxAmount": "0",
796+
"order": {
797+
"accountId": 307608,
798+
"createDate": "2021-11-18T15:13:57-06:00",
799+
"id": 85857762,
800+
"impersonatingUserRecordId": None,
801+
"modifyDate": "2021-11-18T15:14:00-06:00",
802+
"orderQuoteId": None,
803+
"orderTypeId": 11,
804+
"presaleEventId": None,
805+
"privateCloudOrderFlag": False,
806+
"status": "APPROVED",
807+
"userRecordId": 7650493,
808+
"userRecord": {
809+
"accountId": 307608,
810+
"address1": "4849 Alpha Rd",
811+
"city": "Dallas",
812+
"companyName": "SoftLayer Internal - Development Community",
813+
"country": "US",
814+
"createDate": "2019-06-10T15:21:33-07:00",
815+
"daylightSavingsTimeFlag": False,
816+
"denyAllResourceAccessOnCreateFlag": False,
817+
"displayName": "danielc",
818+
"email": "daniel.cabero@jalasoft.com",
819+
"firstName": "daniel",
820+
"forumPasswordHash": "unused",
821+
"iamAuthorizationStatus": 1,
822+
"iamId": "IBMid-550003CUGT",
823+
"id": 7650493,
824+
"isMasterUserFlag": False,
825+
"lastName": "cabero",
826+
"localeId": 1,
827+
"managedByFederationFlag": False,
828+
"managedByOpenIdConnectFlag": True,
829+
"minimumPasswordLifeHours": 0,
830+
"modifyDate": "2019-12-13T07:29:07-06:00",
831+
"openIdConnectUserName": "daniel.cabero@jalasoft.com",
832+
"parentId": 167758,
833+
"passwordExpireDate": None,
834+
"permissionCheckLikeMasterUserFlag": 0,
835+
"postalCode": "75244-4608",
836+
"pptpVpnAllowedFlag": False,
837+
"preventPreviousPasswords": 0,
838+
"savedId": "7650493",
839+
"secondaryLoginManagementFlag": True,
840+
"secondaryLoginRequiredFlag": None,
841+
"secondaryPasswordModifyDate": "2019-06-10T15:21:33-07:00",
842+
"secondaryPasswordTimeoutDays": 0,
843+
"sslVpnAllowedFlag": False,
844+
"state": "TX",
845+
"statusDate": None,
846+
"timezoneId": 113,
847+
"userStatusId": 1001,
848+
"username": "sl307608-dcabero",
849+
"vpnManualConfig": False,
850+
"ibmIdLink": {
851+
"createDate": "2019-06-10T15:21:34-07:00",
852+
"defaultFlag": 1,
853+
"destinationUserAlphanumericId": "daniel%2ecabero@jalasoft%2ecom",
854+
"destinationUserId": None,
855+
"iamIdVerificationFlag": 2,
856+
"id": 1051135,
857+
"realm": "IBMid",
858+
"serviceProviderId": 348,
859+
"uniqueIdentifier": "IBMid-550003CUGT",
860+
"userId": 7650493
861+
},
862+
"locale": {
863+
"friendlyName": "English",
864+
"id": 1,
865+
"languageTag": "en-US",
866+
"name": "English"
867+
},
868+
"timezone": {
869+
"id": 113,
870+
"longName": "(GMT-06:00) America/Chicago - CST",
871+
"name": "America/Chicago",
872+
"offset": "-0600",
873+
"shortName": "CST"
874+
},
875+
"userStatus": {
876+
"id": 1001,
877+
"keyName": "ACTIVE",
878+
"name": "Active"
879+
}
880+
}
881+
}
882+
},
883+
"resourceTableId": 656700
884+
},
885+
"datacenter": {
886+
"id": 1854895,
887+
"longName": "Dallas 13",
888+
"name": "dal13",
889+
"statusId": 2
890+
}
891+
}
892+
]
718893

719894
getUsers = [
720895
{'displayName': 'ChristopherG',

0 commit comments

Comments
 (0)