示例#1
0
        public static bool HasIpForClusterNetwork(IXenConnection masterConnection, Host slaveHost, out bool clusterHostInBond)
        {
            clusterHostInBond = false;
            var clusterHost = masterConnection.Cache.Cluster_hosts.FirstOrDefault();

            if (clusterHost == null)
            {
                return(true);
            }

            var clusterHostPif = clusterHost.Connection.Resolve(clusterHost.PIF);

            if (clusterHostPif == null)
            {
                return(true);
            }

            clusterHostInBond = clusterHostPif.IsBondNIC();

            var pifsWithIPAddress = 0;

            List <string> ids = new List <string>();

            if (clusterHostInBond)
            {
                List <PIF> slaves = new List <PIF>();

                var bonds = masterConnection.ResolveAll(clusterHostPif.bond_master_of);

                foreach (var bond in bonds)
                {
                    slaves.AddRange(masterConnection.ResolveAll(bond.slaves));
                }

                ids.AddRange(slaves.Select(slave => slave.device));
            }
            else
            {
                ids.Add(clusterHostPif.device);
            }

            var pifs = slaveHost.Connection.ResolveAll(slaveHost.PIFs);

            foreach (var pif in pifs)
            {
                if (pif.IsManagementInterface(false) && ids.Contains(pif.device))
                {
                    pifsWithIPAddress += 1;
                }
            }

            return(pifsWithIPAddress == 1);
        }
示例#2
0
        /// <summary>
        /// Retrieves all the server RBAC roles which are able to complete the api method supplied. If on George or less this will return an empty list.
        /// </summary>
        /// <param name="ApiMethodToRoleCheck">RbacMethod to check</param>
        /// <param name="Connection">server connection to retrieve roles from</param>
        /// <returns></returns>
        public static List <Role> ValidRoleList(RbacMethod ApiMethodToRoleCheck, IXenConnection Connection)
        {
            List <Role> rolesAbleToCompleteApiCall = new List <Role>();

            foreach (Role role in Connection.Cache.Roles)
            {
                List <Role> subroles = (List <Role>)Connection.ResolveAll <Role>(role.subroles);
                if (subroles.Find(
                        delegate(Role r)
                {
                    return(r.CanPerform(ApiMethodToRoleCheck));
                })
                    != null)
                {
                    rolesAbleToCompleteApiCall.Add(role);
                }
            }

            // don't do this assert with simulator connections. These will always have no roles.
            if (!Connection.HostnameWithPort.EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase))
            {
                // No roles able to perform API call is a bug, because Pool Admins should be able to do everything.
                // Usually caused by a typo, or by running a new action against an old server without checking.
                System.Diagnostics.Trace.Assert(rolesAbleToCompleteApiCall.Count > 0, String.Format("No roles able to perform API call {0}", ApiMethodToRoleCheck));
            }
            return(rolesAbleToCompleteApiCall);
        }
示例#3
0
        /// <summary>
        /// Given a list of PIFs on the pool master, return a Dictionary mapping each host in the pool to a corresponding list of PIFs on that
        /// host.  The PIFs lists will be sorted by name too.
        /// </summary>
        /// <param name="PIFs_on_master"></param>
        /// <returns></returns>
        public static Dictionary <Host, List <PIF> > PIFsOnAllHosts(List <PIF> PIFs_on_master)
        {
            Dictionary <Host, List <PIF> > result = new Dictionary <Host, List <PIF> >();

            if (PIFs_on_master.Count == 0)
            {
                return(result);
            }

            IXenConnection conn = PIFs_on_master[0].Connection;

            List <string> devices = GetDevices(PIFs_on_master);

            foreach (Host host in conn.Cache.Hosts)
            {
                List <PIF> pifs = new List <PIF>();
                foreach (PIF pif in conn.ResolveAll(host.PIFs))
                {
                    if (devices.Contains(pif.device))
                    {
                        pifs.Add(pif);
                    }
                }

                Sort(pifs);

                result[host] = pifs;
            }

            return(result);
        }
示例#4
0
        public Dictionary <String, String> GetDeviceConfig(IXenConnection connection)
        {
            foreach (PBD pbd in connection.ResolveAll(PBDs))
            {
                return(pbd.device_config);
            }

            return(null);
        }
示例#5
0
        private int RoleCompare(Subject s1, Subject s2)
        {
            List <Role> s1Roles = _connection.ResolveAll(s1.roles);
            List <Role> s2Roles = _connection.ResolveAll(s2.roles);

            s1Roles.Sort();
            s2Roles.Sort();
            // If one subject doesn't have any roles, but it below the one with roles
            if (s1Roles.Count < 1)
            {
                if (s2Roles.Count < 1)
                {
                    return(0);
                }
                return(-1);
            }
            if (s2Roles.Count < 1)
            {
                return(1);
            }

            return(s1Roles[0].CompareTo(s2Roles[0]));
        }
        private void BuildList()
        {
            if (!this.Visible)
            {
                return;
            }
            int selectedIndex = listViewSrs.SelectedIndices.Count == 1 ? listViewSrs.SelectedIndices[0] : -1;

            listViewSrs.BeginUpdate();

            try
            {
                listViewSrs.Items.Clear();

                if (connection == null)
                {
                    return;
                }

                List <PBD> pbds = host != null ? new List <PBD>(connection.ResolveAll(host.PBDs))
                    : new List <PBD>(connection.Cache.PBDs);

                List <String> srs = new List <String>();

                foreach (PBD pbd in pbds)
                {
                    SR sr = pbd.Connection.Resolve(pbd.SR);

                    if (sr == null || sr.IsToolsSR || !sr.Show(Properties.Settings.Default.ShowHiddenVMs))
                    {
                        continue;
                    }

                    // From MSDN:
                    // Returns the zero-based index of item in the sorted List<T>, if item is found;
                    // otherwise, a negative number that is the bitwise complement of the index of
                    // the next element that is larger than item or, if there is no larger element,
                    // the bitwise complement of Count.
                    int index = srs.BinarySearch(sr.opaque_ref);

                    // Don't allow duplicates
                    if (index >= 0)
                    {
                        continue;
                    }

                    sr.PropertyChanged -= sr_PropertyChanged;
                    sr.PropertyChanged += sr_PropertyChanged;

                    index = ~index;
                    srs.Insert(index, sr.opaque_ref);

                    ListViewItem item = new ListViewItem();
                    item.Tag = sr;
                    RefreshRow(item);
                    listViewSrs.Items.Add(item);
                }

                if (selectedIndex >= 0 && selectedIndex < listViewSrs.Items.Count)
                {
                    // Select previously selected item
                    listViewSrs.SelectedIndices.Clear();
                    listViewSrs.SelectedIndices.Add(selectedIndex);
                }
            }
            finally
            {
                listViewSrs.EndUpdate();
            }
            RefreshButtons();
            NeedBuildList = false;
        }
示例#7
0
        public RoleSelectionDialog(IXenConnection connection, Subject[] subjects)
        {
            InitializeComponent();

            _connection = connection;

            this.subjects  = subjects;
            roleAssignment = new Dictionary <Role, List <Subject> >();

            var allAreGroups = subjects.Length > 0 && subjects.All(s => s.IsGroup);
            var allAreUsers  = subjects.Length > 0 && subjects.All(s => !s.IsGroup);

            pictureBoxSubjectType.Image = allAreUsers ? Properties.Resources._000_User_h32bit_16 : Properties.Resources._000_UserAndGroup_h32bit_32;

            if (subjects.Length == 1)
            {
                Subject subject = subjects[0];
                string  sName   = (subject.DisplayName ?? subject.SubjectName ?? Messages.UNKNOWN_AD_USER).Ellipsise(30);
                labelBlurb.Text = string.Format(allAreGroups ? Messages.AD_SELECT_ROLE_GROUP : Messages.AD_SELECT_ROLE_USER, sName);
            }
            else
            {
                if (allAreGroups)
                {
                    labelBlurb.Text = Messages.AD_SELECT_ROLE_GROUP_MANY;
                }
                else if (allAreUsers)
                {
                    labelBlurb.Text = Messages.AD_SELECT_ROLE_USER_MANY;
                }
                else
                {
                    labelBlurb.Text = Messages.AD_SELECT_ROLE_MIXED;
                }
            }

            // Get the list of roles off the server and arrange them into rank
            List <Role> serverRoles = new List <Role>(_connection.Cache.Roles);

            //hide basic permissions, we only want the roles.
            serverRoles.RemoveAll(delegate(Role r){ return(r.subroles.Count < 1); });
            serverRoles.Sort();
            serverRoles.Reverse();
            foreach (Role r in serverRoles)
            {
                roleAssignment.Add(r, new List <Subject>());
            }
            foreach (Subject s in subjects)
            {
                List <Role> subjectRoles = _connection.ResolveAll(s.roles);
                foreach (Role r in subjectRoles)
                {
                    roleAssignment[r].Add(s);
                }
            }
            foreach (Role role in serverRoles)
            {
                DataGridViewRow            r  = new DataGridViewRow();
                DataGridViewCheckBoxCellEx c1 = new DataGridViewCheckBoxCellEx();
                c1.ThreeState = true;
                if (roleAssignment[role].Count == subjects.Length)
                {
                    c1.Value      = CheckState.Checked;
                    c1.CheckState = CheckState.Checked;
                }
                else if (roleAssignment[role].Count == 0)
                {
                    c1.Value      = CheckState.Unchecked;
                    c1.CheckState = CheckState.Unchecked;
                }
                else
                {
                    c1.Value      = CheckState.Indeterminate;
                    c1.CheckState = CheckState.Indeterminate;
                }
                DataGridViewTextBoxCell c2 = new DataGridViewTextBoxCell();
                c2.Value = role.FriendlyName();
                r.Cells.Add(c1);
                r.Cells.Add(c2);
                r.Tag = role;
                gridRoles.Rows.Add(r);
            }
            setRoleDescription();
        }