33 ~~~~~~~~~~~~~~~
44 ISCSI Manager/helpers
55"""
6- from SoftLayer .utils import NestedDict , query_filter , IdentifierMixin
6+ from SoftLayer .utils import IdentifierMixin
77
88
99class 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 )
0 commit comments