-
Notifications
You must be signed in to change notification settings - Fork 194
Issues922 - DC short names in ordering #956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
91c3b8e
added lookup function for datacenter names
allmightyspiff 87637ad
fixed some anaylsis complaints
allmightyspiff e081d7d
changed locatoinGroupId to check for None instead of empty string
allmightyspiff d6a9453
check for default location set to None instead of empty string
allmightyspiff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
""" | ||
# pylint: disable=no-self-use | ||
|
||
from re import match | ||
|
||
from SoftLayer import exceptions | ||
|
||
CATEGORY_MASK = '''id, | ||
|
@@ -341,7 +343,7 @@ def get_price_id_list(self, package_keyname, item_keynames): | |
# can take that ID and create the proper price for us in the location | ||
# in which the order is made | ||
price_id = [p['id'] for p in matching_item['prices'] | ||
if p['locationGroupId'] == ''][0] | ||
if p['locationGroupId'] is None][0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests are still relying on this being an empty string. |
||
prices.append(price_id) | ||
|
||
return prices | ||
|
@@ -443,7 +445,7 @@ def generate_order(self, package_keyname, location, item_keynames, complex_type= | |
# 'domain': 'softlayer.com'}]} | ||
order.update(extras) | ||
order['packageId'] = package['id'] | ||
order['location'] = location | ||
order['location'] = self.get_location_id(location) | ||
order['quantity'] = quantity | ||
order['useHourlyPricing'] = hourly | ||
|
||
|
@@ -471,3 +473,23 @@ def package_locations(self, package_keyname): | |
|
||
regions = self.package_svc.getRegions(id=package['id'], mask=mask) | ||
return regions | ||
|
||
def get_location_id(self, location): | ||
"""Finds the location ID of a given datacenter | ||
|
||
This is mostly used so either a dc name, or regions keyname can be used when ordering | ||
:param str location: Region Keyname (DALLAS13) or datacenter name (dal13) | ||
:returns: integer id of the datacenter | ||
""" | ||
|
||
if isinstance(location, int): | ||
return location | ||
mask = "mask[id,name,regions[keyname]]" | ||
if match(r'[a-zA-Z]{3}[0-9]{2}', location) is not None: | ||
search = {'name': {'operation': location}} | ||
else: | ||
search = {'regions': {'keyname': {'operation': location}}} | ||
datacenter = self.client.call('SoftLayer_Location', 'getDatacenters', mask=mask, filter=search) | ||
if len(datacenter) != 1: | ||
raise exceptions.SoftLayerError("Unable to find location: %s" % location) | ||
return datacenter[0]['id'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to combine the fixtures since they are for the same method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that my method expects only 1 result back, but else where expects multiple results back.... I need to figure out a better way to do these fixtures to deal with different object masks/filters. but that might be for a different project.