private void PopulateMachinesGrid(string platformName)
        {
            VirtualMachinePlatform platform =
                _entities.VirtualMachinePlatforms.FirstOrDefault(x => x.PlatformId.Equals(platformName));

            if (platform != null)
            {
                IEnumerable <VirtualMachine> machines = VirtualMachine.Select(platform: platformName,
                                                                              includePlatforms: true);
                var query =
                    (
                        from m in machines
                        from p in m.VirtualMachinePlatforms
                        where platform.PlatformId.Equals(p.PlatformId)
                        select m
                    ).Distinct();

                _machines.Clear();
                foreach (var item in query)
                {
                    _machines.Add(item);
                }

                machines_DataGridView.DataSource = null;
                machines_DataGridView.DataSource = _machines;
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the VM list.
        /// </summary>
        /// <param name="sessionId">The session id.</param>
        /// <param name="usageState">State of the usage.</param>
        /// <returns></returns>
        private static Collection <VirtualMachine> GetMachineList(string sessionId, VMUsageState usageState)
        {
            var reservedVMList = new Collection <VirtualMachine>();

            foreach (var machine in VirtualMachine.Select(sessionId: sessionId, usageState: usageState))
            {
                reservedVMList.Add(machine);
            }

            return(reservedVMList);
        }
예제 #3
0
        private static List <VirtualMachine> GetMasterList(UserCredential credential, RequestedVMDictionary requestedVMs)
        {
            List <VirtualMachine> masterMachineList = null;

            if (requestedVMs.Count == 0)
            {
                TraceFactory.Logger.Debug("No specific machines requested.");

                // Add all available VMs with no hold ID to the master list
                masterMachineList = VirtualMachine.Select(VMPowerState.PoweredOff, VMUsageState.Available, holdId: null).ToList();
            }
            else
            {
                TraceFactory.Logger.Debug("Specific machines requested.");

                // Add all available VMs with no hold ID to the master list
                masterMachineList = VirtualMachine.Select(VMPowerState.PoweredOff, VMUsageState.Available).ToList();

                // The user requested specific machines, so throw out any machines that are not on that list
                IEnumerable <string> requestedVMNames = requestedVMs.SelectMany(n => n.Value);
                masterMachineList.RemoveAll(n => !requestedVMNames.Contains(n.Name, StringComparer.OrdinalIgnoreCase));
            }

            // If user is not an admin, check for user group rights to the VMs
            if (!credential.HasPrivilege(UserRole.Administrator))
            {
                TraceFactory.Logger.Debug("{0} total machines BEFORE quota".FormatWith(masterMachineList.Count));
                using (var enterpriseTestContext = DbConnect.EnterpriseTestContext())
                {
                    var allowedVMs = enterpriseTestContext.UserGroups
                                     .Where(n => n.Users.Any(m => m.UserName == credential.UserName))
                                     .SelectMany(n => n.FrameworkClients)
                                     .Select(n => n.FrameworkClientHostName).ToList();
                    masterMachineList.RemoveAll(n => !allowedVMs.Contains(n.Name, StringComparer.OrdinalIgnoreCase));
                }
                TraceFactory.Logger.Debug("{0} total machines AFTER quota".FormatWith(masterMachineList.Count));
            }

            return(masterMachineList);
        }