Esempio n. 1
0
        internal DialogResult ShowCreationWarning()
        {
            List <PIF> pifs = BondedPIFs;

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

            if (will_disturb_primary && will_disturb_secondary)
            {
                new ThreeButtonDialog(
                    new ThreeButtonDialog.Details(
                        SystemIcons.Error,
                        Messages.BOND_CREATE_WILL_DISTURB_BOTH,
                        Messages.BOND_CREATE)).ShowDialog(this);

                return(DialogResult.Cancel);
            }

            if (will_disturb_primary)
            {
                Pool pool = Helpers.GetPool(Connection);
                if (pool != null && pool.ha_enabled)
                {
                    new ThreeButtonDialog(
                        new ThreeButtonDialog.Details(
                            SystemIcons.Error,
                            string.Format(Messages.BOND_CREATE_HA_ENABLED, pool.Name),
                            Messages.BOND_CREATE)).ShowDialog(this);

                    return(DialogResult.Cancel);
                }

                return(new ThreeButtonDialog(
                           new ThreeButtonDialog.Details(SystemIcons.Warning, Messages.BOND_CREATE_WILL_DISTURB_PRIMARY, Messages.BOND_CREATE),
                           "BondConfigError",
                           new ThreeButtonDialog.TBDButton(Messages.BOND_CREATE_CONTINUE, DialogResult.OK),
                           ThreeButtonDialog.ButtonCancel).ShowDialog(this));
            }

            if (will_disturb_secondary)
            {
                return(new ThreeButtonDialog(
                           new ThreeButtonDialog.Details(
                               SystemIcons.Warning,
                               Messages.BOND_CREATE_WILL_DISTURB_SECONDARY,
                               Messages.BOND_CREATE),
                           ThreeButtonDialog.ButtonOK,
                           ThreeButtonDialog.ButtonCancel).ShowDialog(this));
            }

            return(DialogResult.OK);
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
        internal bool CanCreateBond()
        {
            List <PIF> pifs = BondedPIFs;

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

            // It is not allowed to bond primary and secondary interfaces together.
            if (will_disturb_primary && will_disturb_secondary)
            {
                using (var dlg = new ThreeButtonDialog(
                           new ThreeButtonDialog.Details(
                               SystemIcons.Error,
                               Messages.BOND_CREATE_WILL_DISTURB_BOTH,
                               Messages.BOND_CREATE)))
                {
                    dlg.ShowDialog(this);
                }

                return(false);
            }

            // Only primary management interface.
            // In this case, clustering interface warning is hidden if it happens to be the management interface.
            if (will_disturb_primary)
            {
                Pool pool = Helpers.GetPool(Connection);
                if (pool != null && pool.ha_enabled)
                {
                    using (var dlg = new ThreeButtonDialog(
                               new ThreeButtonDialog.Details(
                                   SystemIcons.Error,
                                   string.Format(Messages.BOND_CREATE_HA_ENABLED, pool.Name()),
                                   Messages.BOND_CREATE)))
                    {
                        dlg.ShowDialog(this);
                    }

                    return(false);
                }

                DialogResult dialogResult;
                using (var dlg = new ThreeButtonDialog(
                           new ThreeButtonDialog.Details(SystemIcons.Warning, Messages.BOND_CREATE_WILL_DISTURB_PRIMARY, Messages.BOND_CREATE),
                           "BondConfigError",
                           new ThreeButtonDialog.TBDButton(Messages.BOND_CREATE_CONTINUE, DialogResult.OK),
                           ThreeButtonDialog.ButtonCancel))
                {
                    dialogResult = dlg.ShowDialog(this);
                }
                return(dialogResult == DialogResult.OK);
            }

            // Only secondary interface.
            // If there is clustering interface, shows clustering warning. Otherwise, shows secondary interface warning.
            if (will_disturb_secondary)
            {
                DialogResult dialogResult;
                if (will_disturb_clustering)
                {
                    using (var dlg = new ThreeButtonDialog(
                               new ThreeButtonDialog.Details(
                                   SystemIcons.Warning,
                                   Messages.BOND_CREATE_WILL_DISTURB_CLUSTERING,
                                   Messages.BOND_CREATE),
                               ThreeButtonDialog.ButtonOK,
                               ThreeButtonDialog.ButtonCancel))
                    {
                        dialogResult = dlg.ShowDialog(this);
                    }
                }

                else
                {
                    using (var dlg = new ThreeButtonDialog(
                               new ThreeButtonDialog.Details(
                                   SystemIcons.Warning,
                                   Messages.BOND_CREATE_WILL_DISTURB_SECONDARY,
                                   Messages.BOND_CREATE),
                               ThreeButtonDialog.ButtonOK,
                               ThreeButtonDialog.ButtonCancel))
                    {
                        dialogResult = dlg.ShowDialog(this);
                    }
                }

                return(dialogResult == DialogResult.OK);
            }

            return(true);
        }
Esempio n. 4
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 new_name;
            string msg;

            if (network != null && !Helpers.BostonOrGreater(network.Connection) && network.Connection.ResolveAll(network.VIFs).Count > 0)
            {
                // We have a live pre-Boston network.  Tell the user that we're going to rename it.
                new_name = Helpers.MakeUniqueName(Messages.RENAMED_BOND, GetAllNetworkNames(network.Connection));
                msg      = string.Format(Messages.DELETE_BOND_WITH_VIFS_MESSAGE, pif.Name, new_name);
            }
            else
            {
                // It's not in use -- delete the network as well as the bonds and PIFs.
                new_name = null;
                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)
                {
                    new ThreeButtonDialog(
                        new ThreeButtonDialog.Details(
                            SystemIcons.Error,
                            string.Format(Messages.BOND_DELETE_HA_ENABLED, pif.Name, pool.Name),
                            Messages.DELETE_BOND)).ShowDialog(Parent);
                    return;
                }

                string message = string.Format(will_disturb_secondary ? Messages.BOND_DELETE_WILL_DISTURB_BOTH : Messages.BOND_DELETE_WILL_DISTURB_PRIMARY, msg);
                if (DialogResult.OK !=
                    new ThreeButtonDialog(
                        new ThreeButtonDialog.Details(SystemIcons.Warning, message, Messages.DELETE_BOND),
                        "NetworkingConfigWarning",
                        new ThreeButtonDialog.TBDButton(Messages.BOND_DELETE_CONTINUE, DialogResult.OK),
                        ThreeButtonDialog.ButtonCancel).ShowDialog(Parent))
                {
                    return;
                }
            }
            else if (will_disturb_secondary)
            {
                if (DialogResult.OK !=
                    new ThreeButtonDialog(
                        new ThreeButtonDialog.Details(SystemIcons.Warning, string.Format(Messages.BOND_DELETE_WILL_DISTURB_SECONDARY, msg), Messages.XENCENTER),
                        ThreeButtonDialog.ButtonOK,
                        ThreeButtonDialog.ButtonCancel).ShowDialog(Parent))
                {
                    return;
                }
            }
            else
            {
                if (DialogResult.OK !=
                    new ThreeButtonDialog(
                        new ThreeButtonDialog.Details(SystemIcons.Warning, msg, Messages.XENCENTER),
                        new ThreeButtonDialog.TBDButton(Messages.OK, DialogResult.OK, ThreeButtonDialog.ButtonType.ACCEPT, true),
                        ThreeButtonDialog.ButtonCancel).ShowDialog(Program.MainWindow))
                {
                    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, new_name).RunAsync();
            }
        }