Softlayer GO lang库:下订单量

时间:2016-11-23 06:49:40

标签: ibm-cloud-infrastructure

我正在使用SoftLayer GO API客户端库从链接https://github.com/softlayer/softlayer-go

订购耐力量

我遇到了PlaceOrder API的问题

请在下面找到错误消息:

2016/11/22 23:54:51 [DEBUG]路径:https://api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder.json 2016/11/22 23:54:51 [DEBUG]参数:{“parameters”:[{“ComplexType”:“SoftLayer_Container_Product_Order”}]} 2016/11/22 23:54:51 [DEBUG]回复:{“error”:“属性'ComplexType'对'SoftLayer_Container_Product_Order'无效。”,“code”:“SoftLayer_Exception_Public”} SoftLayer_Exception_Public:属性'ComplexType'对'SoftLayer_Container_Product_Order'无效。 (HTTP 500)

我已经为ComplexType属性提供了正确的值。

1 个答案:

答案 0 :(得分:0)

好吧,我不知道你的代码,但我能够使verifyOrder能够订购耐力卷

package main

import (
    "fmt"
    //"log"

    "github.com/softlayer/softlayer-go/datatypes"
    "github.com/softlayer/softlayer-go/services"
    "github.com/softlayer/softlayer-go/session"
    "github.com/softlayer/softlayer-go/sl"
)

func main() {
    sess := session.New() // See above for details about creating a new session

    // Get the Virtual_Guest service
    service := services.GetProductOrderService(sess)

    // Create a Virtual_Guest struct as a template
    vOrderTemplate := datatypes.Container_Product_Order_Network_Storage_Enterprise{}
    vOrderTemplate.Location = sl.String("154820")
    vOrderTemplate.Quantity = sl.Int(1)
    vOrderTemplate.PackageId = sl.Int(240)


    price1 := datatypes.Product_Item_Price{}
    price1.Id = sl.Int(45058)

    price2 := datatypes.Product_Item_Price{}
    price2.Id = sl.Int(45098)

    price3 := datatypes.Product_Item_Price{}
    price3.Id = sl.Int(45068)

    price4 := datatypes.Product_Item_Price{}
    price4.Id = sl.Int(45118)

    price5 := datatypes.Product_Item_Price{}
    price5.Id = sl.Int(46120)

    prices := []datatypes.Product_Item_Price{price1,price2,price3,price4,price5}


    vOrderTemplate.Prices = prices

    vOrderTemplate.OsFormatType = &datatypes.Network_Storage_Iscsi_OS_Type{
                                    Id: sl.Int(12),
                                    KeyName:  sl.String("LINUX"),
                                 }


    vOrd, err := service.VerifyOrder(&vOrderTemplate)


   if err != nil {
        fmt.Printf("%s\n", err)
        return
   } else {
        fmt.Printf("\norder verified with Total Recurring Tax %d\n", *vOrd.TotalRecurringTax)
   }

}

我是GO的新手,很抱歉,如果代码不是很简单:P,我也不知道如何打印响应的所有属性,所以我只打印了一个属性。你可能是GO专家我相信你可以改进代码。

注意确保您在订单中使用正确的价格。

Go中的代码基本上与RESTFul调用相同:

{
  "parameters": [
    {
      "location": 154820,  //Dallas 06
      "packageId": 240,
      "osFormatType": {
        "id": 12,
        "keyName": "LINUX"
      },
      "complexType": "SoftLayer_Container_Product_Order_Network_Storage_Enterprise",
      "prices": [
        {
          "id": 45058   # Endurance Storage
        },
        {
          "id": 45098   # Block Storage
        },
        {
          "id": 45068   # 0.25 IOPS per GB
        },
        {
          "id": 45118   # 20 GB Storage Space
        },
        {
          "id": 46120   # 5 GB Storage Space - Snapshot
        }
      ],
      "quantity": 1
    }
  ]
}

此致