Skip to content

Commit 3afada2

Browse files
committed
Modified filter for ISCSI and snapshot Item price IDs
1 parent 322e290 commit 3afada2

4 files changed

Lines changed: 44 additions & 53 deletions

File tree

SoftLayer/CLI/modules/iscsi.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,32 @@ def execute(self, args):
6060
class CreateISCSI(CLIRunnable):
6161

6262
"""
63-
usage: sl iscsi create --size=SIZE --dc=DC [options]
63+
usage: sl iscsi create [options]
6464
6565
Order/create an iSCSI storage.
6666
6767
Required:
68-
--size=SIZE Size of the iSCSI volume to create
69-
--dc=DC Datacenter to use to create volume in
70-
Optional:
71-
--zero-recurring Prefer <$1 recurring fee
68+
-s, --size=SIZE Size of the iSCSI volume to create
69+
-d, --datacenter=DC Datacenter shortname (sng01, dal05, ...)
7270
"""
7371
action = 'create'
7472
options = ['confirm']
75-
required_params = ['--size', '--dc']
73+
required_params = ['--size', '--datacenter']
7674

7775
def execute(self, args):
7876
iscsi_mgr = ISCSIManager(self.client)
79-
8077
self._validate_create_args(args)
81-
size = int(args.get('--size')),
82-
location = str(args.get('--dc')),
83-
zero_recurring = args.get('--zero-recurring', False)
84-
iscsi_mgr.create_iscsi(size=size, location=location,
85-
zero_recurring=zero_recurring)
78+
size, location = self._parse_create_args(args)
79+
iscsi_mgr.create_iscsi(size=size, location=location)
80+
81+
def _parse_create_args(self, args):
82+
""" Converts CLI arguments to arguments that can be passed into
83+
ISCSIManager.create_iscsi.
84+
:param dict args: CLI arguments
85+
"""
86+
size = int(args['--size'])
87+
location = str(args['--datacenter'])
88+
return size, location
8689

8790
def _validate_create_args(self, args):
8891
""" Raises an ArgumentError if the given arguments are not valid """

SoftLayer/managers/iscsi.py

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
~~~~~~~~~~~~~~~
44
ISCSI Manager/helpers
55
"""
6-
from SoftLayer.utils import NestedDict, query_filter, IdentifierMixin
6+
from SoftLayer.utils import IdentifierMixin
77

88

99
class ISCSIManager(IdentifierMixin, object):
@@ -16,33 +16,20 @@ def __init__(self, client):
1616
self.iscsi_svc = self.client['Network_Storage_Iscsi']
1717
self.product_order = self.client['Product_Order']
1818

19-
def _find_item_prices(self, size, query='', zero_recurring=False):
19+
def _find_item_prices(self, size, categorycode=''):
2020
""" Retrieves the Item Price IDs
2121
"""
22-
23-
item_prices = []
24-
_filter = NestedDict({})
25-
_filter[
26-
'itemPrices'][
27-
'item'][
28-
'description'] = query_filter(
29-
query)
30-
_filter['itemPrices']['item']['capacity'] = query_filter('%s' % size)
31-
32-
if not zero_recurring:
33-
_filter['itemPrices']['recurringFee'] = query_filter('>1')
34-
35-
iscsi_item_prices = self.client['Product_Package'].getItemPrices(
22+
item_prices = self.client['Product_Package'].getItems(
3623
id=0,
37-
filter=_filter.to_dict())
38-
iscsi_item_prices = sorted(
39-
iscsi_item_prices,
40-
key=lambda x:
41-
(float(x['item']['capacity']),
42-
float(x.get('recurringFee', 0))))
43-
for price in iscsi_item_prices:
44-
item_prices.append(price['id'])
45-
return item_prices
24+
mask='id,capacity,prices[id]',
25+
filter={
26+
'items': {
27+
'capacity': {'operation': int(size)},
28+
'categories': {
29+
'categoryCode': {'operation': categorycode}
30+
}}})
31+
item_price = item_prices[0]['prices'][0]['id']
32+
return item_price
4633

4734
def _build_order(self, item_price, location):
4835
""" Returns a dict appropriate to pass into Product_Order::placeOrder()
@@ -54,7 +41,7 @@ def _build_order(self, item_price, location):
5441
'SoftLayer_Container_Product_Order_Network_Storage_Iscsi',
5542
'location': location_id,
5643
'packageId': 0, # storage package
57-
'prices': [{'id': item_price[0]}],
44+
'prices': [{'id': item_price}],
5845
'quantity': 1
5946
}
6047
return order
@@ -66,23 +53,18 @@ def _get_location_id(self, location):
6653
loc_svc = self.client['Location_Datacenter']
6754
datacenters = loc_svc.getDatacenters(mask='mask[longName,id,name]')
6855
for datacenter in datacenters:
69-
if datacenter['name'] == location[0]:
56+
if datacenter['name'] == location:
7057
location = datacenter['id']
7158
return location
7259
raise ValueError('Invalid datacenter name specified.')
7360

74-
def create_iscsi(self, size=None, location=None, zero_recurring=False):
61+
def create_iscsi(self, size=None, location=None):
7562
"""Places an order for iSCSI volume
7663
:param integer size: size of iSCSI volume to create
7764
:param string location: datacenter to use to create volume in
78-
:param boolean zero_recurring: Prefer <$1 recurring fee.
79-
Even if API shows <$1 volumes, many users are not
80-
allowed order them. Those who are allowed to order
81-
the <$1 volumes, can use this flag.
8265
"""
83-
item_price = self._find_item_prices(size,
84-
zero_recurring=zero_recurring,
85-
query='~GB iSCSI SAN Storage')
66+
item_price = self._find_item_prices(int(size),
67+
categorycode='iscsi')
8668
iscsi_order = self._build_order(item_price, location)
8769
self.product_order.verifyOrder(iscsi_order)
8870
self.product_order.placeOrder(iscsi_order)
@@ -145,7 +127,7 @@ def create_snapshot_space(self, volume_id, capacity):
145127
:param integer capacity: capacity in ~GB
146128
"""
147129
item_price = self._find_item_prices(
148-
int(capacity), query='~iSCSI SAN Snapshot Space')
130+
int(capacity), categorycode='iscsi_snapshot_space')
149131
result = self.get_iscsi(
150132
volume_id, mask='mask[id,capacityGb,serviceResource[datacenter]]')
151133
snapshotspaceorder = {
@@ -154,7 +136,7 @@ def create_snapshot_space(self, volume_id, capacity):
154136
Network_Storage_Iscsi_SnapshotSpace',
155137
'location': result['serviceResource']['datacenter']['id'],
156138
'packageId': 0,
157-
'prices': [{'id': item_price[0]}],
139+
'prices': [{'id': item_price}],
158140
'quantity': 1,
159141
'volumeId': volume_id}
160142
self.product_order.verifyOrder(snapshotspaceorder)

SoftLayer/tests/fixtures/Product_Package.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,13 @@ def get_bmc_categories_mock():
10221022

10231023
getCategories = get_server_categories_mock() + get_bmc_categories_mock()
10241024
getItems = [
1025+
{
1026+
'id': 4439,
1027+
'capacity': '1',
1028+
'description': '1 GB iSCSI Storage',
1029+
'itemCategory': {'categoryCode': 'iscsi'},
1030+
'prices': [{'id': 2222}],
1031+
},
10251032
{
10261033
'id': 4440,
10271034
'capacity': '4',

SoftLayer/tests/managers/iscsi_tests.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ def test_invalid_datacenter(self):
4646
size=10, location='foo')
4747

4848
def test_create_iscsi_without_recurringFee(self):
49-
self.iscsi.create_iscsi(size=1, location=['dal05'],
50-
zero_recurring=True)
49+
self.iscsi.create_iscsi(size=1, location='dal05')
5150
f = self.client['Product_Order'].placeOrder
5251
f.assert_called_once_with(
53-
{'prices': [{'id': 22501}],
52+
{'prices': [{'id': 2222}],
5453
'quantity': 1,
5554
'location': 0,
5655
'packageId': 0,
@@ -80,7 +79,7 @@ def test_create_snapshot_space(self):
8079
'complexType':
8180
'SoftLayer_Container_\
8281
Product_Order_Network_Storage_Iscsi_SnapshotSpace',
83-
'prices': [{'id': 22501}],
82+
'prices': [{'id': 2222}],
8483
'quantity': 1
8584
})
8685

0 commit comments

Comments
 (0)