Beispiel #1
0
        private bool GetManagementInterfaceIPChanged(PIF oldManagement, PIF newManagement)
        {
            if (oldManagement == null || newManagement == null)
            {
                throw new Failure(Failure.INTERNAL_ERROR, "Management interface is null.");
            }

            if (oldManagement.ip_configuration_mode == ip_configuration_mode.DHCP)
            {
                if (newManagement.ip_configuration_mode == ip_configuration_mode.DHCP)
                {
                    return(!oldManagement.Equals(newManagement));
                }

                if (newManagement.ip_configuration_mode == ip_configuration_mode.Static)
                {
                    return(IPAddressSettingsChanged(oldManagement, newManagement));
                }
            }
            else if (oldManagement.ip_configuration_mode == ip_configuration_mode.Static)
            {
                if (newManagement.ip_configuration_mode == ip_configuration_mode.Static)
                {
                    return(IPAddressSettingsChanged(oldManagement, newManagement));
                }

                if (newManagement.ip_configuration_mode == ip_configuration_mode.DHCP)
                {
                    return(true);
                }
            }

            throw new Failure(Failure.INTERNAL_ERROR, "Unexpected IP configuration mode.");
        }
Beispiel #2
0
        private void AcceptBtn_Click(object sender, EventArgs e)
        {
            var        newPIFs     = new List <PifTuple>();
            var        newNamePIFs = new List <PifTuple>();
            List <PIF> downPIFs    = new List <PIF>();

            foreach (PIF pif in AllPIFs)
            {
                if (pif.IsManagementInterface(XenAdmin.Properties.Settings.Default.ShowHiddenVMs))
                {
                    downPIFs.Add(pif);
                }
            }

            try
            {
                foreach (NetworkingPropertiesPage page in verticalTabs.Items)
                {
                    CollateChanges(page, page.Tag as PIF, newPIFs, newNamePIFs);
                }
            }
            catch (Failure)
            {
                using (var dlg = new WarningDialog(Messages.NETWORK_RECONFIG_CONNECTION_LOST))
                    dlg.ShowDialog(this);
                this.Close();
                return;
            }

            bool displayWarning = false;
            bool managementInterfaceIPChanged = false;
            PIF  down_management = downPIFs.Find(p => p.management);
            PIF  new_management  = newPIFs.Select(p => p.Item1).FirstOrDefault(p => p.management);

            if (down_management != null)
            {
                if (new_management == null)
                {
                    throw new Failure(Failure.INTERNAL_ERROR, "Bringing down the management interface without bringing another one up is impossible!");
                }

                managementInterfaceIPChanged = GetManagementInterfaceIPChanged(down_management, new_management);
                displayWarning = managementInterfaceIPChanged ||
                                 (down_management.uuid != new_management.uuid ||
                                  down_management.ip_configuration_mode != new_management.ip_configuration_mode);

                if (down_management.Equals(new_management))
                {
                    // Management interface has not changed
                    down_management = null;
                }
            }

            // Any PIFs that are in downPIFs but also in newPIFs need to be removed from the former.
            // downPIFs should contain all those that we no longer want to keep up.
            downPIFs.RemoveAll(p => newPIFs.Any(np => np.Item1.uuid == p.uuid));

            // Remove any PIFs that haven't changed -- there's nothing to do for these ones.  They are in this
            // list originally so that they can be used as a filter against downPIFs.
            newPIFs.RemoveAll(p => !p.Item2);

            newNamePIFs.RemoveAll(p => !p.Item2);

            if (newNamePIFs.Count > 0)
            {
                new SetSecondaryManagementPurposeAction(connection, Pool, newNamePIFs.Select(p => p.Item1).ToList()).RunAsync();
            }

            if (newPIFs.Count > 0 || downPIFs.Count > 0)
            {
                if (displayWarning)
                {
                    string title = Pool == null ? Messages.NETWORKING_PROPERTIES_WARNING_CHANGING_MANAGEMENT_HOST
                        : Messages.NETWORKING_PROPERTIES_WARNING_CHANGING_MANAGEMENT_POOL;

                    DialogResult dialogResult;
                    using (var dlg = new WarningDialog(title,
                                                       new ThreeButtonDialog.TBDButton(Messages.NETWORKING_PROPERTIES_CHANGING_MANAGEMENT_CONTINUE, DialogResult.OK),
                                                       ThreeButtonDialog.ButtonCancel)
                    {
                        HelpName = "NetworkingPropertiesPMIWarning"
                    })
                    {
                        dialogResult = dlg.ShowDialog(this);
                    }
                    if (DialogResult.OK != dialogResult)
                    {
                        DialogResult = DialogResult.None;
                        return;
                    }
                }

                if (down_management == null)
                {
                    // We're actually just changing the IP address, not moving the management interface, so we just pass it in through newPIFs.
                    new_management = null;
                }
                else
                {
                    // We're switching the management interface over, so remove the old one from downPIFs -- it will be special-cased through
                    // down_management and new_management.
                    downPIFs.Remove(down_management);
                }

                // Reverse the lists so that the management interface is always last to be done.  If something's going to go wrong, then we'd like
                // the management interface to be the one that we don't break.
                newPIFs.Reverse();
                downPIFs.Reverse();

                new ChangeNetworkingAction(connection, Pool, Host, newPIFs.Select(p => p.Item1).ToList(), downPIFs,
                                           new_management, down_management, managementInterfaceIPChanged).RunAsync();
            }

            Close();
        }