Search code examples
pythonibm-cloud-infrastructure

Enable VLAN Spanning with Python API


I want to make a REST api call via the SoftLayer Python API to enable VLAN spanning for an account. I found the following link and I am trying to adapt its contents into what I think the call would look like, what I have so far:

url = 'https://' + username + ':' + api_key +'@api.service.softlayer.com/rest/v3/SoftLayer_Account/' + account_id  + '/setVlanSpan.json'
data = '{"parameters":[[{"enabled": "True"}]]}'
response = requests.post(url, data=data)

My question beyond that is where/how to get the account_id in order to feed that to the URL in the post request? If there is a better way to accomplish this task with the python API, then that works too!


Solution

  • It is not necessary to specify the accountId for SoftLayer_Account::setVlanSpan method.

    Try the following change in your code:

    url = 'https://' + username + ':' + api_key +'@api.service.softlayer.com/rest/v3/SoftLayer_Account/setVlanSpan.json'
    data = '{"parameters":["True"]}'
    

    Anyway, you can get the accountId with the following rest request:

    https://$username:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Account/getObject
    
    Method: Get
    

    The "id" property from the response refers to accountId.

    Some references: http://sldn.softlayer.com/article/Python