Skip to content

Commit

Permalink
Merge pull request #910 from allmightyspiff/issues877
Browse files Browse the repository at this point in the history
Updates hardware detail to properly show prices
  • Loading branch information
allmightyspiff authored Dec 18, 2017
2 parents 178dc1e + 5a30fd6 commit 7d98773
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 69 deletions.
89 changes: 27 additions & 62 deletions SoftLayer/CLI/hardware/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@

@click.command()
@click.argument('identifier')
@click.option('--passwords',
is_flag=True,
help='Show passwords (check over your shoulder!)')
@click.option('--price',
is_flag=True,
help='Show associated prices')
@click.option('--passwords', is_flag=True, help='Show passwords (check over your shoulder!)')
@click.option('--price', is_flag=True, help='Show associated prices')
@environment.pass_env
def cli(env, identifier, passwords, price):
"""Get details for a hardware device."""
Expand All @@ -28,71 +24,52 @@ def cli(env, identifier, passwords, price):
table.align['name'] = 'r'
table.align['value'] = 'l'

hardware_id = helpers.resolve_id(hardware.resolve_ids,
identifier,
'hardware')
hardware_id = helpers.resolve_id(hardware.resolve_ids, identifier, 'hardware')
result = hardware.get_hardware(hardware_id)
result = utils.NestedDict(result)

operating_system = utils.lookup(result, 'operatingSystem', 'softwareLicense', 'softwareDescription') or {}
memory = formatting.gb(result.get('memoryCapacity', 0))
owner = None
if utils.lookup(result, 'billingItem') != []:
owner = utils.lookup(result, 'billingItem', 'orderItem', 'order', 'userRecord', 'username')

table.add_row(['id', result['id']])
table.add_row(['guid', result['globalIdentifier'] or formatting.blank()])
table.add_row(['hostname', result['hostname']])
table.add_row(['domain', result['domain']])
table.add_row(['fqdn', result['fullyQualifiedDomainName']])
table.add_row(['status', result['hardwareStatus']['status']])
table.add_row(['datacenter',
result['datacenter']['name'] or formatting.blank()])
table.add_row(['datacenter', result['datacenter']['name'] or formatting.blank()])
table.add_row(['cores', result['processorPhysicalCoreAmount']])
memory = (formatting.gb(result['memoryCapacity'])
if result.get('memoryCapacity')
else formatting.blank())
table.add_row(['memory', memory])
table.add_row(['public_ip',
result['primaryIpAddress'] or formatting.blank()])
table.add_row(['private_ip',
result['primaryBackendIpAddress'] or formatting.blank()])
table.add_row(['ipmi_ip',
result['networkManagementIpAddress'] or formatting.blank()])
operating_system = utils.lookup(result,
'operatingSystem',
'softwareLicense',
'softwareDescription') or {}
table.add_row(['public_ip', result['primaryIpAddress'] or formatting.blank()])
table.add_row(['private_ip', result['primaryBackendIpAddress'] or formatting.blank()])
table.add_row(['ipmi_ip', result['networkManagementIpAddress'] or formatting.blank()])
table.add_row(['os', operating_system.get('name') or formatting.blank()])
table.add_row(['os_version',
operating_system.get('version') or formatting.blank()])

table.add_row(
['created', result['provisionDate'] or formatting.blank()])

if utils.lookup(result, 'billingItem') != []:
table.add_row(['owner', formatting.FormattedItem(
utils.lookup(result, 'billingItem', 'orderItem',
'order', 'userRecord',
'username') or formatting.blank(),
)])
else:
table.add_row(['owner', formatting.blank()])
table.add_row(['os_version', operating_system.get('version') or formatting.blank()])
table.add_row(['created', result['provisionDate'] or formatting.blank()])
table.add_row(['owner', owner or formatting.blank()])

vlan_table = formatting.Table(['type', 'number', 'id'])

for vlan in result['networkVlans']:
vlan_table.add_row([
vlan['networkSpace'], vlan['vlanNumber'], vlan['id']])
vlan_table.add_row([vlan['networkSpace'], vlan['vlanNumber'], vlan['id']])

table.add_row(['vlans', vlan_table])

if result.get('notes'):
table.add_row(['notes', result['notes']])

if price:
total_price = utils.lookup(result,
'billingItem',
'nextInvoiceTotalRecurringAmount') or 0
total_price += sum(p['nextInvoiceTotalRecurringAmount']
for p
in utils.lookup(result,
'billingItem',
'children') or [])
table.add_row(['price_rate', total_price])
total_price = utils.lookup(result, 'billingItem', 'nextInvoiceTotalRecurringAmount') or 0

price_table = formatting.Table(['Item', 'Recurring Price'])
price_table.add_row(['Total', total_price])

for item in utils.lookup(result, 'billingItem', 'children') or []:
price_table.add_row([item['description'], item['nextInvoiceTotalRecurringAmount']])

table.add_row(['prices', price_table])

if passwords:
pass_table = formatting.Table(['username', 'password'])
Expand All @@ -107,16 +84,4 @@ def cli(env, identifier, passwords, price):

table.add_row(['tags', formatting.tags(result['tagReferences'])])

# Test to see if this actually has a primary (public) ip address
try:
if not result['privateNetworkOnlyFlag']:
ptr_domains = (env.client['Hardware_Server']
.getReverseDomainRecords(id=hardware_id))

for ptr_domain in ptr_domains:
for ptr in ptr_domain['resourceRecords']:
table.add_row(['ptr', ptr['data']])
except SoftLayer.SoftLayerAPIError:
pass

env.fout(table)
6 changes: 1 addition & 5 deletions SoftLayer/fixtures/SoftLayer_Hardware_Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
'recurringFee': 1.54,
'nextInvoiceTotalRecurringAmount': 16.08,
'children': [
{'nextInvoiceTotalRecurringAmount': 1},
{'nextInvoiceTotalRecurringAmount': 1},
{'nextInvoiceTotalRecurringAmount': 1},
{'nextInvoiceTotalRecurringAmount': 1},
{'nextInvoiceTotalRecurringAmount': 1},
{'description': 'test', 'nextInvoiceTotalRecurringAmount': 1},
],
'orderItem': {
'order': {
Expand Down
4 changes: 2 additions & 2 deletions tests/CLI/modules/server_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def test_server_details(self):
'os': 'Ubuntu',
'os_version': 'Ubuntu 12.04 LTS',
'owner': 'chechu',
'price_rate': 21.08,
'prices': [{'Item': 'Total', 'Recurring Price': 16.08},
{'Item': 'test', 'Recurring Price': 1}],
'private_ip': '10.1.0.2',
'ptr': '2.0.1.10.in-addr.arpa',
'public_ip': '172.16.1.100',
'remote users': [{'password': 'abc123', 'ipmi_username': 'root'}],
'status': 'ACTIVE',
Expand Down

0 comments on commit 7d98773

Please sign in to comment.