您可以通过virtual.go:EditObject()编辑vsi bandwith分配吗?

时间:2018-07-26 18:21:51

标签: go ibm-cloud-infrastructure

我正在使用此脚本的修改版本:https://softlayer.github.io/go/edit_virtual_guest.go/

除了我的objectTemplate如下外,脚本是相同的:

var objectTemplate datatypes.Virtual_Guest
objectTemplate.BandwidthAllocation = sl.Float(250)

运行后的输出是“ Virtual Guest Server已成功编辑”,但是我的vsi在ui中未显示更新的带宽。

是否可以使用EditObject调用来编辑带宽?可以使用其他api调用来编辑带宽吗?

1 个答案:

答案 0 :(得分:0)

您正在使用的“ bandwidthAllocation”属性无法编辑虚拟服务器的带宽,建议您使用SoftLayer_Product_Order :: placeOrder升级带宽,因为控制门户网站使用此方法和服务来做到这一点。

无法使用EditObject调用来编辑带宽。

这是一个go示例,可用于升级带宽:

/*
Upgrade bandwidth of a virtual server.

Build a SoftLayer_Container_Product_Order_Virtual_Guest object for a new virtual server order and
pass it to the SoftLayer_Product_Order API service to order it.
See below for more details.

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
https://softlayer.github.io/reference/datatypes/SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade/

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
*/


package main

import (
    "fmt"
    "github.com/softlayer/softlayer-go/datatypes"
    "github.com/softlayer/softlayer-go/services"
    "github.com/softlayer/softlayer-go/session"
    "github.com/softlayer/softlayer-go/sl"
    "encoding/json"
)

func main() {
    // SoftLayer API username and key
    username := "set me"
    apikey   := "set me"

    // Declare the id for the virtual server you wish to order.
    vmId := 11111

    // Build a skeleton SoftLayer_Virtual_Guest object.
    virtualGuests := []datatypes.Virtual_Guest {
        {   // id of SoftLayer_Virtual_Guest object
            Id: sl.Int(vmId),
        },
    }

    // Build a skeleton SoftLayer_Product_Item_Price objects. To get the list of valid
    // prices for the package use the SoftLayer_Product_Package:getItems method
    prices := []datatypes.Product_Item_Price {
        { Id: sl.Int(50231) },     // 1000 GB Bandwidth
    }

    properties := []datatypes.Container_Product_Order_Property{
        {
            Name: sl.String("NOTE_GENERAL"),
            Value: sl.String("upgrade bandwidth"),
        },
        {
            Name: sl.String("MAINTENANCE_WINDOW"),
            Value: sl.String("2018-07-26T19:20:14.743Z"),
        },
        {
            Name: sl.String("orderOrigin"),
            Value: sl.String("control"),
        },
    }

    // Build a Container_Product_Order object containing the order you wish to place.
    orderTemplate := datatypes.Container_Product_Order{
        ComplexType   : sl.String("SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade"),
        VirtualGuests : virtualGuests,
        Prices        : prices,
        Properties: properties,
    }

    hardwareContainer := datatypes.Container_Product_Order_Hardware_Server{
        Container_Product_Order: orderTemplate,
    }

    virtualGuestContainer := datatypes.Container_Product_Order_Virtual_Guest{
        Container_Product_Order_Hardware_Server: hardwareContainer,
    }

    orderContainer := &datatypes.Container_Product_Order_Virtual_Guest_Upgrade{
        Container_Product_Order_Virtual_Guest: virtualGuestContainer,
    }


    // Create a session
    sess := session.New(username, apikey)

    // Get SoftLayer_Product_Order service
    service := services.GetProductOrderService(sess)

    // Use verifyOrder() method to check for errors. Replace this with placeOrder() when
    // you are ready to order.
    receipt, err := service.VerifyOrder(orderContainer)
    if err != nil {
        fmt.Printf("\n Unable to place order:\n - %s\n", err)
        return
    }

    // Following helps to print the result in json format.
    jsonFormat, jsonErr := json.MarshalIndent(receipt, "", "    ")
    if jsonErr != nil {
        fmt.Println(jsonErr)
        return
    }

    fmt.Println(string(jsonFormat))
}

要获取商品价格及其相应位置,可以使用以下示例:

/*
GetItemPrices

Retrieve a collection of SoftLayer_Product_Item_Prices that are valid for this package.

Important manual pages:
https://softlayer.github.io/reference/services/SoftLayer_Product_Package/getItemPrices/

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
*/

package main

import (
    "fmt"
    "github.com/softlayer/softlayer-go/services"
    "github.com/softlayer/softlayer-go/session"
    "encoding/json"
    "terraform-provider-softlayer/softlayer"
)


func main() {
    softlayer.Provider()

    // SoftLayer API username and key
    username := "set me"
    apikey   := "set me"

    packageId := 46
    mask := "id;locationGroupId;item[id,keyName,description];pricingLocationGroup[locations[id, name, longName]]"

    // Create a session
    sess := session.New(username, apikey)

    service := services.GetProductPackageService(sess)

    receipt, err := service.Id(packageId).Mask(mask).GetItemPrices()
    if err != nil {
        fmt.Printf("\n Unable to retrieve the item prices:\n - %s\n", err)
        return
    }

    // Following helps to get the result in json format.
    // Following helps to print the result in json format.
    jsonFormat, jsonErr := json.MarshalIndent(receipt, "", "    ")
    if jsonErr != nil {
        fmt.Println(jsonErr)
        return
    }

    fmt.Println(string(jsonFormat))
}