Esempio n. 1
0
        protected override void Run()
        {
            SafeToExit = false;

            if (patch.AppliedOn(host) != DateTime.MaxValue)
            {
                return;
            }

            XenRef <Pool_patch> patchRef = BringPatchToPoolForHost(host, patch);

            Description = string.Format(Messages.APPLYING_PATCH, patch.Name(), host.Name());
            log.DebugFormat("Applying update '{0}' to server '{1}'", patch.Name(), host.Name());

            try
            {
                RelatedTask = Pool_patch.async_apply(Session, patchRef, host.opaque_ref);
                PollToCompletion();
            }
            catch (Failure f)
            {
                log.ErrorFormat("Failed to apply patch '{0}' on server '{1}': '{2}'",
                                patch.Name(), host.Name(), string.Join(", ", f.ErrorDescription)); //CA-339237
                throw;
            }

            log.DebugFormat("Applied update '{0}' to server '{1}'. Result: {2}.", patch.Name(), host.Name(), Result);
            Description = string.Format(Messages.PATCH_APPLIED, patch.Name(), host.Name());
        }
        protected override void Run()
        {
            this.Description = string.Format(Messages.REMOVING_UPDATE, patch.Name());
            List <Pool_patch> poolPatches = new List <Pool_patch>(Connection.Cache.Pool_patches);
            var poolPatch = poolPatches.Find(p => string.Equals(p.uuid, patch.uuid, StringComparison.OrdinalIgnoreCase));

            if (poolPatch != null)
            {
                Pool_patch.pool_clean(Session, poolPatch.opaque_ref);
            }
            Description = String.Format(Messages.REMOVED_UPDATE, patch.Name());
        }
Esempio n. 3
0
        protected override void Run()
        {
            Description = String.Format(Messages.REMOVING_UPDATE, patch.Name());
            try
            {
                RelatedTask = Pool_patch.async_destroy(Session, patch.opaque_ref);
                PollToCompletion();
            }
            catch (Failure f)
            {
                log.Error("Clean up failed", f);
            }

            Description = String.Format(Messages.REMOVED_UPDATE, patch.Name());
        }
Esempio n. 4
0
        protected override void RunWithSession(ref Session session)
        {
            AddProgressStep(string.Format(Messages.UPDATES_WIZARD_REMOVING_UPDATE, _patch.Name(), _pool.Name()));
            XenRef <Task> task = Pool_patch.async_pool_clean(session, _patch.opaque_ref);

            PollTaskForResultAndDestroy(Connection, ref session, task);
        }
Esempio n. 5
0
        protected override void Run()
        {
            SafeToExit = false;

            if (patch.AppliedOn(host) != DateTime.MaxValue)
            {
                return;
            }

            XenRef <Pool_patch> patchRef = BringPatchToPoolForHost(host, patch);

            Description = string.Format(Messages.APPLYING_PATCH, patch.Name(), host.Name());
            log.Debug(Description);

            var result = Pool_patch.apply(Session, patchRef, host.opaque_ref);

            log.DebugFormat(Messages.APPLY_PATCH_LOG_MESSAGE, patch.Name(), host.Name(), result);
            Description = string.Format(Messages.PATCH_APPLIED, patch.Name(), host.Name());
        }
Esempio n. 6
0
        protected override void Run()
        {
            SafeToExit = false;

            if (patch.AppliedOn(host) != DateTime.MaxValue)
            {
                return;
            }

            XenRef <Pool_patch> patchRef = BringPatchToPoolForHost(host, patch);

            Description = string.Format(Messages.APPLYING_PATCH, patch.Name(), host.Name());
            log.DebugFormat("Applying update '{0}' to server '{1}'", patch.Name(), host.Name());

            RelatedTask = Pool_patch.async_apply(Session, patchRef, host.opaque_ref);
            PollToCompletion();

            log.DebugFormat("Applied update '{0}' to server '{1}'. Result: {2}.", patch.Name(), host.Name(), Result);
            Description = string.Format(Messages.PATCH_APPLIED, patch.Name(), host.Name());
        }
Esempio n. 7
0
        private void ApplyPatch()
        {
            XenRef <Pool_patch> patchRef = BringPatchToPoolForHost(host, patch);

            try
            {
                this.Description = String.Format(Messages.APPLYING_PATCH, patch.Name(), host.Name());

                output += String.Format(Messages.APPLY_PATCH_LOG_MESSAGE, patch.Name(), host.Name());
                output += Pool_patch.apply(Session, patchRef, host.opaque_ref);

                this.Description = String.Format(Messages.PATCH_APPLIED, patch.Name(), host.Name());
            }
            catch (Failure f)
            {
                if (f.ErrorDescription.Count > 1 && f.ErrorDescription[0] == XenAPI.Failure.PATCH_APPLY_FAILED)
                {
                    output += Messages.APPLY_PATCH_FAILED_LOG_MESSAGE;
                    output += f.ErrorDescription[1];
                }

                throw;
            }
        }
Esempio n. 8
0
        protected override void RunWithSession(ref Session session)
        {
            var host = GetResolvedHost();

            // evacuate the host, if needed,  before applying the update
            if (_hostNeedsEvacuated)
            {
                EvacuateHost(ref session);
            }

            AddProgressStep(string.Format(Messages.UPDATES_WIZARD_APPLYING_UPDATE, _patch.Name(), host.Name()));
            XenRef <Task> task = Pool_patch.async_apply(session, _patch.opaque_ref, host.opaque_ref);

            PollTaskForResultAndDestroy(Connection, ref session, task);
        }
Esempio n. 9
0
 public ApplyPatchAction(Pool_patch patch, Host host)
     : base(host.Connection, string.Format(Messages.UPDATES_WIZARD_APPLYING_UPDATE, patch.Name(), host.Name()))
 {
     this.patch = patch;
     this.host  = host;
 }
Esempio n. 10
0
        public PoolPatchCleanAction(Pool pool, Pool_patch patch, bool suppressHistory)
            : base(pool.Connection, string.Format(Messages.UPDATES_WIZARD_REMOVING_UPDATE, patch.Name(), pool.Name()), suppressHistory)
        {
            this.patch = patch;
            if (patch == null)
            {
                throw new ArgumentNullException("pool_patch");
            }

            #region RBAC Dependencies
            ApiMethodsToRoleCheck.Add("pool_patch.pool_clean");
            #endregion
        }
        protected override void RunWithSession(ref Session session)
        {
            try
            {
                var existing = (from HostUpdateMapping hum in patchMappings
                                let xpm = hum as XenServerPatchMapping
                                          where xpm != null && xpm.Matches(master, xenServerPatch)
                                          select xpm).FirstOrDefault();

                if (!Helpers.ElyOrGreater(session.Connection))
                {
                    Pool_patch poolPatch = null;
                    var        mapping   = existing as PoolPatchMapping;

                    if (mapping != null && mapping.IsValid)
                    {
                        poolPatch = mapping.Pool_patch;
                    }
                    else
                    {
                        poolPatch = session.Connection.Cache.Pool_patches.FirstOrDefault(pp => string.Equals(pp.uuid, xenServerPatch.Uuid, StringComparison.InvariantCultureIgnoreCase));
                    }

                    if (poolPatch != null && poolPatch.opaque_ref != null)
                    {
                        AddProgressStep(string.Format(Messages.UPDATES_WIZARD_REMOVING_UPDATES_FROM_POOL, poolPatch.Name()));
                        var task = Pool_patch.async_pool_clean(session, mapping.Pool_patch.opaque_ref);
                        PollTaskForResultAndDestroy(Connection, ref session, task);

                        patchMappings.Remove(mapping);
                    }
                }
                else
                {
                    var mapping = existing as PoolUpdateMapping;

                    if (mapping != null && mapping.IsValid)
                    {
                        var poolUpdate = mapping.Pool_update;
                        AddProgressStep(string.Format(Messages.UPDATES_WIZARD_REMOVING_UPDATES_FROM_POOL, poolUpdate.Name()));

                        Pool_update.pool_clean(session, poolUpdate.opaque_ref);

                        if (!poolUpdate.AppliedOnHosts().Any())
                        {
                            Pool_update.destroy(session, poolUpdate.opaque_ref);
                        }

                        patchMappings.Remove(mapping);
                    }
                }
            }
            catch (Exception ex)
            {
                //best effort
                log.Error("Failed to remove update from the server.", ex);
            }
        }
Esempio n. 12
0
        private Problem FindProblem(string errorcode, string found, string required)
        {
            long requiredSpace        = 0;
            long foundSpace           = 0;
            long reclaimableDiskSpace = 0;

            DiskSpaceRequirements diskSpaceReq;

            switch (errorcode)
            {
            case "UPDATE_PRECHECK_FAILED_WRONG_SERVER_VERSION":
                return(new WrongServerVersion(this, Host));

            case "UPDATE_PRECHECK_FAILED_CONFLICT_PRESENT":
                return(new ConflictingUpdatePresent(this, found, Host));

            case "UPDATE_PRECHECK_FAILED_PREREQUISITE_MISSING":
                return(new PrerequisiteUpdateMissing(this, found, Host));

            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.ElyOrGreater(Host.Connection));       // If Ely or greater, we shouldn't get this error

                long.TryParse(found, out foundSpace);
                long.TryParse(required, out requiredSpace);
                // get reclaimable disk space (excluding current patch)
                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);
                }

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

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

            case "UPDATE_PRECHECK_FAILED_OUT_OF_SPACE":
                System.Diagnostics.Trace.Assert(Helpers.ElyOrGreater(Host.Connection));      // If not Ely or greater, we shouldn't get this error
                long.TryParse(found, out foundSpace);
                long.TryParse(required, out requiredSpace);

                diskSpaceReq = new DiskSpaceRequirements(DiskSpaceRequirements.OperationTypes.install, Host, Update.Name(), requiredSpace, foundSpace, 0);

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

            case "OUT_OF_SPACE":
                if (Patch != null || Update != null)
                {
                    var action = Patch != null
                            ? new GetDiskSpaceRequirementsAction(Host, Patch, true)
                            : new GetDiskSpaceRequirementsAction(Host, Update.Name(), Update.installation_size, true);
                    try
                    {
                        action.RunExternal(action.Session);
                    }
                    catch
                    {
                        log.WarnFormat("Could not get disk space requirements");
                    }
                    if (action.Succeeded)
                    {
                        return(Patch != null
                                ? new HostOutOfSpaceProblem(this, Host, Patch, action.DiskSpaceRequirements)
                                : new HostOutOfSpaceProblem(this, Host, Update, action.DiskSpaceRequirements));
                    }
                }
                break;

            case "LICENCE_RESTRICTION":
                return(new LicenseRestrictionProblem(this, Host));

            case "UPDATE_PRECHECK_FAILED_UNKNOWN_ERROR":
                // try to find the problem from the error parameters as xml string
                // e.g.
                //   ErrorDescription[0] = "UPDATE_PRECHECK_FAILED_UNKNOWN_ERROR"
                //   ErrorDescription[1] = "test-update"
                //   ErrorDescription[2] = "<?xml version="1.0" ?><error errorcode="LICENCE_RESTRICTION"></error>"
                return(FindProblem(found));
            }
            return(null);
        }
Esempio n. 13
0
 public RemoveUpdateFile(Pool pool, Pool_patch patch)
     : base(pool.Connection, string.Format(Messages.UPDATES_WIZARD_REMOVING_UPDATE, patch.Name(), pool.Name()))
 {
     this._patchRef = new XenRef <Pool_patch>(patch);
 }
 /// <summary>
 /// This constructor is used to check disk space for uploading a single patch
 /// </summary>
 public CheckDiskSpaceForPatchUploadAction(Host host, Pool_patch patch, bool suppressHistory)
     : this(host, patch.Name(), patch.size, suppressHistory)
 { }
Esempio n. 15
0
        private Problem FindProblem(string errorcode, string param1, string param2, string param3)
        {
            long requiredSpace;
            long foundSpace;
            long reclaimableDiskSpace = 0;

            DiskSpaceRequirements diskSpaceReq;

            switch (errorcode)
            {
            case "UPDATE_PRECHECK_FAILED_WRONG_SERVER_VERSION":
                return(new WrongServerVersion(this, Host));

            case "UPDATE_PRECHECK_FAILED_CONFLICT_PRESENT":
                return(new ConflictingUpdatePresent(this, param2, Host));

            case "UPDATE_PRECHECK_FAILED_PREREQUISITE_MISSING":
                return(new PrerequisiteUpdateMissing(this, param2, Host));

            case "PATCH_PRECHECK_FAILED_WRONG_SERVER_VERSION":
                return(new WrongServerVersion(this, param3, Host));

            case "PATCH_PRECHECK_FAILED_OUT_OF_SPACE":
                System.Diagnostics.Trace.Assert(!Helpers.ElyOrGreater(Host.Connection));       // If Ely or greater, we shouldn't get this error

                long.TryParse(param2, out foundSpace);
                long.TryParse(param3, out requiredSpace);
                // get reclaimable disk space (excluding current patch)
                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 (Exception exception)
                {
                    log.WarnFormat("Plugin call disk-space.get_reclaimable_disk_space on {0} failed with {1}", Host.Name(), exception.Message);
                }

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

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

            case "UPDATE_PRECHECK_FAILED_OUT_OF_SPACE":
                System.Diagnostics.Trace.Assert(Helpers.ElyOrGreater(Host.Connection));      // If not Ely or greater, we shouldn't get this error

                long.TryParse(param2, out foundSpace);
                long.TryParse(param3, out requiredSpace);

                diskSpaceReq = new DiskSpaceRequirements(DiskSpaceRequirements.OperationTypes.install, Host, Update.Name(), requiredSpace, foundSpace, 0);

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

            case "OUT_OF_SPACE":
                if (Patch != null || Update != null)
                {
                    var action = Patch != null
                            ? new GetDiskSpaceRequirementsAction(Host, Patch, true)
                            : new GetDiskSpaceRequirementsAction(Host, Update.Name(), Update.installation_size, true);
                    try
                    {
                        action.RunExternal(action.Session);
                    }
                    catch
                    {
                        log.WarnFormat("Could not get disk space requirements");
                    }
                    if (action.Succeeded)
                    {
                        return(Patch != null
                                ? new HostOutOfSpaceProblem(this, Host, Patch, action.DiskSpaceRequirements)
                                : new HostOutOfSpaceProblem(this, Host, Update, action.DiskSpaceRequirements));
                    }
                }
                break;

            case "LICENCE_RESTRICTION":
                return(new LicenseRestrictionProblem(this, Host));

            case "UPDATE_PRECHECK_FAILED_UNKNOWN_ERROR":
                if (param1 == "CH82" && param2.StartsWith("VSWITCH_CONTROLLER_CONNECTED"))
                {
                    var pool = Helpers.GetPoolOfOne(Host.Connection);
                    if (pool.vSwitchController())
                    {
                        return(new VSwitchControllerProblem(this, pool));
                    }
                    return(null);
                }
                else
                {
                    return(FindProblem(param2));
                }
            }
            return(null);
        }
Esempio n. 16
0
 public ApplyPatchPlanAction(Host host, Pool_patch patch)
     : base(host.Connection, string.Format(Messages.UPDATES_WIZARD_APPLYING_UPDATE, patch.Name(), host.Name()))
 {
     this._host     = new XenRef <Host>(host);
     this._patchRef = new XenRef <Pool_patch>(patch);
 }
Esempio n. 17
0
 /// <summary>
 /// This constructor is used to calculate the disk space requirements for installing or uploading a single patch
 /// </summary>
 public GetDiskSpaceRequirementsAction(Host host, Pool_patch patch, bool suppressHistory)
     : this(host, patch.Name(), patch.size, suppressHistory)
 {
     currentPatch = patch;
 }
Esempio n. 18
0
 protected override void RunWithSession(ref Session session)
 {
     AddProgressStep(string.Format(Messages.UPDATES_WIZARD_REMOVING_UPDATE, _patch.Name(), _pool.Name()));
     AddProgressStep(string.Format(Messages.REMOVING_UPDATE, _patch.Name(), _pool.Name()));
     new PoolPatchCleanAction(_pool, _patch, true).RunExternal(session);
 }