1010
1111
1212ENDURANCE_TIERS = {
13- ' 0.25' : ' 100' ,
14- '2' : ' 200' ,
15- '4' : ' 300'
13+ 0.25 : 100 ,
14+ 2 : 200 ,
15+ 4 : 300 ,
1616}
1717
1818
@@ -22,11 +22,6 @@ class BlockStorageManager(utils.IdentifierMixin, object):
2222 def __init__ (self , client ):
2323 self .configuration = {}
2424 self .client = client
25- self .account = client ['Account' ]
26- self .product_package = self .client ['Product_Package' ]
27- self .block_svc = self .client ['Network_Storage' ]
28- self .block_os_types = self .client ['Network_Storage_Iscsi_OS_Type' ]
29- self .product_order = self .client ['Product_Order' ]
3025
3126 def list_block_volumes (self , datacenter = None , username = None ,
3227 storage_type = None , ** kwargs ):
@@ -95,7 +90,8 @@ def get_block_volume_details(self, volume_id, **kwargs):
9590 'lunId' ,
9691 ]
9792 kwargs ['mask' ] = "mask[%s]" % ',' .join (items )
98- return self .block_svc .getObject (id = volume_id , ** kwargs )
93+ return self .client .call ('Network_Storage' , 'getObject' ,
94+ id = volume_id , ** kwargs )
9995
10096 def get_block_volume_access_list (self , volume_id , ** kwargs ):
10197 """Returns a list of authorized hosts for a specified volume.
@@ -113,7 +109,8 @@ def get_block_volume_access_list(self, volume_id, **kwargs):
113109 'allowedIpAddresses[allowedHost[credential]]' ,
114110 ]
115111 kwargs ['mask' ] = "mask[%s]" % ',' .join (items )
116- return self .block_svc .getObject (id = volume_id , ** kwargs )
112+ return self .client .call ('Network_Storage' , 'getObject' ,
113+ id = volume_id , ** kwargs )
117114
118115 def get_block_volume_snapshot_list (self , volume_id , ** kwargs ):
119116 """Returns a list of snapshots for the specified volume.
@@ -123,29 +120,34 @@ def get_block_volume_snapshot_list(self, volume_id, **kwargs):
123120 :return: Returns a list of snapshots for the specified volume.
124121 """
125122 if 'mask' not in kwargs :
126- items = [
127- 'snapshots.id' ,
128- 'snapshots.notes' ,
129- 'snapshots.snapshotSizeBytes' ,
130- 'snapshots.storageType.keyName' ,
131- 'snapshots.snapshotCreationTimestamp' ,
132- 'snapshots[hourlySchedule,dailySchedule,weeklySchedule]' ,
133- ]
123+ items = '''snapshots[
124+ id,
125+ notes,
126+ snapshotSizeBytes,
127+ storageType[keyName],
128+ snapshotCreationTimestamp
129+ hourlySchedule,
130+ dailySchedule,
131+ weeklySchedule
132+ ]'''
134133 kwargs ['mask' ] = "mask[%s]" % ',' .join (items )
135- return self .block_svc .getObject (id = volume_id , ** kwargs )
134+ return self .client .call ('Network_Storage' , 'getObject' ,
135+ id = volume_id , ** kwargs )
136136
137137 def delete_snapshot (self , snapshot_id ):
138138 """Deletes the specified snapshot object.
139139
140140 :param snapshot_id: The ID of the snapshot object to delete.
141141 """
142- return self .block_svc .deleteObject (id = snapshot_id )
142+ return self .client .call ('Network_Storage' , 'deleteObject' ,
143+ id = snapshot_id )
143144
144145 def order_block_volume (self , storage_type , location , size , os_type ,
145146 iops = None , tier_level = None ):
146147 """Places an order for a block volume.
147148
148- :param storage_type: "Performance" or "Endurance"
149+ :param storage_type: "performance_storage_iscsi" (performance)
150+ or "storage_service_enterprise" (endurance)
149151 :param location: Datacenter in which to order iSCSI volume
150152 :param size: Size of the desired volume, in GB
151153 :param os_type: OS Type to use for volume alignment, see help for list
@@ -162,14 +164,14 @@ def order_block_volume(self, storage_type, location, size, os_type,
162164
163165 base_type_name = 'SoftLayer_Container_Product_Order_Network_'
164166 package = self ._get_package (storage_type )
165- if package [ 'name' ] == 'Performance ' :
167+ if storage_type == 'performance_storage_iscsi ' :
166168 complex_type = base_type_name + 'PerformanceStorage_Iscsi'
167169 prices = [
168170 _find_performance_block_price (package ),
169171 _find_performance_space_price (package , iops ),
170172 _find_performance_iops_price (package , size , iops ),
171173 ]
172- elif package [ 'name' ] == 'Endurance ' :
174+ elif storage_type == 'storage_service_enterprise ' :
173175 complex_type = base_type_name + 'Storage_Enterprise'
174176 prices = [
175177 _find_endurance_block_price (package ),
@@ -190,32 +192,34 @@ def order_block_volume(self, storage_type, location, size, os_type,
190192 'location' : location_id ,
191193 }
192194
193- return self .product_order . placeOrder ( order )
195+ return self .client . call ( 'Product_Order' , 'placeOrder' , order )
194196
195- def _get_package (self , category_code , ** kwargs ):
197+ def _get_package (self , category_code ):
196198 """Returns a product packaged based on type of storage.
197199
198200 :param category_code: Category code of product package.
199- :param kwargs:
200201 :return: Returns a packaged based on type of storage.
201202 """
202- if 'mask' not in kwargs :
203- items = [
204- 'id' ,
205- 'name' ,
206- 'items' ,
207- 'items[prices[categories],attributes]'
208- ]
209- kwargs ['mask' ] = "mask[%s]" % ',' .join (items )
210203
211- _filter = utils .NestedDict (kwargs . get ( 'filter' ) or {})
204+ _filter = utils .NestedDict ({})
212205 _filter ['categories' ]['categoryCode' ] = (
213206 utils .query_filter (category_code ))
214207 _filter ['statusCode' ] = (utils .query_filter ('ACTIVE' ))
215- kwargs ['filter' ] = _filter .to_dict ()
216208
217- func = getattr (self .product_package , 'getAllObjects' )
218- return func (** kwargs ).pop ()
209+ packages = self .client .call ('Product_Package' , 'getAllObjects' ,
210+ filter = _filter .to_dict (),
211+ mask = """
212+ id,
213+ name,
214+ items[prices[categories],attributes]
215+ """ )
216+ if len (packages ) == 0 :
217+ raise ValueError ('No packages were found for %s' % category_code )
218+ if len (packages ) > 1 :
219+ raise ValueError ('More than one package was found for %s'
220+ % category_code )
221+
222+ return packages [0 ]
219223
220224 def _get_location_id (self , location ):
221225 """Returns location id
@@ -297,7 +301,10 @@ def _find_endurance_space_price(package, size, tier_level):
297301 continue
298302
299303 level = ENDURANCE_TIERS .get (tier_level )
300- if price ['capacityRestrictionMinimum' ] != level :
304+ if level < int (price ['capacityRestrictionMinimum' ]):
305+ continue
306+
307+ if level > int (price ['capacityRestrictionMaximum' ]):
301308 continue
302309
303310 return price
@@ -307,8 +314,8 @@ def _find_endurance_space_price(package, size, tier_level):
307314
308315def _find_endurance_tier_price (package , tier_level ):
309316 for item in package ['items' ]:
310- for attribute in item [ 'attributes' ] :
311- if attribute ['value' ] ! = ENDURANCE_TIERS .get (tier_level ):
317+ for attribute in item . get ( 'attributes' , []) :
318+ if int ( attribute ['value' ]) = = ENDURANCE_TIERS .get (tier_level ):
312319 break
313320 else :
314321 continue
0 commit comments