示例#1
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.ManagementPurpose = src.ManagementPurpose;
     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;
 }
示例#2
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.ManagementPurpose);

            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.ManagementPurpose = new_pif.ManagementPurpose;
            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);
        }
示例#3
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.ManagementPurpose = 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);
        }
示例#4
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.ManagementPurpose = 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);
        }
示例#5
0
        /// <summary>
        /// If the "from" PIF is a secondary management interface,
        /// move the management interface name to the "to" PIF instead.
        /// </summary>
        internal static void MoveManagementInterfaceName(AsyncAction action, PIF from, PIF to)
        {
            string managementPurpose = from.ManagementPurpose;

            if (string.IsNullOrEmpty(managementPurpose))
                return;

            log.DebugFormat("Moving management interface name from {0} to {1}...", from.uuid, to.uuid);

            PIF to_clone = (PIF)to.Clone();
            to_clone.ManagementPurpose = from.ManagementPurpose;
            to_clone.SaveChanges(action.Session);

            PIF from_clone = (PIF)from.Clone();
            from_clone.ManagementPurpose = null;
            from_clone.SaveChanges(action.Session);

            log.DebugFormat("Moving management interface name from {0} to {1} done.", from.uuid, to.uuid);
        }
        /// <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);
        }