protected override Problem RunCheck()
        {
            if (!Host.IsLive)
            {
                return(new HostNotLiveWarning(this, Host));
            }

            if (!Host.Connection.IsConnected)
            {
                throw new EndOfStreamException(Helpers.GetName(Host.Connection));
            }

            if (Helpers.CreamOrGreater(Host.Connection))
            {
                var action = new GetDiskSpaceRequirementsAction(Host, size, true, DiskSpaceRequirements.OperationTypes.automatedUpdates);

                try
                {
                    action.RunExternal(action.Session);
                }
                catch
                {
                    log.WarnFormat("Could not get disk space requirements");
                }

                if (action.Succeeded && action.DiskSpaceRequirements.AvailableDiskSpace < size)
                {
                    return(new HostOutOfSpaceProblem(this, Host, action.DiskSpaceRequirements));
                }
            }

            return(null);
        }
Example #2
0
        private Problem FindProblem(string errorcode, string found, string required)
        {
            switch (errorcode)
            {
            case "PATCH_PRECHECK_FAILED_WRONG_SERVER_VERSION":
                return(new WrongServerVersion(this, required, Host));

            case "PATCH_PRECHECK_FAILED_OUT_OF_SPACE":
                System.Diagnostics.Trace.Assert(Helpers.CreamOrGreater(Host.Connection));      // If not Cream or greater, we shouldn't get this error
                long requiredSpace = 0;
                long foundSpace    = 0;
                long.TryParse(found, out foundSpace);
                long.TryParse(required, out requiredSpace);
                // get reclaimable disk space (excluding current patch)
                long reclaimableDiskSpace = 0;
                try
                {
                    var args = new Dictionary <string, string> {
                        { "exclude", Patch.uuid }
                    };
                    var resultReclaimable = Host.call_plugin(Host.Connection.Session, Host.opaque_ref, "disk-space", "get_reclaimable_disk_space", args);
                    reclaimableDiskSpace = Convert.ToInt64(resultReclaimable);
                }
                catch (Failure failure)
                {
                    log.WarnFormat("Plugin call disk-space.get_reclaimable_disk_space on {0} failed with {1}", Host.Name, failure.Message);
                }

                var diskSpaceReq = new DiskSpaceRequirements(DiskSpaceRequirements.OperationTypes.install, Host, Patch.Name, requiredSpace, foundSpace, reclaimableDiskSpace);

                return(new HostOutOfSpaceProblem(this, Host, Patch, diskSpaceReq));

            case "OUT_OF_SPACE":
                if (Helpers.CreamOrGreater(Host.Connection))
                {
                    var action = new GetDiskSpaceRequirementsAction(Host, Patch, true);
                    try
                    {
                        action.RunExternal(action.Session);
                    }
                    catch
                    {
                        log.WarnFormat("Could not get disk space requirements");
                    }
                    if (action.Succeeded)
                    {
                        return(new HostOutOfSpaceProblem(this, Host, Patch, action.DiskSpaceRequirements));
                    }
                }
                break;
            }
            return(null);
        }
Example #3
0
        protected override Problem RunHostCheck()
        {
            if (!Host.Connection.IsConnected)
            {
                throw new EndOfStreamException(Helpers.GetName(Host.Connection));
            }

            var elyOrGreater = Helpers.ElyOrGreater(Host.Connection);

            // check the disk space on host
            var requiredDiskSpace = elyOrGreater
                ? updateSequence[Host].Sum(p => p.InstallationSize)                                                                                        // all updates on this host (for installation)
                : Host.IsMaster()
                    ? updateSequence[Host].Sum(p => p.InstallationSize) + updateSequence.Values.SelectMany(p => p).Distinct().Sum(p => p.InstallationSize) // master: all updates on master (for installation) + all updates in pool (for upload)
                    : updateSequence[Host].Sum(p => p.InstallationSize) * 2;                                                                               // non-master: all updates on this host x 2 (for installation + upload)

            var action = new GetDiskSpaceRequirementsAction(Host, requiredDiskSpace, true, DiskSpaceRequirements.OperationTypes.automatedUpdates);

            try
            {
                action.RunExternal(action.Session);
            }
            catch
            {
                log.WarnFormat("Could not get disk space requirements");
            }

            if (action.Succeeded && action.DiskSpaceRequirements.AvailableDiskSpace < requiredDiskSpace)
            {
                return(new HostOutOfSpaceProblem(this, Host, action.DiskSpaceRequirements));
            }

            // check the disk space for uploading the update files to the pool's SRs (only needs to be done once, so only run this on master)
            if (elyOrGreater && Host.IsMaster())
            {
                var allPatches  = updateSequence.Values.SelectMany(p => p).Distinct().ToList();
                var maxFileSize = allPatches.Max(p => p.DownloadSize);

                var availableSRs = Host.Connection.Cache.SRs.Where(sr => sr.SupportsVdiCreate() && !sr.IsDetached()).ToList();
                var maxSrSize    = availableSRs.Max(sr => sr.FreeSpace());

                // can accomodate the largest file?
                if (maxSrSize < maxFileSize)
                {
                    return(new HostOutOfSpaceProblem(this, Host,
                                                     new DiskSpaceRequirements(DiskSpaceRequirements.OperationTypes.automatedUpdatesUploadOne, Host, null, maxFileSize, maxSrSize, 0)));
                }

                // can accomodate all files?
                var totalFileSize       = allPatches.Sum(p => p.DownloadSize);
                var totalAvailableSpace = availableSRs.Sum(sr => sr.FreeSpace());

                if (totalAvailableSpace < totalFileSize)
                {
                    return(new HostOutOfSpaceProblem(this, Host,
                                                     new DiskSpaceRequirements(DiskSpaceRequirements.OperationTypes.automatedUpdatesUploadAll, Host, null, totalFileSize, totalAvailableSpace, 0)));
                }
            }

            return(null);
        }