Beispiel #1
0
        /// <summary>
        /// Configure an IP address, management purpose, and set the disallow_unplug flag on the given existing_pif.
        /// </summary>
        /// <param name="new_pif">The source of the new IP details</param>
        /// <param name="existing_pif">The PIF to configure</param>
        internal static void BringUp(AsyncAction action, PIF new_pif, string new_ip, PIF existing_pif, int hi)
        {
            bool primary = string.IsNullOrEmpty(new_pif.GetManagementPurpose());

            int lo  = action.PercentComplete;
            int inc = (hi - lo) / (primary ? 2 : 3);

            log.DebugFormat("Bringing PIF {0} {1} up as {2}/{3}, {4}, {5}...", existing_pif.Name(), existing_pif.uuid,
                            new_ip, new_pif.netmask, new_pif.gateway, new_pif.DNS);
            action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_BRINGING_UP, existing_pif.Name());

            PIF p = (PIF)existing_pif.Clone();

            p.disallow_unplug = !primary;
            p.SetManagementPurpose(new_pif.GetManagementPurpose());
            p.SaveChanges(action.Session);

            action.PercentComplete = lo + inc;

            ReconfigureIP(action, new_pif, existing_pif, new_ip, action.PercentComplete + inc);
            if (!primary)
            {
                Plug(action, existing_pif, hi);
            }

            action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_BRINGING_UP_DONE, existing_pif.Name());
            log.DebugFormat("Brought PIF {0} {1} up.", existing_pif.Name(), existing_pif.uuid);
        }
Beispiel #2
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);
        }
 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);
     }
 }
Beispiel #4
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);
        }
        /// <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);
        }
Beispiel #6
0
        /// <summary>
        /// Clear the disallow_unplug and ManagementPurpose on the given NIC.
        /// </summary>
        private static void Depurpose(AsyncAction action, PIF pif, int hi)
        {
            log.DebugFormat("Depurposing PIF {0} {1}...", pif.Name(), pif.uuid);
            action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_DEPURPOSING, pif.Name());

            PIF p = (PIF)pif.Clone();

            p.disallow_unplug = false;
            p.SetManagementPurpose(null);
            p.SaveChanges(action.Session);

            action.PercentComplete = hi;

            log.DebugFormat("Depurposed PIF {0} {1}.", pif.Name(), pif.uuid);
            action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_DEPURPOSED, pif.Name());
        }
Beispiel #7
0
        /// <summary>
        /// Remove the IP address from the given PIF.
        /// </summary>
        private static void ClearIP(AsyncAction action, PIF pif, int hi)
        {
            // if the network is used by clustering, then we don't remove the IP address
            if (pif.IsUsedByClustering())
            {
                return;
            }

            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);
        }
Beispiel #8
0
        /// <summary>
        /// Switch the host's management interface from its current setting over to the given PIF.
        /// </summary>
        private static void ReconfigureManagement_(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());

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

            PIF p = (PIF)pif.Clone();

            p.disallow_unplug = false;
            p.SetManagementPurpose(null);
            p.SaveChanges(action.Session);

            action.PercentComplete = mid;

            action.RelatedTask = XenAPI.Host.async_management_reconfigure(action.Session, pif.opaque_ref);
            action.PollToCompletion(mid, hi);

            log.DebugFormat("Switched to PIF {0} {1} for management.", pif.Name(), pif.uuid);
            action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_MANAGEMENT_RECONFIGURED, pif.Name());
        }
Beispiel #9
0
            private void updateCell(int index)
            {
                switch (index)
                {
                case 0:
                    Cells[0].Value = pif.Name();
                    break;

                case 1:
                    Cells[1].Value = pif.MAC;
                    break;

                case 2:
                    Cells[2].Value = pif.Carrier() ? Messages.CONNECTED : Messages.DISCONNECTED;
                    break;

                case 3:
                    Cells[3].Value = pif.Carrier() ? pif.Speed() : Messages.HYPHEN;
                    break;

                case 4:
                    Cells[4].Value = pif.Carrier() ? pif.Duplex() : Messages.HYPHEN;
                    break;

                case 5:
                    Cells[5].Value = vendor;
                    break;

                case 6:
                    Cells[6].Value = device;
                    break;

                case 7:
                    Cells[7].Value = busPath;
                    break;

                case 8:
                    Cells[8].Value = pif.FCoECapable().ToYesNoStringI18n();
                    break;
                }
            }
Beispiel #10
0
            private void Update()
            {
                _cellName.Value      = Pif.Name();
                _cellMac.Value       = Pif.MAC;
                _cellConnected.Value = Pif.Carrier() ? Messages.CONNECTED : Messages.DISCONNECTED;
                _cellSpeed.Value     = Pif.Carrier() ? Pif.Speed() : Messages.HYPHEN;
                _cellDuplex.Value    = Pif.Carrier() ? Pif.Duplex() : Messages.HYPHEN;

                var pifMetrics = Pif.PIFMetrics();

                _cellVendor.Value  = pifMetrics == null ? Messages.HYPHEN : pifMetrics.vendor_name;
                _cellDevice.Value  = pifMetrics == null ? Messages.HYPHEN : pifMetrics.device_name;
                _cellBusPath.Value = pifMetrics == null ? Messages.HYPHEN : pifMetrics.pci_bus_path;

                _cellFcoe.Value = Pif.FCoECapable().ToYesNoStringI18n();

                if (!Pif.SriovCapable())
                {
                    _cellSriov.Value = Messages.NO;
                }
                else if (!Pif.IsSriovPhysicalPIF())
                {
                    _cellSriov.Value = Messages.SRIOV_NETWORK_SHOULD_BE_CREATED;
                }
                else
                {
                    var networkSriov = Pif.Connection.Resolve(Pif.sriov_physical_PIF_of[0]);

                    if (networkSriov == null || networkSriov.requires_reboot)
                    {
                        _cellSriov.Value = Messages.HOST_NEEDS_REBOOT_ENABLE_SRIOV;
                        return;
                    }

                    PIF sriovLogicalPif = Pif.Connection.Resolve(networkSriov.logical_PIF);

                    if (sriovLogicalPif == null || !sriovLogicalPif.currently_attached)
                    {
                        _cellSriov.Value = Messages.SRIOV_LOGICAL_PIF_UNPLUGGED;
                        return;
                    }

                    var sriovSupported = "";
                    var action         = new DelegatedAsyncAction(Pif.Connection, "", "", "", delegate(Session session)
                    {
                        try
                        {
                            var remainingCapacity = Network_sriov.get_remaining_capacity(session, Pif.sriov_physical_PIF_of[0].opaque_ref);
                            sriovSupported        = string.Format(Messages.REMAINING_VFS, remainingCapacity);
                        }
                        catch
                        {
                            sriovSupported = Messages.YES;
                        }
                    },
                                                                  true);

                    action.Completed += delegate
                    {
                        Program.Invoke(Program.MainWindow, () => _cellSriov.Value = sriovSupported);
                    };
                    action.RunAsync();
                }
            }
Beispiel #11
0
        public override string Name()
        {
            PIF pif = FindMaster();

            return(pif == null ? "" : pif.Name());
        }
Beispiel #12
0
        protected sealed override void ExecuteCore(SelectedItemCollection selection)
        {
            //It only supports one item selected for now
            Trace.Assert(selection.Count == 1);

            XenAPI.Network network = (XenAPI.Network)selection.FirstAsXenObject;
            List <PIF>     pifs    = network.Connection.ResolveAll(network.PIFs);

            if (pifs.Count == 0)
            {
                // Should never happen as long as the caller is enabling the button correctly, but
                // it's possible in a tiny window across disconnecting.
                log.Error("Network has no PIFs");
                return;
            }

            // We just want one, so that we can name it.
            PIF pif = pifs[0];

            string msg = string.Format(Messages.DELETE_BOND_MESSAGE, pif.Name());

            bool will_disturb_primary   = NetworkingHelper.ContainsPrimaryManagement(pifs);
            bool will_disturb_secondary = NetworkingHelper.ContainsSecondaryManagement(pifs);

            if (will_disturb_primary)
            {
                Pool pool = Helpers.GetPool(network.Connection);
                if (pool != null && pool.ha_enabled)
                {
                    using (var dlg = new ErrorDialog(string.Format(Messages.BOND_DELETE_HA_ENABLED, pif.Name(), pool.Name()))
                    {
                        WindowTitle = Messages.DELETE_BOND
                    })
                    {
                        dlg.ShowDialog(Parent);
                    }
                    return;
                }

                string message = string.Format(will_disturb_secondary ? Messages.BOND_DELETE_WILL_DISTURB_BOTH : Messages.BOND_DELETE_WILL_DISTURB_PRIMARY, msg);

                DialogResult result;
                using (var dlg = new WarningDialog(message,
                                                   new ThreeButtonDialog.TBDButton(Messages.BOND_DELETE_CONTINUE, DialogResult.OK),
                                                   ThreeButtonDialog.ButtonCancel)
                {
                    HelpName = "NetworkingConfigWarning",
                    WindowTitle = Messages.DELETE_BOND
                })
                {
                    result = dlg.ShowDialog(Parent);
                }
                if (DialogResult.OK != result)
                {
                    return;
                }
            }
            else if (will_disturb_secondary)
            {
                DialogResult dialogResult;
                using (var dlg = new WarningDialog(string.Format(Messages.BOND_DELETE_WILL_DISTURB_SECONDARY, msg),
                                                   ThreeButtonDialog.ButtonOK,
                                                   ThreeButtonDialog.ButtonCancel))
                {
                    dialogResult = dlg.ShowDialog(Parent);
                }
                if (DialogResult.OK != dialogResult)
                {
                    return;
                }
            }
            else
            {
                DialogResult dialogResult;
                using (var dlg = new WarningDialog(msg,
                                                   new ThreeButtonDialog.TBDButton(Messages.OK, DialogResult.OK, selected: true),
                                                   ThreeButtonDialog.ButtonCancel))
                {
                    dialogResult = dlg.ShowDialog(Parent);
                }
                if (DialogResult.OK != dialogResult)
                {
                    return;
                }
            }

            // The UI shouldn't offer deleting a bond in this case, but let's make sure we've
            // done the right thing and that the bond hasn't been deleted in the meantime. (CA-27436).
            Bond bond = pif.BondMasterOf();

            if (bond != null)
            {
                new Actions.DestroyBondAction(bond).RunAsync();
            }
        }
Beispiel #13
0
        public void Repopulate()
        {
            if (network == null || host == null)
            {
                return;
            }

            populateHostNicList();

            //set minimum value for VLAN
            numUpDownVLAN.Minimum = Helpers.VLAN0Allowed(network.Connection) ? 0 : 1;

            PIF pif = GetNetworksPIF();

            if (pif != null)
            {
                bool editable = Editable(pif);

                HostVLanLabel.Visible = editable;
                HostNicLabel.Visible  = editable;
                numUpDownVLAN.Visible = editable;
                HostPNICList.Visible  = editable;
                nicHelpLabel.Visible  = editable;

                if (editable)
                {
                    // virtual pif (external network on VLAN)
                    numUpDownVLAN.Value = pif.VLAN;
                    PIF ThePhysicalPIF = FindAssociatedPhysicalPIF();
                    if (ThePhysicalPIF != null)
                    {
                        HostPNICList.SelectedItem = ThePhysicalPIF.Name();
                    }
                    else
                    {
                        HostPNICList.SelectedItem = pif.Name();
                    }
                }

                bool hasBondMode = network.IsBond();
                groupBoxBondMode.Visible = hasBondMode;

                bool supportsLinkAggregation = Helpers.SupportsLinkAggregationBond(network.Connection);
                radioButtonLacpSrcMac.Visible = radioButtonLacpTcpudpPorts.Visible = supportsLinkAggregation;

                if (hasBondMode)
                {
                    switch (NetworkBondMode)
                    {
                    case bond_mode.balance_slb:
                        radioButtonBalanceSlb.Checked = true;
                        break;

                    case bond_mode.active_backup:
                        radioButtonActiveBackup.Checked = true;
                        break;

                    case bond_mode.lacp:
                        if (supportsLinkAggregation)
                        {
                            switch (HashingAlgorithm)
                            {
                            case Bond.hashing_algoritm.tcpudp_ports:
                                radioButtonLacpTcpudpPorts.Checked = true;
                                break;

                            default:
                                radioButtonLacpSrcMac.Checked = true;
                                break;
                            }
                        }
                        break;
                    }
                }
            }
            else
            {
                // internal network
                HostVLanLabel.Visible = true;
                HostNicLabel.Visible  = true;
                numUpDownVLAN.Visible = true;
                HostVLanLabel.Visible = true;
                HostPNICList.Visible  = true;
                nicHelpLabel.Visible  = true;

                groupBoxBondMode.Visible  = false;
                numUpDownVLAN.Enabled     = false;
                HostPNICList.SelectedItem = HostPNICList.Items[0];
            }

            foreach (VIF v in network.Connection.ResolveAll <VIF>(network.VIFs))
            {
                VM vm = network.Connection.Resolve <VM>(v.VM);
                if (vm.power_state != vm_power_state.Running || vm.GetVirtualisationStatus(out _).HasFlag(VM.VirtualisationStatus.IO_DRIVERS_INSTALLED))
                {
                    continue;
                }

                runningVMsWithoutTools = true;
                break;
            }

            // Populate Automatic checkbox
            autoCheckBox.Checked = network.GetAutoPlug();
            autoCheckBox.Enabled = !network.IsGuestInstallerNetwork();
            // in case some odd value has been set on the CLI
            numericUpDownMTU.Maximum = Math.Max(network.MTU, XenAPI.Network.MTU_MAX);
            numericUpDownMTU.Minimum = Math.Min(network.MTU, XenAPI.Network.MTU_MIN);
            numericUpDownMTU.Value   = network.MTU;
            numericUpDownMTU.Visible = network.CanUseJumboFrames();
        }
Beispiel #14
0
            private void updateCell(int index)
            {
                switch (index)
                {
                case 0:
                    Cells[0].Value = pif.Name();
                    break;

                case 1:
                    Cells[1].Value = pif.MAC;
                    break;

                case 2:
                    Cells[2].Value = pif.Carrier() ? Messages.CONNECTED : Messages.DISCONNECTED;
                    break;

                case 3:
                    Cells[3].Value = pif.Carrier() ? pif.Speed() : Messages.HYPHEN;
                    break;

                case 4:
                    Cells[4].Value = pif.Carrier() ? pif.Duplex() : Messages.HYPHEN;
                    break;

                case 5:
                    Cells[5].Value = vendor;
                    break;

                case 6:
                    Cells[6].Value = device;
                    break;

                case 7:
                    Cells[7].Value = busPath;
                    break;

                case 8:
                    Cells[8].Value = pif.FCoECapable().ToYesNoStringI18n();
                    break;

                case 9:
                    string sriovSupported = "";
                    if (!pif.SriovCapable() || !pif.IsSriovPhysicalPIF())
                    {
                        sriovSupported = !pif.SriovCapable() ? Messages.NO : Messages.SRIOV_DISABLED;
                        Cells[9].Value = sriovSupported;
                    }
                    else
                    {
                        DelegatedAsyncAction action = new DelegatedAsyncAction(pif.Connection,
                                                                               "", "", "",
                                                                               delegate(Session session)
                        {
                            try
                            {
                                var remainingCapacity = Network_sriov.get_remaining_capacity(session, pif.sriov_physical_PIF_of[0].opaque_ref);
                                sriovSupported        = string.Format(Messages.REAMININF_VFS, remainingCapacity);
                            }
                            catch
                            {
                                sriovSupported = Messages.YES;
                            }
                        },
                                                                               true);

                        action.Completed += delegate
                        {
                            Program.Invoke(Program.MainWindow, delegate { Cells[9].Value = sriovSupported; });
                        };
                        action.RunAsync();
                    }

                    break;
                }
            }