为VM配置仅限专用网络标志,但我无法为其指定最大网络速度。
userName := "xxx" apiKey := "xxx" endpoint := "https://api.softlayer.com/rest/v3" sess := session.New(userName, apiKey, endpoint) guestService := services.GetVirtualGuestService(sess) vGuestTemplate := datatypes.Virtual_Guest{ Hostname: sl.String("testhost1000m"), Domain: sl.String("domain.com"), MaxMemory: sl.Int(2), StartCpus: sl.Int(1), Datacenter: &datatypes.Location{Name: sl.String("wdc01")}, OperatingSystemReferenceCode: sl.String("UBUNTU_LATEST"), LocalDiskFlag: sl.Bool(true), HourlyBillingFlag: sl.Bool(true), PrivateNetworkOnlyFlag: sl.Bool(true), //Private network flag. PrimaryBackendNetworkComponent: &datatypes.Virtual_Guest_Network_Component{ NetworkVlan: &datatypes.Network_Vlan{Id: sl.Int(1299491)}, MaxSpeed: sl.Int(1000), }, } vGuest, err := guestService.Mask("id;domain").CreateObject(&vGuestTemplate)
答案 0 :(得分:0)
问题出在MaxSpeed属性的位置。 MaxSpeed是与PrimaryBackenNetworkComponent不同的属性, 它必须在networkComponents属性中。
要创建新VM,您必须使用此rest api示例:
/*
Create a new Virtual Guest with Vlans and MaxSpeed
createObject() enables the creation of computing instances on an account. This method is a simplified alternative to
interacting with the ordering system directly.
In order to create a computing instance, a template object must be sent in with a few required values.
When this method returns an order will have been placed for a computing instance of the specified configuration.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/createObject/
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/generateOrderTemplate/
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest
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"
// Create a Virtual_Guest instance as a template
vGuestTemplate := datatypes.Virtual_Guest{
Hostname: sl.String("sample"),
Domain: sl.String("example.com"),
MaxMemory: sl.Int(2),
StartCpus: sl.Int(1),
Datacenter: &datatypes.Location{Name: sl.String("dal05")},
OperatingSystemReferenceCode: sl.String("UBUNTU_LATEST"),
LocalDiskFlag: sl.Bool(true),
HourlyBillingFlag: sl.Bool(true),
PrivateNetworkOnlyFlag: sl.Bool(true),
NetworkComponents: []datatypes.Virtual_Guest_Network_Component{
{ MaxSpeed: sl.Int( 1000) },
},
PrimaryBackendNetworkComponent : &datatypes.Virtual_Guest_Network_Component{
NetworkVlan: &datatypes.Network_Vlan{
Id: sl.Int(971077),
},
},
}
// Create a session
sess := session.New(username, apikey)
// Get SoftLayer_Virtual_Guest service
service := services.GetVirtualGuestService(sess)
// Use generateOrderTemplate() method to check for errors. Replace this with createObject() when
// you are ready to order.
receipt, err := service.GenerateOrderTemplate(&vGuestTemplate)
if err != nil {
fmt.Printf("\n Unable to create a virtual server:\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))
}
使用generateOrderTemplate()方法检查错误。准备好创建VM时,将其替换为createObject()。