Esempio n. 1
0
        private void UnplugPBDs()
        {
            if (SR.PBDs.Count < 1)
            {
                return;
            }

            foreach (XenRef <PBD> pbd in SR.PBDs)
            {
                PBD.async_unplug(Session, pbd.opaque_ref);
            }
        }
Esempio n. 2
0
        protected override void RunWithSession(ref Session session)
        {
            Host hostObject = TryResolveWithTimeout(_host);

            PBD.CheckAndPlugPBDsFor(Connection.ResolveAll(hostObject.resident_VMs));

            Host.disable(session, _host.opaque_ref);

            Status = Messages.PLAN_ACTION_STATUS_MIGRATING_VMS_FROM_HOST;
            XenRef <Task> task = Host.async_evacuate(session, _host.opaque_ref);

            PollTaskForResultAndDestroy(Connection, ref session, task);
        }
Esempio n. 3
0
        private void DestroyPBDs(ref int inc)
        {
            if (SR.PBDs.Count < 1)
            {
                return;
            }

            foreach (XenRef <PBD> pbd in SR.PBDs)
            {
                RelatedTask = PBD.async_destroy(Session, pbd.opaque_ref);
                PollToCompletion(PercentComplete, PercentComplete + inc);
            }
        }
Esempio n. 4
0
            public RepairTreeNode(SR sr, Host host, PBD pdb)
            {
                SR   = sr;
                Host = host;
                PBD  = pdb;

                if (host == null)
                {
                    Text = sr.Name;
                }
                else
                {
                    Text = host.Name;
                }
            }
Esempio n. 5
0
        protected override Problem RunCheck()
        {
            if (!Host.IsLive())
            {
                return(new HostNotLiveWarning(this, Host));
            }

            IEnumerable <VM> runningOrPausedVMs = GetRunningOrPausedVMs(Host);
            IEnumerable <SR> brokenSRs          = PBD.GetSRs(PBD.GetUnpluggedPBDsFor(runningOrPausedVMs));

            foreach (SR sr in brokenSRs)
            {
                return(new BrokenSR(this, sr));
            }
            return(null);
        }
Esempio n. 6
0
        protected void EvacuateHost(ref Session session)
        {
            var hostObj = GetResolvedHost();

            Title = string.Format(Messages.PLANACTION_VMS_MIGRATING, hostObj.Name());
            PBD.CheckAndPlugPBDsFor(Connection.ResolveAll(hostObj.resident_VMs));

            log.DebugFormat("Disabling host {0}", hostObj.Name());
            Host.disable(session, HostXenRef.opaque_ref);

            Status = Messages.PLAN_ACTION_STATUS_MIGRATING_VMS_FROM_HOST;
            log.DebugFormat("Migrating VMs from host {0}", hostObj.Name());
            XenRef <Task> task = Host.async_evacuate(session, HostXenRef.opaque_ref);

            PollTaskForResultAndDestroy(Connection, ref session, task);
        }
Esempio n. 7
0
        protected void EvacuateHost(ref Session session)
        {
            var hostObj = GetResolvedHost();

            var vms = hostObj.GetRunningVMs();

            if (hostObj.enabled)
            {
                AddProgressStep(string.Format(Messages.UPDATES_WIZARD_ENTERING_MAINTENANCE_MODE, hostObj.Name()));
                log.DebugFormat("Disabling host {0}", hostObj.Name());
                Host.disable(session, HostXenRef.opaque_ref);
            }

            if (vms.Count > 0)
            {
                PBD.CheckPlugPBDsForVMs(Connection, vms);

                try
                {
                    AddProgressStep(string.Format(Messages.PLANACTION_VMS_MIGRATING, hostObj.Name()));
                    log.DebugFormat("Migrating VMs from host {0}", hostObj.Name());

                    XenRef <Task> task = Host.async_evacuate(session, HostXenRef.opaque_ref);
                    PollTaskForResultAndDestroy(Connection, ref session, task);
                }
                catch (Failure f)
                {
                    if (f.ErrorDescription.Count > 0 && f.ErrorDescription[0] == Failure.HOST_NOT_ENOUGH_FREE_MEMORY)
                    {
                        log.WarnFormat("Host {0} cannot be evacuated: {1}", hostObj.Name(), f.Message);
                        throw new Exception(string.Format(Messages.PLAN_ACTION_FAILURE_NOT_ENOUGH_MEMORY, hostObj.Name()), f);
                    }

                    if (f.ErrorDescription.Count > 0 && f.ErrorDescription[0] == Failure.NO_HOSTS_AVAILABLE)
                    {
                        log.WarnFormat("Host {0} cannot be evacuated: {1}", hostObj.Name(), f.Message);
                        if (hostObj.Connection.Cache.Hosts.Any(h => h.updates_requiring_reboot.Count > 0 && !h.enabled))
                        {
                            throw new Exception(string.Format(Messages.PLAN_ACTION_FAILURE_NO_HOSTS_AVAILABLE, hostObj.Name()));
                        }
                    }
                    throw;
                }
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Try to forget an SR that has previously failed to completely plug.  Nothrow guarantee.
 /// </summary>
 private void ForgetFailedSR(XenRef <SR> sr)
 {
     try
     {
         foreach (XenRef <PBD> pbd in XenAPI.SR.get_PBDs(Session, sr.opaque_ref))
         {
             if (PBD.get_currently_attached(Session, pbd))
             {
                 PBD.unplug(Session, pbd);
             }
         }
         XenAPI.SR.forget(Session, sr.opaque_ref);
     }
     catch
     {
         log.Debug("SR.forget() failed! Continuing anyway");
     }
 }
Esempio n. 9
0
        private void UnplugPBDs(ref int inc)
        {
            if (SR.PBDs.Count < 1)
            {
                return;
            }

            //CA-176935, CA-173497 - we need to run Unplug for the master last - creating a new list of hosts where the master is always the last
            var allPBDRefsToNonMaster = new List <XenRef <PBD> >();
            var allPBDRefsToMaster    = new List <XenRef <PBD> >();

            var master = Helpers.GetMaster(Connection);

            foreach (var pbdRef in SR.PBDs)
            {
                var pbd = Connection.Resolve(pbdRef);
                if (pbd != null)
                {
                    if (pbd.host != null)
                    {
                        var host = Connection.Resolve(pbd.host);
                        if (master != null && host != null && host.uuid == master.uuid)
                        {
                            allPBDRefsToMaster.Add(pbdRef);
                        }
                        else
                        {
                            allPBDRefsToNonMaster.Add(pbdRef);
                        }
                    }
                }
            }

            var allPBDRefs = new List <XenRef <PBD> >();

            allPBDRefs.AddRange(allPBDRefsToNonMaster);
            allPBDRefs.AddRange(allPBDRefsToMaster);

            foreach (XenRef <PBD> pbd in allPBDRefs)
            {
                RelatedTask = PBD.async_unplug(Session, pbd.opaque_ref);
                PollToCompletion(PercentComplete, PercentComplete + inc);
            }
        }
Esempio n. 10
0
        protected void EvacuateHost(ref Session session)
        {
            var hostObj = GetResolvedHost();

            var vms = hostObj.GetRunningVMs();

            AddProgressStep(string.Format(Messages.UPDATES_WIZARD_ENTERING_MAINTENANCE_MODE, hostObj.Name()));
            log.DebugFormat("Disabling host {0}", hostObj.Name());
            Host.disable(session, HostXenRef.opaque_ref);

            if (vms.Count > 0)
            {
                PBD.CheckPlugPBDsForVMs(Connection, vms);
                AddProgressStep(string.Format(Messages.PLANACTION_VMS_MIGRATING, hostObj.Name()));
                log.DebugFormat("Migrating VMs from host {0}", hostObj.Name());
                XenRef <Task> task = Host.async_evacuate(session, HostXenRef.opaque_ref);
                PollTaskForResultAndDestroy(Connection, ref session, task);
            }
        }
Esempio n. 11
0
        protected override void Run()
        {
            log.Debug("Running SR Reconfigure Action");
            log.DebugFormat("SR uuid = '{0}'", sr.uuid);
            log.DebugFormat("name = '{0}'", name);
            log.DebugFormat("description = '{0}'", description);

            Description = Messages.ACTION_SR_ATTACHING;

            // Repair the SR with new PBDs for each host in the pool
            PBD pbdTemplate = new PBD();

            pbdTemplate.currently_attached = false;
            pbdTemplate.device_config      = dconf;
            pbdTemplate.SR = new XenRef <SR>(sr.opaque_ref);

            int         delta     = 100 / (Connection.Cache.HostCount * 2);
            List <Host> _listHost = new List <Host>(Connection.Cache.Hosts);

            Util.masterFirst(_listHost);
            foreach (Host host in _listHost)
            {
                // Create the PBD
                log.DebugFormat("Creating PBD for host {0}", host.Name);
                this.Description = String.Format(Messages.ACTION_SR_REPAIR_CREATE_PBD, Helpers.GetName(host));
                pbdTemplate.host = new XenRef <Host>(host.opaque_ref);
                RelatedTask      = PBD.async_create(this.Session, pbdTemplate);
                PollToCompletion(PercentComplete, PercentComplete + delta);
                XenRef <PBD> pbdRef = new XenRef <PBD>(this.Result);

                // Now plug the PBD
                log.DebugFormat("Plugging PBD for host {0}", host.Name);
                this.Description = String.Format(Messages.ACTION_SR_REPAIR_PLUGGING_PBD, Helpers.GetName(host));
                RelatedTask      = PBD.async_plug(this.Session, pbdRef);
                PollToCompletion(PercentComplete, PercentComplete + delta);
            }

            // Update the name and description of the SR
            XenAPI.SR.set_name_label(Session, sr.opaque_ref, name);
            XenAPI.SR.set_name_description(Session, sr.opaque_ref, description);

            Description = Messages.ACTION_SR_ATTACH_SUCCESSFUL;
        }
Esempio n. 12
0
        /// <summary>
        /// Check currently LUN against miami host
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="pbd"></param>
        /// <returns></returns>
        private bool UniquenessCheckMiami(IXenConnection connection, PBD pbd)
        {
            if (!pbd.device_config.ContainsKey(SCSIID))
            {
                return(false);
            }

            String scsiID = pbd.device_config[SCSIID];
            String myLUN  = getIscsiLUN();

            if (!LunMap.ContainsKey(myLUN))
            {
                return(false);
            }

            ISCSIInfo info = LunMap[myLUN];

            return(info.ScsiID == scsiID);
        }
Esempio n. 13
0
        protected override void RunWithSession(ref Session session)
        {
            Host hostObject = TryResolveWithTimeout(_host);

            // If there are no patches that require reboot, we skip the evacuate-reboot-bringbabiesback sequence
            // But we only do this if we indicated that host restart should be avoided (by initializing the AvoidRestartHosts property)
            if (Helpers.ElyOrGreater(hostObject) && AvoidRestartHosts != null)
            {
                log.DebugFormat("Checking host.patches_requiring_reboot now on '{0}'...", hostObject);

                if (hostObject.patches_requiring_reboot.Count > 0)
                {
                    AvoidRestartHosts.Remove(hostObject.uuid);

                    log.DebugFormat("Restart is needed now (hostObject.patches_requiring_reboot has {0} items in it). Evacuating now. Will restart after.", hostObject.patches_requiring_reboot.Count);
                }
                else
                {
                    if (!AvoidRestartHosts.Contains(hostObject.uuid))
                    {
                        AvoidRestartHosts.Add(hostObject.uuid);
                    }

                    log.Debug("Will skip scheduled restart (livepatching succeeded), because hostObject.patches_requiring_reboot is empty.");

                    return;
                }
            }

            visible = true;

            PBD.CheckAndPlugPBDsFor(Connection.ResolveAll(hostObject.resident_VMs));

            log.DebugFormat("Disabling host {0}", hostObject.Name);
            Host.disable(session, _host.opaque_ref);

            Status = Messages.PLAN_ACTION_STATUS_MIGRATING_VMS_FROM_HOST;
            log.DebugFormat("Migrating VMs from host {0}", hostObject.Name);
            XenRef <Task> task = Host.async_evacuate(session, _host.opaque_ref);

            PollTaskForResultAndDestroy(Connection, ref session, task);
        }
Esempio n. 14
0
        private bool SrUsingLunExists(out SR theSr)
        {
            theSr = null;

            if (string.IsNullOrEmpty(getIscsiLUN()))
            {
                return(false);
            }

            foreach (IXenConnection connection in ConnectionsManager.XenConnectionsCopy)
            {
                foreach (SR sr in connection.Cache.SRs)
                {
                    if (sr.GetSRType(false) != SR.SRTypes.lvmoiscsi && sr.GetSRType(false) != SR.SRTypes.gfs2)
                    {
                        continue;
                    }

                    if (sr.PBDs.Count < 1)
                    {
                        continue;
                    }

                    PBD pbd = connection.Resolve(sr.PBDs[0]);

                    if (pbd == null)
                    {
                        continue;
                    }

                    if (pbd.device_config.TryGetValue(SCSIID, out var scsiId) &&
                        LunMap.TryGetValue(getIscsiLUN(), out var info) &&
                        info.ScsiID == scsiId)
                    {
                        theSr = sr;
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 15
0
        /// <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>();
            var isUsedByClustering = Connection.Cache.Clusters.Any(cluster => cluster.network.opaque_ref == pif.network.opaque_ref);

            if (!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);
        }
Esempio n. 16
0
        protected override void Run()
        {
            foreach (XenRef <PBD> pbd in sr.PBDs)
            {
                RelatedTask = PBD.async_destroy(Session, pbd.opaque_ref);
                PollToCompletion();
            }

            Description = Messages.ACTION_SR_ATTACHING;

            // Now repair the SR with new PBDs for each host in the pool
            PBD pbdTemplate = new PBD();

            pbdTemplate.currently_attached = false;
            pbdTemplate.device_config      = dconf;
            pbdTemplate.SR = new XenRef <SR>(sr.opaque_ref);

            int         delta     = 100 / (Connection.Cache.HostCount * 2);
            List <Host> _listHost = new List <Host>(Connection.Cache.Hosts);

            masterFirst(_listHost);
            foreach (Host host in _listHost)
            {
                // Create the PBD
                log.DebugFormat("Creating PBD for host {0}", host.Name);
                this.Description = String.Format(Messages.ACTION_SR_REPAIR_CREATE_PBD, Helpers.GetName(host));
                pbdTemplate.host = new XenRef <Host>(host.opaque_ref);
                RelatedTask      = PBD.async_create(this.Session, pbdTemplate);
                PollToCompletion(PercentComplete, PercentComplete + delta);
                XenRef <PBD> pbdRef = new XenRef <PBD>(this.Result);

                // Now plug the PBD
                log.DebugFormat("Plugging PBD for host {0}", host.Name);
                this.Description = String.Format(Messages.ACTION_SR_REPAIR_PLUGGING_PBD, Helpers.GetName(host));
                RelatedTask      = PBD.async_plug(this.Session, pbdRef);
                PollToCompletion(PercentComplete, PercentComplete + delta);
            }

            Description = Messages.ACTION_SR_ATTACH_SUCCESSFUL;
        }
Esempio n. 17
0
        /// <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)
        {
            var isUsedByClustering = Connection.Cache.Clusters.Any(cluster => cluster.network.opaque_ref == pif.network.opaque_ref);

            if (!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);
            }
        }
        private List <SRDeviceConfig> GetFCSRDeviceConfigList(List <SR> requiredSRs)
        {
            List <SRDeviceConfig> srDeviceConfigList = new List <SRDeviceConfig>();

            List <SR> fcSRList = requiredSRs.FindAll(FibreChannelSR);

            foreach (SR fcSR in fcSRList)
            {
                Dictionary <string, string> dconf = null;
                if (fcSR.PBDs.Count > 0)
                {
                    dconf = PBD.get_device_config(MetadataSession, fcSR.PBDs[0].opaque_ref);
                }

                if (dconf != null)
                {
                    srDeviceConfigList.Add(new SRDeviceConfig(fcSR, dconf));
                }
            }

            return(srDeviceConfigList);
        }
Esempio n. 19
0
        protected override void RunWithSession(ref Session session)
        {
            PBD.CheckPlugPBDsForVMs(Connection, _vms);

            int vmCount = _vms.Count;

            for (int i = 0; i < _vms.Count; i++)
            {
                var           vmRef = _vms[i];
                XenRef <Task> task  = DoPerVM(session, vmRef);

                try
                {
                    var j = i;
                    PollTaskForResult(Connection, ref session, task,
                                      progress => PercentComplete = (progress + 100 * j) / vmCount);
                }
                finally
                {
                    Task.destroy(session, task);
                }
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Check currently LUN against miami host
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="pbd"></param>
        /// <returns></returns>
        private bool UniquenessCheckMiami(IXenConnection connection, PBD pbd)
        {
            if (!pbd.device_config.ContainsKey(SCSIID))
            {
                return(false);
            }
            foreach (string s in pbd.device_config.Keys)
            {
                String scsiID = pbd.device_config[s];
                String myLUN  = getIscsiLUN();

                if (!LunMap.ContainsKey(myLUN))
                {
                    return(false);
                }

                ISCSIInfo info = LunMap[myLUN];
                if (info.ScsiID == scsiID)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 21
0
        /// <summary>
        /// Destroys any PBDs on the SR and sets the SR to be unshared.
        ///
        /// No throw.
        /// </summary>
        private void rollback()
        {
            try
            {
                Description = string.Format(Messages.SR_SHARE_REVERTING2, SR.Name);

                foreach (PBD broke in Connection.ResolveAll(SR.PBDs))
                {
                    if (!broke.currently_attached && !broke.Locked)
                    {
                        PBD.destroy(Session, broke.opaque_ref);
                    }
                }

                XenAPI.SR.set_shared(Session, SR.opaque_ref, false);

                Description = string.Format(Messages.SR_SHARE_REVERTED, SR.Name);
            }
            catch (Exception e)
            {
                log.Error("Exception rolling back SR shared action");
                log.Error(e, e);
            }
        }
        private void ComposeSRData()
        {
            m_SRs = new List <SRInfo>();
            var SRs = new List <XenAPI.SR>(Connection.Cache.SRs);

            SRs.Sort();
            foreach (XenAPI.SR sr in SRs)
            {
                if (Cancelling)
                {
                    throw new CancelledException();
                }

                string srSizeString = SRSizeString(sr);

                string locationStr    = "";
                bool   haveLocation   = false;
                bool   haveServerPath = false;
                bool   haveDevice     = false;
                bool   haveTargetIQN  = false;
                bool   haveSCSIid     = false;
                foreach (XenRef <PBD> pbdRef in sr.PBDs)
                {
                    PBD pbd = sr.Connection.Resolve(pbdRef);

                    if (!haveLocation && pbd.device_config.ContainsKey("location"))
                    {
                        haveLocation = true;
                        locationStr += "location:" + pbd.device_config["location"] + ";";
                    }
                    if (!haveDevice && pbd.device_config.ContainsKey("device"))
                    {
                        haveDevice   = true;
                        locationStr += "device:" + pbd.device_config["device"] + ";";
                    }
                    if (!haveSCSIid && pbd.device_config.ContainsKey("SCSIid"))
                    {
                        haveSCSIid   = true;
                        locationStr += "SCSIid:" + pbd.device_config["SCSIid"] + ";";
                    }
                    if (!haveTargetIQN && pbd.device_config.ContainsKey("targetIQN"))
                    {
                        haveTargetIQN = true;
                        locationStr  += "targetIQN:" + pbd.device_config["targetIQN"] + ";";
                    }
                    if (!haveServerPath && pbd.device_config.ContainsKey("server"))
                    {
                        haveServerPath = true;
                        locationStr   += "server:" + pbd.device_config["server"];
                        if (pbd.device_config.ContainsKey("serverpath"))
                        {
                            locationStr += pbd.device_config["serverpath"] + ";";
                        }
                        else
                        {
                            locationStr += ";";
                        }
                    }
                }
                if (locationStr.Length == 0)
                {
                    locationStr = Messages.HYPHEN;
                }

                SRInfo buf = new SRInfo(sr.Name(), sr.uuid, sr.type, srSizeString, locationStr, sr.Description());
                m_SRs.Add(buf);
                PercentComplete = Convert.ToInt32((++itemIndex) * baseIndex / itemCount);
            }
        }
Esempio n. 23
0
        public object hostcollect(Session session)
        {
            ArrayList vmc = new ArrayList();
            int       ne  = 1;
            string    log;
            string    entry;
            string    mydocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);


            try
            {
                //Session session = new Session(server, Convert.ToInt32(port));
                //session.login_with_password(username, password);


                List <XenRef <Host> >     hostRefs = Host.get_all(session);
                List <XenRef <Host_cpu> > hcpuRefs = Host_cpu.get_all(session);


                foreach (XenRef <Host> hostRef in hostRefs)
                {
                    Host host = Host.get_record(session, hostRef);
                    XenRef <Host_metrics> gmsref = Host.get_metrics(session, host.opaque_ref);
                    Host_metrics          gms    = Host_metrics.get_record(session, gmsref);

                    vmc.Add("Xenserver Name:");
                    try
                    {
                        vmc.Add(Convert.ToString(host.name_label));
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }

                    vmc.Add("Hostname:");
                    try
                    {
                        vmc.Add(Convert.ToString(host.hostname));
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }

                    vmc.Add("Is Host alive:");
                    try
                    {
                        vmc.Add(Convert.ToString(gms.live));
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }

                    vmc.Add("IP address:");
                    try
                    {
                        vmc.Add("Not displayed in demo version");
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }

                    vmc.Add("Total Host Memory:");
                    try
                    {
                        vmc.Add("Not displayed in demo version");
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }
                    vmc.Add("Host Memory Free:");
                    try
                    {
                        vmc.Add("Not displayed in demo version");
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }
                    vmc.Add("Number CPU cores:");
                    try
                    {
                        vmc.Add("Not displayed in demo version");
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }
                    try
                    {
                        foreach (XenRef <Host_cpu> hcpuRef in hcpuRefs)
                        {
                            Host_cpu hcpu = Host_cpu.get_record(session, hcpuRef);


                            if (hcpu.host.ServerOpaqueRef == hostRef)
                            {
                                vmc.Add("CPU Core Number:");
                                try
                                {
                                    vmc.Add(Convert.ToString(hcpu.number));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("CPU Core Vendor:");
                                try
                                {
                                    vmc.Add(Convert.ToString(hcpu.vendor));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("CPU Core Model Name:");
                                try
                                {
                                    vmc.Add(Convert.ToString(hcpu.modelname));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("CPU Core Speed:");
                                try
                                {
                                    vmc.Add("Not displayed in demo version");
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("CPU Core Stepping Revesion:");
                                try
                                {
                                    vmc.Add(hcpu.stepping);
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("CPU Core Family:");
                                try
                                {
                                    vmc.Add(Convert.ToString(hcpu.family));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                            }
                        }
                    }
                    catch
                    {
                    }

                    vmc.Add("ISCSI IQN Name:");
                    try
                    {
                        vmc.Add("Not displayed in demo version");
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }
                    vmc.Add("Number of Allowed Operations:");
                    try
                    {
                        vmc.Add(Convert.ToString(host.allowed_operations.Count));
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }
                    try
                    {
                        for (int i = 0; i <= host.allowed_operations.Count - 1;)
                        {
                            vmc.Add("Allowed Operation:");
                            try
                            {
                                vmc.Add(Convert.ToString(host.allowed_operations[i]));
                            }
                            catch
                            {
                                vmc.Add("Data not available");
                                log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                writelog.entry(log, entry);
                                ne++;
                            }
                            i = i + 1;
                        }
                    }
                    catch
                    {
                    }

                    vmc.Add("Xenserver version:");
                    try
                    {
                        vmc.Add(Convert.ToString(host.software_version["product_version"]));
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }
                    vmc.Add("Build Number:");
                    try
                    {
                        vmc.Add(Convert.ToString(host.software_version["build_number"]));
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }
                    vmc.Add("Kernel version:");
                    try
                    {
                        vmc.Add(Convert.ToString(host.software_version["linux"]));
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }
                    vmc.Add("API version:");
                    try
                    {
                        vmc.Add(Convert.ToString(host.API_version_vendor));
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }
                    vmc.Add("Number of Physical Block Devices (PBD):");
                    try
                    {
                        vmc.Add(Convert.ToString(host.PBDs.Count));
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }
                    try
                    {
                        for (int i = 0; i <= host.PBDs.Count - 1;)
                        {
                            if (host.PBDs[i].ServerOpaqueRef == "OpaqueRef:NULL")
                            {
                            }
                            else
                            {
                                PBD pbd = PBD.get_record(session, host.PBDs[i].ServerOpaqueRef);

                                Dictionary <String, String> dict = null;
                                dict = pbd.device_config;
                                String pdninfo = null;
                                foreach (String keyStr in dict.Keys)
                                {
                                    if (keyStr == "location" || keyStr == "device")
                                    {
                                        pdninfo = (String)(dict[keyStr]);
                                        vmc.Add("Physical Block Devices:");
                                        try
                                        {
                                            vmc.Add(Convert.ToString(pdninfo));
                                        }
                                        catch
                                        {
                                            log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                            entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                            writelog.entry(log, entry);
                                            ne++;
                                        }
                                    }
                                }
                                i = i + 1;
                            }
                        }
                    }
                    catch
                    {
                    }
                    vmc.Add("Number of Physical NICs (PIF):");
                    try
                    {
                        vmc.Add(Convert.ToString(host.PIFs.Count));
                    }
                    catch
                    {
                        vmc.Add("Data not available");
                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                        writelog.entry(log, entry);
                        ne++;
                    }
                    try
                    {
                        for (int i = 0; i <= host.PIFs.Count - 1;)
                        {
                            if (host.PIFs[i].ServerOpaqueRef == "OpaqueRef:NULL")
                            {
                            }
                            else
                            {
                                PIF         vbd = PIF.get_record(session, Convert.ToString(host.PIFs[i].ServerOpaqueRef));
                                PIF_metrics pif = PIF_metrics.get_record(session, vbd.metrics);


                                vmc.Add("PIF IP Address:");
                                try
                                {
                                    vmc.Add("Not displayed in demo version");
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("PIF Netmask:");
                                try
                                {
                                    vmc.Add(Convert.ToString(vbd.netmask));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("PIF DHCP/Static:");
                                try
                                {
                                    vmc.Add(Convert.ToString(vbd.ip_configuration_mode));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("PIF MAC Address:");
                                try
                                {
                                    vmc.Add("Not displayed in demo version");
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("PIF DNS servers:");
                                try
                                {
                                    vmc.Add("Not displayed in demo version");
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("PIF Gateway:");
                                try
                                {
                                    vmc.Add(Convert.ToString(vbd.gateway));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                if (vbd.other_config.Count >= 1)
                                {
                                    vmc.Add("PIF Domain:");
                                    try
                                    {
                                        vmc.Add(Convert.ToString(vbd.other_config["domain"]));
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                        writelog.entry(log, entry);
                                        ne++;
                                    }
                                }
                                vmc.Add("PIF VLAN ID:");
                                try
                                {
                                    vmc.Add(Convert.ToString(vbd.VLAN));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("PIF MTU:");
                                try
                                {
                                    vmc.Add(Convert.ToString(vbd.MTU));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("PIF Device:");
                                try
                                {
                                    vmc.Add(Convert.ToString(vbd.device));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("Is PIF attached:");
                                try
                                {
                                    vmc.Add(Convert.ToString(vbd.currently_attached));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }

                                vmc.Add("PIF Device Name:");
                                try
                                {
                                    vmc.Add(Convert.ToString(pif.device_name));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("PIF Device ID:");
                                try
                                {
                                    vmc.Add(Convert.ToString(pif.device_id));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("PIF Vendor Name:");
                                try
                                {
                                    vmc.Add(Convert.ToString(pif.vendor_name));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("PIF Vendor ID:");
                                try
                                {
                                    vmc.Add(Convert.ToString(pif.vendor_id));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("PIF Speed:");
                                if (Convert.ToString(pif.speed) == "65535")
                                {
                                    vmc.Add("PIF not connected");
                                }
                                else
                                {
                                    try
                                    {
                                        vmc.Add(Convert.ToString(pif.speed));
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                        entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                        writelog.entry(log, entry);
                                        ne++;
                                    }
                                }
                                vmc.Add("PIF is set to duplex:");
                                try
                                {
                                    vmc.Add(Convert.ToString(pif.duplex));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("PIF PCI Bus:");
                                try
                                {
                                    vmc.Add(Convert.ToString(pif.pci_bus_path));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;
                                }
                                vmc.Add("PIF Carrier:");
                                try
                                {
                                    vmc.Add(Convert.ToString(pif.carrier));
                                }
                                catch
                                {
                                    vmc.Add("Data not available");
                                    log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                    entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Error " + ne;
                                    writelog.entry(log, entry);
                                    ne++;;
                                }
                                i = i + 1;
                            }
                        }
                    }
                    catch
                    {
                    }
                    ne = 1;
                }
                log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Finished ";
                writelog.entry(log, entry);
            }
            catch
            {
                log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                entry = DateTime.Now.ToString("HH:mm:ss") + " Host Collection Failed";
                writelog.entry(log, entry);
            }
            if ((vmc.Count & 2) == 0)
            {
            }
            else
            {
                vmc.Add(" ");
            }



            return(vmc);
        }
Esempio n. 24
0
        protected override void Run()
        {
            log.Debug("Running SR repair");
            log.DebugFormat("SR='{0}'", SR.Name());

            //CA-176935, CA-173497 - we need to run Plug for the master first - creating a new list of hosts where the master is always first
            var allHosts = new List <Host>();

            var master = Helpers.GetMaster(Connection);

            if (master != null)
            {
                allHosts.Add(master);
            }

            foreach (var host in Connection.Cache.Hosts)
            {
                if (!allHosts.Contains(host))
                {
                    allHosts.Add(host);
                }
            }

            foreach (Host host in allHosts)
            {
                Host stoHost = SR.GetStorageHost();
                if (SR.shared ||
                    (stoHost != null && host.opaque_ref == stoHost.opaque_ref))
                {
                    _hostList.Add(host);
                }
            }

            if (_hostList.Count == 0)
            {
                return;
            }

            for (int i = 0; i < _hostList.Count; i++)
            {
                log.DebugFormat("_hostList[{0}]='{1}'", i, _hostList[i].Name());
            }

            int max   = _hostList.Count * 2;
            int delta = 100 / max;

            foreach (Host host in _hostList)
            {
                if (!host.HasPBDTo(SR) && SR.shared && SR.PBDs.Count > 0)
                {
                    PBD template = SR.Connection.Resolve(SR.PBDs[0]);
                    if (template != null)
                    {
                        this.Description = string.Format(Messages.ACTION_SR_REPAIR_CREATE_PBD, Helpers.GetName(host));
                        log.Debug(this.Description);

                        var newPbd = new PBD
                        {
                            currently_attached = false,
                            device_config      = new Dictionary <string, string>(template.device_config),
                            SR   = template.SR,
                            host = new XenRef <Host>(host.opaque_ref)
                        };

                        try
                        {
                            RelatedTask = XenAPI.PBD.async_create(this.Session, newPbd);

                            if (PercentComplete + delta <= 100)
                            {
                                PollToCompletion(PercentComplete, PercentComplete + delta);
                            }
                            else
                            {
                                PollToCompletion(PercentComplete, 100);
                                PercentComplete = 100;
                            }
                        }
                        catch (XenAPI.Failure f)
                        {
                            failure            = f;
                            failureDescription = Description;
                        }
                    }
                }
                else
                {
                    PercentComplete += delta;
                }

                PBD thePBD = host.GetPBDTo(SR);
                if (thePBD != null && !thePBD.currently_attached)
                {
                    this.Description = string.Format(Messages.ACTION_SR_REPAIR_PLUGGING_PBD, Helpers.GetName(host));
                    log.Debug(this.Description);

                    try
                    {
                        RelatedTask = XenAPI.PBD.async_plug(this.Session, thePBD.opaque_ref);

                        if (PercentComplete + delta <= 100)
                        {
                            PollToCompletion(PercentComplete, PercentComplete + delta);
                        }
                        else
                        {
                            PollToCompletion(PercentComplete, 100);
                            PercentComplete = 100;
                        }
                    }
                    catch (XenAPI.Failure f)
                    {
                        failure            = f;
                        failureDescription = Description;
                    }
                }
                else
                {
                    PercentComplete += delta;
                }
            }

            if (failure != null && failureDescription != null)
            {
                Description = failureDescription;
                throw failure;
            }

            // CA-14928: Sometimes we have too many PBDs if there has just been a host
            // eject and the GC hasn't collected the PBD yet.
            //
            //if (SR.PBDs.Count != _hostList.Count && SR.shared && !SR.IsToolsSR)
            //{
            //    throw new Exception(Messages.ACTION_SR_REPAIR_FAILED);
            //}
            if (isSharedAction)
            {
                Description = string.Format(Messages.ACTION_SR_SHARE_SUCCESSFUL, SR.NameWithoutHost());
            }
            else
            {
                Description = string.Format(Messages.ACTION_SR_REPAIR_SUCCESSFUL, SR.NameWithoutHost());
            }
        }
        protected override void RunWithSession(ref Session session)
        {
            Status = Messages.PLAN_ACTION_STATUS_RECONNECTING_STORAGE;
            PBD.CheckAndBestEffortPlugPBDsFor(Connection, _vms);

            //
            // CA-17428: Apply hotfixes to a pool of hosts through XenCenter fails.
            //
            // Host do reenable themselves anyway, so just wait 1 min for that,
            // occasionally poking it.
            //

            int retries = 0;

            Status = Messages.PLAN_ACTION_STATUS_REENABLING_HOST;
            while (!Host.get_enabled(session, _host.opaque_ref))
            {
                retries++;

                Thread.Sleep(1000);

                try
                {
                    Host.enable(session, _host.opaque_ref);
                }
                catch (Exception e)
                {
                    if (retries > 60)
                    {
                        throw;
                    }

                    log.Debug(string.Format("Cannot enable host {0}. Retrying in 1 sec.", _host.opaque_ref), e);
                }
            }

            if (_enableOnly)
            {
                return;
            }

            int vmCount  = _vms.Count;
            int vmNumber = 0;

            foreach (VM vm in Connection.ResolveAll(_vms))
            {
                int tries = 0;

                if (vm.power_state != vm_power_state.Running)
                {
                    continue; // vm may have been shutdown or suspended.
                }
                do
                {
                    tries++;

                    try
                    {
                        Status = string.Format(Messages.PLAN_ACTION_STATUS_MIGRATING_VM_X_OF_Y, vmNumber + 1, vmCount);

                        log.DebugFormat("Migrating VM '{0}' back to Host '{1}'", Helpers.GetName(vm),
                                        Helpers.GetName(Connection.Resolve(_host)));

                        PollTaskForResultAndDestroy(Connection, ref session,
                                                    VM.async_live_migrate(session, vm.opaque_ref, _host.opaque_ref),
                                                    (vmNumber * 100) / vmCount, ((vmNumber + 1) * 100) / vmCount);

                        vmNumber++;
                    }
                    catch (Failure e)
                    {
                        // When trying to put the first vm back, we get all sorts
                        // of errors ie storage not plugged yet etc.  Just ignore them for now

                        if (vmNumber > 0 || tries > 24)
                        {
                            throw;
                        }

                        log.Debug(string.Format("Error migrating VM '{0}' back to Host '{1}'",
                                                Helpers.GetName(vm), Helpers.GetName(Connection.Resolve(_host))), e);

                        Thread.Sleep(5000);
                    }
                } while (vmNumber == 0);
            }

            Host hostModelObject = Connection.Resolve(_host);

            if (hostModelObject != null)
            {
                log.DebugFormat("Cleaning up evacuated VMs from Host '{0}'", hostModelObject.Name);
                hostModelObject.ClearEvacuatedVMs(session);
            }
        }
Esempio n. 26
0
        protected override void Run()
        {
            if (xo == null)
            {
                return;
            }
            Host theHost = xo as Host;

            // Dom0 Memory usage alert is an exception. While configuration for all the alerts (eg. related to the Host) have to be saved to this "xo",
            // dom0 Memory usage's has to be in the Dom0's other config.
            //
            var dom0_memory_usage = perfmonDefinitions.FirstOrDefault(d => d.IsDom0MemoryUsage);

            if (dom0_memory_usage != null)
            {
                perfmonDefinitions.Remove(dom0_memory_usage);

                var dom0Vm = theHost == null ? null : theHost.ControlDomainZero;
                if (dom0Vm != null)
                {
                    var dom0PerfmonDefinitions = PerfmonDefinition.GetPerfmonDefinitions(dom0Vm).ToList();

                    bool found = false;
                    for (int ii = 0; ii < dom0PerfmonDefinitions.Count; ii++)
                    {
                        var pmd = dom0PerfmonDefinitions[ii];
                        if (pmd != null && pmd.IsDom0MemoryUsage)
                        {
                            dom0PerfmonDefinitions[ii] = dom0_memory_usage;
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        dom0PerfmonDefinitions.Add(dom0_memory_usage);
                    }

                    string dom0PerfmonConfigXML = PerfmonDefinition.GetPerfmonDefinitionXML(dom0PerfmonDefinitions);
                    Helpers.SetOtherConfig(Session, dom0Vm, PerfmonDefinition.PERFMON_KEY_NAME, dom0PerfmonConfigXML);
                }
            }
            else
            {
                var dom0Vm = theHost == null ? null : theHost.ControlDomainZero;
                if (dom0Vm != null)
                {
                    var dom0PerfmonDefinitions = PerfmonDefinition.GetPerfmonDefinitions(dom0Vm).ToList();

                    int found = dom0PerfmonDefinitions.RemoveAll(d => d.IsDom0MemoryUsage);
                    if (found > 0)
                    {
                        string dom0PerfmonDefinitionsXml = PerfmonDefinition.GetPerfmonDefinitionXML(dom0PerfmonDefinitions);
                        Helpers.SetOtherConfig(Session, dom0Vm, PerfmonDefinition.PERFMON_KEY_NAME, dom0PerfmonDefinitionsXml);
                    }
                }
            }

            if (perfmonDefinitions == null || perfmonDefinitions.Count == 0)
            {
                Helpers.RemoveFromOtherConfig(Session, xo, PerfmonDefinition.PERFMON_KEY_NAME);
            }
            else
            {
                string perfmonConfigXML = PerfmonDefinition.GetPerfmonDefinitionXML(perfmonDefinitions);
                Helpers.SetOtherConfig(Session, xo, PerfmonDefinition.PERFMON_KEY_NAME, perfmonConfigXML);
            }

            var hosts = new List <Host>();

            if (theHost == null)
            {
                VM vm = xo as VM;
                if (vm == null)
                {
                    SR sr = xo as SR;
                    if (sr != null)
                    {
                        foreach (var pbdRef in sr.PBDs)
                        {
                            PBD pbd = sr.Connection.Resolve(pbdRef);
                            if (pbd == null)
                            {
                                continue;
                            }

                            var host = pbd.Connection.Resolve(pbd.host);
                            if (host != null)
                            {
                                hosts.Add(host);
                            }
                        }
                    }
                }
                else
                {
                    var host = vm.Home();
                    if (host != null)
                    {
                        hosts.Add(host);
                    }
                }
            }
            else
            {
                hosts.Add(theHost);
            }

            foreach (var host in hosts)
            {
                try
                {
                    //NB The refresh causes the server to re-read the configuration
                    //immediately. But even if the refresh fails, the change will be
                    //noticed, just a bit later.

                    new ExecutePluginAction(host.Connection, host,
                                            XenServerPlugins.PLUGIN_PERFMON_PLUGIN,
                                            XenServerPlugins.PLUGIN_PERFMON_FUNCTION_REFRESH,
                                            new Dictionary <string, string>(), true).RunExternal(Session);
                }
                catch (Exception e)
                {
                    // Handle perfmon randomly being stopped
                    if (e.Message.StartsWith(XenServerPlugins.PLUGIN_PERFMON_ERROR_NOT_RUNNING))
                    {
                        // start perfmon and try again
                        try
                        {
                            new ExecutePluginAction(host.Connection, host,
                                                    XenServerPlugins.PLUGIN_PERFMON_PLUGIN,
                                                    XenServerPlugins.PLUGIN_PERFMON_FUNCTION_START,
                                                    new Dictionary <string, string>(), true).RunExternal(Session);

                            new ExecutePluginAction(host.Connection, host,
                                                    XenServerPlugins.PLUGIN_PERFMON_PLUGIN,
                                                    XenServerPlugins.PLUGIN_PERFMON_FUNCTION_REFRESH,
                                                    new Dictionary <string, string>(), true).RunExternal(Session);
                        }
                        catch (Exception ex)
                        {
                            log.DebugFormat("Perfmon refresh failed ({0}). Alerts will start being produced within half an hour.", ex.Message);
                        }
                    }
                    else
                    {
                        log.DebugFormat("Perfmon refresh failed ({0}). Alerts will start being produced within half an hour.", e.Message);
                    }
                }
            }
        }
Esempio n. 27
0
        public List <WinAPI.SR> GetSRList(ServerInfo hostInfo)
        {
            List <WinAPI.SR> list = new List <WinAPI.SR>();

            try
            {
                Session session = OpenSessionAndLogin(hostInfo);

                Pool   pool                    = null;
                string masterHostRef           = null;
                List <XenRef <Pool> > poolList = Pool.get_all(session);
                if (list.Count > 0)
                {
                    pool = Pool.get_record(session, poolList[0]);
                }
                if (pool == null || pool.master == null)
                {
                    masterHostRef = session.get_this_host();
                }
                else
                {
                    masterHostRef = (string)pool.master;
                }


                List <XenRef <SR> > srRefs = SR.get_all(session);
                foreach (XenRef <SR> srRef in srRefs)
                {
                    SR   sr = SR.get_record(session, (string)srRef);
                    bool allCurrentlyAttached    = true;
                    bool isOtherLocalSr          = false;
                    List <XenRef <PBD> > pbdRefs = SR.get_PBDs(session, (string)srRef);
                    foreach (XenRef <PBD> pbdRef in pbdRefs)
                    {
                        PBD  pbd = PBD.get_record(session, (string)pbdRef);
                        bool currentlyAttached = pbd.currently_attached;
                        if (!currentlyAttached)
                        {
                            allCurrentlyAttached = false;
                            break;
                        }

                        string hostRef = (string)pbd.host;
                        if (!sr.shared && !hostRef.Equals(masterHostRef))
                        {
                            isOtherLocalSr = true; //非master主机的本地存储池
                            break;
                        }
                    }
                    if (!allCurrentlyAttached)
                    {
                        continue;
                    }

                    if (!isOtherLocalSr && this.IsValidSR(sr) && sr.physical_size > 0L && sr.physical_size - sr.physical_utilisation > 0L)
                    {
                        list.Add(sr);
                    }
                }

                //List<XenRef<Host>> list2 = Host.get_all(session);
                //foreach (XenRef<PBD> ref2 in Host.get_record(session, list2[0]).PBDs)
                //{
                //    XenRef<WinAPI.SR> ref3 = PBD.get_SR(session, (string) ref2);
                //    WinAPI.SR sr = WinAPI.SR.get_record(session, (string) ref3);
                //    if ((this.IsValidSR(sr) && ((list2.Count < 2) || this.IsSharedSR(sr))) && (sr.physical_size > 0L))
                //    {
                //        list.Add(sr);
                //    }
                //}
            }
            catch (Exception exception)
            {
                LOG.Error("Unable to get service SRs from WinServer! Exception caught...", exception);
            }
            return(list);
        }
Esempio n. 28
0
        protected override void Run()
        {
            log.Debug("Running SR.Introduce");
            log.DebugFormat("SR uuid='{0}'", _srUuid);
            log.DebugFormat("name='{0}'", _srName);
            log.DebugFormat("description='{0}'", _srDescription);
            log.DebugFormat("type='{0}'", _srType);
            log.DebugFormat("content type='{0}'", _srContentType);
            log.DebugFormat("is shared='{0}'", _srIsShared);

            Description = Messages.ACTION_SR_ATTACHING;
            // If SR is already attached, forget it (it may be in a broken invisible state with no PBDs)
            try
            {
                log.Debug("Performing preemptive SR.forget()");
                RelatedTask = XenAPI.SR.async_forget(this.Session, XenAPI.SR.get_by_uuid(this.Session,
                                                                                         _srUuid).opaque_ref);
                PollToCompletion(0, 5);
            }
            catch (Failure)
            {
                // Allow failure
            }

            // Introduce the existing SR
            RelatedTask = XenAPI.SR.async_introduce(this.Session, _srUuid, _srName,
                                                    _srDescription, _srType.ToString(), _srContentType,
                                                    _srIsShared, new Dictionary <string, string>());
            PollToCompletion(5, 10);

            // cache result, in order to reassign it later
            string introducedSr = Result;

            // Now repair the SR with new PBDs for each host in the pool
            XenAPI.PBD pbdTemplate = new PBD();
            pbdTemplate.currently_attached = false;
            pbdTemplate.device_config      = _dconf;
            pbdTemplate.SR = new XenRef <SR>(Result);
            int delta = 90 / Connection.Cache.HostCount / 2;

            foreach (Host host in Connection.Cache.Hosts)
            {
                // Create the PBD
                log.DebugFormat("Creating PBD for host {0}", host.Name());
                this.Description = string.Format(Messages.ACTION_SR_REPAIR_CREATE_PBD, Helpers.GetName(host));
                pbdTemplate.host = new XenRef <Host>(host.opaque_ref);
                RelatedTask      = PBD.async_create(this.Session, pbdTemplate);
                PollToCompletion(PercentComplete, PercentComplete + delta);
                XenRef <PBD> pbdRef = new XenRef <PBD>(this.Result);

                // Now plug the PBD
                log.DebugFormat("Plugging PBD for host {0}", host.Name());
                this.Description = string.Format(Messages.ACTION_SR_REPAIR_PLUGGING_PBD, Helpers.GetName(host));
                RelatedTask      = XenAPI.PBD.async_plug(this.Session, pbdRef);
                PollToCompletion(PercentComplete, PercentComplete + delta);
            }

            // reassign result
            Result = introducedSr;

            if (isFirstSharedNonISOSR())
            {
                SR new_sr = Connection.WaitForCache(new XenRef <SR>(Result), GetCancelling);
                if (Cancelling)
                {
                    throw new CancelledException();
                }
                if (new_sr == null)
                {
                    throw new Failure(Failure.HANDLE_INVALID, "SR", Result);
                }

                // Set this SR to be the default
                new SrAction(SrActionKind.SetAsDefault, new_sr).RunExternal(Session);
            }

            Description = Messages.ACTION_SR_ATTACH_SUCCESSFUL;
        }
Esempio n. 29
0
        protected void BringBabiesBack(ref Session session, List <XenRef <VM> > vmrefs, bool enableOnly)
        {
            // CA-17428: Apply hotfixes to a pool of hosts through XenCenter fails.
            // Hosts do reenable themselves anyway, so just wait 1 min for that,
            // occasionally poking it.

            WaitForHostToBecomeEnabled(session, true);

            if (enableOnly || vmrefs.Count == 0)
            {
                return;
            }

            int vmCount  = vmrefs.Count;
            int vmNumber = 0;

            var hostObj = GetResolvedHost();

            AddProgressStep(string.Format(Messages.PLAN_ACTION_STATUS_REPATRIATING_VMS, hostObj.Name()));
            PBD.CheckPlugPBDsForVMs(Connection, vmrefs, true);

            foreach (var vmRef in vmrefs)
            {
                var vm = Connection.Resolve(vmRef);
                if (vm == null)
                {
                    continue;
                }

                int tries = 0;

                if (vm.power_state != vm_power_state.Running)
                {
                    continue; // vm may have been shutdown or suspended.
                }
                do
                {
                    tries++;

                    try
                    {
                        log.DebugFormat("Migrating VM '{0}' back to Host '{1}'", vm.Name(), hostObj.Name());

                        PollTaskForResultAndDestroy(Connection, ref session,
                                                    VM.async_live_migrate(session, vm.opaque_ref, HostXenRef.opaque_ref),
                                                    (vmNumber * 100) / vmCount, ((vmNumber + 1) * 100) / vmCount);

                        vmNumber++;
                    }
                    catch (Failure e)
                    {
                        // When trying to put the first vm back, we get all sorts
                        // of errors ie storage not plugged yet etc.  Just ignore them for now

                        if (vmNumber > 0 || tries > 24)
                        {
                            throw;
                        }

                        log.Debug(string.Format("Error migrating VM '{0}' back to Host '{1}'", vm.Name(), hostObj.Name()), e);

                        Thread.Sleep(5000);
                    }
                } while (vmNumber == 0);
            }

            log.DebugFormat("Cleaning up evacuated VMs from Host '{0}'", hostObj.Name());
            Host.ClearEvacuatedVMs(session, HostXenRef);
        }
Esempio n. 30
0
        public void Build()
        {
            treeView.BeginUpdate();
            RepairButton.Enabled = false;
            bool firstTime      = treeView.Nodes.Count == 0;
            bool anythingBroken = false;
            bool hostsAvailable = false;

            for (int i = 0; i < _srList.Count; i++)
            {
                // persist expanded-state of node, or default to true
                bool isExpanded = true;

                if (_srList[i].IsBroken() || !_srList[i].MultipathAOK)
                {
                    anythingBroken = true;
                }

                if (firstTime)
                {
                    treeView.Nodes.Add(new RepairTreeNode(_srList[i], null, null));
                }
                else
                {
                    isExpanded = treeView.Nodes[i].IsExpanded;
                }

                RepairTreeNode srNode = (RepairTreeNode)treeView.Nodes[i];
                srNode.Nodes.Clear();


                if (imageList.Images.ContainsKey(srNode.SR.opaque_ref))
                {
                    imageList.Images.RemoveByKey(srNode.SR.opaque_ref);
                }
                imageList.Images.Add(srNode.SR.opaque_ref, Images.GetImage16For(srNode.SR));

                srNode.ImageKey = srNode.SR.opaque_ref;

                List <Host> hosts = new List <Host>(srNode.SR.Connection.Cache.Hosts);
                hosts.Sort();
                foreach (Host host in hosts)
                {
                    if (host != null)
                    {
                        Host storageHost = srNode.SR.GetStorageHost();

                        if (srNode.SR.shared || (storageHost != null && host.opaque_ref == storageHost.opaque_ref))
                        {
                            PBD pdb = null;

                            foreach (PBD p in srNode.SR.Connection.ResolveAll <PBD>(srNode.SR.PBDs))
                            {
                                if (srNode.SR.Connection.Resolve <Host>(p.host) == host)
                                {
                                    pdb = p;
                                }
                            }

                            RepairTreeNode hostNode = new RepairTreeNode(srNode.SR, host, pdb);
                            srNode.Nodes.Add(hostNode);

                            if (imageList.Images.ContainsKey(host.opaque_ref))
                            {
                                imageList.Images.RemoveByKey(host.opaque_ref);
                            }
                            imageList.Images.Add(host.opaque_ref, Images.GetImage16For(host));

                            hostNode.ImageKey = host.opaque_ref;
                            hostsAvailable    = true;
                        }
                    }
                }

                if (isExpanded)
                {
                    srNode.Expand();
                }
                else
                {
                    srNode.Collapse();
                }
            }
            // we only want to enable the repair button if
            // - there is a broken sr
            // - we have successfully found the right hosts to patch up pbds for
            // - we are not in the process of repairing already
            RepairButton.Enabled = anythingBroken && hostsAvailable && !ActionInProgress;


            treeView.EndUpdate();
        }