【问题标题】:how is Softlayer location defined when working with SoftLayer API?使用 SoftLayer API 时如何定义 Softlayer 位置?
【发布时间】:2018-07-16 16:27:52
【问题描述】:

我正在编写一个使用 SoftLayer API 的 Python 脚本(示例代码 place_order_several_vms_vlan.py,https://softlayer.github.io/python/)。要设置的一个属性是“位置”。在这种情况下,SoftLayer 的位置属性是如何定义的?

到目前为止,我只能使用“AMSTERDAM”。其他任何东西,例如 DAL05,都失败了。

如果有人可以提供在使用 SoftLayer API 时可以在此上下文中使用的位置列表。

【问题讨论】:

  • 使用其他位置时出现什么错误。

标签: python api location ibm-cloud-infrastructure


【解决方案1】:

该位置是您的虚拟机将被配置的位置,您使用的 python 脚本示例是在 AMSTERDAM 位置下一个新的虚拟机订单。

要获取所有可用于配置您的 vm 的位置,请使用这个 rest api。

方法:获取

https://[username]:[apiKey]@api.softlayer.com/rest/v3.1/SoftLayer_Location/getDatacenters

参考:

https://softlayer.github.io/reference/services/SoftLayer_Location/getDatacenters/

您必须记住,每个位置的商品价格都不同。

要获取商品价格及其位置,您可以使用以下 rest api:

方法:获取

https://[username]:[apiKey]@api.softlayer.com/rest/v3.1/SoftLayer_Product_Package/46/getItemPrices?objectMask=mask[pricingLocationGroup[locations]]

响应例如将是这样的:

{
        "currentPriceFlag": null,
        "hourlyRecurringFee": ".018",
        "id": 112475,
        "itemId": 857,
        "laborFee": "0",
        "locationGroupId": 503,
        "onSaleFlag": null,
        "oneTimeFee": "0",
        "quantity": null,
        "recurringFee": "11.21",
        "setupFee": "0",
        "sort": 0,
        "tierMinimumThreshold": null,
        "item": {
            "capacity": "1",
            "description": "1 x 2.0 GHz or higher Core",
            "id": 857,
            "itemTaxCategoryId": 166,
            "keyName": "GUEST_CORE_1",
            "softwareDescriptionId": null,
            "units": "CORE",
            "upgradeItemId": null
        },
        "pricingLocationGroup": {
            "description": "Location Group 2",
            "id": 503,
            "locationGroupTypeId": 82,
            "name": "Location Group 2",
            "securityLevelId": null,
            "locations": [
                {
                    "id": 449610,
                    "longName": "Montreal 1",
                    "name": "mon01",
                    "statusId": 2
                },
                {
                    "id": 449618,
                    "longName": "Montreal 2",
                    "name": "mon02",
                    "statusId": 2
                },
                {
                    "id": 448994,
                    "longName": "Toronto 1",
                    "name": "tor01",
                    "statusId": 2
                },
                {
                    "id": 350993,
                    "longName": "Toronto 2",
                    "name": "tor02",
                    "statusId": 2
                },
                {
                    "id": 221894,
                    "longName": "Amsterdam 2",
                    "name": "ams02",
                    "statusId": 2
                },
                {
                    "id": 265592,
                    "longName": "Amsterdam 1",
                    "name": "ams01",
                    "statusId": 2
                },
                {
                    "id": 814994,
                    "longName": "Amsterdam 3",
                    "name": "ams03",
                    "statusId": 2
                }
            ]
        }
    },

例如对于“1 x 2.0 GHz 或更高的核心”商品,商品价格 ID 将为“id”:112475,您将看到该商品的可用位置。

如果您没有找到某个项目的位置是因为该项目的价格是标准的,这意味着该项目的所有位置都可用。

参考:

https://softlayer.github.io/reference/services/SoftLayer_Product_Package/getItemPrices/

【讨论】:

  • 谢谢@F.Ojeda。在运行 API getDatacenters 时,对于阿姆斯特丹的数据中心,它只返回 { 'id':265592, 'longName':'Amsterdam 1', 'name':'ams01', 'statusId':2 }, { 'id': 814994, 'longName':'阿姆斯特丹 3', 'name':'ams03', 'statusId':2 },
  • 没有匹配“阿姆斯特丹”的内容。请注意,原始示例脚本仅在定义了 location="AMSTERDAM" 时才有效。没有其他工作。我试图找出我可以在我的脚本中使用的其他值
  • 现在,我了解您的第二点 - 并非所有数据中心都提供所有价格套餐。谢谢你。此外,当数据中心 ID 分配给位置时,它可以工作。但是,看来我可以为该位置分配一个字符串,例如“AMSTERDAM”。 SL 中的“阿姆斯特丹”是什么?它是属性之一吗?
  • python 脚本示例使用的是阿姆斯特丹 1 位置,您可以使用请求响应中的位置 id 在数据中心请求中搜索该 id 来验证它。只有两个阿姆斯特丹位置与控制门户阿姆斯特丹 1 和阿姆斯特丹 3 相同。
  • 您可以为该位置分配一个字符串,在这种情况下,当您仅添加阿姆斯特丹时,它是阿姆斯特丹 1,但如果您想添加阿姆斯特丹 3,您必须像 Amstedam03 一样添加。其余位置相同。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多