예제 #1
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);
        }