@@ -164,17 +164,14 @@ def add_subnet(self, subnet_type, quantity=None, endpoint_id=None, version=4,
164164 # item description.
165165 price_id = None
166166 quantity_str = str (quantity )
167- package_items = package .getItems (id = 0 )
167+ package_items = package .getItems (id = 0 , mask = 'mask[prices[packageReferences[package[keyName]]]]' )
168168 for item in package_items :
169169 category_code = utils .lookup (item , 'itemCategory' , 'categoryCode' )
170170 if all ([category_code == category ,
171171 item .get ('capacity' ) == quantity_str ,
172172 version == 4 or (version == 6 and
173173 desc in item ['description' ])]):
174- if version == 4 and subnet_type == 'static' :
175- price_id = item ['prices' ][1 ]['id' ]
176- else :
177- price_id = item ['prices' ][0 ]['id' ]
174+ price_id = self .get_subnet_item_price (item , subnet_type , version )
178175 break
179176
180177 order = {
@@ -195,6 +192,24 @@ def add_subnet(self, subnet_type, quantity=None, endpoint_id=None, version=4,
195192 else :
196193 return self .client ['Product_Order' ].placeOrder (order )
197194
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+
198213 def assign_global_ip (self , global_ip_id , target ):
199214 """Assigns a global IP address to a specified target.
200215
0 commit comments