Ejemplo n.º 1
0
        public static Task <Either <PowershellFailure, Unit> > DetachUndefinedDvdDrives(
            IPowershellEngine engine,
            TypedPsObject <VirtualMachineInfo> vmInfo,
            Seq <VMDriveStorageSettings> plannedStorageSettings,
            Func <string, Task> reportProgress)

        {
            var controllersAndLocations = plannedStorageSettings.Where(x => x.Type == VirtualMachineDriveType.DVD)
                                          .Map(x => new { x.ControllerNumber, x.ControllerLocation })
                                          .GroupBy(x => x.ControllerNumber)
                                          .ToImmutableDictionary(x => x.Key, x => x.Map(y => y.ControllerLocation).ToImmutableArray());


            return(FindAndApply(vmInfo,
                                i => i.DVDDrives,
                                hd =>
            {
                //ignore cloud init drive, will be handled later
                if (hd.ControllerLocation == 63 && hd.ControllerNumber == 0)
                {
                    return false;
                }

                var detach = !controllersAndLocations.ContainsKey(hd.ControllerNumber) ||
                             !controllersAndLocations[hd.ControllerNumber].Contains(hd.ControllerLocation);

                return detach;
            },
                                i => engine.RunAsync(PsCommandBuilder.Create().AddCommand("Remove-VMDvdDrive")
                                                     .AddParameter("VMDvdDrive", i.PsObject))).Map(x => x.Lefts().HeadOrNone())
                   .MatchAsync(
                       Some: l => LeftAsync <PowershellFailure, Unit>(l).ToEither(),
                       None: () => RightAsync <PowershellFailure, Unit>(Unit.Default)
                       .ToEither()));
        }
Ejemplo n.º 2
0
        public static Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > CreateVirtualMachine(
            IPowershellEngine engine,
            string vmName,
            string storageIdentifier,
            string vmPath,
            int startupMemory)
        {
            var memoryStartupBytes = startupMemory * 1024L * 1024;


            return(engine.GetObjectsAsync <VirtualMachineInfo>(PsCommandBuilder.Create()
                                                               .AddCommand("New-VM")
                                                               .AddParameter("Name", storageIdentifier)
                                                               .AddParameter("Path", vmPath)
                                                               .AddParameter("MemoryStartupBytes", memoryStartupBytes)
                                                               .AddParameter("Generation", 2))
                   .MapAsync(x => x.Head).MapAsync(
                       result =>
            {
                engine.RunAsync(PsCommandBuilder.Create().AddCommand("Get-VMNetworkAdapter")
                                .AddParameter("VM", result.PsObject).AddCommand("Remove-VMNetworkAdapter"));

                return result;
            })
                   .BindAsync(info => RenameVirtualMachine(engine, info, vmName)));
        }
 public ScriptController(IConfigurationRepository configurationRepository, IScriptManagementLogic scriptLogic, IPowershellEngine powershell)
 {
     this.powershell              = powershell;
     this.scriptLogic             = scriptLogic;
     this.configurationRepository = configurationRepository;
     this.http = new HttpResponseHandler(this);
 }
Ejemplo n.º 4
0
        public static async Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > CloudInit(
            TypedPsObject <VirtualMachineInfo> vmInfo,
            string vmConfigPath,
            VirtualMachineProvisioningConfig provisioningConfig,
            IPowershellEngine engine,
            Func <string, Task <Unit> > reportProgress
            )
        {
            var remove = await RemoveConfigDriveDisk(vmInfo, engine).BindAsync(u => vmInfo.RecreateOrReload(engine)).ConfigureAwait(false);


            if (provisioningConfig.Method == ProvisioningMethod.None || remove.IsLeft)
            {
                return(remove);
            }


            var configDriveIsoPath = Path.Combine(vmConfigPath, "configdrive.iso");

            await reportProgress("Updating configdrive disk").ConfigureAwait(false);

            await from _ in CreateConfigDriveDirectory(vmConfigPath).AsTask()
            select _;

            GenerateConfigDriveDisk(configDriveIsoPath, provisioningConfig.Hostname,
                                    provisioningConfig.UserData);

            return(await InsertConfigDriveDisk(configDriveIsoPath, vmInfo, engine));
        }
Ejemplo n.º 5
0
        public static async Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > CloudInit(
            TypedPsObject <VirtualMachineInfo> vmInfo,
            string vmConfigPath,
            string storageIdentifier,
            string hostname,
            JObject userdata,
            IPowershellEngine engine,
            Func <string, Task <Unit> > reportProgress
            )
        {
            var vmPath             = Path.Combine(vmConfigPath, storageIdentifier);
            var configDriveIsoPath = Path.Combine(vmPath, "configdrive.iso");

            await reportProgress("Updating configdrive disk").ConfigureAwait(false);

            var res = await CreateConfigDriveDirectory(vmPath)
                      .Bind(_ => EjectConfigDriveDisk(configDriveIsoPath, vmInfo, engine))
                      .ToAsync()
                      .IfRightAsync(
                info =>
            {
                GenerateConfigDriveDisk(configDriveIsoPath, hostname, userdata);
                return(InsertConfigDriveDisk(configDriveIsoPath, info, engine));
            }).ConfigureAwait(false);

            return(res.Return(vmInfo));
        }
 public ConvergeTaskRequestedEventHandler(
     IPowershellEngine engine,
     IBus bus)
 {
     _engine = engine;
     _bus    = bus;
 }
Ejemplo n.º 7
0
        private static Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > EjectConfigDriveDisk(
            string configDriveIsoPath,
            TypedPsObject <VirtualMachineInfo> vmInfo,
            IPowershellEngine engine)
        {
            var res = vmInfo.GetList(l => l.DVDDrives,
                                     drive => configDriveIsoPath.Equals(drive.Path, StringComparison.OrdinalIgnoreCase))
                      .Apply(dvdDriveList =>
            {
                var array = dvdDriveList.ToArray();

                if (array.Length > 1)
                {
                    array.Take(array.Length - 1).Iter(r =>
                                                      engine.Run(PsCommandBuilder.Create()
                                                                 .AddCommand("Remove-VMDvdDrive")
                                                                 .AddParameter("VMDvdDrive", r.PsObject)));
                }

                return(vmInfo.GetList(l => l.DVDDrives, drive => configDriveIsoPath.Equals(drive.Path, StringComparison.OrdinalIgnoreCase)));
            }).Apply(driveInfos =>
            {
                return(driveInfos.Map(driveInfo => engine.Run(PsCommandBuilder.Create()
                                                              .AddCommand("Set-VMDvdDrive")
                                                              .AddParameter("VMDvdDrive", driveInfo.PsObject)
                                                              .AddParameter("Path", null)))
                       .Traverse(x => x).Map(
                           x => vmInfo.Recreate()));
            });

            return(res);
        }
Ejemplo n.º 8
0
        private static Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > InsertConfigDriveDisk(
            string configDriveIsoPath,
            TypedPsObject <VirtualMachineInfo> vmInfo,
            IPowershellEngine engine)
        {
            return
                (from dvdDrive in GetOrCreateInfoAsync(vmInfo,
                                                       l => l.DVDDrives,
                                                       drive => drive.ControllerLocation == 63 && drive.ControllerNumber == 0,
                                                       () => engine.GetObjectsAsync <DvdDriveInfo>(
                                                           PsCommandBuilder.Create().AddCommand("Add-VMDvdDrive")
                                                           .AddParameter("VM", vmInfo.PsObject)
                                                           .AddParameter("ControllerNumber", 0)
                                                           .AddParameter("ControllerLocation", 63)
                                                           .AddParameter("PassThru"))
                                                       )

                 from _ in engine.RunAsync(PsCommandBuilder.Create()

                                           .AddCommand("Set-VMDvdDrive")
                                           .AddParameter("VMDvdDrive", dvdDrive.PsObject)
                                           .AddParameter("Path", configDriveIsoPath))

                 from vmInfoRecreated in vmInfo.RecreateOrReload(engine)
                 select vmInfoRecreated);
        }
Ejemplo n.º 9
0
        public static async Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > Disk(
            VirtualMachineDiskConfig diskConfig,
            IPowershellEngine engine,
            TypedPsObject <VirtualMachineInfo> vmInfo,
            MachineConfig vmConfig,
            Func <string, Task> reportProgress)
        {
            if (!File.Exists(diskConfig.Path))
            {
                await reportProgress($"Create VHD: {diskConfig.Name}").ConfigureAwait(false);

                await engine.RunAsync(PsCommandBuilder.Create().Script(
                                          $"New-VHD -Path \"{diskConfig.Path}\" -ParentPath \"{diskConfig.Template}\" -Differencing"),
                                      reportProgress : p => ReportPowershellProgress($"Create VHD {diskConfig.Name}", p, reportProgress)).ConfigureAwait(false);
            }

            await GetOrCreateInfoAsync(vmInfo,
                                       i => i.HardDrives,
                                       disk => diskConfig.Path.Equals(disk.Path, StringComparison.OrdinalIgnoreCase),
                                       async() =>
            {
                await reportProgress($"Add VHD: {diskConfig.Name}").ConfigureAwait(false);
                return(await engine.GetObjectsAsync <HardDiskDriveInfo>(PsCommandBuilder.Create()
                                                                        .AddCommand("Add-VMHardDiskDrive")
                                                                        .AddParameter("VM", vmInfo.PsObject)
                                                                        .AddParameter("Path", diskConfig.Path)).ConfigureAwait(false));
            }).ConfigureAwait(false);

            return(vmInfo.Recreate());
        }
Ejemplo n.º 10
0
 public NodeLogic(IConfigurationRepository configurationRepository, IAuthorizationLogic authorizationLogic, ActiveDirectoryIdentityProviderLogic adIdpLogic, IPowershellEngine powershell, IAuditLogic auditLogic, CertificateManagementLogic certificateManagement, IPrivateCertificateProcessing privateCertificateProcessing)
 {
     this.auditLogic = auditLogic;
     this.powershell = powershell;
     this.configurationRepository = configurationRepository;
     this.authorizationLogic      = authorizationLogic;
     this.adIdpLogic                   = adIdpLogic;
     this.certificateManagement        = certificateManagement;
     this.privateCertificateProcessing = privateCertificateProcessing;
 }
Ejemplo n.º 11
0
 public static Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > RenameVirtualMachine(
     IPowershellEngine engine,
     TypedPsObject <VirtualMachineInfo> vmInfo,
     string newName)
 {
     return(engine.RunAsync(PsCommandBuilder.Create()
                            .AddCommand("Rename-VM")
                            .AddParameter("VM", vmInfo.PsObject)
                            .AddParameter("NewName", newName)
                            ).BindAsync(u => vmInfo.RecreateOrReload(engine)));
 }
Ejemplo n.º 12
0
 private static Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > RemoveConfigDriveDisk(
     TypedPsObject <VirtualMachineInfo> vmInfo,
     IPowershellEngine engine)
 {
     return(FindAndApply(vmInfo, l => l.DVDDrives,
                         drive => drive.ControllerLocation == 63 && drive.ControllerNumber == 0,
                         drive => engine.RunAsync(PsCommandBuilder.Create()
                                                  .AddCommand("Remove-VMDvdDrive")
                                                  .AddParameter("VMDvdDrive", drive.PsObject)))
            .Map(list => list.Lefts().HeadOrNone()).MatchAsync(
                None: () => vmInfo.RecreateOrReload(engine),
                Some: l => LeftAsync <PowershellFailure, TypedPsObject <VirtualMachineInfo> >(l).ToEither()));
 }
 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);
 }
Ejemplo n.º 14
0
        public static Task <Either <PowershellFailure, Unit> > DetachUndefinedDrives(
            IPowershellEngine engine,
            TypedPsObject <VirtualMachineInfo> vmInfo,
            Seq <VMDriveStorageSettings> plannedStorageSettings,
            HostSettings hostSettings,
            Func <string, Task> reportProgress)

        {
            return((from currentDiskSettings in Storage.DetectDiskStorageSettings(vmInfo.Value.HardDrives,
                                                                                  hostSettings, engine).ToAsync()
                    from _ in DetachUndefinedHardDrives(engine, vmInfo, plannedStorageSettings,
                                                        currentDiskSettings, reportProgress).ToAsync()
                    from __ in DetachUndefinedDvdDrives(engine, vmInfo, plannedStorageSettings, reportProgress).ToAsync()
                    select Unit.Default).ToEither());
        }
Ejemplo n.º 15
0
        public static async Task Definition(
            IPowershellEngine engine,
            TypedPsObject <VirtualMachineInfo> vmInfo,
            MachineConfig vmConfig,
            Func <string, Task> reportProgress)
        {
            if (vmInfo.Value.Generation >= 2)
            {
                await engine.GetObjectsAsync <VMFirmwareInfo>(PsCommandBuilder.Create()
                                                              .AddCommand("Get-VMFirmware")
                                                              .AddParameter("VM", vmInfo.PsObject)).MapAsync(async(firmwareInfo) =>
                {
                    if (firmwareInfo.Head.Value.SecureBoot != OnOffState.Off)
                    {
                        await reportProgress($"Configure VM Firmware - Secure Boot: {OnOffState.Off}")
                        .ConfigureAwait(false);

                        await engine.RunAsync(PsCommandBuilder.Create()
                                              .AddCommand("Set-VMFirmware")
                                              .AddParameter("VM", vmInfo.PsObject)
                                              .AddParameter("EnableSecureBoot", OnOffState.Off)).ConfigureAwait(false);
                    }
                }).ConfigureAwait(false);
            }


            if (vmInfo.Value.ProcessorCount != vmConfig.VM.Cpu.Count)
            {
                await reportProgress($"Configure VM Processor: Count: {vmConfig.VM.Cpu.Count}").ConfigureAwait(false);

                await engine.RunAsync(PsCommandBuilder.Create()
                                      .AddCommand("Set-VMProcessor")
                                      .AddParameter("VM", vmInfo.PsObject)
                                      .AddParameter("Count", vmConfig.VM.Cpu.Count)).ConfigureAwait(false);
            }

            var memoryStartupBytes = vmConfig.VM.Memory.Startup * 1024L * 1024;

            if (vmInfo.Value.MemoryStartup != memoryStartupBytes)
            {
                await reportProgress($"Configure VM Memory: Startup: {vmConfig.VM.Memory.Startup} MB").ConfigureAwait(false);

                await engine.RunAsync(PsCommandBuilder.Create()
                                      .AddCommand("Set-VMMemory")
                                      .AddParameter("VM", vmInfo.PsObject)
                                      .AddParameter("StartupBytes", memoryStartupBytes)).ConfigureAwait(false);
            }
        }
Ejemplo n.º 16
0
 private static Task <Either <PowershellFailure, Unit> > InsertConfigDriveDisk(
     string configDriveIsoPath,
     TypedPsObject <VirtualMachineInfo> vmInfo,
     IPowershellEngine engine)
 {
     return(vmInfo.GetList(l => l.DVDDrives, drive => string.IsNullOrWhiteSpace(drive.Path))
            .HeadOrNone().MatchAsync(
                None: () => engine.RunAsync(
                    PsCommandBuilder.Create().AddCommand("Add-VMDvdDrive")
                    .AddParameter("VM", vmInfo.PsObject).AddParameter("Path", configDriveIsoPath)),
                Some: dvdDriveInfo => engine.RunAsync(PsCommandBuilder.Create()
                                                      .AddCommand("Set-VMDvdDrive")
                                                      .AddParameter("VMDvdDrive", dvdDriveInfo.PsObject)
                                                      .AddParameter("Path", configDriveIsoPath)
                                                      )));
 }
Ejemplo n.º 17
0
        public static async Task <Either <PowershellFailure, TypedPsObject <VirtualMachineInfo> > > NetworkAdapter(
            VirtualMachineNetworkAdapterConfig networkAdapterConfig,
            IPowershellEngine engine,
            TypedPsObject <VirtualMachineInfo> vmInfo,
            MachineConfig machineConfig,
            Func <string, Task> reportProgress)
        {
            var optionalAdapter = await GetOrCreateInfoAsync(vmInfo,
                                                             i => i.NetworkAdapters,
                                                             adapter => networkAdapterConfig.Name.Equals(adapter.Name, StringComparison.OrdinalIgnoreCase),
                                                             async() =>
            {
                await reportProgress($"Add Network Adapter: {networkAdapterConfig.Name}").ConfigureAwait(false);
                return(await engine.GetObjectsAsync <VMNetworkAdapter>(PsCommandBuilder.Create()
                                                                       .AddCommand("Add-VmNetworkAdapter")
                                                                       .AddParameter("Passthru")
                                                                       .AddParameter("VM", vmInfo.PsObject)
                                                                       .AddParameter("Name", networkAdapterConfig.Name)
                                                                       .AddParameter("StaticMacAddress", UseOrGenerateMacAddress(networkAdapterConfig, vmInfo))
                                                                       .AddParameter("SwitchName", networkAdapterConfig.SwitchName)).ConfigureAwait(false));
            }).ConfigureAwait(false);

            return(optionalAdapter.Map(_ => vmInfo.Recreate()));

            //optionalAdapter.Map(async (adapter) =>
            //{
            //    if (!adapter.Value.Connected || adapter.Value.SwitchName != networkConfig.SwitchName)
            //    {
            //        await reportProgress($"Connect Network Adapter {adapter.Value.Name} to switch {networkConfig.SwitchName}").ConfigureAwait(false);
            //        await engine.RunAsync(
            //            PsCommandBuilder.Create().AddCommand("Connect-VmNetworkAdapter")
            //                .AddParameter("VMNetworkAdapter", adapter.PsObject)
            //                .AddParameter("SwitchName", networkConfig.SwitchName)).ConfigureAwait(false);

            //    }
            //});
            return(vmInfo.Recreate());
        }
Ejemplo n.º 18
0
        public static async Task <Either <PowershellFailure, Seq <CurrentVMDiskStorageSettings> > > DetectDiskStorageSettings(
            IEnumerable <HardDiskDriveInfo> hdInfos, HostSettings hostSettings, IPowershellEngine engine)
        {
            var r = await hdInfos.Where(x => !string.IsNullOrWhiteSpace(x.Path))
                    .ToSeq().MapToEitherAsync(hdInfo =>
            {
                var res =
                    (
                        from vhdInfo in GetVhdInfo(hdInfo.Path, engine).ToAsync()
                        from snapshotInfo in GetSnapshotAndActualVhd(vhdInfo, engine).ToAsync()
                        let vhdPath = snapshotInfo.ActualVhd.Map(vhd => vhd.Value.Path).IfNone(hdInfo.Path)
                                      let parentPath = snapshotInfo.ActualVhd.Map(vhd => vhd.Value.ParentPath)
                                                       let snapshotPath = snapshotInfo.SnapshotVhd.Map(vhd => vhd.Value.Path)
                                                                          let nameAndId = PathToStorageNames(Path.GetDirectoryName(vhdPath), hostSettings.DefaultVirtualHardDiskPath)
                                                                                          let diskSize = vhdInfo.Map(v => v.Value.Size).IfNone(0)
                                                                                                         select
                                                                                                         new CurrentVMDiskStorageSettings
                {
                    Type = VirtualMachineDriveType.VHD,
                    Path = Path.GetDirectoryName(vhdPath),
                    Name = Path.GetFileNameWithoutExtension(vhdPath),
                    AttachPath = snapshotPath.IsSome? snapshotPath: vhdPath,
                    ParentPath = parentPath,
                    StorageNames = nameAndId.Names,
                    StorageIdentifier = nameAndId.StorageIdentifier,
                    SizeBytes = diskSize,
                    Frozen = snapshotPath.IsSome,
                    AttachedVMId = hdInfo.Id,
                    ControllerNumber = hdInfo.ControllerNumber,
                    ControllerLocation = hdInfo.ControllerLocation,
                }).ToEither();
                return(res);
            });

            return(r);
        }
 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());
Ejemplo n.º 20
0
        public static Task <Either <PowershellFailure, (Option <TypedPsObject <VhdInfo> > SnapshotVhd, Option <TypedPsObject <VhdInfo> > ActualVhd)> > GetSnapshotAndActualVhd(Option <TypedPsObject <VhdInfo> > vhdInfo, IPowershellEngine engine)
        {
            return(vhdInfo.MapAsync(async(info) =>
            {
                var firstSnapshotVhdOption = Option <TypedPsObject <VhdInfo> > .None;
                var snapshotVhdOption = Option <TypedPsObject <VhdInfo> > .None;
                var actualVhdOption = Option <TypedPsObject <VhdInfo> > .None;

                // check for snapshots, return parent path if it is not a snapshot
                if (string.Equals(Path.GetExtension(info.Value.Path), ".avhdx", StringComparison.OrdinalIgnoreCase))
                {
                    snapshotVhdOption = vhdInfo;
                    firstSnapshotVhdOption = vhdInfo;
                }
                else
                {
                    actualVhdOption = vhdInfo;
                }

                while (actualVhdOption.IsNone)
                {
                    var eitherVhdInfo = await snapshotVhdOption.ToEither(new PowershellFailure
                    {
                        Message = "Storage failure: Missing snapshot "
                    })

                                        .Map(snapshotVhd => string.IsNullOrWhiteSpace(snapshotVhd?.Value?.ParentPath)
                            ? Option <string> .None
                            : Option <string> .Some(snapshotVhd.Value.ParentPath))
                                        .Bind(o => o.ToEither(new PowershellFailure
                    {
                        Message = "Storage failure: Missing snapshot parent path"
                    }))
                                        .BindAsync(path => GetVhdInfo(path, engine))
                                        .BindAsync(o => o.ToEither(new PowershellFailure
                    {
                        Message = "Storage failure: Missing snapshot parent"
                    }))
                                        .ConfigureAwait(false);


                    if (eitherVhdInfo.IsLeft)
                    {
                        return Prelude
                        .Left <PowershellFailure, (Option <TypedPsObject <VhdInfo> > SnapshotVhd,
                                                   Option <TypedPsObject <VhdInfo> > ActualVhd)>(eitherVhdInfo.LeftAsEnumerable()
                                                                                                 .FirstOrDefault());
                    }

                    info = eitherVhdInfo.IfLeft(new TypedPsObject <VhdInfo>(null));


                    if (string.Equals(Path.GetExtension(info.Value.Path), ".avhdx", StringComparison.OrdinalIgnoreCase))
                    {
                        snapshotVhdOption = info;
                    }
                    else
                    {
                        actualVhdOption = info;
                    }
                }

                return Prelude.Right((firstSnapshotVhdOption, actualVhdOption));
            }).IfNone(Prelude.Right((Option <TypedPsObject <VhdInfo> > .None, Option <TypedPsObject <VhdInfo> > .None))));
        }
Ejemplo n.º 21
0
        public static async Task <Either <PowershellFailure, Option <TypedPsObject <VhdInfo> > > > GetVhdInfo(string path, IPowershellEngine engine)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return(Option <TypedPsObject <VhdInfo> > .None);
            }

            var res = await engine.GetObjectsAsync <VhdInfo>(new PsCommandBuilder().AddCommand("Get-VHD").AddArgument(path)).MapAsync(s => s.HeadOrNone());

            return(res);
        }
Ejemplo n.º 22
0
 public static Task <Either <PowershellFailure, Seq <VMDriveStorageSettings> > > PlanDriveStorageSettings(
     MachineConfig config, VMStorageSettings storageSettings, HostSettings hostSettings, IPowershellEngine engine)
 {
     return(config.VM.Drives
            .ToSeq().MapToEitherAsync((index, c) =>
                                      DriveConfigToDriveStorageSettings(index, c, storageSettings, hostSettings)));
 }
Ejemplo n.º 23
0
 public VirtualMachineStateTransitionHandler(IBus bus, IPowershellEngine engine) : base(bus, engine)
 {
 }
 private static Task <Either <PowershellFailure, Seq <TypedPsObject <VirtualMachineInfo> > > > GetVmInfo(string id,
                                                                                                         IPowershellEngine engine)
 {
     return(Prelude.Cond <string>((c) => !string.IsNullOrWhiteSpace(c))(id).MatchAsync(
                None:  () =>
     {
         return Seq <TypedPsObject <VirtualMachineInfo> > .Empty;
     },
                Some: (s) =>
     {
         return engine.GetObjectsAsync <VirtualMachineInfo>(PsCommandBuilder.Create()
                                                            .AddCommand("get-vm").AddParameter("Id", s)
                                                            //this a bit dangerous, because there may be other errors causing the
                                                            //command to fail. However there seems to be no other way except parsing error response
                                                            .AddParameter("ErrorAction", "SilentlyContinue")
                                                            );
     }));
 }
        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);
            }));
        }
Ejemplo n.º 26
0
 public VirtualMachineStartHandler(IBus bus, IPowershellEngine engine) : base(bus, engine)
 {
 }
 public GuestNetworkAdapterChangedEventHandler(IBus bus, IPowershellEngine engine)
 {
     _bus    = bus;
     _engine = engine;
 }
        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);
        }
Ejemplo n.º 29
0
        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);
        }
Ejemplo n.º 30
0
 public InventoryRequestedEventHandler(IBus bus, IPowershellEngine engine)
 {
     _bus    = bus;
     _engine = engine;
 }