fix(esxi): Allow the creation of duplicate vcenter machines.

Create vm with name whose vlaue is localVM.Uuid and try to rename again.
This commit is contained in:
rainzm
2020-05-15 21:36:19 +08:00
parent 3e8b854dbe
commit e9d0764be9
2 changed files with 17 additions and 10 deletions
+6 -1
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
}
+11 -9
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,
@@ -862,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)
@@ -1008,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),