使用SoftLayer Python API placeOrder将磁盘添加到vm

时间:2016-10-05 17:45:58

标签: python curl ibm-cloud-infrastructure

我使用自定义图像模板创建了一个softlayer虚拟机。我可以使用curl将SAN磁盘添加到我的虚拟机中,但是我尝试使用Python SoftLayer库不成功。我收到以下错误:

SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_Order_InvalidContainer): Invalid container specified: SoftLayer_Container_Product_Order. Ordering a server or service requires a specific container type, not the generic base order container.

这是我的代码:

self.client = SoftLayer.Client(username='myusername@email.com', api_key='key')
console_id = 11111111

order = {
        "parameters": [{
            "virtualGuests": [{"id": console_id}],
            "prices": [{
                "id": 113031,
                "categories": [{
                    "categoryCode": "guest_disk1",
                    "complexType": "SoftLayer_Product_Item_Category"
                }],
                "complexType": "SoftLayer_Product_Item_Price"
            },
                {
                    "id": 112707,
                    "categories": [{
                        "categoryCode": "guest_disk2",
                        "complexType": "SoftLayer_Product_Item_Category"
                    }],
                    "complexType": "SoftLayer_Product_Item_Price"
                }
            ],
            "properties": [
                {"name": "NOTE_GENERAL", "value": "adding disks"},
                {"name": "MAINTENANCE_WINDOW", "value": "now"}
            ],
            "complexType": "SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade"
        }]
    }

# response = self.client['Product_Order'].placeOrder(order, False)        
response = self.client.call('Product_Order', 'placeOrder', order)

print response

如果我运行以下curl命令,但我的vm更新成功:

curl -X POST --data @updatefile https://myusername%40email%2Ecom:apikey@api.softlayer.com/rest/v3.1/SoftLayer_Product_Order/placeOrder

updatefile的内容:

{
"parameters": [{
    "virtualGuests":[{"id":11111111}],
    "prices": [{
        "id": 113031,
        "categories": [{
            "categoryCode": "guest_disk1",
            "complexType": "SoftLayer_Product_Item_Category"
        }],
        "complexType": "SoftLayer_Product_Item_Price"
    },

    {
        "id": 112707,
        "categories": [{
            "categoryCode": "guest_disk2",
            "complexType": "SoftLayer_Product_Item_Category"
        }],
        "complexType": "SoftLayer_Product_Item_Price"
    }
    ],
    "properties": [
    {"name": "NOTE_GENERAL","value": "adding disks"},
    {"name": "MAINTENANCE_WINDOW","value": "now"}
    ],
    "complexType": "SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade"
}]
}

知道我做错了吗?

1 个答案:

答案 0 :(得分:0)

是的,因为当你使用Softlayer的python客户端时,你不必指定"参数"您的订单中的属性仅用于RESTful请求,删除它并且它应该可以工作。

试试这个:

self.client = SoftLayer.Client(username='myusername@email.com', api_key='key')
console_id = 11111111

order = {
            "virtualGuests": [{"id": console_id}],
            "prices": [{
                "id": 113031,
                "categories": [{
                    "categoryCode": "guest_disk1",
                    "complexType": "SoftLayer_Product_Item_Category"
                }],
                "complexType": "SoftLayer_Product_Item_Price"
            },
                {
                    "id": 112707,
                    "categories": [{
                        "categoryCode": "guest_disk2",
                        "complexType": "SoftLayer_Product_Item_Category"
                    }],
                    "complexType": "SoftLayer_Product_Item_Price"
                }
            ],
            "properties": [
                {"name": "NOTE_GENERAL", "value": "adding disks"},
                {"name": "MAINTENANCE_WINDOW", "value": "now"}
            ],
            "complexType": "SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade"
    }

response = self.client['Product_Order'].placeOrder(order)        


print response

此致