Skip to content

Commit 627e039

Browse files
Merge pull request #1358 from FernandoOjeda/ft_subnet_create
Fix create subnet static for ipv4 price.
2 parents b8f4ca3 + 01064aa commit 627e039

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

SoftLayer/managers/network.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -164,14 +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-
price_id = item['prices'][0]['id']
174+
price_id = self.get_subnet_item_price(item, subnet_type, version)
175175
break
176176

177177
order = {
@@ -192,6 +192,24 @@ def add_subnet(self, subnet_type, quantity=None, endpoint_id=None, version=4,
192192
else:
193193
return self.client['Product_Order'].placeOrder(order)
194194

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+
195213
def assign_global_ip(self, global_ip_id, target):
196214
"""Assigns a global IP address to a specified target.
197215

tests/managers/network_tests.py

+8
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ def test_add_subnet_for_ipv4(self):
100100

101101
self.assertEqual(fixtures.SoftLayer_Product_Order.verifyOrder, result)
102102

103+
result = self.network.add_subnet('static',
104+
quantity=8,
105+
endpoint_id=1234,
106+
version=4,
107+
test_order=True)
108+
109+
self.assertEqual(fixtures.SoftLayer_Product_Order.verifyOrder, result)
110+
103111
def test_add_subnet_for_ipv6(self):
104112
# Test a public IPv6 order
105113
result = self.network.add_subnet('public',

0 commit comments

Comments
 (0)