Skip to content

Commit c2d1eef

Browse files
Merge pull request softlayer#674 from camporter/remove-hardcoded-category-ids
Remove hardcoded category ids for category codes
2 parents dfc131f + a2c4057 commit c2d1eef

3 files changed

Lines changed: 35 additions & 11 deletions

File tree

SoftLayer/CLI/virt/upgrade.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ def cli(env, identifier, cpu, private, memory, network):
3333
"Continue?")):
3434
raise exceptions.CLIAbort('Aborted')
3535

36+
if memory:
37+
memory = int(memory / 1024)
38+
3639
if not vsi.upgrade(vs_id,
3740
cpus=cpu,
38-
memory=memory/1024,
41+
memory=memory,
3942
nic_speed=network,
4043
public=not private):
4144
raise exceptions.CLIAbort('VS Upgrade Failed')

SoftLayer/fixtures/SoftLayer_Product_Package.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,39 +188,49 @@
188188
'description': 'Public & Private Networks',
189189
'itemCategory': {'categoryCode': 'Uplink Port Speeds'},
190190
'prices': [{'id': 1122,
191-
'categories': [{'id': 26, 'name': 'Uplink Port Speeds'}]}],
191+
'categories': [{'id': 26,
192+
'name': 'Uplink Port Speeds',
193+
'categoryCode': 'port_speed'}]}],
192194
},
193195
{
194196
'id': 2233,
195197
'capacity': '1000',
196198
'description': 'Public & Private Networks',
197199
'itemCategory': {'categoryCode': 'Uplink Port Speeds'},
198200
'prices': [{'id': 4477,
199-
'categories': [{'id': 26, 'name': 'Uplink Port Speeds'}]}],
201+
'categories': [{'id': 26,
202+
'name': 'Uplink Port Speeds',
203+
'categoryCode': 'port_speed'}]}],
200204
},
201205
{
202206
'id': 1239,
203207
'capacity': '2',
204208
'description': 'RAM',
205209
'itemCategory': {'categoryCode': 'RAM'},
206210
'prices': [{'id': 1133,
207-
'categories': [{'id': 3, 'name': 'RAM'}]}],
211+
'categories': [{'id': 3,
212+
'name': 'RAM',
213+
'categoryCode': 'ram'}]}],
208214
},
209215
{
210216
'id': 1240,
211217
'capacity': '4',
212218
'description': 'Private Computing Instance',
213219
'itemCategory': {'categoryCode': 'Computing Instance'},
214220
'prices': [{'id': 1007,
215-
'categories': [{'id': 80, 'name': 'Computing Instance'}]}],
221+
'categories': [{'id': 80,
222+
'name': 'Computing Instance',
223+
'categoryCode': 'guest_core'}]}],
216224
},
217225
{
218226
'id': 1250,
219227
'capacity': '4',
220228
'description': 'Computing Instance',
221229
'itemCategory': {'categoryCode': 'Computing Instance'},
222230
'prices': [{'id': 1144,
223-
'categories': [{'id': 80, 'name': 'Computing Instance'}]}],
231+
'categories': [{'id': 80,
232+
'name': 'Computing Instance',
233+
'categoryCode': 'guest_core'}]}],
224234
},
225235
{
226236
'id': 4439,

SoftLayer/managers/vs.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ def capture(self, instance_id, name, additional_disks=False, notes=None):
697697
698698
:param integer instance_id: the instance ID to edit
699699
:param string name: name assigned to the image
700-
:param string additional_disks: set to true to include all additional
700+
:param bool additional_disks: set to true to include all additional
701701
attached storage devices
702702
:param string notes: notes about this particular image
703703
@@ -780,7 +780,13 @@ def upgrade(self, instance_id, cpus=None, memory=None,
780780

781781
def _get_package_items(self):
782782
"""Following Method gets all the item ids related to VS."""
783-
mask = "mask[description,capacity,prices[id,categories[name,id]]]"
783+
mask = [
784+
'description',
785+
'capacity',
786+
'prices[id,categories[name,id,categoryCode]]'
787+
]
788+
mask = "mask[%s]" % ','.join(mask)
789+
784790
package_type = "VIRTUAL_SERVER_INSTANCE"
785791
package_id = self.ordering_manager.get_package_id_by_type(package_type)
786792
package_service = self.client['Product_Package']
@@ -796,12 +802,17 @@ def _get_item_id_for_upgrade(self, package_items, option, value,
796802
:param int value: The value of the parameter to be upgraded
797803
:param bool public: CPU will be in Private/Public Node.
798804
"""
799-
vs_id = {'memory': 3, 'cpus': 80, 'nic_speed': 26}
805+
option_category = {
806+
'memory': 'ram',
807+
'cpus': 'guest_core',
808+
'nic_speed': 'port_speed'
809+
}
810+
800811
for item in package_items:
801812
categories = item['prices'][0]['categories']
802813
for category in categories:
803-
if not (category['id'] == vs_id[option] and
804-
item['capacity'] == str(value)):
814+
if not (category['categoryCode'] == option_category[option] and
815+
str(item['capacity']) == str(value)):
805816
continue
806817
if option == 'cpus':
807818
if public and ('Private' not in item['description']):

0 commit comments

Comments
 (0)