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
        /// <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.SetManagementPurspose(src.GetManagementPurpose());
            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);
        }
Beispiel #3
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.GetManagementPurpose();

            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.SetManagementPurpose(from.GetManagementPurpose());
            to_clone.SaveChanges(action.Session);

            PIF from_clone = (PIF)from.Clone();

            from_clone.SetManagementPurpose(null);
            from_clone.SaveChanges(action.Session);

            log.DebugFormat("Moving management interface name from {0} to {1} done.", from.uuid, to.uuid);
        }
Beispiel #4
0
        private string Purpose(PIF pif)
        {
            string purpose = pif.GetManagementPurpose();

            return(string.IsNullOrEmpty(purpose) ? Messages.NETWORKING_PROPERTIES_PURPOSE_UNKNOWN : purpose);
        }
Beispiel #5
0
            public PIFRow(Host host, PIF pif)
            {
                this.pif = pif;

                // cell for the name of the management interface
                DataGridViewTextBoxCell nameCell = new DataGridViewTextBoxCell();

                nameCell.Value = Helpers.GetName(host);
                Cells.Add(nameCell);

                // the icon cell
                DataGridViewImageCell iconCell = new DataGridViewImageCell();

                iconCell.Value = Images.GetImage16For(pif);
                Cells.Add(iconCell);

                // the management purpose cell
                DataGridViewTextBoxCell interfaceCell = new DataGridViewTextBoxCell();
                string purpose;

                if (pif.management)
                {
                    purpose = Messages.MANAGEMENT;
                }
                else
                {
                    var managementPurpose = pif.GetManagementPurpose();
                    purpose = string.IsNullOrEmpty(managementPurpose) ? Messages.NETWORKING_PROPERTIES_PURPOSE_UNKNOWN : managementPurpose;
                }
                interfaceCell.Value = purpose;
                Cells.Add(interfaceCell);

                // the network cell
                DataGridViewTextBoxCell networkCell = new DataGridViewTextBoxCell();

                networkCell.Value = host.Connection.Resolve(pif.network).ToString();
                Cells.Add(networkCell);

                // the NIC cell
                DataGridViewTextBoxCell nicCell = new DataGridViewTextBoxCell();

                nicCell.Value = Helpers.GetName(pif);
                Cells.Add(nicCell);

                // the IP Setup cell
                DataGridViewTextBoxCell ipSetupCell = new DataGridViewTextBoxCell();

                ipSetupCell.Value = pif.IpConfigurationModeString();
                Cells.Add(ipSetupCell);

                // the ip address of the interface
                DataGridViewTextBoxCell ipCell = new DataGridViewTextBoxCell();

                ipCell.Value = pif.IP;
                Cells.Add(ipCell);
                // the subnet mask address of the interface
                DataGridViewTextBoxCell subnetCell = new DataGridViewTextBoxCell();

                subnetCell.Value = pif.netmask;
                Cells.Add(subnetCell);

                // the gateway address of the interface
                DataGridViewTextBoxCell gatewayCell = new DataGridViewTextBoxCell();

                gatewayCell.Value = pif.gateway;
                Cells.Add(gatewayCell);
                // the dns address of the interface
                DataGridViewTextBoxCell dnsCell = new DataGridViewTextBoxCell();

                dnsCell.Value = pif.DNS;
                Cells.Add(dnsCell);
            }