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);
 }
        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> > > EnsureCreated(Option <TypedPsObject <VirtualMachineInfo> > vmInfo, MachineConfig config, VMStorageSettings storageSettings, IPowershellEngine engine)
 {
     return(vmInfo.MatchAsync(
                None: () => Converge.CreateVirtualMachine(engine, config.Name, storageSettings.StorageIdentifier,
                                                          config.VM.Path,
                                                          config.VM.Memory.Startup),
                Some: s => s
                ));
 }
#pragma warning disable 1998
        private async Task <Either <PowershellFailure, MachineConfig> > ApplyStorageSettings(MachineConfig config, VMStorageSettings storageSettings, HostSettings hostSettings)
#pragma warning restore 1998
        {
            if (string.IsNullOrWhiteSpace(config.VM.Path))
            {
                config.VM.Path = hostSettings.DefaultDataPath; //storage identifier will be added automatically by ps command
            }

            foreach (var diskConfig in config.VM.Disks)
            {
                var diskRoot = hostSettings.DefaultVirtualHardDiskPath;
                diskRoot        = Path.Combine(diskRoot, storageSettings.StorageIdentifier);
                diskConfig.Path = Path.Combine(diskRoot, $"{diskConfig.Name}.vhdx");
            }

            return(config);
        }
 private static Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > EnsureCreated(Option <TypedPsObject <VirtualMachineInfo> > vmInfo, MachineConfig config, VMStorageSettings storageSettings, IPowershellEngine engine)
 {
     return(vmInfo.MatchAsync(
                None: () =>
                storageSettings.StorageIdentifier.ToEither(new PowershellFailure {
         Message = "Unknown storage identifier, cannot create new virtual machine"
     })
                .BindAsync(storageIdentifier => Converge.CreateVirtualMachine(engine, config.Name, storageIdentifier,
                                                                              storageSettings.VMPath,
                                                                              config.VM.Memory.Startup)),
                Some: s => s
                ));
 }