Skip to content

Commit e3226d4

Browse files
Merge branch 'issue1345' of https://github.com/caberos/softlayer-python into caberos-issue1345
2 parents 48306c4 + e00b921 commit e3226d4

File tree

3 files changed

+76
-55
lines changed

3 files changed

+76
-55
lines changed

SoftLayer/CLI/hardware/create_options.py

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ def _preset_prices_table(sizes, tables):
8181
preset_prices_table.sortby = 'Value'
8282
preset_prices_table.align = 'l'
8383
for size in sizes:
84-
preset_prices_table.add_row([size['name'], size['key'], "%.4f" % size['hourlyRecurringFee'],
85-
"%.4f" % size['recurringFee']])
84+
if (_verify_prices("%.4f" % size['hourlyRecurringFee'])) or (_verify_prices("%.4f" % size['recurringFee'])):
85+
preset_prices_table.add_row([size['name'], size['key'], "%.4f" % size['hourlyRecurringFee'],
86+
"%.4f" % size['recurringFee']])
8687
tables.append(preset_prices_table)
8788

8889

@@ -98,14 +99,16 @@ def _os_prices_table(operating_systems, tables):
9899
os_prices_table.align = 'l'
99100
for operating_system in operating_systems:
100101
for price in operating_system['prices']:
101-
cr_max = _get_price_data(price, 'capacityRestrictionMaximum')
102-
cr_min = _get_price_data(price, 'capacityRestrictionMinimum')
103-
cr_type = _get_price_data(price, 'capacityRestrictionType')
104-
os_prices_table.add_row(
105-
[operating_system['key'],
106-
_get_price_data(price, 'hourlyRecurringFee'),
107-
_get_price_data(price, 'recurringFee'),
108-
"%s - %s %s" % (cr_min, cr_max, cr_type)])
102+
if (_verify_prices(_get_price_data(price, 'hourlyRecurringFee'))) or (
103+
_verify_prices(_get_price_data(price, 'recurringFee'))):
104+
cr_max = _get_price_data(price, 'capacityRestrictionMaximum')
105+
cr_min = _get_price_data(price, 'capacityRestrictionMinimum')
106+
cr_type = _get_price_data(price, 'capacityRestrictionType')
107+
os_prices_table.add_row(
108+
[operating_system['key'],
109+
_get_price_data(price, 'hourlyRecurringFee'),
110+
_get_price_data(price, 'recurringFee'),
111+
"%s - %s %s" % (cr_min, cr_max, cr_type)])
109112
tables.append(os_prices_table)
110113

111114

@@ -121,17 +124,32 @@ def _port_speed_prices_table(port_speeds, tables):
121124
port_speed_prices_table.align = 'l'
122125
for speed in port_speeds:
123126
for price in speed['prices']:
124-
cr_max = _get_price_data(price, 'capacityRestrictionMaximum')
125-
cr_min = _get_price_data(price, 'capacityRestrictionMinimum')
126-
cr_type = _get_price_data(price, 'capacityRestrictionType')
127-
port_speed_prices_table.add_row(
128-
[speed['key'], speed['speed'],
129-
_get_price_data(price, 'hourlyRecurringFee'),
130-
_get_price_data(price, 'recurringFee'),
131-
"%s - %s %s" % (cr_min, cr_max, cr_type)])
127+
if (_verify_prices(_get_price_data(price, 'hourlyRecurringFee'))) or (
128+
_verify_prices(_get_price_data(price, 'recurringFee'))):
129+
cr_max = _get_price_data(price, 'capacityRestrictionMaximum')
130+
cr_min = _get_price_data(price, 'capacityRestrictionMinimum')
131+
cr_type = _get_price_data(price, 'capacityRestrictionType')
132+
port_speed_prices_table.add_row(
133+
[speed['key'], speed['speed'],
134+
_get_price_data(price, 'hourlyRecurringFee'),
135+
_get_price_data(price, 'recurringFee'),
136+
"%s - %s %s" % (cr_min, cr_max, cr_type)])
132137
tables.append(port_speed_prices_table)
133138

134139

140+
def _verify_prices(prices):
141+
"""Verify the prices is higher to zero(0) or is '-'.
142+
143+
param prices: value to verify.
144+
Returns: true false.
145+
146+
"""
147+
if prices == '-':
148+
return True
149+
else:
150+
return float(prices) > 0
151+
152+
135153
def _extras_prices_table(extras, tables):
136154
"""Shows Server extras prices cost and capacity restriction.
137155
@@ -143,14 +161,16 @@ def _extras_prices_table(extras, tables):
143161
extras_prices_table.align = 'l'
144162
for extra in extras:
145163
for price in extra['prices']:
146-
cr_max = _get_price_data(price, 'capacityRestrictionMaximum')
147-
cr_min = _get_price_data(price, 'capacityRestrictionMinimum')
148-
cr_type = _get_price_data(price, 'capacityRestrictionType')
149-
extras_prices_table.add_row(
150-
[extra['key'],
151-
_get_price_data(price, 'hourlyRecurringFee'),
152-
_get_price_data(price, 'recurringFee'),
153-
"%s - %s %s" % (cr_min, cr_max, cr_type)])
164+
if (_verify_prices(_get_price_data(price, 'hourlyRecurringFee'))) or (
165+
_verify_prices(_get_price_data(price, 'recurringFee'))):
166+
cr_max = _get_price_data(price, 'capacityRestrictionMaximum')
167+
cr_min = _get_price_data(price, 'capacityRestrictionMinimum')
168+
cr_type = _get_price_data(price, 'capacityRestrictionType')
169+
extras_prices_table.add_row(
170+
[extra['key'],
171+
_get_price_data(price, 'hourlyRecurringFee'),
172+
_get_price_data(price, 'recurringFee'),
173+
"%s - %s %s" % (cr_min, cr_max, cr_type)])
154174
tables.append(extras_prices_table)
155175

156176

@@ -176,12 +196,14 @@ def _location_item_prices(location_prices, tables):
176196
location_prices_table.sortby = 'keyName'
177197
location_prices_table.align = 'l'
178198
for price in location_prices:
179-
cr_max = _get_price_data(price, 'capacityRestrictionMaximum')
180-
cr_min = _get_price_data(price, 'capacityRestrictionMinimum')
181-
cr_type = _get_price_data(price, 'capacityRestrictionType')
182-
location_prices_table.add_row(
183-
[price['item']['keyName'], price['id'],
184-
_get_price_data(price, 'hourlyRecurringFee'),
185-
_get_price_data(price, 'recurringFee'),
186-
"%s - %s %s" % (cr_min, cr_max, cr_type)])
199+
if (_verify_prices(_get_price_data(price, 'hourlyRecurringFee'))) or (
200+
_verify_prices(_get_price_data(price, 'recurringFee'))):
201+
cr_max = _get_price_data(price, 'capacityRestrictionMaximum')
202+
cr_min = _get_price_data(price, 'capacityRestrictionMinimum')
203+
cr_type = _get_price_data(price, 'capacityRestrictionType')
204+
location_prices_table.add_row(
205+
[price['item']['keyName'], price['id'],
206+
_get_price_data(price, 'hourlyRecurringFee'),
207+
_get_price_data(price, 'recurringFee'),
208+
"%s - %s %s" % (cr_min, cr_max, cr_type)])
187209
tables.append(location_prices_table)

SoftLayer/fixtures/SoftLayer_Product_Package.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,8 @@
866866
'referenceCode': 'REDHAT_5_64'
867867
},
868868
'prices': [{'id': 1122,
869-
'hourlyRecurringFee': 0.0,
870-
'recurringFee': 0.0,
869+
'hourlyRecurringFee': 0.10,
870+
'recurringFee': 0.10,
871871
'categories': [{'id': 26,
872872
'name': 'Uplink Port Speeds',
873873
'categoryCode': 'port_speed'}]}],
@@ -879,8 +879,8 @@
879879
'description': 'Public & Private Networks',
880880
'itemCategory': {'categoryCode': 'Uplink Port Speeds'},
881881
'prices': [{'id': 4477,
882-
'hourlyRecurringFee': 0.0,
883-
'recurringFee': 0.0,
882+
'hourlyRecurringFee': 0.10,
883+
'recurringFee': 0.10,
884884
'categories': [{'id': 26,
885885
'name': 'Uplink Port Speeds',
886886
'categoryCode': 'port_speed'}]}],
@@ -921,8 +921,8 @@
921921
'itemCategory': {'categoryCode': 'Computing Instance'},
922922
'prices': [{'id': 1144,
923923
'locationGroupId': None,
924-
'hourlyRecurringFee': 0.0,
925-
'recurringFee': 0.0,
924+
'hourlyRecurringFee': 0.10,
925+
'recurringFee': 0.10,
926926
'categories': [{'id': 80,
927927
'name': 'Computing Instance',
928928
'categoryCode': 'guest_core'}]}],
@@ -948,39 +948,39 @@
948948
'capacity': '1',
949949
'description': '1 GB iSCSI Storage',
950950
'itemCategory': {'categoryCode': 'iscsi'},
951-
'prices': [{'id': 2222, 'hourlyRecurringFee': 0.0, 'recurringFee': 0.0}],
951+
'prices': [{'id': 2222, 'hourlyRecurringFee': 0.10, 'recurringFee': 0.10}],
952952
},
953953
{
954954
'id': 1121,
955955
'keyName': 'KeyName081',
956956
'capacity': '20',
957957
'description': '20 GB iSCSI snapshot',
958958
'itemCategory': {'categoryCode': 'iscsi_snapshot_space'},
959-
'prices': [{'id': 2014, 'hourlyRecurringFee': 0.0}],
959+
'prices': [{'id': 2014, 'hourlyRecurringFee': 0.10}],
960960
},
961961
{
962962
'id': 4440,
963963
'keyName': 'KeyName019',
964964
'capacity': '4',
965965
'description': '4 Portable Public IP Addresses',
966966
'itemCategory': {'categoryCode': 'sov_sec_ip_addresses_pub'},
967-
'prices': [{'id': 4444, 'hourlyRecurringFee': 0.0, 'recurringFee': 0.0}],
967+
'prices': [{'id': 4444, 'hourlyRecurringFee': 0.10, 'recurringFee': 0.10}],
968968
},
969969
{
970970
'id': 8880,
971971
'keyName': 'KeyName0199',
972972
'capacity': '8',
973973
'description': '8 Portable Public IP Addresses',
974974
'itemCategory': {'categoryCode': 'sov_sec_ip_addresses_pub'},
975-
'prices': [{'id': 8888, 'hourlyRecurringFee': 0.0, 'recurringFee': 0.0}],
975+
'prices': [{'id': 8888, 'hourlyRecurringFee': 0.10, 'recurringFee': 0.10}],
976976
},
977977
{
978978
'id': 44400,
979979
'keyName': 'KeyName0155',
980980
'capacity': '4',
981981
'description': '4 Portable Private IP Addresses',
982982
'itemCategory': {'categoryCode': 'sov_sec_ip_addresses_priv'},
983-
'prices': [{'id': 44441, 'hourlyRecurringFee': 0.0, 'recurringFee': 0.0}],
983+
'prices': [{'id': 44441, 'hourlyRecurringFee': 0.10, 'recurringFee': 0.10}],
984984
},
985985
{
986986
'id': 88800,
@@ -1012,7 +1012,7 @@
10121012
'capacity': '0',
10131013
'description': 'Global IPv6',
10141014
'itemCategory': {'categoryCode': 'global_ipv6'},
1015-
'prices': [{'id': 611, 'hourlyRecurringFee': 0.0, 'recurringFee': 0.0}],
1015+
'prices': [{'id': 611, 'hourlyRecurringFee': 0.10, 'recurringFee': 0.10}],
10161016
},
10171017
{'attributes': [],
10181018
'capacity': '0',
@@ -1056,16 +1056,16 @@
10561056
'keyName': 'OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT',
10571057
'prices': [{'accountRestrictions': [],
10581058
'currentPriceFlag': '',
1059-
'hourlyRecurringFee': '0',
1059+
'hourlyRecurringFee': '0.10',
10601060
'id': 37650,
10611061
"locationGroupId": '',
10621062
'itemId': 4702,
10631063
'laborFee': '0',
10641064
'onSaleFlag': '',
10651065
'oneTimeFee': '0',
10661066
'quantity': '',
1067-
'recurringFee': '0',
1068-
'setupFee': '0',
1067+
'recurringFee': '0.1',
1068+
'setupFee': '0.1',
10691069
'sort': 9}],
10701070
'softwareDescription': {'id': 1362,
10711071
'longDescription': 'Ubuntu / 14.04-64',

tests/CLI/modules/server_tests.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,17 @@ def test_create_options_prices(self):
367367

368368
self.assert_no_fail(result)
369369
output = json.loads(result.output)
370-
self.assertEqual(output[1][0]['Hourly'], "%.4f" % 0.0)
371-
self.assertEqual(output[1][0]['Value'], 'M1_64X512X25')
372-
self.assertEqual(output[1][0]['Size'], 'M1.64x512x25')
370+
self.assertEqual(output[2][0]['Monthly'], str(0.1))
371+
self.assertEqual(output[2][0]['OS Key'], 'OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT')
373372

374373
def test_create_options_location(self):
375374
result = self.run_command(['server', 'create-options', '--prices', 'dal13'])
376375

377376
self.assert_no_fail(result)
378377
output = json.loads(result.output)
379-
self.assertEqual(output[1][0]['Monthly'], "%.4f" % 0.0)
380-
self.assertEqual(output[1][0]['Hourly'], "%.4f" % 0.0)
381-
self.assertEqual(output[1][0]['Value'], 'M1_64X512X25')
378+
print(output)
379+
self.assertEqual(output[2][0]['Monthly'], str(0.1))
380+
self.assertEqual(output[2][0]['OS Key'], 'OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT')
382381

383382
@mock.patch('SoftLayer.HardwareManager.place_order')
384383
def test_create_server(self, order_mock):

0 commit comments

Comments
 (0)