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
22 changes: 22 additions & 0 deletions SoftLayer/CLI/virt/detail.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Get details for a virtual server."""
# :license: MIT, see LICENSE for more details.

import logging

import click

import SoftLayer
Expand All @@ -9,6 +11,8 @@
from SoftLayer.CLI import helpers
from SoftLayer import utils

LOGGER = logging.getLogger(__name__)


@click.command()
@click.argument('identifier')
Expand Down Expand Up @@ -45,6 +49,7 @@ def cli(env, identifier, passwords=False, price=False):
table.add_row(['active_transaction', formatting.active_txn(result)])
table.add_row(['datacenter',
result['datacenter']['name'] or formatting.blank()])
_cli_helper_dedicated_host(env, result, table)
operating_system = utils.lookup(result,
'operatingSystem',
'softwareLicense',
Expand Down Expand Up @@ -138,3 +143,20 @@ def cli(env, identifier, passwords=False, price=False):
pass

env.fout(table)


def _cli_helper_dedicated_host(env, result, table):
"""Get details on dedicated host for a virtual server."""

dedicated_host_id = utils.lookup(result, 'dedicatedHost', 'id')
if dedicated_host_id:
table.add_row(['dedicated_host_id', dedicated_host_id])
# Try to find name of dedicated host
try:
dedicated_host = env.client.call('Virtual_DedicatedHost', 'getObject',
id=dedicated_host_id)
except SoftLayer.SoftLayerAPIError:
LOGGER.error('Unable to get dedicated host id %s', dedicated_host_id)
dedicated_host = {}
table.add_row(['dedicated_host',
dedicated_host.get('name') or formatting.blank()])
10 changes: 10 additions & 0 deletions SoftLayer/fixtures/SoftLayer_Virtual_DedicatedHost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
getObject = {
'id': 37401,
'memoryCapacity': 242,
'modifyDate': '',
'name': 'test-dedicated',
'diskCapacity': 1200,
'createDate': '2017-10-16T12:50:23-05:00',
'cpuCount': 56,
'accountId': 1199911
}
1 change: 1 addition & 0 deletions SoftLayer/fixtures/SoftLayer_Virtual_Guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'networkVlans': [{'networkSpace': 'PUBLIC',
'vlanNumber': 23,
'id': 1}],
'dedicatedHost': {'id': 37401},
'operatingSystem': {
'passwords': [{'username': 'user', 'password': 'pass'}],
'softwareLicense': {
Expand Down
21 changes: 21 additions & 0 deletions tests/CLI/modules/vs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import mock

from SoftLayer.CLI import exceptions
from SoftLayer import SoftLayerAPIError
from SoftLayer import testing


Expand Down Expand Up @@ -42,6 +43,8 @@ def test_detail_vs(self):
'cores': 2,
'created': '2013-08-01 15:23:45',
'datacenter': 'TEST00',
'dedicated_host': 'test-dedicated',
'dedicated_host_id': 37401,
'hostname': 'vs-test1',
'domain': 'test.sftlyr.ws',
'fqdn': 'vs-test1.test.sftlyr.ws',
Expand Down Expand Up @@ -88,6 +91,24 @@ def test_detail_vs_empty_tag(self):
['example-tag'],
)

def test_detail_vs_dedicated_host_not_found(self):
ex = SoftLayerAPIError('SoftLayer_Exception', 'Not found')
mock = self.set_mock('SoftLayer_Virtual_DedicatedHost', 'getObject')
mock.side_effect = ex
result = self.run_command(['vs', 'detail', '100'])
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output)['dedicated_host_id'], 37401)
self.assertIsNone(json.loads(result.output)['dedicated_host'])

def test_detail_vs_no_dedicated_host_hostname(self):
mock = self.set_mock('SoftLayer_Virtual_DedicatedHost', 'getObject')
mock.return_value = {'this_is_a_fudged_Virtual_DedicatedHost': True,
'name_is_not_provided': ''}
result = self.run_command(['vs', 'detail', '100'])
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output)['dedicated_host_id'], 37401)
self.assertIsNone(json.loads(result.output)['dedicated_host'])

def test_create_options(self):
result = self.run_command(['vs', 'create-options'])

Expand Down