Skip to content

Commit 449e6d5

Browse files
Merge branch 'master' into issues874
2 parents 730ed0f + 0ff9f33 commit 449e6d5

File tree

17 files changed

+298
-52
lines changed

17 files changed

+298
-52
lines changed

SoftLayer/CLI/hardware/guests.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Lists the Virtual Guests running on this server."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import exceptions
9+
from SoftLayer.CLI import formatting
10+
from SoftLayer.CLI import helpers
11+
from SoftLayer import utils
12+
13+
14+
@click.command()
15+
@click.argument('identifier')
16+
@environment.pass_env
17+
def cli(env, identifier):
18+
"""Lists the Virtual Guests running on this server."""
19+
20+
mgr = SoftLayer.HardwareManager(env.client)
21+
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
22+
hw_guests = mgr.get_hardware_guests(hw_id)
23+
24+
if not hw_guests:
25+
raise exceptions.CLIAbort("No Virtual Guests found.")
26+
27+
table = formatting.Table(['id', 'hostname', 'CPU', 'Memory', 'Start Date', 'Status', 'powerState'])
28+
table.sortby = 'hostname'
29+
for guest in hw_guests:
30+
table.add_row([
31+
guest['id'],
32+
guest['hostname'],
33+
'%i %s' % (guest['maxCpu'], guest['maxCpuUnits']),
34+
guest['maxMemory'],
35+
utils.clean_time(guest['createDate']),
36+
guest['status']['keyName'],
37+
guest['powerState']['keyName']
38+
])
39+
40+
env.fout(table)

SoftLayer/CLI/hardware/reload.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
@click.command()
1414
@click.argument('identifier')
1515
@click.option('--postinstall', '-i',
16-
help=("Post-install script to download "
17-
"(Only HTTPS executes, HTTP leaves file in /root"))
16+
help=("Post-install script to download (Only HTTPS executes, HTTP leaves file in /root"))
1817
@helpers.multi_option('--key', '-k', help="SSH keys to add to the root user")
18+
@click.option('--lvm', '-l', is_flag=True, default=False, show_default=True,
19+
help="A flag indicating that the provision should use LVM for all logical drives.")
1920
@environment.pass_env
20-
def cli(env, identifier, postinstall, key):
21+
def cli(env, identifier, postinstall, key, lvm):
2122
"""Reload operating system on a server."""
2223

2324
hardware = SoftLayer.HardwareManager(env.client)
24-
hardware_id = helpers.resolve_id(hardware.resolve_ids,
25-
identifier,
26-
'hardware')
25+
hardware_id = helpers.resolve_id(hardware.resolve_ids, identifier, 'hardware')
2726
key_list = []
2827
if key:
2928
for single_key in key:
@@ -33,4 +32,4 @@ def cli(env, identifier, postinstall, key):
3332
if not (env.skip_confirmations or formatting.no_going_back(hardware_id)):
3433
raise exceptions.CLIAbort('Aborted')
3534

36-
hardware.reload(hardware_id, postinstall, key_list)
35+
hardware.reload(hardware_id, postinstall, key_list, lvm)

SoftLayer/CLI/order/preset_list.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def cli(env, package_keyname, keyword):
4343

4444
for preset in presets:
4545
table.add_row([
46-
preset['name'],
47-
preset['keyName'],
48-
preset['description']
46+
str(preset['name']).strip(),
47+
str(preset['keyName']).strip(),
48+
str(preset['description']).strip()
4949
])
5050
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@
237237
('hardware:detail', 'SoftLayer.CLI.hardware.detail:cli'),
238238
('hardware:billing', 'SoftLayer.CLI.hardware.billing:cli'),
239239
('hardware:edit', 'SoftLayer.CLI.hardware.edit:cli'),
240+
('hardware:guests', 'SoftLayer.CLI.hardware.guests:cli'),
240241
('hardware:list', 'SoftLayer.CLI.hardware.list:cli'),
241242
('hardware:power-cycle', 'SoftLayer.CLI.hardware.power:power_cycle'),
242243
('hardware:power-off', 'SoftLayer.CLI.hardware.power:power_off'),

SoftLayer/CLI/virt/detail.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from SoftLayer.CLI import environment
1010
from SoftLayer.CLI import formatting
1111
from SoftLayer.CLI import helpers
12+
from SoftLayer.CLI.virt.storage import get_local_type
1213
from SoftLayer import utils
1314

1415
LOGGER = logging.getLogger(__name__)
@@ -200,15 +201,3 @@ def _get_security_table(result):
200201
return secgroup_table
201202
else:
202203
return None
203-
204-
205-
def get_local_type(disks):
206-
"""Returns the virtual server local disk type.
207-
208-
:param disks: virtual serve local disks.
209-
"""
210-
disk_type = 'System'
211-
if 'SWAP' in disks['diskImage']['description']:
212-
disk_type = 'Swap'
213-
214-
return disk_type

SoftLayer/CLI/virt/list.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from SoftLayer.CLI import environment
99
from SoftLayer.CLI import formatting
1010
from SoftLayer.CLI import helpers
11-
11+
from SoftLayer import utils
1212

1313
# pylint: disable=unnecessary-lambda
1414

@@ -93,3 +93,22 @@ def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network,
9393
for value in columns.row(guest)])
9494

9595
env.fout(table)
96+
97+
hardware_guests = vsi.get_hardware_guests()
98+
for hardware in hardware_guests:
99+
if hardware['virtualHost']['guests']:
100+
title = "Hardware(id = {hardwareId}) guests associated".format(hardwareId=hardware['id'])
101+
table_hardware_guest = formatting.Table(['id', 'hostname', 'CPU', 'Memory', 'Start Date', 'Status',
102+
'powerState'], title=title)
103+
table_hardware_guest.sortby = 'hostname'
104+
for guest in hardware['virtualHost']['guests']:
105+
table_hardware_guest.add_row([
106+
guest['id'],
107+
guest['hostname'],
108+
'%i %s' % (guest['maxCpu'], guest['maxCpuUnits']),
109+
guest['maxMemory'],
110+
utils.clean_time(guest['createDate']),
111+
guest['status']['keyName'],
112+
guest['powerState']['keyName']
113+
])
114+
env.fout(table_hardware_guest)

SoftLayer/CLI/virt/storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def get_local_type(disks):
6767
:param disks: virtual serve local disks.
6868
"""
6969
disk_type = 'System'
70-
if 'SWAP' in disks['diskImage']['description']:
70+
if 'SWAP' in disks.get('diskImage', {}).get('description', []):
7171
disk_type = 'Swap'
7272

7373
return disk_type

SoftLayer/fixtures/SoftLayer_Account.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,28 @@
146146
'id': 6660
147147
}
148148
},
149+
"virtualHost": {
150+
"accountId": 11111,
151+
"id": 22222,
152+
"name": "vmware.chechu.com",
153+
"guests": [
154+
{
155+
"accountId": 11111,
156+
"createDate": "2019-09-05T17:03:42-06:00",
157+
"hostname": "NSX-T Manager",
158+
"id": 33333,
159+
"maxCpu": 16,
160+
"maxCpuUnits": "CORE",
161+
"maxMemory": 49152,
162+
"powerState": {
163+
"keyName": "RUNNING",
164+
"name": "Running"
165+
},
166+
"status": {
167+
"keyName": "ACTIVE",
168+
"name": "Active"
169+
}
170+
}]}
149171
}, {
150172
'id': 1001,
151173
'metricTrackingObject': {'id': 4},
@@ -190,7 +212,13 @@
190212
'vlanNumber': 3672,
191213
'id': 19082
192214
},
193-
]
215+
],
216+
"virtualHost": {
217+
"accountId": 11111,
218+
"id": 22222,
219+
"name": "host14.vmware.chechu.com",
220+
"guests": []
221+
}
194222
}, {
195223
'id': 1002,
196224
'metricTrackingObject': {'id': 5},
@@ -234,9 +262,21 @@
234262
'vlanNumber': 3672,
235263
'id': 19082
236264
},
237-
]
265+
],
266+
"virtualHost": {
267+
"accountId": 11111,
268+
"id": 22222,
269+
"name": "host14.vmware.chechu.com",
270+
"guests": []
271+
}
238272
}, {
239273
'id': 1003,
274+
"virtualHost": {
275+
"accountId": 11111,
276+
"id": 22222,
277+
"name": "host14.vmware.chechu.com",
278+
"guests": []
279+
}
240280
}]
241281
getDomains = [{'name': 'example.com',
242282
'id': 12345,

SoftLayer/fixtures/SoftLayer_Hardware_Server.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,23 @@
242242
}
243243
}
244244
]
245+
246+
getVirtualHost = {
247+
"accountId": 11111,
248+
"createDate": "2018-10-08T10:54:48-06:00",
249+
"description": "host16.vmware.chechu.com",
250+
"hardwareId": 22222,
251+
"id": 33333,
252+
"name": "host16.vmware.chechu.com",
253+
"uuid": "00000000-0000-0000-0000-0cc11111",
254+
"hardware": {
255+
"accountId": 11111,
256+
"domain": "chechu.com",
257+
"hostname": "host16.vmware",
258+
"id": 22222,
259+
"hardwareStatus": {
260+
"id": 5,
261+
"status": "ACTIVE"
262+
}
263+
}
264+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
getGuests = [
2+
{
3+
"accountId": 11111,
4+
"createDate": "2019-09-05T17:03:42-06:00",
5+
"fullyQualifiedDomainName": "NSX-T Manager",
6+
"hostname": "NSX-T Manager",
7+
"id": 22222,
8+
"maxCpu": 16,
9+
"maxCpuUnits": "CORE",
10+
"maxMemory": 49152,
11+
"startCpus": 16,
12+
"powerState": {
13+
"keyName": "RUNNING",
14+
"name": "Running"
15+
},
16+
"status": {
17+
"keyName": "ACTIVE",
18+
"name": "Active"
19+
}
20+
},
21+
{
22+
"accountId": 11111,
23+
"createDate": "2019-09-23T06:00:53-06:00",
24+
"hostname": "NSX-T Manager2",
25+
"id": 33333,
26+
"maxCpu": 12,
27+
"maxCpuUnits": "CORE",
28+
"maxMemory": 49152,
29+
"startCpus": 12,
30+
"statusId": 1001,
31+
"powerState": {
32+
"keyName": "RUNNING",
33+
"name": "Running"
34+
},
35+
"status": {
36+
"keyName": "ACTIVE",
37+
"name": "Active"
38+
}
39+
}
40+
]

0 commit comments

Comments
 (0)