1212
1313@click .command ()
1414@click .argument ('identifier' )
15- @click .option ('--passwords' ,
16- is_flag = True ,
17- help = 'Show passwords (check over your shoulder!)' )
18- @click .option ('--price' ,
19- is_flag = True ,
20- help = 'Show associated prices' )
15+ @click .option ('--passwords' , is_flag = True , help = 'Show passwords (check over your shoulder!)' )
16+ @click .option ('--price' , is_flag = True , help = 'Show associated prices' )
2117@environment .pass_env
2218def cli (env , identifier , passwords , price ):
2319 """Get details for a hardware device."""
@@ -28,71 +24,52 @@ def cli(env, identifier, passwords, price):
2824 table .align ['name' ] = 'r'
2925 table .align ['value' ] = 'l'
3026
31- hardware_id = helpers .resolve_id (hardware .resolve_ids ,
32- identifier ,
33- 'hardware' )
27+ hardware_id = helpers .resolve_id (hardware .resolve_ids , identifier , 'hardware' )
3428 result = hardware .get_hardware (hardware_id )
3529 result = utils .NestedDict (result )
3630
31+ operating_system = utils .lookup (result , 'operatingSystem' , 'softwareLicense' , 'softwareDescription' ) or {}
32+ memory = formatting .gb (result .get ('memoryCapacity' , 0 ))
33+ owner = None
34+ if utils .lookup (result , 'billingItem' ) != []:
35+ owner = utils .lookup (result , 'billingItem' , 'orderItem' , 'order' , 'userRecord' , 'username' )
36+
3737 table .add_row (['id' , result ['id' ]])
3838 table .add_row (['guid' , result ['globalIdentifier' ] or formatting .blank ()])
3939 table .add_row (['hostname' , result ['hostname' ]])
4040 table .add_row (['domain' , result ['domain' ]])
4141 table .add_row (['fqdn' , result ['fullyQualifiedDomainName' ]])
4242 table .add_row (['status' , result ['hardwareStatus' ]['status' ]])
43- table .add_row (['datacenter' ,
44- result ['datacenter' ]['name' ] or formatting .blank ()])
43+ table .add_row (['datacenter' , result ['datacenter' ]['name' ] or formatting .blank ()])
4544 table .add_row (['cores' , result ['processorPhysicalCoreAmount' ]])
46- memory = (formatting .gb (result ['memoryCapacity' ])
47- if result .get ('memoryCapacity' )
48- else formatting .blank ())
4945 table .add_row (['memory' , memory ])
50- table .add_row (['public_ip' ,
51- result ['primaryIpAddress' ] or formatting .blank ()])
52- table .add_row (['private_ip' ,
53- result ['primaryBackendIpAddress' ] or formatting .blank ()])
54- table .add_row (['ipmi_ip' ,
55- result ['networkManagementIpAddress' ] or formatting .blank ()])
56- operating_system = utils .lookup (result ,
57- 'operatingSystem' ,
58- 'softwareLicense' ,
59- 'softwareDescription' ) or {}
46+ table .add_row (['public_ip' , result ['primaryIpAddress' ] or formatting .blank ()])
47+ table .add_row (['private_ip' , result ['primaryBackendIpAddress' ] or formatting .blank ()])
48+ table .add_row (['ipmi_ip' , result ['networkManagementIpAddress' ] or formatting .blank ()])
6049 table .add_row (['os' , operating_system .get ('name' ) or formatting .blank ()])
61- table .add_row (['os_version' ,
62- operating_system .get ('version' ) or formatting .blank ()])
63-
64- table .add_row (
65- ['created' , result ['provisionDate' ] or formatting .blank ()])
66-
67- if utils .lookup (result , 'billingItem' ) != []:
68- table .add_row (['owner' , formatting .FormattedItem (
69- utils .lookup (result , 'billingItem' , 'orderItem' ,
70- 'order' , 'userRecord' ,
71- 'username' ) or formatting .blank (),
72- )])
73- else :
74- table .add_row (['owner' , formatting .blank ()])
50+ table .add_row (['os_version' , operating_system .get ('version' ) or formatting .blank ()])
51+ table .add_row (['created' , result ['provisionDate' ] or formatting .blank ()])
52+ table .add_row (['owner' , owner or formatting .blank ()])
7553
7654 vlan_table = formatting .Table (['type' , 'number' , 'id' ])
77-
7855 for vlan in result ['networkVlans' ]:
79- vlan_table .add_row ([
80- vlan [ 'networkSpace' ], vlan [ 'vlanNumber' ], vlan [ 'id' ]])
56+ vlan_table .add_row ([vlan [ 'networkSpace' ], vlan [ 'vlanNumber' ], vlan [ 'id' ]])
57+
8158 table .add_row (['vlans' , vlan_table ])
8259
8360 if result .get ('notes' ):
8461 table .add_row (['notes' , result ['notes' ]])
8562
8663 if price :
87- total_price = utils .lookup (result ,
88- 'billingItem' ,
89- 'nextInvoiceTotalRecurringAmount' ) or 0
90- total_price += sum ( p [ 'nextInvoiceTotalRecurringAmount' ]
91- for p
92- in utils .lookup (result ,
93- 'billingItem' ,
94- 'children' ) or [])
95- table .add_row (['price_rate ' , total_price ])
64+ total_price = utils .lookup (result , 'billingItem' , 'nextInvoiceTotalRecurringAmount' ) or 0
65+
66+ price_table = formatting . Table ([ 'Item' , 'Recurring Price' ])
67+ price_table . add_row ([ 'Total' , total_price ])
68+
69+ for item in utils .lookup (result , 'billingItem' , 'children' ) or []:
70+ price_table . add_row ([ item [ 'description' ], item [ 'nextInvoiceTotalRecurringAmount' ]])
71+
72+ table .add_row (['prices ' , price_table ])
9673
9774 if passwords :
9875 pass_table = formatting .Table (['username' , 'password' ])
@@ -107,16 +84,4 @@ def cli(env, identifier, passwords, price):
10784
10885 table .add_row (['tags' , formatting .tags (result ['tagReferences' ])])
10986
110- # Test to see if this actually has a primary (public) ip address
111- try :
112- if not result ['privateNetworkOnlyFlag' ]:
113- ptr_domains = (env .client ['Hardware_Server' ]
114- .getReverseDomainRecords (id = hardware_id ))
115-
116- for ptr_domain in ptr_domains :
117- for ptr in ptr_domain ['resourceRecords' ]:
118- table .add_row (['ptr' , ptr ['data' ]])
119- except SoftLayer .SoftLayerAPIError :
120- pass
121-
12287 env .fout (table )
0 commit comments