Skip to content

Commit 7c1a3ea

Browse files
Merge pull request #1036 from FernandoOjeda/fo_vs_create_flavor_test
Fixed pricing display when using VS flavors
2 parents 86d658b + c837331 commit 7c1a3ea

File tree

7 files changed

+438
-30
lines changed

7 files changed

+438
-30
lines changed

SoftLayer/CLI/virt/create.py

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -270,33 +270,19 @@ def cli(env, **args):
270270
output = []
271271
if args.get('test'):
272272
result = vsi.verify_create_instance(**data)
273-
total_monthly = 0.0
274-
total_hourly = 0.0
275-
276-
table = formatting.Table(['Item', 'cost'])
277-
table.align['Item'] = 'r'
278-
table.align['cost'] = 'r'
279-
280-
for price in result['prices']:
281-
total_monthly += float(price.get('recurringFee', 0.0))
282-
total_hourly += float(price.get('hourlyRecurringFee', 0.0))
283-
if args.get('billing') == 'hourly':
284-
rate = "%.2f" % float(price['hourlyRecurringFee'])
285-
elif args.get('billing') == 'monthly':
286-
rate = "%.2f" % float(price['recurringFee'])
287-
288-
table.add_row([price['item']['description'], rate])
289-
290-
total = 0
291-
if args.get('billing') == 'hourly':
292-
total = total_hourly
293-
elif args.get('billing') == 'monthly':
294-
total = total_monthly
295-
296-
billing_rate = 'monthly'
297-
if args.get('billing') == 'hourly':
298-
billing_rate = 'hourly'
299-
table.add_row(['Total %s cost' % billing_rate, "%.2f" % total])
273+
274+
if result['presetId']:
275+
ordering_mgr = SoftLayer.OrderingManager(env.client)
276+
item_prices = ordering_mgr.get_item_prices(result['packageId'])
277+
preset_prices = ordering_mgr.get_preset_prices(result['presetId'])
278+
search_keys = ["guest_core", "ram"]
279+
for price in preset_prices['prices']:
280+
if price['item']['itemCategory']['categoryCode'] in search_keys:
281+
item_key_name = price['item']['keyName']
282+
_add_item_prices(item_key_name, item_prices, result)
283+
284+
table = _build_receipt_table(result['prices'], args.get('billing'))
285+
300286
output.append(table)
301287
output.append(formatting.FormattedItem(
302288
None,
@@ -334,6 +320,35 @@ def cli(env, **args):
334320
env.fout(output)
335321

336322

323+
def _add_item_prices(item_key_name, item_prices, result):
324+
"""Add the flavor item prices to the rest o the items prices"""
325+
for item in item_prices:
326+
if item_key_name == item['item']['keyName']:
327+
if 'pricingLocationGroup' in item:
328+
for location in item['pricingLocationGroup']['locations']:
329+
if result['location'] == str(location['id']):
330+
result['prices'].append(item)
331+
332+
333+
def _build_receipt_table(prices, billing="hourly"):
334+
"""Retrieve the total recurring fee of the items prices"""
335+
total = 0.000
336+
table = formatting.Table(['Cost', 'Item'])
337+
table.align['Cost'] = 'r'
338+
table.align['Item'] = 'l'
339+
for price in prices:
340+
rate = 0.000
341+
if billing == "hourly":
342+
rate += float(price.get('hourlyRecurringFee', 0.000))
343+
else:
344+
rate += float(price.get('recurringFee', 0.000))
345+
total += rate
346+
347+
table.add_row(["%.3f" % rate, price['item']['description']])
348+
table.add_row(["%.3f" % total, "Total %s cost" % billing])
349+
return table
350+
351+
337352
def _validate_args(env, args):
338353
"""Raises an ArgumentError if the given arguments are not valid."""
339354

SoftLayer/fixtures/SoftLayer_Product_Package.py

Lines changed: 174 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@
916916
'prices': [{'id': 611}],
917917
}]
918918

919-
getItemPrices = [
919+
getItemPricesISCSI = [
920920
{
921921
'currentPriceFlag': '',
922922
'id': 2152,
@@ -1341,6 +1341,179 @@
13411341
}]
13421342
}]
13431343

1344+
getItemPrices = [
1345+
{
1346+
"hourlyRecurringFee": ".093",
1347+
"id": 204015,
1348+
"recurringFee": "62",
1349+
"item": {
1350+
"description": "4 x 2.0 GHz or higher Cores",
1351+
"id": 859,
1352+
"keyName": "GUEST_CORES_4",
1353+
},
1354+
"pricingLocationGroup": {
1355+
"id": 503,
1356+
"locations": [
1357+
{
1358+
"id": 449610,
1359+
"longName": "Montreal 1",
1360+
"name": "mon01",
1361+
"statusId": 2
1362+
},
1363+
{
1364+
"id": 449618,
1365+
"longName": "Montreal 2",
1366+
"name": "mon02",
1367+
"statusId": 2
1368+
},
1369+
{
1370+
"id": 448994,
1371+
"longName": "Toronto 1",
1372+
"name": "tor01",
1373+
"statusId": 2
1374+
},
1375+
{
1376+
"id": 350993,
1377+
"longName": "Toronto 2",
1378+
"name": "tor02",
1379+
"statusId": 2
1380+
},
1381+
{
1382+
"id": 221894,
1383+
"longName": "Amsterdam 2",
1384+
"name": "ams02",
1385+
"statusId": 2
1386+
},
1387+
{
1388+
"id": 265592,
1389+
"longName": "Amsterdam 1",
1390+
"name": "ams01",
1391+
"statusId": 2
1392+
},
1393+
{
1394+
"id": 814994,
1395+
"longName": "Amsterdam 3",
1396+
"name": "ams03",
1397+
"statusId": 2
1398+
}
1399+
]
1400+
}
1401+
},
1402+
{
1403+
"hourlyRecurringFee": ".006",
1404+
"id": 204663,
1405+
"recurringFee": "4.1",
1406+
"item": {
1407+
"description": "100 GB (LOCAL)",
1408+
"id": 3899,
1409+
"keyName": "GUEST_DISK_100_GB_LOCAL_3",
1410+
},
1411+
"pricingLocationGroup": {
1412+
"id": 503,
1413+
"locations": [
1414+
{
1415+
"id": 449610,
1416+
"longName": "Montreal 1",
1417+
"name": "mon01",
1418+
"statusId": 2
1419+
},
1420+
{
1421+
"id": 449618,
1422+
"longName": "Montreal 2",
1423+
"name": "mon02",
1424+
"statusId": 2
1425+
},
1426+
{
1427+
"id": 448994,
1428+
"longName": "Toronto 1",
1429+
"name": "tor01",
1430+
"statusId": 2
1431+
},
1432+
{
1433+
"id": 350993,
1434+
"longName": "Toronto 2",
1435+
"name": "tor02",
1436+
"statusId": 2
1437+
},
1438+
{
1439+
"id": 221894,
1440+
"longName": "Amsterdam 2",
1441+
"name": "ams02",
1442+
"statusId": 2
1443+
},
1444+
{
1445+
"id": 265592,
1446+
"longName": "Amsterdam 1",
1447+
"name": "ams01",
1448+
"statusId": 2
1449+
},
1450+
{
1451+
"id": 814994,
1452+
"longName": "Amsterdam 3",
1453+
"name": "ams03",
1454+
"statusId": 2
1455+
}
1456+
]
1457+
}
1458+
},
1459+
{
1460+
"hourlyRecurringFee": ".217",
1461+
"id": 204255,
1462+
"recurringFee": "144",
1463+
"item": {
1464+
"description": "16 GB ",
1465+
"id": 1017,
1466+
"keyName": "RAM_16_GB",
1467+
},
1468+
"pricingLocationGroup": {
1469+
"id": 503,
1470+
"locations": [
1471+
{
1472+
"id": 449610,
1473+
"longName": "Montreal 1",
1474+
"name": "mon01",
1475+
"statusId": 2
1476+
},
1477+
{
1478+
"id": 449618,
1479+
"longName": "Montreal 2",
1480+
"name": "mon02",
1481+
"statusId": 2
1482+
},
1483+
{
1484+
"id": 448994,
1485+
"longName": "Toronto 1",
1486+
"name": "tor01",
1487+
"statusId": 2
1488+
},
1489+
{
1490+
"id": 350993,
1491+
"longName": "Toronto 2",
1492+
"name": "tor02",
1493+
"statusId": 2
1494+
},
1495+
{
1496+
"id": 221894,
1497+
"longName": "Amsterdam 2",
1498+
"name": "ams02",
1499+
"statusId": 2
1500+
},
1501+
{
1502+
"id": 265592,
1503+
"longName": "Amsterdam 1",
1504+
"name": "ams01",
1505+
"statusId": 2
1506+
},
1507+
{
1508+
"id": 814994,
1509+
"longName": "Amsterdam 3",
1510+
"name": "ams03",
1511+
"statusId": 2
1512+
}
1513+
]
1514+
}
1515+
}
1516+
]
13441517
getActivePresets = [
13451518
{
13461519
"description": "M1.64x512x25",
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
getObject = {
2+
"id": 405,
3+
"keyName": "AC1_8X60X25",
4+
"prices": [
5+
{
6+
"hourlyRecurringFee": "1.425",
7+
"id": 207345,
8+
"recurringFee": "936.23",
9+
"item": {
10+
"description": "1 x P100 GPU",
11+
"id": 10933,
12+
"keyName": "1_X_P100_GPU",
13+
"itemCategory": {
14+
"categoryCode": "guest_pcie_device0",
15+
"id": 1259
16+
}
17+
}
18+
},
19+
{
20+
"hourlyRecurringFee": "0",
21+
"id": 2202,
22+
"recurringFee": "0",
23+
"item": {
24+
"description": "25 GB (SAN)",
25+
"id": 1178,
26+
"keyName": "GUEST_DISK_25_GB_SAN",
27+
"itemCategory": {
28+
"categoryCode": "guest_disk0",
29+
"id": 81
30+
}
31+
}
32+
},
33+
{
34+
"hourlyRecurringFee": ".342",
35+
"id": 207361,
36+
"recurringFee": "224.69",
37+
"item": {
38+
"description": "60 GB",
39+
"id": 10939,
40+
"keyName": "RAM_0_UNIT_PLACEHOLDER_10",
41+
"itemCategory": {
42+
"categoryCode": "ram",
43+
"id": 3
44+
}
45+
}
46+
},
47+
{
48+
"hourlyRecurringFee": ".181",
49+
"id": 209595,
50+
"recurringFee": "118.26",
51+
"item": {
52+
"description": "8 x 2.0 GHz or higher Cores",
53+
"id": 11307,
54+
"keyName": "GUEST_CORE_8",
55+
"itemCategory": {
56+
"categoryCode": "guest_core",
57+
"id": 80
58+
}
59+
}
60+
}
61+
]
62+
}

0 commit comments

Comments
 (0)