【问题标题】:How to retrieve all the licenses associated with an account using Python API如何使用 Python API 检索与帐户关联的所有许可证
【发布时间】:2018-10-02 13:27:12
【问题描述】:

我正在尝试检索与特定帐户 ID 下的每个硬件组件(实例)关联的许可证信息(许可证名称、许可证版本、到期日期等)。有人可以帮助列出在特定帐户 ID 下关联的所有硬件组件以及附加到每个硬件组件的所有软件许可证吗?

【问题讨论】:

  • 我不确定您要从 API 中检索什么,您是在谈论 Vmware/netapp 许可证吗?如果您可以提供屏幕截图或描述该信息位于 UI 的哪个部分,将会很有帮助
  • @alec_djnn 刚刚看过了。感谢您的帮助,但这无助于我正在寻找特定于 IBM-cloud-infrastructure 的目的。
  • @AlbertCamacho 是的,我正在尝试检索所有许可证信息,例如 vSAN 许可证、vCenter 许可证和计费项目 ID、每个订单 ID 以及与之关联的硬件。通常,它们位于 vCenter 下,但我们不想在那里查询。

标签: python ibm-cloud ibm-cloud-infrastructure


【解决方案1】:

要检索 vCenter、vSAN、SRM 等所有 VMware 许可证,您可以使用以下 rest 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 许可证”,您只需在其余 api 请求中将“VMware”数据替换为“NetApp”即可。

似乎无法通过 api 了解这些许可证附加了哪些硬件,而您可以通过控制门户看到相同的硬件。此信息不在数据库中,因为这些许可证是在服务器内部/手动添加的。

参考:

https://softlayer.github.io/reference/services/SoftLayer_Account/getActiveAccountLicenses/ https://softlayer.github.io/reference/datatypes/SoftLayer_Software_AccountLicense/

【讨论】:

  • 感谢您对 REST 请求的帮助。你能帮忙解释一下 Python 的调用是什么吗?我已经有可用的 python-softlayer 客户端连接,所以会很方便。我尝试运行上面的 GET 请求,但它给出了“拒绝访问”错误(从 console.bluemix.net 生成的密钥。
  • 我用 python 脚本示例更新了论坛,“访问被拒绝”错误是因为您没有将 [username] 和 [apiKey] 替换为您的凭据。
  • @F.Odeja 感谢您对 python 调用的帮助。这真的很有帮助。使用在响应中检索到的计费项目 ID,我也在寻找与之关联的订单 ID,这可能吗?
  • 是的,可以获得订单ID。尝试将“id”数据添加到脚本中的 objectMask,例如:'mask[billingItem[id,cancellationDate,orderItem[order[id,createDate]]],softwareDescription[name,manufacturer]]
  • 在以下文档中,您将找到可以添加到 objectMask 的数据类型:softlayer.github.io/reference/datatypes/SoftLayer_Billing_Itemsoftlayer.github.io/reference/datatypes/…softlayer.github.io/reference/datatypes/SoftLayer_Billing_Order,其他文档将帮助您如何使用 ¨object-口罩¨:softlayer.github.io/article/object-masks
猜你喜欢
  • 1970-01-01
  • 2017-11-08
  • 1970-01-01
  • 2013-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多