如何使用 Python API 检索与帐户关联的所有许可证
How to retrieve all the licenses associated with an account using Python API
我正在尝试检索与特定帐户 ID 下的每个硬件组件(实例)关联的许可证信息(许可证名称、许可证版本、到期日期等...)。有人可以帮助列出特定帐户 ID 下关联的所有硬件组件以及每个硬件组件附带的所有软件许可证吗?
要检索所有 VMware 许可证,如 vCenter、vSAN、SRM 等,您可以使用以下剩余 api:
方法:获取
https://[username]:[apiKey]@api.softlayer.com/rest/v3.1/SoftLayer_Account/getActiveAccountLicenses?objectMask=mask[billingItem[id,cancellationDate,orderItem[order[createDate]]],softwareDescription[name,manufacturer]]&objectFilter={"activeAccountLicenses":{"softwareDescription":{"manufacturer":{"operation":"VMware"}}}}
用您的凭据替换 [username] 和 [apiKey]。
或者您可以使用下面的 python 脚本示例:
"""
GetActiveAccountLicenses
Retrieve the active account software licenses owned by an account.
Important manual pages:
https://softlayer.github.io/reference/services/SoftLayer_Account/getActiveAccountLicenses/
https://softlayer.github.io/reference/datatypes/SoftLayer_Software_AccountLicense/
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import json
import SoftLayer
# For nice debug output:
from pprint import pprint as pp
# Your SoftLayer API username and key.
API_USERNAME = 'set me'
# Generate one at https://control.softlayer.com/account/users
API_KEY = 'set me'
objectMask = 'mask[billingItem[id,cancellationDate,orderItem[order[createDate]]],softwareDescription[name,manufacturer,' \
'virtualLicense]]'
objectFilter = {"activeAccountLicenses":{"softwareDescription":{"manufacturer":{"operation":"VMware"}}}}
client = SoftLayer.create_client_from_env(
username=API_USERNAME,
api_key=API_KEY
)
try:
accountLicenses = client['SoftLayer_Account'].getActiveAccountLicenses(mask=objectMask, filter= objectFilter)
print(json.dumps(accountLicenses, sort_keys=True, indent=2, separators=(',', ': ')))
except SoftLayer.SoftLayerAPIError as e:
pp('Unable to retrieve the account licenses faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString))
您将得到如下例所示的响应:
{
"accountId": 11111,
"capacity": "4",
"key": "4ADFG-5GSDL-20FDF9-SFSD3-FSDF5",
"units": "CPU",
"billingItem": {
"cancellationDate": null,
"id": 22222,
"orderItem": {
"categoryCode": "software_license",
"description": "vCenter Server Appliance 6.0",
"id": 33333,
"recurringFee": "0",
"setupTaxAmount": "0",
"order": {
"createDate": "2018-03-13T05:30:26-06:00"
}
}
},
"softwareDescription": {
"manufacturer": "VMware",
"name": "vCenter"
}
},
如果您想检索 "NetApp Licenses",您只需在其余 api 请求中将 "VMware" 数据替换为 "NetApp"。
似乎无法通过 api 知道这些许可证附加了哪些硬件,您可以通过控制门户看到同样的情况。此信息不在数据库中,因为这些许可证已添加 internally/manually 在服务器中。
参考:
https://softlayer.github.io/reference/services/SoftLayer_Account/getActiveAccountLicenses/
https://softlayer.github.io/reference/datatypes/SoftLayer_Software_AccountLicense/
我正在尝试检索与特定帐户 ID 下的每个硬件组件(实例)关联的许可证信息(许可证名称、许可证版本、到期日期等...)。有人可以帮助列出特定帐户 ID 下关联的所有硬件组件以及每个硬件组件附带的所有软件许可证吗?
要检索所有 VMware 许可证,如 vCenter、vSAN、SRM 等,您可以使用以下剩余 api:
方法:获取
https://[username]:[apiKey]@api.softlayer.com/rest/v3.1/SoftLayer_Account/getActiveAccountLicenses?objectMask=mask[billingItem[id,cancellationDate,orderItem[order[createDate]]],softwareDescription[name,manufacturer]]&objectFilter={"activeAccountLicenses":{"softwareDescription":{"manufacturer":{"operation":"VMware"}}}}
用您的凭据替换 [username] 和 [apiKey]。
或者您可以使用下面的 python 脚本示例:
"""
GetActiveAccountLicenses
Retrieve the active account software licenses owned by an account.
Important manual pages:
https://softlayer.github.io/reference/services/SoftLayer_Account/getActiveAccountLicenses/
https://softlayer.github.io/reference/datatypes/SoftLayer_Software_AccountLicense/
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import json
import SoftLayer
# For nice debug output:
from pprint import pprint as pp
# Your SoftLayer API username and key.
API_USERNAME = 'set me'
# Generate one at https://control.softlayer.com/account/users
API_KEY = 'set me'
objectMask = 'mask[billingItem[id,cancellationDate,orderItem[order[createDate]]],softwareDescription[name,manufacturer,' \
'virtualLicense]]'
objectFilter = {"activeAccountLicenses":{"softwareDescription":{"manufacturer":{"operation":"VMware"}}}}
client = SoftLayer.create_client_from_env(
username=API_USERNAME,
api_key=API_KEY
)
try:
accountLicenses = client['SoftLayer_Account'].getActiveAccountLicenses(mask=objectMask, filter= objectFilter)
print(json.dumps(accountLicenses, sort_keys=True, indent=2, separators=(',', ': ')))
except SoftLayer.SoftLayerAPIError as e:
pp('Unable to retrieve the account licenses faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString))
您将得到如下例所示的响应:
{
"accountId": 11111,
"capacity": "4",
"key": "4ADFG-5GSDL-20FDF9-SFSD3-FSDF5",
"units": "CPU",
"billingItem": {
"cancellationDate": null,
"id": 22222,
"orderItem": {
"categoryCode": "software_license",
"description": "vCenter Server Appliance 6.0",
"id": 33333,
"recurringFee": "0",
"setupTaxAmount": "0",
"order": {
"createDate": "2018-03-13T05:30:26-06:00"
}
}
},
"softwareDescription": {
"manufacturer": "VMware",
"name": "vCenter"
}
},
如果您想检索 "NetApp Licenses",您只需在其余 api 请求中将 "VMware" 数据替换为 "NetApp"。
似乎无法通过 api 知道这些许可证附加了哪些硬件,您可以通过控制门户看到同样的情况。此信息不在数据库中,因为这些许可证已添加 internally/manually 在服务器中。
参考:
https://softlayer.github.io/reference/services/SoftLayer_Account/getActiveAccountLicenses/ https://softlayer.github.io/reference/datatypes/SoftLayer_Software_AccountLicense/