1

As shown below, the new SoftLayer Datacenter in Norway is not recognized by the API. This call works with other Datacenters.

SoftLayer.managers.hardware._get_location(package, "osl01")

Traceback (most recent call last):
...
SoftLayer.exceptions.SoftLayerError: Could not find valid location for: 'osl01'
pgra
  • 13
  • 3

2 Answers2

0

I am not able to replicate this using Bare Metal (Package 200) as a test. Can you specify which package ID you are seeing this with?

import SoftLayer
import json

package_id = 200
datacenter = 'osl01'

client = SoftLayer.Client()

location_object_filter = {
    'name': {'operation': datacenter}
}

location_object_mask = "priceGroups"

location = client["SoftLayer_Location_Datacenter"].getDatacenters(filter=location_object_filter, mask=location_object_mask)

if len(location) == 0:
    # error handling
    exit()

# lookup location group ids
location_group_ids = []
for location_group in location[0]["priceGroups"]:
    location_group_ids.append(location_group["id"])

object_filter_standard = {
    'items': {
        "prices": {
            "locationGroupId": {
                "operation": "is null"
            }
        }
    }
}

standard_items = client["SoftLayer_Product_Package"].getItems(id=package_id, filter=object_filter_standard)

object_filter_location = {
    'items': {
        "prices": {
            "locationGroupId": {
                "operation": "in",
                "options": [
                    {
                        "name": "data",
                        "value": location_group_ids
                    }
                ]
            }
        }
    }
}

location_items = client["SoftLayer_Product_Package"].getItems(id=package_id, filter=object_filter_location)

# let's key by item id
items = {}

for standard_item in standard_items:
    for location_item in location_items:
        if location_item["id"] == standard_item["id"]:
            items[location_item["id"]] = location_item
            break

    if standard_item["id"] not in items:
        items[standard_item["id"]] = standard_item


print(json.dumps(items, sort_keys=True, indent=2, separators=(',', ': ')))
greyhoundforty
  • 239
  • 2
  • 9
  • That is odd, I am not able to replicate this with 257 or 251. If you are able to use the code example here https://softlayer.github.io/python/location_based_pricing/ then it may be with the Python manager (helper). If that is the case you may want to open an issue at https://github.com/softlayer/softlayer-python/issues. – greyhoundforty Dec 23 '16 at 15:42
0

Could you provide information about how are you getting package object? or the object that you are sending?

The package 257 has "Oslo 1" datacenter in regions assigned, but for 251 package is expected, because the package has not available "Oslo 1" as a region

  • Does this help? `File "/home/blueboxadmin/sambol/venv/local/lib/python2.7/site-packages/SoftLayer/managers/hardware.py", line 738, in _get_location % location) SoftLayer.exceptions.SoftLayerError: Could not find valid location for: 'osl01'` – sambol Dec 23 '16 at 16:34
  • Well, it's necessary to get the way that you are getting the **package**, because if you print **package['regions']**, I'm really sure that you don't have 'Oslo 1' as datacenter, this method **_get_location** just gets the specific region from the **package** object that you send, so the issue is in the way that you are getting **package** object – Ruber Cuellar Valenzuela Dec 23 '16 at 17:27
  • Here's how we're getting the package: https://gist.github.com/msambol/20ab5b573a45494a207e26a959d55a61 – sambol Dec 27 '16 at 14:15
  • I'm able to get the package but you're correct in that **package['regions']** does _not_ have **osl01** in it. Is this a fault in our code or yours? – sambol Dec 27 '16 at 14:33
  • That's your fault, because as I told you before: **The package 257 has "Oslo 1" datacenter in regions assigned, but for 251 package is expected, because the package has not available "Oslo 1" as a region** So, it would be really important to get the way that you are getting package variable, in order to verify why you are not able to see **Oslo 1** – Ruber Cuellar Valenzuela Jan 03 '17 at 13:44