Skip to content

Commit

Permalink
When a VMX file is not found but a NVRAM file, VIX thinks the VM exists
Browse files Browse the repository at this point in the history
We make sure that if a VMX is not found, nothing else would exist inside
that VM directory. This is to avoid VIX failing thinking the VM clone
exists when in reality it does not.
  • Loading branch information
c4milo committed Sep 19, 2014
1 parent e528eab commit 0d583f9
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions provider/vix/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,27 +169,26 @@ func (v *VM) Create() (string, error) {
return "", err
}

newvmx := filepath.Join(usr.HomeDir, ".terraform", "vix", "vms",
image.Checksum, v.Name, v.Name+".vmx")
baseVMDir := filepath.Join(usr.HomeDir, ".terraform", "vix", "vms",
image.Checksum, v.Name)

newvmx := filepath.Join(baseVMDir, v.Name+".vmx")

if _, err = os.Stat(newvmx); err != os.ErrExist {
log.Printf("[INFO] Cloning gold vm into %s...", newvmx)
// If there is not a VMX file, make sure nothing else is in there either.
// We were seeing VIX 13004 errors when only a nvram file existed.
os.RemoveAll(baseVMDir)

log.Printf("[INFO] Cloning Gold virtual machine into %s...", newvmx)
_, err := vm.Clone(govix.CLONETYPE_FULL, newvmx)

// If there is an error and the error is other than "The snapshot already exists"
// then return the error
if err != nil && err.(*govix.VixError).Code != 13004 {
return "", err
}

// Makes sure the first time the VM is created it has no virtual network adapters
// log.Printf("[DEBUG] Removing all virtual network adapters from cloned VM...")
// err = clonedVM.RemoveAllNetworkAdapters()
// if err != nil {
// return "", err
// }
} else {
log.Printf("[INFO] VM Clone %s already exist, moving on.", newvmx)
log.Printf("[INFO] Virtual Machine clone %s already exist, moving on.", newvmx)
}

if err = v.Update(newvmx); err != nil {
Expand Down

0 comments on commit 0d583f9

Please sign in to comment.