November 23, 2017


list_roles.py
list_roles.py

'''
List roles.

The script retrieves all the roles in a brand account.
It displays the same result like in https://agent.softlayer.com/administration/role/list

Important manual pages
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getPermissionRoles
http://sldn.softlayer.com/reference/datatypes/SoftLayer_User_Permission_Role
http://sldn.softlayer.com/article/Object-Masks

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
'''

import SoftLayer.API
import json

USERNAME = 'set me'
API_KEY = 'set me'

client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)

accountService = client['SoftLayer_Account']
objectMask = "mask[userCount]"

try:
    result = accountService.getPermissionRoles(mask=objectMask)
    print(json.dumps(result, sort_keys=True, indent=2, separators=(',', ': ')))
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to list the roles. "
          % (e.faultCode, e.faultString))

Feedback?

We would love to hear it
Open an issue