Last active
October 2, 2020 02:51
-
-
Save codegold79/a07f922029f9dc9ad52e6f7f4fcc1e5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (c *vsClient) applyCfgs(ctx context.Context, moVM mo.VirtualMachine, mor types.ManagedObjectReference, cfgs []vmConfig) (*object.Task, error) { | |
vm := object.NewVirtualMachine(c.govmomi.Client, mor) | |
desiredSpec := generateDesiredSpec(cfgs, moVM) | |
task, err := vm.Reconfigure(ctx, desiredSpec) | |
if err != nil { | |
return nil, err | |
} | |
if debug { | |
log.Println("VM reconfigured with", desiredSpec) | |
} | |
return task, nil | |
} | |
func generateDesiredSpec(cfgs []vmConfig, moVM mo.VirtualMachine) types.VirtualMachineConfigSpec { | |
var spec types.VirtualMachineConfigSpec | |
for _, c := range cfgs { | |
switch c.name { | |
case "numCPU": | |
spec.NumCPUs = int32(c.valInt) | |
case "memoryMB": | |
spec.MemoryMB = int64(c.valInt) | |
case "numCoresPerSocket": | |
spec.NumCoresPerSocket = int32(c.valInt) | |
case "memoryHotAddEnabled": | |
spec.MemoryHotAddEnabled = &c.valBool | |
case "cpuHotRemoveEnabled": | |
spec.CpuHotRemoveEnabled = &c.valBool | |
case "cpuHotAddEnabled": | |
spec.CpuHotAddEnabled = &c.valBool | |
} | |
} | |
// Set ChangeVersion to guard against updates that have happened between when | |
// configInfo is read and when it is applied. | |
spec.ChangeVersion = moVM.Config.ChangeVersion | |
return spec | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment