如何在创建虚拟服务器时配置固定IP地址,而不是分配动态IP地址。我使用下面的代码,但对我不起作用。请提出一种配置固定IP地址的最佳方法。
代码:
sess := session.New(username, apikey)
// Get the Virtual_Guest service
service := services.GetVirtualGuestService(sess)
// Create a Virtual_Guest struct as a template
vGuestTemplate := datatypes.Virtual_Guest{
// Set Creation values - use helpers from the sl package to set pointer values.
// Unset (nil) values are not sent
Hostname: sl.String("test-vim-02"),
Domain: sl.String("test-ibm.com"),
MaxMemory: sl.Int(4096),
StartCpus: sl.Int(4),
Datacenter: &datatypes.Location{Name: sl.String("sjc04")},
OperatingSystemReferenceCode: sl.String("UBUNTU_LATEST"),
LocalDiskFlag: sl.Bool(true),
PrivateNetworkOnlyFlag: sl.Bool(true),
PrimaryBackendIpAddress: sl.String("10.82.111.48"),
PrimaryBackendNetworkComponent: &datatypes.Virtual_Guest_Network_Component{
NetworkVlan: &datatypes.Network_Vlan{
Id: sl.Int(24L),
},
PrimarySubnet: &datatypes.Network_Subnet{
Id: sl.Int(19L),
},
MaxSpeed: sl.Int(1000),
},
}
// Tell the API to create the virtual guest
newGuest, err := service.CreateObject(&vGuestTemplate)
// optional error checking...
if err != nil {
log.Fatal(err)
}
// Print the ID of the new guest. Don't forget to dereference
fmt.Printf("New guest %d created", *newGuest.Id)
答案 0 :(得分:0)
很遗憾,创建VSI时将无法配置ip地址。设置过程在子网中查找可用的IP地址,并将其分配给VSI。
有关更多信息,请参见以下链接: