Merge pull request #6375 from rainzm/fix/isinit

Fix/esxi
This commit is contained in:
Zexi Li
2020-05-16 17:41:24 +08:00
committed by GitHub
5 changed files with 54 additions and 22 deletions
+3
View File
@@ -1187,6 +1187,9 @@ func (manager *SGuestManager) validateCreateData(
rootDiskConfig.SizeMb = sysMinDiskMB
}
}
if len(rootDiskConfig.Driver) == 0 {
rootDiskConfig.Driver = osProf.DiskDriver
}
log.Debugf("ROOT DISK: %#v", rootDiskConfig)
input.Disks[0] = rootDiskConfig
//data.Set("disk.0", jsonutils.Marshal(rootDiskConfig))
+12 -5
View File
@@ -151,10 +151,15 @@ func (as *SAgentStorage) agentCreateGuest(ctx context.Context, data *jsonutils.J
if err != nil {
return errors.Wrapf(err, "%s: fail to unmarshal to esxi.SCreateVMParam", hostutils.ParamsError)
}
_, err = host.CreateVM2(ctx, ds, createParam)
vm, err := host.CreateVM2(ctx, ds, createParam)
if err != nil {
return errors.Wrap(err, "SHost.CreateVM2")
}
name, _ := descDict.GetString("name")
err = as.tryRenameVm(ctx, vm, name)
if err != nil {
return errors.Wrapf(err, "RenameVm name '%s'", name)
}
return nil
}
@@ -197,6 +202,7 @@ func (as *SAgentStorage) AgentDeployGuest(ctx context.Context, data interface{})
if err != nil {
return nil, errors.Wrap(err, "agentRebuildRoot")
}
init = true
}
var (
@@ -285,10 +291,11 @@ func (as *SAgentStorage) AgentDeployGuest(ctx context.Context, data interface{})
DiskPath: rootPath,
GuestDesc: &guestDesc,
DeployInfo: &deployapi.DeployInfo{
PublicKey: &key,
Deploys: deployArray,
Password: passwd,
IsInit: init,
PublicKey: &key,
Deploys: deployArray,
Password: passwd,
IsInit: init,
WindowsDefaultAdminUser: true,
},
VddkInfo: &vddkInfo,
})
+11
View File
@@ -125,6 +125,17 @@ func NewCDROMDev(path string, key, ctlKey int32) types.BaseVirtualDevice {
return &device
}
func NewUSBController(key *int32) types.BaseVirtualDevice {
device := types.VirtualUSBController{}
device.DeviceInfo = &types.Description{
Label: "USB controller",
}
if key != nil {
device.Key = *key
}
return &device
}
func NewVNICDev(host *SHost, mac, driver string, vlanId int32, key, ctlKey, index int32) (types.BaseVirtualDevice, error) {
desc := types.Description{Label: fmt.Sprintf("Network adapter %d", index+1), Summary: "VM Network"}
+24 -16
View File
@@ -692,9 +692,10 @@ func (self *SHost) CreateVM2(ctx context.Context, ds *SDatastore, params SCreate
func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreateVMParam) (*SVirtualMachine, error) {
deviceChange := make([]types.BaseVirtualDeviceConfigSpec, 0, 5)
// name first
if len(params.Name) == 0 {
params.Name = params.Uuid
// uuid first
name := params.Name
if len(params.Uuid) != 0 {
name = params.Uuid
}
datastorePath := fmt.Sprintf("[%s] ", ds.GetRelName())
@@ -718,7 +719,7 @@ func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreat
}
spec := types.VirtualMachineConfigSpec{
Name: params.Name,
Name: name,
Version: version,
Uuid: params.Uuid,
GuestId: guestId,
@@ -795,12 +796,17 @@ func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreat
index = ideIdx % 2
ideIdx += 1
}
log.Debugf("size: %d, image path: %s, uuid: %s, index: %d, ctrlKey: %d", size, imagePath, uuid, index, ctrlKey)
log.Debugf("size: %d, image path: %s, uuid: %s, index: %d, ctrlKey: %d, driver: %s.", size, imagePath, uuid,
index, ctrlKey, disk.Driver)
spec := addDevSpec(NewDiskDev(size, imagePath, uuid, int32(index), 2000, int32(ctrlKey)))
spec.FileOperation = "create"
deviceChange = append(deviceChange, spec)
}
// add usb to support mouse
usbController := addDevSpec(NewUSBController(nil))
deviceChange = append(deviceChange, usbController)
nics := params.Nics
for _, nic := range nics {
index, _ := nic.Int("index")
@@ -857,8 +863,7 @@ func (self *SHost) DoCreateVM(ctx context.Context, ds *SDatastore, params SCreat
return NewVirtualMachine(self.manager, &moVM, self.datacenter), nil
}
func (host *SHost) CloneVM(ctx context.Context, from *SVirtualMachine, ds *SDatastore,
params SCreateVMParam) (*SVirtualMachine, error) {
func (host *SHost) CloneVM(ctx context.Context, from *SVirtualMachine, ds *SDatastore, params SCreateVMParam) (*SVirtualMachine, error) {
ovm := from.getVmObj()
deviceChange := make([]types.BaseVirtualDeviceConfigSpec, 0, 5)
@@ -1003,11 +1008,13 @@ func (host *SHost) CloneVM(ctx context.Context, from *SVirtualMachine, ds *SData
Location: relocateSpec,
}
if len(params.Name) == 0 {
params.Name = params.Uuid
// uuid first
name := params.Name
if len(params.Uuid) != 0 {
name = params.Uuid
}
spec := types.VirtualMachineConfigSpec{
Name: params.Name,
Name: name,
Uuid: params.Uuid,
NumCPUs: int32(params.Cpu),
MemoryMB: int64(params.Mem),
@@ -1326,13 +1333,14 @@ func (host *SHost) findVlanDVPG(vlanId int32) (*SDistributedVirtualPortgroup, er
if dvpg.ContainHost(host) {
return dvpg, nil
}
msg := "Find dvpg with correct vlan but it didn't contain this host"
log.Debugf(msg)
// add host to dvg
log.Debugf("Find dvpg with correct vlan but it didn't contain this host")
err := dvpg.AddHostToDVS(host)
if err != nil {
return nil, errors.Wrapf(err, "dvpg %s add host to dvs error", dvpg.GetName())
}
return dvpg, nil
// err := dvpg.AddHostToDVS(host)
// if err != nil {
// return nil, errors.Wrapf(err, "dvpg %s add host to dvs error", dvpg.GetName())
// }
continue
}
}
return nil, nil
+4 -1
View File
@@ -270,7 +270,10 @@ func (disk *SVirtualDisk) GetDriver() string {
controller := disk.vm.getVdev(disk.getControllerKey())
name := controller.GetDriver()
name = strings.Replace(name, "controller", "", -1)
return driverMap[name]
if driver, ok := driverMap[name]; ok {
return driver
}
return name
}
func (disk *SVirtualDisk) GetCacheMode() string {