private Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > ConvergeVm( TypedPsObject <VirtualMachineInfo> vmInfo, MachineConfig machineConfig, VMStorageSettings storageSettings, HostSettings hostSettings, IPowershellEngine engine) { return (from infoFirmware in Converge.Firmware(vmInfo, machineConfig, engine, ProgressMessage) from infoCpu in Converge.Cpu(infoFirmware, machineConfig.VM.Cpu, engine, ProgressMessage) from infoDrives in Converge.Drives(infoCpu, machineConfig, storageSettings, hostSettings, engine, ProgressMessage) from infoNetworks in Converge.NetworkAdapters(infoDrives, machineConfig.VM.NetworkAdapters.ToSeq(), machineConfig, engine, ProgressMessage) from infoCloudInit in Converge.CloudInit(infoNetworks, storageSettings.VMPath, machineConfig.Provisioning, engine, ProgressMessage) select infoCloudInit); }
protected override async Task <Either <PowershellFailure, Unit> > HandleCommand(TypedPsObject <VirtualMachineInfo> vmInfo, T command, IPowershellEngine engine) { var result = await engine.RunAsync(new PsCommandBuilder().AddCommand(TransitionPowerShellCommand) .AddParameter("VM", vmInfo.PsObject)).ConfigureAwait(false); return(result); }
private Task <Either <PowershellFailure, Seq <TypedPsObject <MinimizedVMNetworkAdapter> > > > GetNetworkAdapters(TypedPsObject <MinimizedVirtualMachineInfo> vm) { return(_engine.GetObjectsAsync <MinimizedVMNetworkAdapter>( new PsCommandBuilder().AddCommand("Get-VMNetworkAdapter") .AddParameter("VM", vm.PsObject))); }
protected override Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > HandleCommand(TypedPsObject <VirtualMachineInfo> vmInfo, T command, IPowershellEngine engine) => engine.RunAsync(new PsCommandBuilder().AddCommand(TransitionPowerShellCommand).AddParameter("VM", vmInfo.PsObject)) .MapAsync(u => vmInfo.Recreate());
private Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > ConvergeVm(TypedPsObject <VirtualMachineInfo> vmInfo, MachineConfig machineConfig, VMStorageSettings storageSettings, IPowershellEngine engine) { return (from infoFirmware in Converge.Firmware(vmInfo, machineConfig, engine, ProgressMessage) from infoCpu in Converge.Cpu(infoFirmware, machineConfig.VM.Cpu, engine, ProgressMessage) from infoDisks in Converge.Disks(infoCpu, machineConfig.VM.Disks.ToSeq(), machineConfig, engine, ProgressMessage) from infoNetworks in Converge.NetworkAdapters(infoDisks, machineConfig.VM.NetworkAdapters.ToSeq(), machineConfig, engine, ProgressMessage) from infoCloudInit in Converge.CloudInit(infoNetworks, machineConfig.VM.Path, storageSettings.StorageIdentifier, machineConfig.Provisioning.Hostname, machineConfig.Provisioning?.UserData, engine, ProgressMessage) select infoCloudInit); //Converge.Firmware(vmInfo, machineConfig, engine, ProgressMessage) //.BindAsync(info => Converge.Cpu(info, machineConfig.VMConfig.Cpu, engine, ProgressMessage)) //.BindAsync(info => Converge.Disks(info, machineConfig.VMConfig.Disks?.ToSeq(), machineConfig, engine, ProgressMessage)) //.BindAsync(info => Converge.CloudInit( // info, machineConfig.VMConfig.Path, machineConfig.Provisioning.Hostname, machineConfig.Provisioning?.UserData, engine, ProgressMessage)).ConfigureAwait(false); //await Converge.Definition(engine, vmInfo, config, ProgressMessage).ConfigureAwait(false); //await ProgressMessage("Generate Virtual Machine provisioning disk").ConfigureAwait(false); }
private static Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > EnsureNameConsistent(TypedPsObject <VirtualMachineInfo> vmInfo, MachineConfig config, IPowershellEngine engine) { return(Prelude.Cond <(string currentName, string newName)>((names) => !string.IsNullOrWhiteSpace(names.newName) && !names.newName.Equals(names.currentName, StringComparison.InvariantCulture))((vmInfo.Value.Name, config.Name)) .MatchAsync( None: () => { return vmInfo; }, Some: (some) => { return Converge.RenameVirtualMachine(engine, vmInfo, config.Name); })); }
protected abstract Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > HandleCommand( TypedPsObject <VirtualMachineInfo> vmInfo, T command, IPowershellEngine engine);
public static Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > Reload(this TypedPsObject <VirtualMachineInfo> vmInfo, IPowershellEngine engine) { return(engine.GetObjectsAsync <VirtualMachineInfo>( new PsCommandBuilder().AddCommand("Get-VM").AddParameter("Id", vmInfo.Value.Id)) .BindAsync(r => r.HeadOrNone().ToEither(new PowershellFailure { Message = "Failed to refresh VM data" }))); }
public static Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > RecreateOrReload(this TypedPsObject <VirtualMachineInfo> vmInfo, IPowershellEngine engine) { return(Prelude.Try(vmInfo.Recreate().Apply( r => Prelude.RightAsync <PowershellFailure, TypedPsObject <VirtualMachineInfo> >(r).ToEither())) .MatchAsync( Fail: f => vmInfo.Reload(engine), Succ: s => s)); }
public static Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > Remove(this TypedPsObject <VirtualMachineInfo> vmInfo, IPowershellEngine engine) { return(engine.RunAsync(new PsCommandBuilder().AddCommand("Remove-VM").AddParameter("VM", vmInfo.PsObject) .AddParameter("Force")) .MapAsync(u => vmInfo)); }
public static Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > StopIfRunning(this TypedPsObject <VirtualMachineInfo> vmInfo, IPowershellEngine engine) { if (vmInfo.Value.State == VirtualMachineState.Running || vmInfo.Value.State == VirtualMachineState.RunningCritical) { return(engine.RunAsync(new PsCommandBuilder().AddCommand("Stop-VM").AddParameter("VM", vmInfo.PsObject) .AddParameter("Force")).MapAsync(u => vmInfo.Recreate())); } return(Prelude.Right <PowershellFailure, TypedPsObject <VirtualMachineInfo> >(vmInfo).AsTask()); }
protected override Task <PsVMResult> HandleCommand(TypedPsObject <VirtualMachineInfo> vmInfo, DestroyMachineCommand command, IPowershellEngine engine) { return(vmInfo .StopIfRunning(engine) .BindAsync(v => v.Remove(engine))); }