0
votes

We've been using our SoftLayer API script to order baremetal servers for the past year without any issues. When I tried to place a new order today using quote, 2032985, I got the following error:

File "./order-softlayer-servers.py", line 69, in place_SoftLayerOrder order['orderContainers'][0]['hardware'] = [] KeyError: 'orderContainers'

The last successful order that I placed was on Jan 18, 2017. Was there a recent change to the API data model; such as orderContainers? Below is the main portion of my script.

Thank you.

import SoftLayer.API

def place_SoftLayerOrder(orderList,quote_id):
order = getOrderContainer(quote_id)

order['orderContainers'][0]['hardware'] = []

for server in orderList:
    print server
    order['orderContainers'][0]['hardware'].insert(0,{'hostname': server, 'domain': 'sl-netbase.com'})

order['orderContainers'][0]['quantity'] = len(orderList)

order['presetId'] = None

result = client['Billing_Order_Quote'].placeOrder(order, id=quote_id)
pp(result)
return result
2
Use {} to format your code. - codeforester

2 Answers

0
votes

Nope nothing has changed, but the problem in your code seems to be the way that it is fetching the quote order, because according the error it seems that the retrieved quote order does not contain the "orderContainers" key, so please review that your method to retrieve the order quote contains the key orderContainers.

keep in mind that you need to use the method SoftLayer_Billing_Order_Quote::getRecalculatedOrderContainer to get the quote order, and that the result will contain orderContainers only if your quote contains different server flavors(I mean different configuration of servers) if they are the same configuration (even if the quote contains several servers) the result will not contain the object "orderContainer" so your code needs to chek and handle those scenarios.

Regards

0
votes

That is correct. I am using getRecalculatedOrderContainer method to get the quote order. Each quote contains only one server.

My getOrderContainer(quote_id) is listed below. This is not a new script. I've been using this script to place my orders for the past year. I don't think it is the quote because I tried several other quotes and got the same error. The last successful order that I placed was on Jan 18. Very odd.

def getOrderContainer(quote_id): container = client['Billing_Order_Quote'].getRecalculatedOrderContainer( id=quote_id)

return container