Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions SoftLayer/managers/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def place_order(self, **kwargs):

See get_create_options() for valid arguments.

:param string size: server size name
:param string size: server size name or presetId
:param string hostname: server hostname
:param string domain: server domain name
:param string location: location (datacenter) name
Expand Down Expand Up @@ -467,13 +467,18 @@ def _generate_create_dict(self,
'hostname': hostname,
'domain': domain,
}

try:
size = _get_preset_id(package, size)
except SoftLayer.SoftLayerError as err:
if not err.message.startswith('Could not find valid size for'):
raise
size = size
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you asked I check if a size exists with its name before take ID.

I check with try/except, and raise other exceptions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant, modify _get_preset_id to return the valid id based on either a keyName or preset id

def _get_preset_id(package, size):
    """Get the preset id given the keyName of the preset."""
    for preset in package['activePresets']:
        if preset['keyName'] == size:
            return preset['id']
        elif preset['id'] == size:
            return preset['id']

    raise SoftLayer.SoftLayerError("Could not find valid size for: '%s'" % size)

Also, the build scripts need to pass before I will merge a change.
You might need to pull in my new changes in the master branch as I've included some unit test fixes since this request was made.

order = {
'hardware': [hardware],
'location': location['keyname'],
'prices': [{'id': price} for price in prices],
'packageId': package['id'],
'presetId': _get_preset_id(package, size),
'presetId': size,
'useHourlyPricing': hourly,
}

Expand Down