Пример #1
0
 void PIF_CollectionChanged(object sender, CollectionChangeEventArgs e)
 {
     if (e.Action == CollectionChangeAction.Remove)
     {
         PIF pif = e.Element as PIF;
         UnregisterPIFEventHandlers(pif);
     }
     Program.Invoke(this, updateList);
 }
Пример #2
0
        private Dictionary <XenAPI.Network, List <NetworkingPropertiesPage> > MakeProposedInUseMap()
        {
            Dictionary <XenAPI.Network, List <NetworkingPropertiesPage> > inusemap =
                new Dictionary <XenAPI.Network, List <NetworkingPropertiesPage> >();

            foreach (NetworkingPropertiesPage page in verticalTabs.Items)
            {
                XenAPI.Network network = (XenAPI.Network)page.NetworkComboBox.SelectedItem;

                if (network == null)
                {
                    PIF pif = page.Tag as PIF;
                    if (pif == null)
                    {
                        continue;
                    }
                    network = pif.Connection.Resolve(pif.network);
                    if (network == null)
                    {
                        continue;
                    }
                }

                if (network.PIFs.Count == 0)
                {
                    continue;
                }

                if (!inusemap.ContainsKey(network))
                {
                    inusemap[network] = new List <NetworkingPropertiesPage>();
                }
                inusemap[network].Add(page);
            }

            foreach (XenAPI.Network network in connection.Cache.Networks)
            {
                if (network.Show(Properties.Settings.Default.ShowHiddenVMs))
                {
                    if (connection.ResolveAll(network.PIFs).Find(p => !p.IsTunnelAccessPIF) == null)  // no PIFs, or all the PIFs are tunnel access PIFs so the network is a CHIN
                    {
                        continue;
                    }
                    PIF pif = FindPIFForThisHost(network.PIFs);
                    if (pif != null && pif.IsInUseBondSlave)
                    {
                        continue;
                    }
                    if (!inusemap.ContainsKey(network))
                    {
                        inusemap[network] = null;
                    }
                }
            }

            return(inusemap);
        }
Пример #3
0
        protected override void Run()
        {
            PIF pifOnMaster = null;

            if (selectedPifs.Count == 0)
            {
                return;
            }

            foreach (PIF thePif in selectedPifs)
            {
                Host host = thePif.Connection.Resolve <XenAPI.Host>(thePif.host);
                if (host == null)
                {
                    continue;
                }

                if (host.IsMaster())
                {
                    pifOnMaster = thePif;
                    break;
                }
            }
            Connection.ExpectDisruption = true;

            //Enable SR-IOV network on Pool requires enabling master first.
            if (pifOnMaster != null)
            {
                selectedPifs.Remove(pifOnMaster);
                selectedPifs.Insert(0, pifOnMaster);
            }

            int inc = 100 / selectedPifs.Count;
            int lo  = 0;

            // Create the new network
            XenRef <XenAPI.Network> networkRef = XenAPI.Network.create(Session, newNetwork);

            try
            {
                foreach (PIF thePif in selectedPifs)
                {
                    RelatedTask = Network_sriov.async_create(Session, thePif.opaque_ref, networkRef);
                    PollToCompletion(lo, lo + inc);
                    lo += inc;
                }
            }
            catch (Exception)
            {
                if (lo == 0)
                {
                    DestroyNetwork(networkRef);
                }
                throw;
            }
        }
Пример #4
0
        private void UnregisterPIFEventHandlers(PIF pif)
        {
            pif.PropertyChanged -= PIF_PropertyChangedEventHandler;
            var pifMetrics = pif.PIFMetrics();

            if (pifMetrics != null)
            {
                pifMetrics.PropertyChanged -= PropertyChangedEventHandler;
            }
        }
Пример #5
0
        internal static void ReconfigureIP(AsyncAction action, PIF new_pif, PIF existing_pif, string ip, int hi)
        {
            log.DebugFormat("Reconfiguring IP on {0} {1} ...", existing_pif.Name(), existing_pif.uuid);

            action.RelatedTask = PIF.async_reconfigure_ip(action.Session, existing_pif.opaque_ref,
                                                          new_pif.ip_configuration_mode, ip, new_pif.netmask, new_pif.gateway, new_pif.DNS);
            action.PollToCompletion(action.PercentComplete, hi);

            log.DebugFormat("Reconfiguring IP on {0} {1} done.", existing_pif.Name(), existing_pif.uuid);
        }
Пример #6
0
        private void DeleteBondButton_Click(object sender, EventArgs e)
        {
            PIF pif = ((PIFRow)dataGridView1.SelectedRows[0]).pif;

            System.Diagnostics.Trace.Assert(pif.IsBondNIC);
            XenAPI.Network network            = pif.Connection.Resolve(pif.network);
            var            destroyBondCommand = new DestroyBondCommand(Program.MainWindow, network);

            destroyBondCommand.Execute();
        }
Пример #7
0
 internal static void Plug(AsyncAction action, PIF pif, int hi)
 {
     if (!PIF.get_currently_attached(action.Session, pif.opaque_ref))
     {
         log.DebugFormat("Plugging {0} {1} ...", pif.Name, pif.uuid);
         action.RelatedTask = PIF.async_plug(action.Session, pif.opaque_ref);
         action.PollToCompletion(action.PercentComplete, hi);
         log.DebugFormat("Plugging {0} {1} done.", pif.Name, pif.uuid);
     }
 }
Пример #8
0
        private void Plug(PIF p)
        {
            if (p.currently_attached)
            {
                // We will try and plug the PIF even if it seems to be already plugged (CA-75969)
                log.DebugFormat("Plugging PIF '{0}': this PIF is currently attached. Will try to plug anyway", p.uuid);
            }

            PIF.plug(Session, p.opaque_ref);
        }
Пример #9
0
        private void updateList()
        {
            PIFRow selected = null;

            if (dataGridView1.SelectedRows.Count > 0)
            {
                selected = dataGridView1.SelectedRows[0] as PIFRow;
            }

            try
            {
                dataGridView1.SuspendLayout();
                dataGridView1.Rows.Clear();

                if (host != null)
                {
                    foreach (PIF PIF in host.Connection.ResolveAll(host.PIFs))
                    {
                        if (!PIF.IsPhysical())
                        {
                            continue;
                        }

                        RegisterPIFEventHandlers(PIF);

                        PIFRow p = new PIFRow(PIF);
                        dataGridView1.Rows.Add(p);
                        if (selected != null && p.pif == selected.pif)
                        {
                            p.Selected = true;
                        }
                    }

                    //show the FCoE column for Dundee or higher hosts only
                    ColumnFCoECapable.Visible = Helpers.DundeeOrGreater(host);

                    //CA-47050: the Device column should be autosized to Fill, but should not become smaller than a minimum
                    //width, which here is chosen to be the column header width. To find what this width is
                    //set temporarily the column's autosize mode to ColumnHeader.
                    ColumnDeviceName.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
                    int storedWidth = ColumnDeviceName.Width;
                    ColumnDeviceName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                    ColumnDeviceName.MinimumWidth = storedWidth;

                    if (dataGridView1.SortedColumn != null)
                    {
                        dataGridView1.Sort(dataGridView1.SortedColumn, dataGridView1.SortOrder == SortOrder.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending);
                    }
                }
            }
            finally
            {
                dataGridView1.ResumeLayout();
            }
        }
Пример #10
0
        private void ReconfigureSecondaryManagement(PIF src, PIF dest, int hi)
        {
            System.Diagnostics.Trace.Assert(!bostonOrGreater);

            int mid = (PercentComplete + hi) / 2;

            PIF new_dest = NetworkingHelper.CopyIPConfig(src, dest);

            NetworkingActionHelpers.BringDown(this, src, mid);
            NetworkingActionHelpers.BringUp(this, new_dest, dest, hi);
        }
Пример #11
0
        private void ReconfigureManagementInterfaces(List <PIF> slaves, PIF new_master, int hi)
        {
            int lo  = PercentComplete;
            int inc = (hi - lo) / slaves.Count;

            foreach (PIF pif in slaves)
            {
                lo += inc;
                NetworkingActionHelpers.MoveManagementInterfaceName(this, pif, new_master);
            }
        }
Пример #12
0
        protected override void Run()
        {
            foreach (var pif in Connection.ResolveAll(network.PIFs))
            {
                PIF.set_disallow_unplug(Session, pif.opaque_ref, true);
            }
            var cluster = new Cluster(); // this Cluster object is only used for getting the default values for token_timeout and token_timeout_coefficient

            Cluster.pool_create(Session, network.opaque_ref, "corosync", cluster.token_timeout, cluster.token_timeout_coefficient);
            Description = string.Format(Messages.ENABLED_CLUSTERING_ON_POOL, Pool.Name());
        }
Пример #13
0
        /// <summary>
        /// Remove the IP address from the given PIF.
        /// </summary>
        private static void ClearIP(AsyncAction action, PIF pif, int hi)
        {
            log.DebugFormat("Removing IP address from {0} {1}...", pif.Name, pif.uuid);
            action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_BRINGING_DOWN, pif.Name);

            action.RelatedTask = PIF.async_reconfigure_ip(action.Session, pif.opaque_ref, ip_configuration_mode.None, "", "", "", "");
            action.PollToCompletion(action.PercentComplete, hi);

            action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_BRINGING_DOWN_DONE, pif.Name);
            log.DebugFormat("Removed IP address from {0} {1}.", pif.Name, pif.uuid);
        }
Пример #14
0
 private bool PIFContains(List <PIF> l, PIF p)
 {
     foreach (PIF p2 in l)
     {
         if (p2.uuid == p.uuid)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #15
0
        private void datagridview_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0)
            {
                DeleteBondButton.Enabled = false;
                return;
            }
            PIF pif = ((PIFRow)dataGridView1.SelectedRows[0]).pif;

            DeleteBondButton.Enabled = pif != null && pif.BondMasterOf != null && !pif.BondMasterOf.Locked;
        }
Пример #16
0
        /// <summary>
        /// Switch the Pool's management interface from its current setting over to the given PIF.
        /// </summary>
        private static void PoolManagementReconfigure_(AsyncAction action, PIF pif, int hi)
        {
            log.DebugFormat("Switching to PIF {0} {1} for management...", pif.Name(), pif.uuid);
            action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_MANAGEMENT_RECONFIGURING, pif.Name());

            action.RelatedTask = Pool.async_management_reconfigure(action.Session, pif.network.opaque_ref);
            action.PollToCompletion(action.PercentComplete, hi);

            action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_MANAGEMENT_RECONFIGURED, pif.Name());
            log.DebugFormat("Switched to PIF {0} {1} for management...", pif.Name(), pif.uuid);
        }
Пример #17
0
        private void BringUp(PIF new_pif, PIF existing_pif, int hi)
        {
            string ip = existing_pif.IP;

            if (new_pif.ip_configuration_mode == ip_configuration_mode.Static)
            {
                ip = Pool == null ? new_pif.IP : GetIPInRange(new_pif.IP, existing_pif);
            }

            NetworkingActionHelpers.BringUp(this, new_pif, ip, existing_pif, hi);
        }
Пример #18
0
        private void RegisterPIFEventHandlers(PIF pif)
        {
            pif.PropertyChanged -= PIF_PropertyChangedEventHandler;
            pif.PropertyChanged += PIF_PropertyChangedEventHandler;

            if (pif.PIFMetrics != null)
            {
                pif.PIFMetrics.PropertyChanged -= PropertyChangedEventHandler;
                pif.PIFMetrics.PropertyChanged += PropertyChangedEventHandler;
            }
        }
Пример #19
0
        internal static void ReconfigureSinglePrimaryManagement(AsyncAction action, PIF src, PIF dest, int hi)
        {
            PIF new_dest = NetworkingHelper.CopyIPConfig(src, dest);

            // We put an IP address on the destination interface, then we reconfigure the management interface onto it.

            int mid = (hi + action.PercentComplete) / 2;

            BringUp(action, new_dest, new_dest.IP, dest, mid);
            ReconfigureManagement(action, src, new_dest, true, false, hi, true);
        }
Пример #20
0
        public NetworkingProperties(Host host, PIF selectedPIF) : this()
        {
            Host       = host;
            Pool       = null;
            connection = host.Connection;
            ObjectName = Helpers.GetName(host);

            BlurbLabel.Text = string.Format(Messages.NETWORKING_PROPERTIES_BLURB_HOST, ObjectName);

            Configure(selectedPIF);
        }
Пример #21
0
        private void updateList()
        {
            PIFRow selected = null;

            if (dataGridView1.SelectedRows.Count > 0)
            {
                selected = dataGridView1.SelectedRows[0] as PIFRow;
            }

            try
            {
                dataGridView1.SuspendLayout();
                dataGridView1.Rows.Clear();

                if (host != null)
                {
                    foreach (PIF PIF in host.Connection.ResolveAll(host.PIFs))
                    {
                        if (!PIF.IsPhysical())
                        {
                            continue;
                        }

                        RegisterPIFEventHandlers(PIF);

                        PIFRow p = new PIFRow(PIF);
                        dataGridView1.Rows.Add(p);
                        if (selected != null && p.Pif == selected.Pif)
                        {
                            p.Selected = true;
                        }
                    }

                    //show the FCoE column for Dundee or higher hosts only
                    ColumnFCoECapable.Visible = Helpers.DundeeOrGreater(host);

                    //show the SR-IOV column for Kolkata or higher hosts only
                    ColumnSriovCapable.Visible = Helpers.KolkataOrGreater(host);

                    HelpersGUI.ResizeGridViewColumnToHeader(ColumnDeviceName);
                    HelpersGUI.ResizeGridViewColumnToHeader(ColumnSriovCapable);

                    if (dataGridView1.SortedColumn != null)
                    {
                        dataGridView1.Sort(dataGridView1.SortedColumn, dataGridView1.SortOrder == SortOrder.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending);
                    }
                }
            }
            finally
            {
                dataGridView1.ResumeLayout();
            }
        }
Пример #22
0
        private string GetIPInRange(string range_start, PIF existing_pif)
        {
            int i = Array.FindIndex(Hosts, h => h.opaque_ref == existing_pif.host);

            if (i == -1)
            {
                throw new Failure(Failure.INTERNAL_ERROR, Messages.HOST_GONE);
            }

            string[] bits = range_start.Split('.');
            return(string.Format("{0}.{1}.{2}.{3}", bits[0], bits[1], bits[2], int.Parse(bits[3]) + i));
        }
Пример #23
0
        /// <summary>
        /// Copy the IP details from src to a clone of dest, and return the clone.
        /// </summary>
        public static PIF CopyIPConfig(PIF src, PIF dest)
        {
            PIF result = (PIF)dest.Clone();

            result.SetManagementPurspose(src.GetManagementPurpose());
            result.ip_configuration_mode = src.ip_configuration_mode;
            result.IP      = src.IP;
            result.netmask = src.netmask;
            result.gateway = src.gateway;
            result.DNS     = src.DNS;
            return(result);
        }
Пример #24
0
        private void CreateNonBonded()
        {
            XenAPI.Network network = PopulateNewNetworkObj();
            PIF            nic     = pageNetworkDetails.SelectedHostNic;
            long           vlan    = pageNetworkDetails.VLAN;

            NetworkAction action = pageNetworkType.SelectedNetworkType == NetworkTypes.External
                                       ? new NetworkAction(xenConnection, network, nic, vlan)
                                       : new NetworkAction(xenConnection, network, true);

            action.RunAsync();
        }
Пример #25
0
 /// <summary>
 /// Return the bond equivalent to the given one, but on the given host.  Returns if no
 /// such thing exists.
 /// </summary>
 /// <param name="host"></param>
 /// <param name="bond"></param>
 /// <returns></returns>
 public static Bond FindBond(Host host, Bond bond)
 {
     foreach (Bond b in host.Connection.Cache.Bonds)
     {
         PIF master = host.Connection.Resolve(b.master);
         if (master != null && master.host.opaque_ref == host.opaque_ref && BondMatches(b, bond))
         {
             return(b);
         }
     }
     return(null);
 }
        public void CreateExternalNetwork()
        {
            Assert.True(DatabaseManager.ConnectionFor(dbName).Cache.PIFs.Length > 0);
            PIF           pif           = DatabaseManager.ConnectionFor(dbName).Cache.PIFs[0];
            NetworkAction networkAction = new NetworkAction(DatabaseManager.ConnectionFor(dbName), newNetwork, pif, 2);

            networkAction.Completed += networkAction_Completed;
            networkAction.RunAsync();
            AutoResetEvent.WaitOne();
            DatabaseManager.RefreshCacheFor(dbName);
            Assert.AreEqual(networks + 1, DatabaseManager.ConnectionFor(dbName).Cache.Networks.Length);
        }
Пример #27
0
        public NetworkingProperties(Host host, PIF selectedPIF) : this()
        {
            Host                  = host;
            Pool                  = null;
            connection            = host.Connection;
            ObjectName            = Helpers.GetName(host);
            AllowManagementOnVLAN = !Helpers.FeatureForbidden(connection, Host.RestrictManagementOnVLAN);

            BlurbLabel.Text = string.Format(Messages.NETWORKING_PROPERTIES_BLURB_HOST, ObjectName);

            Configure(selectedPIF);
        }
Пример #28
0
        private NetworkComboBoxItem CreateNewItem(PIF pif)
        {
            var network = PopulateConnection.Resolve(pif.network);

            return(new NetworkComboBoxItem
            {
                IncludePoolNameInComboBox = IncludePoolNameInComboBox,
                IsManagement = pif.management,
                Network = network,
                NetworkIsConnected = pif.LinkStatus == PIF.LinkState.Connected,
                HasIPAddress = pif.IsManagementInterface(false)
            });
        }
Пример #29
0
        private List <int> GetVLANList(PIF nic)
        {
            List <int> vlans = new List <int>();

            foreach (PIF pif in nic.Connection.Cache.PIFs)
            {
                if (pif.device == nic.device)
                {
                    vlans.Add((int)pif.VLAN);
                }
            }

            return(vlans);
        }
Пример #30
0
        private static void PrintPhysicalInterfaces(Session session)
        {
            System.Console.WriteLine("\n*** Physical network interfaces: ***\n");

            foreach (PIF pif in PIF.get_all_records(session).Values)
            {
                // resolve the host reference in the pif
                Host host = Host.get_record(session, pif.host);

                System.Console.WriteLine("Host: {0}", host.name_label);
                System.Console.WriteLine("IP: {0}", pif.IP);
                System.Console.WriteLine("MAC address: {0}", pif.MAC);
                System.Console.WriteLine("-");
            }
        }