Skip to content

Commit

Permalink
fix pull issue when you had more machines starting with the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
cjlapao committed Sep 9, 2024
1 parent 9aa76a3 commit 8a57944
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/catalog/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,19 @@ func (s *CatalogManifestService) renameMachineWithParallelsDesktop(ctx baseconte
return
}

if len(vms) != 1 {
var vm *api_models.ParallelsVM
if len(vms) > 1 {
for _, searchVM := range vms {
if searchVM.Name == r.MachineName {
vm = &searchVM
break
}
}
} else if len(vms) == 1 {
vm = &vms[0]
}

if vm == nil {
notFoundError := errors.Newf("Machine %v not found", r.MachineName)
ctx.LogErrorf("Error getting machine %v: %v", r.MachineName, notFoundError)
response.AddError(notFoundError)
Expand All @@ -416,11 +428,11 @@ func (s *CatalogManifestService) renameMachineWithParallelsDesktop(ctx baseconte
}

// Renaming only if the name is different
if vms[0].Name != r.MachineName {
response.ID = vms[0].ID
if vm.Name != r.MachineName {
response.ID = vm.ID
renameRequest := api_models.RenameVirtualMachineRequest{
ID: vms[0].ID,
CurrentName: vms[0].Name,
ID: vm.ID,
CurrentName: vm.Name,
NewName: r.MachineName,
}

Expand Down Expand Up @@ -453,15 +465,27 @@ func (s *CatalogManifestService) startMachineWithParallelsDesktop(ctx basecontex
return
}

if len(vms) != 1 {
var vm *api_models.ParallelsVM
if len(vms) > 1 {
for _, searchVM := range vms {
if searchVM.Name == r.MachineName {
vm = &searchVM
break
}
}
} else if len(vms) == 1 {
vm = &vms[0]
}

if vm == nil {
notFoundError := errors.Newf("Machine %v not found", r.MachineName)
ctx.LogErrorf("Error getting machine %v: %v", r.MachineName, notFoundError)
response.AddError(notFoundError)
response.CleanupRequest.AddLocalFileCleanupOperation(r.LocalMachineFolder, true)
return
}

if err := parallelsDesktopSvc.StartVm(ctx, vms[0].ID); err != nil {
if err := parallelsDesktopSvc.StartVm(ctx, vm.ID); err != nil {
ctx.LogErrorf("Error starting machine %v: %v", r.MachineName, err)
response.AddError(err)
response.CleanupRequest.AddLocalFileCleanupOperation(r.LocalMachineFolder, true)
Expand Down

0 comments on commit 8a57944

Please sign in to comment.