Beispiel #1
0
        /// <summary>
        /// Remove the IP address from the given PIF.
        /// </summary>
        private static void ClearIP(AsyncAction action, PIF pif, int hi)
        {
            // if the network is used by clustering, then we don't remove the IP address
            if (pif.IsUsedByClustering())
            {
                return;
            }

            log.DebugFormat("Removing IP address from {0} {1}...", pif.Name(), pif.uuid);
            action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_BRINGING_DOWN, pif.Name());

            action.RelatedTask = PIF.async_reconfigure_ip(action.Session, pif.opaque_ref, ip_configuration_mode.None, "", "", "", "");
            action.PollToCompletion(action.PercentComplete, hi);

            action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_BRINGING_DOWN_DONE, pif.Name());
            log.DebugFormat("Removed IP address from {0} {1}.", pif.Name(), pif.uuid);
        }
        /// <summary>
        /// Disable clustering on the host (if the network is used by clustering), before changing the management interface;
        /// Before disabling clustering we also unplug all the GFS2 SRs
        /// </summary>
        private void DisableClustering(PIF pif, out List <PBD> gfs2Pbds)
        {
            gfs2Pbds = new List <PBD>();
            if (!pif.IsUsedByClustering())
            {
                return;
            }

            var host = Connection.Resolve(pif.host);

            if (host == null)
            {
                return;
            }

            var clusterHost = Connection.Cache.Cluster_hosts.FirstOrDefault(c => c.host.opaque_ref == host.opaque_ref);

            if (clusterHost == null)
            {
                return;
            }

            // unplug the GFS2 SRs, saving the list of the PBDs unplugged, to plug back later
            foreach (var pbd in Connection.ResolveAll(host.PBDs).Where(pbd => pbd.currently_attached))
            {
                var sr = Connection.Resolve(pbd.SR);
                if (sr != null && sr.GetSRType(true) == SR.SRTypes.gfs2)
                {
                    gfs2Pbds.Add(pbd);
                    Description = string.Format(Messages.ACTION_SR_DETACHING, sr.Name(), host.Name());
                    PBD.unplug(Session, pbd.opaque_ref);
                }
            }

            // disable clustering
            Description = string.Format(Messages.DISABLING_CLUSTERING_ON_POOL, host.Name());
            log.Debug(Description);
            Cluster_host.disable(Session, clusterHost.opaque_ref);
        }
        /// <summary>
        /// Enable clustering on the host (if the network is used by clustering), after the management interface has been changed;
        /// After enabling clustering we also plug back all the GFS2 SRs that we unplugged
        /// </summary>
        private void EnableClustering(PIF pif, List <PBD> gfs2Pbds)
        {
            if (!pif.IsUsedByClustering())
            {
                return;
            }

            var host = Connection.Resolve(pif.host);

            if (host == null)
            {
                return;
            }

            var clusterHost = Connection.Cache.Cluster_hosts.FirstOrDefault(c => c.host.opaque_ref == host.opaque_ref);

            if (clusterHost == null)
            {
                return;
            }

            Description = string.Format(Messages.ENABLING_CLUSTERING_ON_POOL, host.Name());
            log.Debug(Description);
            PIF.set_disallow_unplug(Session, pif.opaque_ref, true);
            Cluster_host.enable(Session, clusterHost.opaque_ref);

            // plug the GFS2 SRs
            foreach (var pbd in gfs2Pbds.Where(pbd => !pbd.currently_attached))
            {
                var sr = Connection.Resolve(pbd.SR);
                if (sr != null)
                {
                    Description = string.Format(Messages.ACTION_SR_ATTACHING_TITLE, sr.Name(), host.Name());
                }
                PBD.plug(Session, pbd.opaque_ref);
            }
        }