Skip to content

Commit de19801

Browse files
Merge pull request #888 from flavio-fernandes/dedicated_host_details.merge
virtual detail: show dedicated host info, if applicable
2 parents 483b106 + 11b478f commit de19801

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

SoftLayer/CLI/virt/detail.py

+22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Get details for a virtual server."""
22
# :license: MIT, see LICENSE for more details.
33

4+
import logging
5+
46
import click
57

68
import SoftLayer
@@ -9,6 +11,8 @@
911
from SoftLayer.CLI import helpers
1012
from SoftLayer import utils
1113

14+
LOGGER = logging.getLogger(__name__)
15+
1216

1317
@click.command()
1418
@click.argument('identifier')
@@ -45,6 +49,7 @@ def cli(env, identifier, passwords=False, price=False):
4549
table.add_row(['active_transaction', formatting.active_txn(result)])
4650
table.add_row(['datacenter',
4751
result['datacenter']['name'] or formatting.blank()])
52+
_cli_helper_dedicated_host(env, result, table)
4853
operating_system = utils.lookup(result,
4954
'operatingSystem',
5055
'softwareLicense',
@@ -138,3 +143,20 @@ def cli(env, identifier, passwords=False, price=False):
138143
pass
139144

140145
env.fout(table)
146+
147+
148+
def _cli_helper_dedicated_host(env, result, table):
149+
"""Get details on dedicated host for a virtual server."""
150+
151+
dedicated_host_id = utils.lookup(result, 'dedicatedHost', 'id')
152+
if dedicated_host_id:
153+
table.add_row(['dedicated_host_id', dedicated_host_id])
154+
# Try to find name of dedicated host
155+
try:
156+
dedicated_host = env.client.call('Virtual_DedicatedHost', 'getObject',
157+
id=dedicated_host_id)
158+
except SoftLayer.SoftLayerAPIError:
159+
LOGGER.error('Unable to get dedicated host id %s', dedicated_host_id)
160+
dedicated_host = {}
161+
table.add_row(['dedicated_host',
162+
dedicated_host.get('name') or formatting.blank()])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
getObject = {
2+
'id': 37401,
3+
'memoryCapacity': 242,
4+
'modifyDate': '',
5+
'name': 'test-dedicated',
6+
'diskCapacity': 1200,
7+
'createDate': '2017-10-16T12:50:23-05:00',
8+
'cpuCount': 56,
9+
'accountId': 1199911
10+
}

SoftLayer/fixtures/SoftLayer_Virtual_Guest.py

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
'networkVlans': [{'networkSpace': 'PUBLIC',
4545
'vlanNumber': 23,
4646
'id': 1}],
47+
'dedicatedHost': {'id': 37401},
4748
'operatingSystem': {
4849
'passwords': [{'username': 'user', 'password': 'pass'}],
4950
'softwareLicense': {

tests/CLI/modules/vs_tests.py

+21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import mock
1010

1111
from SoftLayer.CLI import exceptions
12+
from SoftLayer import SoftLayerAPIError
1213
from SoftLayer import testing
1314

1415

@@ -42,6 +43,8 @@ def test_detail_vs(self):
4243
'cores': 2,
4344
'created': '2013-08-01 15:23:45',
4445
'datacenter': 'TEST00',
46+
'dedicated_host': 'test-dedicated',
47+
'dedicated_host_id': 37401,
4548
'hostname': 'vs-test1',
4649
'domain': 'test.sftlyr.ws',
4750
'fqdn': 'vs-test1.test.sftlyr.ws',
@@ -88,6 +91,24 @@ def test_detail_vs_empty_tag(self):
8891
['example-tag'],
8992
)
9093

94+
def test_detail_vs_dedicated_host_not_found(self):
95+
ex = SoftLayerAPIError('SoftLayer_Exception', 'Not found')
96+
mock = self.set_mock('SoftLayer_Virtual_DedicatedHost', 'getObject')
97+
mock.side_effect = ex
98+
result = self.run_command(['vs', 'detail', '100'])
99+
self.assert_no_fail(result)
100+
self.assertEqual(json.loads(result.output)['dedicated_host_id'], 37401)
101+
self.assertIsNone(json.loads(result.output)['dedicated_host'])
102+
103+
def test_detail_vs_no_dedicated_host_hostname(self):
104+
mock = self.set_mock('SoftLayer_Virtual_DedicatedHost', 'getObject')
105+
mock.return_value = {'this_is_a_fudged_Virtual_DedicatedHost': True,
106+
'name_is_not_provided': ''}
107+
result = self.run_command(['vs', 'detail', '100'])
108+
self.assert_no_fail(result)
109+
self.assertEqual(json.loads(result.output)['dedicated_host_id'], 37401)
110+
self.assertIsNone(json.loads(result.output)['dedicated_host'])
111+
91112
def test_create_options(self):
92113
result = self.run_command(['vs', 'create-options'])
93114

0 commit comments

Comments
 (0)