Softlayer从主品牌帐户获取客户列表

时间:2017-05-09 05:24:55

标签: python ibm-cloud-infrastructure

如何使用python获取主品牌帐户的客户列表。

我试过这样:

import Softlayer
client = Sotlayer.Client(api_key='xxxxx',username='xxxxxxx')
brand_id ='xxxxx'
brand_users  = client['Brand'].getUsers(id=brand_id)

我无法获得所有客户名单

1 个答案:

答案 0 :(得分:1)

试试这个:

'''
Get owned account

The script retrieves all the owned accounts for an arbitrary brand,
the script makes a call to getOwnedBrands() method to retrieve
the brands where the account belongs, then it calls the getAllOwnedAccounts()
method to get the owned accounts for every brand.

Important manual pages
http://sldn.softlayer.com/reference/services/SoftLayer_Account
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getOwnedBrands
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getAllOwnedAccounts
http://sldn.softlayer.com/reference/services/SoftLayer_Brand
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Brand

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

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

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

accountService = client['SoftLayer_Account']
brandService = client['SoftLayer_Brand']

# Getting the brands
brands = accountService.getOwnedBrands()
for brand in brands:
    brandId = brand['id']
    # Getting the owned Accounts
    accounts = brandService.getAllOwnedAccounts(id=brandId)
    for account in accounts:
        print(account['companyName'])