예제 #1
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            ResizeVerticalTabs(verticalTabs.Items.Count + 1);
            verticalTabs.SelectedItem = MakeSecondaryPage(null, AuxTabName());

            NetworkingPropertiesPage page = verticalTabs.SelectedItem as NetworkingPropertiesPage;

            RefreshNetworkComboBox(MakeProposedInUseMap(), page);
            ConfigurePage(page, null);
        }
예제 #2
0
        void prop_page_DeleteButtonClicked(object sender, EventArgs e)
        {
            NetworkingPropertiesPage prop_page = (NetworkingPropertiesPage)sender;
            int selectedIndex = verticalTabs.SelectedIndex;

            verticalTabs.Items.Remove(prop_page);
            verticalTabs.SelectedIndex = selectedIndex < verticalTabs.Items.Count - 1 ? selectedIndex : verticalTabs.Items.Count - 1;
            ContentPanel.Controls.Remove(prop_page);
            RefreshNetworkComboBoxes();
            RefreshButtons();
            ResizeVerticalTabs(verticalTabs.Items.Count);
        }
예제 #3
0
        private void AddTabContents(NetworkingPropertiesPage prop_page)
        {
            prop_page.HostCount               = connection.Cache.HostCount;
            prop_page.ValidChanged           += prop_page_ValidChanged;
            prop_page.DeleteButtonClicked    += prop_page_DeleteButtonClicked;
            prop_page.NetworkComboBoxChanged += prop_page_NetworkComboBoxChanged;
            prop_page.Parent = ContentPanel;
            prop_page.Dock   = DockStyle.Fill;

            verticalTabs.Items.Add(prop_page);

            RefreshButtons();
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pif">May be null, in which case the page is configured with reasonable defaults.</param>
        /// <param name="purpose"></param>
        /// <returns></returns>
        private NetworkingPropertiesPage MakeSecondaryPage(PIF pif, string purpose)
        {
            NetworkingPropertiesPage prop_page = MakeSecondaryPage(purpose);

            if (pif != null)
            {
                prop_page.Tag = pif;
            }

            if (pif == null)
            {
                prop_page.SelectName();
            }

            return(prop_page);
        }
예제 #5
0
        private void verticalTabs_MouseClick(object sender, MouseEventArgs e)
        {
            int pageIndex = verticalTabs.IndexFromPoint(e.Location);

            if (pageIndex < 0 || !MouseIsOnDeleteIcon(e.Location))
            {
                return;
            }

            NetworkingPropertiesPage page = verticalTabs.Items[pageIndex] as NetworkingPropertiesPage;

            if (page != null)
            {
                prop_page_DeleteButtonClicked(page, new EventArgs());
                HideTooltip();
            }
        }
예제 #6
0
        private NetworkingPropertiesPage MakeSecondaryPage(string purpose)
        {
            NetworkingPropertiesPage prop_page = new NetworkingPropertiesPage(NetworkingPropertiesPage.Type.SECONDARY);

            prop_page.Pool                = Pool != null;
            prop_page.Purpose             = purpose;
            prop_page.PurposeTextBox.Text = purpose;
            prop_page.RefreshButtons();

            prop_page.PurposeTextBox.TextChanged +=
                (EventHandler) delegate(object sender, EventArgs e)
            {
                prop_page.Text = prop_page.PurposeTextBox.Text;
            };

            AddTabContents(prop_page);

            return(prop_page);
        }
예제 #7
0
        private bool MouseIsOnDeleteIcon(Point mouseLocation)
        {
            int pageIndex = verticalTabs.IndexFromPoint(mouseLocation);

            if (pageIndex < 0)
            {
                return(false);
            }

            NetworkingPropertiesPage page = verticalTabs.Items[pageIndex] as NetworkingPropertiesPage;

            if (page == null)
            {
                return(false);
            }

            var bounds = page.DeleteIconBounds;

            return(bounds.Contains(mouseLocation));
        }
예제 #8
0
        private NetworkingPropertiesPage MakeSecondaryPage(string purpose)
        {
            NetworkingPropertiesPage prop_page = new NetworkingPropertiesPage(NetworkingPropertiesPage.Type.SECONDARY);

            prop_page.Pool                = Pool != null;
            prop_page.Purpose             = purpose;
            prop_page.PurposeTextBox.Text = purpose;
            prop_page.RefreshButtons();

            prop_page.PurposeTextBox.TextChanged += (sender, e) =>
            {
                if (sender is NetworkingPropertiesPage page)
                {
                    page.Text = page.PurposeTextBox.Text;
                }
            };
            AddTabContents(prop_page);

            return(prop_page);
        }
예제 #9
0
        private void Configure(PIF selectedPIF)
        {
            Text = string.Format(Messages.NETWORKING_PROPERTIES_TITLE, ObjectName);

            ShownPIFs = GetKnownPIFs(false);
            AllPIFs   = GetKnownPIFs(true);

            PIF management_pif = AllPIFs.Find(pif => pif.management);

            if (management_pif == null)
            {
                // Cache has not been populated yet, or is being cleared.
                return;
            }

            bool ha = (Pool != null && Pool.ha_enabled);  // CA-24714
            NetworkingPropertiesPage management_page = new NetworkingPropertiesPage(ha ? NetworkingPropertiesPage.Type.PRIMARY_WITH_HA : NetworkingPropertiesPage.Type.PRIMARY);

            management_page.Purpose = Messages.MANAGEMENT;
            AddTabContents(management_page);
            management_page.Tag = management_pif;

            foreach (PIF pif in ShownPIFs)
            {
                if (pif.opaque_ref != management_pif.opaque_ref && pif.IsSecondaryManagementInterface(true))
                {
                    MakeSecondaryPage(pif, Purpose(pif));
                }
            }

            var inusemap = MakeProposedInUseMap();

            foreach (NetworkingPropertiesPage page in verticalTabs.Items)
            {
                page.Pool = Pool != null;
                RefreshNetworkComboBox(inusemap, page);
            }

            foreach (NetworkingPropertiesPage page in verticalTabs.Items)
            {
                ConfigurePage(page, page.Tag as PIF);
            }

            if (selectedPIF != null)
            {
                foreach (NetworkingPropertiesPage item in verticalTabs.Items)
                {
                    if (item.Tag == selectedPIF)
                    {
                        verticalTabs.SelectedItem = item;
                        break;
                    }
                }
            }
            else
            {
                verticalTabs.SelectedIndex = 0;
            }

            ResizeVerticalTabs(verticalTabs.Items.Count);
            verticalTabs.AdjustItemTextBounds = GetItemTextBounds;
        }
예제 #10
0
        /// <summary>
        /// Will throw an exception if the network has gone away.
        /// </summary>
        /// <param name="page"></param>
        /// <param name="oldPIF"></param>
        /// <param name="newPIFs"></param>
        /// <param name="newNamePIFs"></param>
        private void CollateChanges(NetworkingPropertiesPage page, PIF oldPIF, List <PifTuple> newPIFs, List <PifTuple> newNamePIFs)
        {
            bool changed     = false;
            bool changedName = false;

            if (oldPIF == null)
            {
                // This tab is newly created.

                XenAPI.Network network = (XenAPI.Network)page.NetworkComboBox.SelectedItem;
                oldPIF = FindPIFForThisHost(network.PIFs);
                if (oldPIF == null)
                {
                    throw new Failure(Failure.INTERNAL_ERROR, "Network has gone away");
                }
                changed = true;
            }
            else
            {
                // This tab was populated when this dialog was launched.

                XenAPI.Network network = connection.Resolve(oldPIF.network);

                if ((XenAPI.Network)page.NetworkComboBox.SelectedItem != network)
                {
                    // The user has changed the network, so find the one we're using now.
                    XenAPI.Network new_network = (XenAPI.Network)page.NetworkComboBox.SelectedItem;
                    oldPIF = FindPIFForThisHost(new_network.PIFs);
                    if (oldPIF == null)
                    {
                        throw new Failure(Failure.INTERNAL_ERROR, "Network has gone away");
                    }
                    changed = true;
                }
            }

            PIF newPIF = (PIF)oldPIF.Clone();

            newPIF.PropertyChanged += (sender, e) => { changed = true; };

            PIF newNamePIF = (PIF)oldPIF.Clone();

            newNamePIF.PropertyChanged += (sender, e) => { changedName = true; };

            if (page.DHCPIPRadioButton.Checked)
            {
                newPIF.ip_configuration_mode = ip_configuration_mode.DHCP;
            }
            else
            {
                newPIF.ip_configuration_mode = ip_configuration_mode.Static;
                newPIF.netmask = page.SubnetTextBox.Text;
                newPIF.gateway = page.GatewayTextBox.Text;
                newPIF.IP      = page.IPAddressTextBox.Text;

                List <string> dns = new List <string>();
                if (page.PreferredDNSTextBox.Text.Length > 0)
                {
                    dns.Add(page.PreferredDNSTextBox.Text);
                }
                if (page.AlternateDNS1TextBox.Text.Length > 0)
                {
                    dns.Add(page.AlternateDNS1TextBox.Text);
                }
                if (page.AlternateDNS2TextBox.Text.Length > 0)
                {
                    dns.Add(page.AlternateDNS2TextBox.Text);
                }
                var newDns = string.Join(",", dns.ToArray());

                newPIF.DNS = newDns;
            }

            newPIF.management = page.type != NetworkingPropertiesPage.Type.SECONDARY;

            if (page.type == NetworkingPropertiesPage.Type.SECONDARY)
            {
                if (changed)
                {
                    newPIF.SetManagementPurpose(page.PurposeTextBox.Text);
                }
                else
                {
                    newNamePIF.SetManagementPurpose(page.PurposeTextBox.Text);
                }
            }

            newPIFs.Add(new PifTuple(newPIF, changed));
            newNamePIFs.Add(new PifTuple(newNamePIF, changedName));
        }
예제 #11
0
        /// <summary>
        /// Will throw an exception if the network has gone away.
        /// </summary>
        /// <param name="page"></param>
        /// <param name="oldPIF"></param>
        /// <param name="newPIFs"></param>
        private void CollateChanges(NetworkingPropertiesPage page, PIF oldPIF, List<PIF> newPIFs)
        {
            bool changed = false;

            if (oldPIF == null)
            {
                // This tab is newly created.

                XenAPI.Network network = (XenAPI.Network)page.NetworkComboBox.SelectedItem;
                oldPIF = FindPIFForThisHost(network.PIFs);
                if (oldPIF == null)
                    throw new Failure(Failure.INTERNAL_ERROR, "Network has gone away");
                changed = true;
            }
            else
            {
                // This tab was populated when this dialog was launched.

                XenAPI.Network network = connection.Resolve(oldPIF.network);

                if ((XenAPI.Network)page.NetworkComboBox.SelectedItem != network)
                {
                    // The user has changed the network, so find the one we're using now.
                    XenAPI.Network new_network = (XenAPI.Network)page.NetworkComboBox.SelectedItem;
                    oldPIF = FindPIFForThisHost(new_network.PIFs);
                    if (oldPIF == null)
                        throw new Failure(Failure.INTERNAL_ERROR, "Network has gone away");
                    changed = true;
                }
            }

            PIF newPIF = (PIF)oldPIF.Clone();
            newPIF.Changed = changed;

            if (page.DHCPIPRadioButton.Checked)
            {
                newPIF.ip_configuration_mode = ip_configuration_mode.DHCP;
            }
            else
            {
                newPIF.ip_configuration_mode = ip_configuration_mode.Static;
                newPIF.netmask = page.SubnetTextBox.Text;
                newPIF.gateway = page.GatewayTextBox.Text;
                newPIF.IP = page.IPAddressTextBox.Text;
                List<string> dns = new List<string>();
                if (page.PreferredDNSTextBox.Text.Length > 0)
                    dns.Add(page.PreferredDNSTextBox.Text);
                if (page.AlternateDNS1TextBox.Text.Length > 0)
                    dns.Add(page.AlternateDNS1TextBox.Text);
                if (page.AlternateDNS2TextBox.Text.Length > 0)
                    dns.Add(page.AlternateDNS2TextBox.Text);

                newPIF.DNS = string.Join(",", dns.ToArray());
            }

            if (page.type == NetworkingPropertiesPage.Type.SECONDARY)
            {
                newPIF.ManagementPurpose = page.PurposeTextBox.Text;
                newPIF.management = false;
            }
            else
                newPIF.management = true;

            newPIFs.Add(newPIF);
        }
예제 #12
0
        private void Configure(PIF selectedPIF)
        {
            Text = string.Format(Messages.NETWORKING_PROPERTIES_TITLE, ObjectName);

            ShownPIFs = GetKnownPIFs(false);
            AllPIFs = GetKnownPIFs(true);

            PIF management_pif =
                AllPIFs.Find(
                    delegate(PIF pif) { return pif.management; });

            if (management_pif == null)
            {
                // Cache has not been populated yet, or is being cleared.
                return;
            }

            bool ha = (Pool != null && Pool.ha_enabled);  // CA-24714
            NetworkingPropertiesPage management_page = new NetworkingPropertiesPage(ha ? NetworkingPropertiesPage.Type.PRIMARY_WITH_HA : NetworkingPropertiesPage.Type.PRIMARY);
            management_page.Purpose = Messages.MANAGEMENT;
            AddTabContents(management_page);
            management_page.Tag = management_pif;

            foreach (PIF pif in ShownPIFs)
            {
                if (pif.opaque_ref != management_pif.opaque_ref && pif.IsSecondaryManagementInterface(true))
                {
                    MakeSecondaryPage(pif, Purpose(pif));
                }
            }

            Dictionary<XenAPI.Network, List<NetworkingPropertiesPage>> inusemap =
                MakeProposedInUseMap();
            foreach (NetworkingPropertiesPage page in verticalTabs.Items)
            {
                page.Pool = Pool != null;
                RefreshNetworkComboBox(inusemap, page);
            }

            foreach (NetworkingPropertiesPage page in verticalTabs.Items)
            {
                ConfigurePage(page, page.Tag as PIF);
            }
            if (selectedPIF != null)
            {
                foreach (NetworkingPropertiesPage item in verticalTabs.Items)
                {
                    if (item.Tag == selectedPIF)
                    {
                        verticalTabs.SelectedItem = item;
                         break;
                    }
                }
            }
            else
                verticalTabs.SelectedIndex = 0;
            ResizeVerticalTabs(verticalTabs.Items.Count);
            verticalTabs.AdjustItemTextBounds = GetItemTextBounds;
        }
예제 #13
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pif">May be null, in which case the page is configured with reasonable defaults.</param>
        private void ConfigurePage(NetworkingPropertiesPage page, PIF pif)
        {
            if (pif == null)
            {
                page.SelectFirstUnusedNetwork();

                page.SubnetTextBox.Text = "";
                page.GatewayTextBox.Text = "";
                page.IPAddressTextBox.Text = "";

                page.DHCPIPRadioButton.Checked = true;
            }
            else
            {
                page.NetworkComboBox.SelectedItem = connection.Resolve(pif.network);

                page.SubnetTextBox.Text = pif.netmask;
                page.GatewayTextBox.Text = pif.gateway;
                page.IPAddressTextBox.Text = pif.IP;

                page.DHCPIPRadioButton.Checked = pif.ip_configuration_mode == ip_configuration_mode.DHCP;
            }

            string[] addresses = pif == null ? new string[] { "" } : pif.DNS.Split(',');
            page.PreferredDNSTextBox.Text = addresses[0];
            page.AlternateDNS1TextBox.Text = addresses.Length == 1 ? "" : addresses[1];
            page.AlternateDNS2TextBox.Text = addresses.Length <= 2 ? "" : addresses[2];
        }
예제 #14
0
 private void RefreshNetworkComboBox(Dictionary <XenAPI.Network, List <NetworkingPropertiesPage> > InUseMap, NetworkingPropertiesPage page)
 {
     page.RefreshNetworkComboBox(InUseMap, ManagementNetwork(), AllowManagementOnVLAN);
 }
예제 #15
0
        private void AddTabContents(NetworkingPropertiesPage prop_page)
        {
            prop_page.HostCount = connection.Cache.HostCount;
            prop_page.ValidChanged += new EventHandler(prop_page_ValidChanged);
            prop_page.DeleteButtonClicked += new EventHandler(prop_page_DeleteButtonClicked);
            prop_page.NetworkComboBoxChanged += new EventHandler(prop_page_NetworkComboBoxChanged);
            prop_page.Parent = ContentPanel;
            prop_page.Dock = DockStyle.Fill;

            verticalTabs.Items.Add(prop_page);

            RefreshButtons();
        }
예제 #16
0
 private void RefreshNetworkComboBox(Dictionary<XenAPI.Network, List<NetworkingPropertiesPage>> InUseMap, NetworkingPropertiesPage page)
 {
     page.RefreshNetworkComboBox(InUseMap, ManagementNetwork());
 }
예제 #17
0
        private NetworkingPropertiesPage MakeSecondaryPage(string purpose)
        {
            NetworkingPropertiesPage prop_page = new NetworkingPropertiesPage(NetworkingPropertiesPage.Type.SECONDARY);
            prop_page.Pool = Pool != null;
            prop_page.Purpose = purpose;
            prop_page.PurposeTextBox.Text = purpose;
            prop_page.RefreshButtons();

            prop_page.PurposeTextBox.TextChanged +=
                (EventHandler)delegate(object sender, EventArgs e)
                {
                    prop_page.Text = prop_page.PurposeTextBox.Text;
                };

            AddTabContents(prop_page);

            return prop_page;
        }