Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Softlayer API时,如何定义Softlayer位置?_Python_Api_Location_Ibm Cloud Infrastructure - Fatal编程技术网

Python 使用Softlayer API时,如何定义Softlayer位置?

Python 使用Softlayer API时,如何定义Softlayer位置?,python,api,location,ibm-cloud-infrastructure,Python,Api,Location,Ibm Cloud Infrastructure,我正在编写一个使用SoftLayer API的Python脚本(示例代码place_order_几个_vms_vlan.py at)。要设置的一个属性是“位置”。在此上下文中,如何为SoftLayer定义位置属性 到目前为止,我只能用“阿姆斯特丹”。其他任何东西,比如DAL05,都失败了 如果有人能提供在使用SoftLayer API时可在此上下文中使用的位置列表,我们将不胜感激。该位置是配置虚拟机的位置,您使用的python脚本示例是在阿姆斯特丹位置下新的虚拟机订单 要获取所有可用于配置vm的

我正在编写一个使用SoftLayer API的Python脚本(示例代码place_order_几个_vms_vlan.py at)。要设置的一个属性是“位置”。在此上下文中,如何为SoftLayer定义位置属性

到目前为止,我只能用“阿姆斯特丹”。其他任何东西,比如DAL05,都失败了


如果有人能提供在使用SoftLayer API时可在此上下文中使用的位置列表,我们将不胜感激。

该位置是配置虚拟机的位置,您使用的python脚本示例是在阿姆斯特丹位置下新的虚拟机订单

要获取所有可用于配置vm的位置,请使用此rest api

方法:获取

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

您必须记住,每个地点的商品价格都不同

要获取项目价格及其位置,可以使用以下rest api:

方法:获取

https://[username]:[apiKey]@api.softlayer.com/rest/v3.1/SoftLayer_Location/getDatacenters
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
                }
            ]
        }
    },
e、 g.对于项目“1 x 2.0 GHz或更高的核心”,项目价格id将为“id”:112475,您将看到该项目的可用位置

如果找不到某个项目的位置是因为该项目的价格是标准的,则表示该项目的所有位置都可用

参考:


当您使用其他位置时,会出现什么错误。谢谢@F.Ojeda。在运行API getDatacenters时,对于阿姆斯特丹的数据中心,它只返回{'id':265592,'longName':'Amsterdam 1','name':'ams01','statusId':2},{'id':814994,'longName':'Amsterdam 3','name':'ams03','statusId':2},与“Amsterdam”不匹配。注意,原始示例脚本仅在定义location=“AMSTERDAM”时有效。没有别的办法。我试图找出我可以在脚本中使用的其他值。现在,我理解您的第二点-并非所有数据中心都提供所有价格包。非常感谢。此外,当数据中心ID分配给location时,它也可以工作。但是,我似乎可以为该位置指定一个字符串,如“AMSTERDAM”。SL中的“阿姆斯特丹”是什么?它是属性之一吗?python脚本示例使用Amsterdam 1 location,您可以使用请求响应中的位置id在数据中心请求中搜索该id来验证它。只有两个阿姆斯特丹位置,与控制门户阿姆斯特丹1和阿姆斯特丹3相同。您可以为该位置分配字符串,在本例中,当您仅添加阿姆斯特丹时,它是阿姆斯特丹1,但如果您要添加阿姆斯特丹3,则必须像amsterdam03一样添加。其余位置也一样。