Example #1
0
        public PoolPatchMapping(XenServerPatch xenServerPatch, Pool_update pool_update, Host masterHost)
        {
            if (xenServerPatch == null)
                throw new ArgumentNullException("xenServerPatch");

            if (pool_update == null)
                throw new ArgumentNullException("pool_update");

            if (masterHost == null)
                throw new ArgumentNullException("masterHost");

            this.XenServerPatch = xenServerPatch;
            this.Pool_update = pool_update;
            this.MasterHost = masterHost;
        }
        private void singleAction_Completed(ActionBase sender)
        {
            var action = sender as AsyncAction;
            if (action == null)
                return;

            action.Changed -= singleAction_Changed;
            action.Completed -= singleAction_Completed;

            Program.Invoke(this, () =>
            {
                if (action.Succeeded)
                {
                    Host master = Helpers.GetMaster(action.Connection);

                    if (action is UploadPatchAction)
                    {
                        _patch = (action as UploadPatchAction).PatchRefs[master];
                        _poolUpdate = null;
                        AddToUploadedUpdates(SelectedNewPatchPath, master);
                    }

                    if (action is CopyPatchFromHostToOther && action.Host != null)
                    {
                        _poolUpdate = null;
                        _patch = action.Host.Connection.Cache.Resolve((action as CopyPatchFromHostToOther).NewPatchRef);
                    }

                    if (_patch != null && !NewUploadedPatches.ContainsKey(_patch))
                    {
                        NewUploadedPatches.Add(_patch, SelectedNewPatchPath);
                        _poolUpdate = null;
                    }

                    if (action is UploadSupplementalPackAction)
                    {
                        _patch = null;

                        foreach (var vdiRef in (action as UploadSupplementalPackAction).VdiRefsToCleanUp)
                        {
                            SuppPackVdis[vdiRef.Key] = action.Connection.Resolve(vdiRef.Value);
                        }

                        AllCreatedSuppPackVdis.AddRange(SuppPackVdis.Values.Where(vdi => !AllCreatedSuppPackVdis.Contains(vdi)));

                        AddToUploadedUpdates(SelectedNewPatchPath, master);

                        if (Helpers.ElyOrGreater(action.Connection))
                        {
                            var newPoolUpdate = ((UploadSupplementalPackAction)action).PoolUpdate;

                            if (newPoolUpdate != null)
                            {
                                _poolUpdate = newPoolUpdate;
                                AllIntroducedPoolUpdates.Add(PoolUpdate);
                            }
                        }
                    }

                    if (action is DownloadAndUnzipXenServerPatchAction)
                    {
                        SelectedNewPatchPath = ((DownloadAndUnzipXenServerPatchAction)action).PatchPath;
                        if (SelectedUpdateAlert is XenServerPatchAlert && (SelectedUpdateAlert as XenServerPatchAlert).Patch != null)
                        {
                            AllDownloadedPatches.Add((SelectedUpdateAlert as XenServerPatchAlert).Patch.Uuid, SelectedNewPatchPath);
                        }
                        _patch = null;
                        PrepareUploadActions();
                        TryUploading();
                    }
                }
                else // if !action.Succeeded
                {
                    if (action is UploadSupplementalPackAction)
                    {
                        _patch = null;
                        _poolUpdate = null;

                        foreach (var vdiRef in (action as UploadSupplementalPackAction).VdiRefsToCleanUp)
                        {
                            SuppPackVdis[vdiRef.Key] = action.Connection.Resolve(vdiRef.Value);
                        }

                        AllCreatedSuppPackVdis.AddRange(SuppPackVdis.Values.Where(vdi => !AllCreatedSuppPackVdis.Contains(vdi)));
                    }
                }
            });
        }
        private void PrepareUploadActions()
        {
            OnPageUpdated();
            SuppPackVdis.Clear();
            uploadActions.Clear();

            //Upload the patches to the masters if it is necessary
            List<Host> masters = SelectedMasters;

            foreach (Host selectedServer in masters)
            {
                AsyncAction action = null;
                switch (SelectedUpdateType)
                {
                    case UpdateType.NewRetail:
                        if (CanUploadUpdateOnHost(SelectedNewPatchPath, selectedServer))
                        {
                            bool deleteFileOnCancel = AllDownloadedPatches.ContainsValue(SelectedNewPatchPath);
                            action = new UploadPatchAction(selectedServer.Connection, SelectedNewPatchPath, true, deleteFileOnCancel);
                        }
                        break;
                    case UpdateType.Existing:
                        if (!PatchExistsOnPool(_patch, selectedServer))
                        {
                            //Download patch from server Upload in the selected server
                            action = new CopyPatchFromHostToOther(SelectedExistingPatch.Connection, selectedServer,
                                                                  SelectedExistingPatch);
                        }
                        break;
                    case UpdateType.ISO:
                        if (CanUploadUpdateOnHost(SelectedNewPatchPath, selectedServer))
                        {
                            _poolUpdate = null;
                            _patch = null;

                            action = new UploadSupplementalPackAction(
                            selectedServer.Connection,
                            SelectedServers.Where(s => s.Connection == selectedServer.Connection).ToList(),
                            SelectedNewPatchPath,
                            true);
                        }
                        break;
                }
                if (action != null)
                {
                    action.Changed += singleAction_Changed;
                    action.Completed += singleAction_Completed;
                }
                else
                {
                    _patch = GetPatchFromPatchPath();
                }
                uploadActions.Add(selectedServer, action);
            }

            foreach (KeyValuePair<Host, AsyncAction> uploadAction in uploadActions)
            {
                flickerFreeListBox1.Items.Add(uploadAction);
            }

            flickerFreeListBox1.Refresh();
            OnPageUpdated();
        }
        protected virtual List<KeyValuePair<string, List<Check>>> GenerateChecks(Pool_update update)
        {
            List<KeyValuePair<string, List<Check>>> checks = GenerateCommonChecks();

            List<Check> checkGroup;

            //Checking other things
            if (update != null)
            {
                checks.Add(new KeyValuePair<string, List<Check>>(Messages.CHECKING_SERVER_SIDE_STATUS, new List<Check>()));
                checkGroup = checks[checks.Count - 1].Value;
                foreach (Host host in SelectedServers)
                {
                    List<Pool_update> updates = new List<Pool_update>(host.Connection.Cache.Pool_updates);
                    Pool_update poolUpdateFromHost = updates.Find(otherPatch => string.Equals(otherPatch.uuid, update.uuid, StringComparison.OrdinalIgnoreCase));
                    checkGroup.Add(new PatchPrecheckCheck(host, poolUpdateFromHost, LivePatchCodesByHost));
                }
            }

            //Checking if the host needs a reboot
            if (!IsInAutomatedUpdatesMode)
            {
                checks.Add(new KeyValuePair<string, List<Check>>(Messages.CHECKING_SERVER_NEEDS_REBOOT, new List<Check>()));
                checkGroup = checks[checks.Count - 1].Value;
                var guidance = update != null
                    ? update.after_apply_guidance
                    : new List<update_after_apply_guidance> {update_after_apply_guidance.restartHost};
                foreach (var host in SelectedServers)
                {
                    checkGroup.Add(new HostNeedsRebootCheck(host, guidance, LivePatchCodesByHost));
                }
            }

            //Checking can evacuate host
            if (update == null || update.after_apply_guidance.Contains(update_after_apply_guidance.restartHost))
            {
                checks.Add(new KeyValuePair<string, List<Check>>(Messages.CHECKING_CANEVACUATE_STATUS, new List<Check>()));
                checkGroup = checks[checks.Count - 1].Value;
                foreach (Host host in SelectedServers)
                {
                    checkGroup.Add(new AssertCanEvacuateCheck(host, LivePatchCodesByHost));
                }
            }

            return checks;
        }
 public PatchPrecheckCheck(Host host, Pool_update update, Dictionary<string, livepatch_status> livePatchCodesByHost)
     : base(host)
 {
     _update = update;
     this.livePatchCodesByHost = livePatchCodesByHost;
 }
 public PatchPrecheckCheck(Host host, Pool_update update)
     : this(host, update, null)
 {
 }
        private string UploadSupplementalPack(SR sr)
        {
            this.Description = String.Format(Messages.SUPP_PACK_UPLOADING_TO, sr.Name);

            String result;
            log.DebugFormat("Creating vdi of size {0} bytes on SR '{1}'", diskSize, sr.Name);

            VDI vdi = NewVDI(sr);
            XenRef<VDI> vdiRef = null;
            try
            {
                vdiRef = VDI.create(Session, vdi);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("{0} {1}", "Failed to create VDI", ex.Message);
                throw;
            }

            log.DebugFormat("Uploading file '{0}' to VDI '{1}' on SR '{2}'", suppPackFilePath, vdi.Name, sr.Name);

            Host localStorageHost = sr.GetStorageHost();

            string hostUrl;
            if (localStorageHost == null)
            {
                Uri uri = new Uri(Session.Url);
                hostUrl = uri.Host;
            }
            else
            {
                log.DebugFormat("SR is not shared -- redirecting to {0}", localStorageHost.address);
                hostUrl = localStorageHost.address;
            }

            log.DebugFormat("Using {0} for import", hostUrl);

            try
            {
                HTTP.UpdateProgressDelegate progressDelegate = delegate(int percent)
                {
                    var actionPercent = (int)(((totalUploaded * 100) + percent) / totalCount);
                    Tick(actionPercent, Description);
                };

                Session session = NewSession();
                RelatedTask = Task.create(Session, "uploadTask", hostUrl);

                result = HTTPHelper.Put(progressDelegate, GetCancelling, true, Connection, RelatedTask, ref session,  suppPackFilePath, hostUrl,
                                        (HTTP_actions.put_sss)HTTP_actions.put_import_raw_vdi,
                                        session.uuid, vdiRef.opaque_ref);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("{0} {1}", "Failed to import a virtual disk over HTTP.", ex.Message);
                if (vdiRef != null)
                    RemoveVDI(Session, vdiRef);
                throw;
            }
            finally
            {
                Task.destroy(Session, RelatedTask);
                RelatedTask = null;
            }

            if (localStorageHost != null)
                VdiRefsToCleanUp.Add(localStorageHost, vdiRef);
            else // shared SR
                foreach (var server in servers)
                    VdiRefsToCleanUp.Add(server, vdiRef);

            //introduce ISO for Ely and higher
            if (Helpers.ElyOrGreater(Connection))
            {
                try
                {
                    var poolUpdateRef = Pool_update.introduce(Connection.Session, vdiRef);
                    poolUpdate = Connection.WaitForCache(poolUpdateRef);

                    if (poolUpdate == null)
                        throw new Exception(Messages.UPDATE_ERROR_INTRODUCE); // This should not happen, because such case will result in a XAPI Failure. But this code has to be protected at this point.

                    VdiRefsToCleanUp.Clear();
                }
                catch (Failure ex)
                {
                    if (ex.ErrorDescription != null && ex.ErrorDescription.Count > 1 && string.Equals("UPDATE_ALREADY_EXISTS", ex.ErrorDescription[0], StringComparison.InvariantCultureIgnoreCase))
                    {
                        string uuidFound = ex.ErrorDescription[1];

                        poolUpdate = Connection.Cache.Pool_updates.FirstOrDefault(pu => string.Equals(pu.uuid, uuidFound, System.StringComparison.InvariantCultureIgnoreCase));

                        //clean-up the VDI we've just created
                        try
                        {
                            RemoveVDI(Session, vdiRef);

                            //remove the vdi that have just been cleaned up
                            var remaining = VdiRefsToCleanUp.Where(kvp => kvp.Value != null && kvp.Value.opaque_ref != vdiRef.opaque_ref).ToList();
                            VdiRefsToCleanUp.Clear();
                            remaining.ForEach(rem => VdiRefsToCleanUp.Add(rem.Key, rem.Value));
                        }
                        catch
                        {
                            //best effort cleanup
                        }

                    }
                    else
                    {
                        throw;
                    }
                }
                catch (Exception ex)
                {
                    log.ErrorFormat("Upload failed when introducing update from VDI {0} on {1}: {2}", vdi.opaque_ref, Connection, ex.Message);
                    poolUpdate = null;

                    throw;
                }
            }
            else
            {
                poolUpdate = null;
            }

            totalUploaded++;
            Description = String.Format(Messages.SUPP_PACK_UPLOADED, sr.Name);
            return result;
        }
 public HostOutOfSpaceProblem(Check check, Host host, Pool_update update, DiskSpaceRequirements diskSpaceReq)
     : base(check, host)
 {
     this.update = update;
     this.diskSpaceReq = diskSpaceReq;
 }
Example #9
0
 private static AsyncAction GetCleanUpPoolUpdateAction(Pool_update poolUpdate)
 {
     return
         new DelegatedAsyncAction(poolUpdate.Connection, Messages.REMOVE_PATCH, "", "", session =>
         {
             try
             {
                 Pool_update.pool_clean(session, poolUpdate.opaque_ref);
                 if(!poolUpdate.AppliedOnHosts.Any())
                     Pool_update.destroy(session, poolUpdate.opaque_ref);
             }
             catch (Failure f)
             {
                 log.Error("Clean up failed", f);
             }
         });
 }
 public ApplyPoolUpdatePlanAction(Host host, Pool_update patch)
     : base(host.Connection, string.Format(Messages.UPDATES_WIZARD_APPLYING_UPDATE, patch.Name, host.Name))
 {
     this.host = host;
     this.poolUpdate = patch;
 }
Example #11
0
        private void ApplyUpdate(Host host, Pool_update update)
        {
            // Set the correct connection object, for RecomputeCanCancel
            Connection = host.Connection;
            Session session = host.Connection.DuplicateSession();

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

                output += String.Format(Messages.APPLY_PATCH_LOG_MESSAGE, update.Name, host.Name);

                var poolUpdates = new List<Pool_update>(session.Connection.Cache.Pool_updates);
                var poolUpdate = poolUpdates.FirstOrDefault(u => u != null && string.Equals(u.uuid, update.uuid, StringComparison.OrdinalIgnoreCase));

                if (poolUpdate == null)
                    throw new Exception("Pool_update not found");

                if (!poolUpdate.AppliedOn(host))
                {
                    Pool_update.apply(session, poolUpdate.opaque_ref, host.opaque_ref);

                    this.Description = String.Format(Messages.PATCH_APPLIED, update.Name, host.Name);
                }
                else
                {
                    this.Description = String.Format(Messages.PATCH_APPLIED, update.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];
                }

                log.Error(output, f);

                throw;
            }
            finally
            {
                Connection = null;
            }
        }
Example #12
0
        private KeyValuePair<string, string> CreateWarningRow(Host host, Pool_update update)
        {
            var key = String.Format(Messages.GENERAL_PANEL_UPDATE_KEY, update.Name, host.Name);
            var value = string.Format(Messages.GENERAL_PANEL_UPDATE_REBOOT_WARNING, host.Name, update.Name);

            return new KeyValuePair<string, string>(key, value);
        }
        private List<PlanAction> CompilePoolUpdateActionList(Host host, Pool_update poolUpdate)
        {
            List<PlanAction> actions = new List<PlanAction>();

            if (SelectedUpdateType != UpdateType.ISO || poolUpdate == null)
                return actions;

            List<XenRef<VM>> runningVMs = RunningVMs(host);

            actions.Add(new ApplyPoolUpdatePlanAction(host, poolUpdate));

            if (poolUpdate.after_apply_guidance.Contains(update_after_apply_guidance.restartHost)
                && !(LivePatchCodesByHost != null && LivePatchCodesByHost.ContainsKey(host.uuid) && LivePatchCodesByHost[host.uuid] == livepatch_status.ok_livepatch_complete))
            {
                actions.Add(new EvacuateHostPlanAction(host));
                actions.Add(new RebootHostPlanAction(host));
                actions.Add(new BringBabiesBackAction(runningVMs, host, false));
            }

            if (poolUpdate.after_apply_guidance.Contains(update_after_apply_guidance.restartXAPI))
            {
                actions.Add(new RestartAgentPlanAction(host));
            }

            if (poolUpdate.after_apply_guidance.Contains(update_after_apply_guidance.restartHVM))
            {
                actions.Add(new RebootVMsPlanAction(host, RunningHvmVMs(host)));
            }

            if (poolUpdate.after_apply_guidance.Contains(update_after_apply_guidance.restartPV))
            {
                actions.Add(new RebootVMsPlanAction(host, RunningPvVMs(host)));
            }

            return actions;
        }