Skip to content

Commit 743af77

Browse files
Merge pull request #1780 from BrianSantivanez/issue1777
Match `virtual detail --prices` option with `hardware detail --prices` option
2 parents 44773e6 + 1e5afdc commit 743af77

File tree

4 files changed

+73
-7
lines changed

4 files changed

+73
-7
lines changed

SoftLayer/CLI/virt/detail.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,9 @@ def cli(env, identifier, passwords=False, price=False):
9797
total_price = utils.lookup(result,
9898
'billingItem',
9999
'nextInvoiceTotalRecurringAmount') or 0
100-
total_price += sum(p['nextInvoiceTotalRecurringAmount']
101-
for p
102-
in utils.lookup(result,
103-
'billingItem',
104-
'children') or [])
105-
table.add_row(['price_rate', total_price])
100+
if total_price != 0:
101+
table.add_row(['Prices', _price_table(utils.lookup(result, 'billingItem'), total_price)])
102+
table.add_row(['Price rate', total_price])
106103

107104
if passwords:
108105
pass_table = formatting.Table(['software', 'username', 'password'])
@@ -156,6 +153,17 @@ def _bw_table(bw_data):
156153
return table
157154

158155

156+
def _price_table(billing_item, total_price):
157+
"""Returns an item table"""
158+
price_table = formatting.Table(['Item', 'CategoryCode', 'Recurring Price'])
159+
price_table.add_row(['Total', '-', total_price])
160+
items = billing_item['nextInvoiceChildren']
161+
for item in items:
162+
if item.get('recurringFee') is not None:
163+
price_table.add_row([item['description'], item['categoryCode'], item['recurringFee']])
164+
return price_table
165+
166+
159167
def _cli_helper_dedicated_host(env, result, table):
160168
"""Get details on dedicated host for a virtual server."""
161169

SoftLayer/fixtures/SoftLayer_Virtual_Guest.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,60 @@
3434
'nextInvoiceTotalRecurringAmount': 1
3535
}
3636
],
37+
"nextInvoiceChildren": [
38+
{
39+
"allowCancellationFlag": 1,
40+
"associatedBillingItemId": "738974962",
41+
"cancellationDate": "2022-11-03T23:00:01-06:00",
42+
"categoryCode": "os_usage",
43+
"createDate": "2022-10-04T17:00:08-06:00",
44+
"cycleStartDate": "2022-10-04T17:00:08-06:00",
45+
"description": "CentOS 8.x Usage is 743.9997 hours Used",
46+
"id": 999303609,
47+
"laborFee": "0",
48+
"laborFeeTaxRate": "0",
49+
"lastBillDate": None,
50+
"modifyDate": None,
51+
"nextBillDate": "2022-11-03T23:00:00-06:00",
52+
"oneTimeFee": "0",
53+
"oneTimeFeeTaxRate": "0",
54+
"orderItemId": None,
55+
"parentId": None,
56+
"recurringFee": "0",
57+
"recurringFeeTaxRate": "0",
58+
"recurringMonths": 1,
59+
"serviceProviderId": 1,
60+
"setupFee": "0",
61+
"setupFeeTaxRate": "0",
62+
"associatedBillingItem": None
63+
},
64+
{
65+
"allowCancellationFlag": 1,
66+
"associatedBillingItemId": "738974962",
67+
"cancellationDate": "2022-11-03T23:00:01-06:00",
68+
"categoryCode": "guest_core_usage",
69+
"createDate": "2022-10-04T17:00:09-06:00",
70+
"cycleStartDate": "2022-10-04T17:00:09-06:00",
71+
"description": "CPU Cores: a suspendable product.",
72+
"id": 999303621,
73+
"laborFee": "0",
74+
"laborFeeTaxRate": "0",
75+
"lastBillDate": None,
76+
"modifyDate": None,
77+
"nextBillDate": "2022-11-03T23:00:00-06:00",
78+
"oneTimeFee": "0",
79+
"oneTimeFeeTaxRate": "0",
80+
"orderItemId": None,
81+
"parentId": None,
82+
"recurringFee": "1.54",
83+
"recurringFeeTaxRate": "0",
84+
"recurringMonths": 1,
85+
"serviceProviderId": 1,
86+
"setupFee": "0",
87+
"setupFeeTaxRate": "0",
88+
"associatedBillingItem": None
89+
},
90+
],
3791
'package': {
3892
"id": 835,
3993
"keyName": "PUBLIC_CLOUD_SERVER"

SoftLayer/managers/vs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ def get_instance(self, instance_id, **kwargs):
246246
'''billingItem[id,nextInvoiceTotalRecurringAmount,
247247
package[id,keyName],
248248
children[description,categoryCode,nextInvoiceTotalRecurringAmount],
249+
nextInvoiceChildren[description,
250+
categoryCode,
251+
recurringFee,
252+
nextInvoiceTotalRecurringAmount],
249253
orderItem[id,
250254
order.userRecord[username],
251255
preset.keyName]],'''

tests/CLI/modules/vs/vs_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_detail_vs(self):
167167
self.assert_no_fail(result)
168168
output = json.loads(result.output)
169169
self.assertEqual(output['notes'], 'notes')
170-
self.assertEqual(output['price_rate'], 6.54)
170+
self.assertEqual(output['Price rate'], 1.54)
171171
self.assertEqual(output['users'][0]['username'], 'user')
172172
self.assertEqual(output['vlans'][0]['number'], 23)
173173
self.assertEqual(output['owner'], 'chechu')

0 commit comments

Comments
 (0)