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
69 changes: 42 additions & 27 deletions SoftLayer/CLI/virt/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,33 +270,19 @@ def cli(env, **args):
output = []
if args.get('test'):
result = vsi.verify_create_instance(**data)
total_monthly = 0.0
total_hourly = 0.0

table = formatting.Table(['Item', 'cost'])
table.align['Item'] = 'r'
table.align['cost'] = 'r'

for price in result['prices']:
total_monthly += float(price.get('recurringFee', 0.0))
total_hourly += float(price.get('hourlyRecurringFee', 0.0))
if args.get('billing') == 'hourly':
rate = "%.2f" % float(price['hourlyRecurringFee'])
elif args.get('billing') == 'monthly':
rate = "%.2f" % float(price['recurringFee'])

table.add_row([price['item']['description'], rate])

total = 0
if args.get('billing') == 'hourly':
total = total_hourly
elif args.get('billing') == 'monthly':
total = total_monthly

billing_rate = 'monthly'
if args.get('billing') == 'hourly':
billing_rate = 'hourly'
table.add_row(['Total %s cost' % billing_rate, "%.2f" % total])

if result['presetId']:
ordering_mgr = SoftLayer.OrderingManager(env.client)
item_prices = ordering_mgr.get_item_prices(result['packageId'])
preset_prices = ordering_mgr.get_preset_prices(result['presetId'])
search_keys = ["guest_core", "ram"]
for price in preset_prices['prices']:
if price['item']['itemCategory']['categoryCode'] in search_keys:
item_key_name = price['item']['keyName']
_add_item_prices(item_key_name, item_prices, result)

table = _build_receipt_table(result['prices'], args.get('billing'))

output.append(table)
output.append(formatting.FormattedItem(
None,
Expand Down Expand Up @@ -334,6 +320,35 @@ def cli(env, **args):
env.fout(output)


def _add_item_prices(item_key_name, item_prices, result):
"""Add the flavor item prices to the rest o the items prices"""
for item in item_prices:
if item_key_name == item['item']['keyName']:
if 'pricingLocationGroup' in item:
for location in item['pricingLocationGroup']['locations']:
if result['location'] == str(location['id']):
result['prices'].append(item)


def _build_receipt_table(prices, billing="hourly"):
"""Retrieve the total recurring fee of the items prices"""
total = 0.000
table = formatting.Table(['Cost', 'Item'])
table.align['Cost'] = 'r'
table.align['Item'] = 'l'
for price in prices:
rate = 0.000
if billing == "hourly":
rate += float(price.get('hourlyRecurringFee', 0.000))
else:
rate += float(price.get('recurringFee', 0.000))
total += rate

table.add_row(["%.3f" % rate, price['item']['description']])
table.add_row(["%.3f" % total, "Total %s cost" % billing])
return table


def _validate_args(env, args):
"""Raises an ArgumentError if the given arguments are not valid."""

Expand Down
175 changes: 174 additions & 1 deletion SoftLayer/fixtures/SoftLayer_Product_Package.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@
'prices': [{'id': 611}],
}]

getItemPrices = [
getItemPricesISCSI = [
{
'currentPriceFlag': '',
'id': 2152,
Expand Down Expand Up @@ -1341,6 +1341,179 @@
}]
}]

getItemPrices = [
{
"hourlyRecurringFee": ".093",
"id": 204015,
"recurringFee": "62",
"item": {
"description": "4 x 2.0 GHz or higher Cores",
"id": 859,
"keyName": "GUEST_CORES_4",
},
"pricingLocationGroup": {
"id": 503,
"locations": [
{
"id": 449610,
"longName": "Montreal 1",
"name": "mon01",
"statusId": 2
},
{
"id": 449618,
"longName": "Montreal 2",
"name": "mon02",
"statusId": 2
},
{
"id": 448994,
"longName": "Toronto 1",
"name": "tor01",
"statusId": 2
},
{
"id": 350993,
"longName": "Toronto 2",
"name": "tor02",
"statusId": 2
},
{
"id": 221894,
"longName": "Amsterdam 2",
"name": "ams02",
"statusId": 2
},
{
"id": 265592,
"longName": "Amsterdam 1",
"name": "ams01",
"statusId": 2
},
{
"id": 814994,
"longName": "Amsterdam 3",
"name": "ams03",
"statusId": 2
}
]
}
},
{
"hourlyRecurringFee": ".006",
"id": 204663,
"recurringFee": "4.1",
"item": {
"description": "100 GB (LOCAL)",
"id": 3899,
"keyName": "GUEST_DISK_100_GB_LOCAL_3",
},
"pricingLocationGroup": {
"id": 503,
"locations": [
{
"id": 449610,
"longName": "Montreal 1",
"name": "mon01",
"statusId": 2
},
{
"id": 449618,
"longName": "Montreal 2",
"name": "mon02",
"statusId": 2
},
{
"id": 448994,
"longName": "Toronto 1",
"name": "tor01",
"statusId": 2
},
{
"id": 350993,
"longName": "Toronto 2",
"name": "tor02",
"statusId": 2
},
{
"id": 221894,
"longName": "Amsterdam 2",
"name": "ams02",
"statusId": 2
},
{
"id": 265592,
"longName": "Amsterdam 1",
"name": "ams01",
"statusId": 2
},
{
"id": 814994,
"longName": "Amsterdam 3",
"name": "ams03",
"statusId": 2
}
]
}
},
{
"hourlyRecurringFee": ".217",
"id": 204255,
"recurringFee": "144",
"item": {
"description": "16 GB ",
"id": 1017,
"keyName": "RAM_16_GB",
},
"pricingLocationGroup": {
"id": 503,
"locations": [
{
"id": 449610,
"longName": "Montreal 1",
"name": "mon01",
"statusId": 2
},
{
"id": 449618,
"longName": "Montreal 2",
"name": "mon02",
"statusId": 2
},
{
"id": 448994,
"longName": "Toronto 1",
"name": "tor01",
"statusId": 2
},
{
"id": 350993,
"longName": "Toronto 2",
"name": "tor02",
"statusId": 2
},
{
"id": 221894,
"longName": "Amsterdam 2",
"name": "ams02",
"statusId": 2
},
{
"id": 265592,
"longName": "Amsterdam 1",
"name": "ams01",
"statusId": 2
},
{
"id": 814994,
"longName": "Amsterdam 3",
"name": "ams03",
"statusId": 2
}
]
}
}
]
getActivePresets = [
{
"description": "M1.64x512x25",
Expand Down
62 changes: 62 additions & 0 deletions SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
getObject = {
"id": 405,
"keyName": "AC1_8X60X25",
"prices": [
{
"hourlyRecurringFee": "1.425",
"id": 207345,
"recurringFee": "936.23",
"item": {
"description": "1 x P100 GPU",
"id": 10933,
"keyName": "1_X_P100_GPU",
"itemCategory": {
"categoryCode": "guest_pcie_device0",
"id": 1259
}
}
},
{
"hourlyRecurringFee": "0",
"id": 2202,
"recurringFee": "0",
"item": {
"description": "25 GB (SAN)",
"id": 1178,
"keyName": "GUEST_DISK_25_GB_SAN",
"itemCategory": {
"categoryCode": "guest_disk0",
"id": 81
}
}
},
{
"hourlyRecurringFee": ".342",
"id": 207361,
"recurringFee": "224.69",
"item": {
"description": "60 GB",
"id": 10939,
"keyName": "RAM_0_UNIT_PLACEHOLDER_10",
"itemCategory": {
"categoryCode": "ram",
"id": 3
}
}
},
{
"hourlyRecurringFee": ".181",
"id": 209595,
"recurringFee": "118.26",
"item": {
"description": "8 x 2.0 GHz or higher Cores",
"id": 11307,
"keyName": "GUEST_CORE_8",
"itemCategory": {
"categoryCode": "guest_core",
"id": 80
}
}
}
]
}
Loading