gpt4 book ai didi

go - 您可以通过 virtual.go :EditObject()? 编辑 vdi 带宽分配吗

转载 作者:数据小太阳 更新时间:2023-10-29 03:22:23 24 4
gpt4 key购买 nike

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

脚本是一样的,除了我的 objectTemplate 看起来像:

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

运行后的输出是“Virtual Guest Server was successfully edited”但是我的 vsi 没有在 ui 中显示更新的带宽。

是否可以使用 EditObject 调用来编辑带宽?是否可以使用不同的 API 调用来编辑带宽?

最佳答案

您正在使用的“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))
}

关于go - 您可以通过 virtual.go :EditObject()? 编辑 vdi 带宽分配吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51545307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com