@@ -164,14 +164,14 @@ def add_subnet(self, subnet_type, quantity=None, endpoint_id=None, version=4,
164
164
# item description.
165
165
price_id = None
166
166
quantity_str = str (quantity )
167
- package_items = package .getItems (id = 0 )
167
+ package_items = package .getItems (id = 0 , mask = 'mask[prices[packageReferences[package[keyName]]]]' )
168
168
for item in package_items :
169
169
category_code = utils .lookup (item , 'itemCategory' , 'categoryCode' )
170
170
if all ([category_code == category ,
171
171
item .get ('capacity' ) == quantity_str ,
172
172
version == 4 or (version == 6 and
173
173
desc in item ['description' ])]):
174
- price_id = item [ 'prices' ][ 0 ][ 'id' ]
174
+ price_id = self . get_subnet_item_price ( item , subnet_type , version )
175
175
break
176
176
177
177
order = {
@@ -192,6 +192,24 @@ def add_subnet(self, subnet_type, quantity=None, endpoint_id=None, version=4,
192
192
else :
193
193
return self .client ['Product_Order' ].placeOrder (order )
194
194
195
+ @staticmethod
196
+ def get_subnet_item_price (item , subnet_type , version ):
197
+ """Get the subnet specific item price id.
198
+
199
+ :param version: 4 for IPv4, 6 for IPv6.
200
+ :param subnet_type: Type of subnet to add: private, public, global,static.
201
+ :param item: Subnet item.
202
+ """
203
+ price_id = None
204
+ if version == 4 and subnet_type == 'static' :
205
+ for item_price in item ['prices' ]:
206
+ for package_reference in item_price ['packageReferences' ]:
207
+ if subnet_type .upper () in package_reference ['package' ]['keyName' ]:
208
+ price_id = item_price ['id' ]
209
+ else :
210
+ price_id = item ['prices' ][0 ]['id' ]
211
+ return price_id
212
+
195
213
def assign_global_ip (self , global_ip_id , target ):
196
214
"""Assigns a global IP address to a specified target.
197
215
0 commit comments