private void UploadUpdate(IXenConnection conn, Session session, Host master, string path)
        {
            var uploadIsoAction = new UploadSupplementalPackAction(conn, new List <Host> {
                master
            }, path, true);

            uploadIsoAction.Changed   += uploadAction_Changed;
            uploadIsoAction.Completed += uploadAction_Completed;
            inProgressAction           = uploadIsoAction;
            uploadIsoAction.RunExternal(session);

            var poolUpdate = uploadIsoAction.PoolUpdate;

            if (poolUpdate == null)
            {
                log.ErrorFormat("Upload finished successfully, but Pool_update object has not been found for update {0} on host (uuid={1}).",
                                xenServerPatch != null ? $"(uuid={xenServerPatch.Uuid})" : GetUpdateName(), conn);

                throw new Exception(Messages.ACTION_UPLOADPATCHTOMASTERPLANACTION_FAILED);
            }

            var newMapping = new PoolUpdateMapping(xenServerPatch, poolUpdate, Helpers.GetMaster(conn))
            {
                SrsWithUploadedUpdatesPerHost = new Dictionary <Host, SR>(uploadIsoAction.SrsWithUploadedUpdatesPerHost)
            };

            if (!mappings.Contains(newMapping))
            {
                mappings.Add(newMapping);
            }
        }
        private void UploadSuppPack(IXenConnection conn, Session session, string path)
        {
            var uploadIsoAction = new UploadSupplementalPackAction(conn, selectedServers, path, true);

            uploadIsoAction.Changed   += uploadAction_Changed;
            uploadIsoAction.Completed += uploadAction_Completed;
            inProgressAction           = uploadIsoAction;
            uploadIsoAction.RunExternal(session);

            var poolUpdate = uploadIsoAction.PoolUpdate;

            var suppPackVdis = new Dictionary <Host, VDI>();

            foreach (var kvp in uploadIsoAction.VdiRefsPerHost)
            {
                var vdi = kvp.Key.Connection.Resolve(kvp.Value);
                if (vdi != null)
                {
                    suppPackVdis.Add(kvp.Key, vdi);
                }
            }

            var newMapping = new SuppPackMapping(updateFilePath, poolUpdate, Helpers.GetMaster(conn))
            {
                SrsWithUploadedUpdatesPerHost = new Dictionary <Host, SR>(uploadIsoAction.SrsWithUploadedUpdatesPerHost),
                SuppPackVdis = suppPackVdis
            };

            if (!mappings.Contains(newMapping))
            {
                mappings.Add(newMapping);
            }
        }
Beispiel #3
0
        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.Legacy:
                    if (CanUploadUpdateOnHost(SelectedNewPatchPath, selectedServer))
                    {
                        bool deleteFileOnCancel = AllDownloadedPatches.ContainsValue(SelectedNewPatchPath);
                        action = new UploadPatchAction(selectedServer.Connection, SelectedNewPatchPath, true, deleteFileOnCancel);
                    }
                    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
                {
                    _poolUpdate = GetUpdateFromUpdatePath();
                    _patch      = GetPatchFromPatchPath();
                }
                uploadActions.Add(selectedServer, action);
            }

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

            flickerFreeListBox1.Refresh();
            OnPageUpdated();
        }
Beispiel #4
0
        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 (_patch == null || !PatchExistsOnPool(_patch, selectedServer))
                    {
                        action = new UploadPatchAction(selectedServer.Connection, SelectedNewPatch, true);
                    }
                    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.NewSuppPack:
                    action = new UploadSupplementalPackAction(
                        selectedServer.Connection,
                        SelectedServers.Where(s => s.Connection == selectedServer.Connection).ToList(),
                        SelectedNewPatch,
                        true);
                    break;
                }
                if (action != null)
                {
                    action.Changed   += singleAction_Changed;
                    action.Completed += singleAction_Completed;
                }
                uploadActions.Add(selectedServer, action);
            }

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

            flickerFreeListBox1.Refresh();
            OnPageUpdated();
        }
Beispiel #5
0
        private void UploadAndApplyUpdate(Host host, Session session)
        {
            var update = host.Connection.Cache.Find_By_Uuid <Pool_update>(UUID);

            if (update == null)
            {
                var master   = Helpers.GetMaster(host.Connection);
                var filePath = Path.Combine(Program.AssemblyDir, String.Format("{0}.{1}", Filename, Branding.UpdateIso));
                var action   = new UploadSupplementalPackAction(master.Connection, new List <Host> {
                    master
                }, filePath, false);
                action.RunExternal(session);
                update = action.PoolUpdate;
            }
            new ApplyUpdateAction(update, host, false).RunExternal(session);
        }
        private void UploadSuppPack(Host master, IXenConnection connection, Session session, string suppPack)
        {
            if (!uploadedSuppPacks.ContainsKey(master))
            {
                UploadSupplementalPackAction uploadIsoAction;
                try
                {
                    AddProgressStep(string.Format(Messages.UPDATES_WIZARD_UPLOADING_UPDATE, suppPack, connection.Name));

                    uploadIsoAction = new UploadSupplementalPackAction(connection, new List <Host> {
                        master
                    }, suppPackPath, true);
                    uploadIsoAction.Changed   += uploadAction_Changed;
                    uploadIsoAction.Completed += uploadAction_Completed;
                    uploadIsoAction.RunExternal(session);
                }
                catch (Exception ex)
                {
                    log.Error(string.Format("Upload failed for update {0} on connection {1}", suppPack, connection), ex);
                    throw;
                }

                var poolupdate = uploadIsoAction.PoolUpdate;
                if (poolupdate == null)
                {
                    log.ErrorFormat(
                        "Upload finished successfully, but Pool_update object has not been found for update {0} on connection {1}.",
                        suppPack, connection);
                    throw new Exception(Messages.ACTION_UPLOADPATCHTOMASTERPLANACTION_FAILED);
                }

                uploadedSuppPacks.Add(master, poolupdate);
            }
            else if (host.uuid == master.uuid)
            {
                AddProgressStep(string.Format(Messages.UPDATES_WIZARD_SKIPPING_UPLOAD, suppPack, connection.Name));
            }
        }
        protected override void RunWithSession(ref Session session)
        {
            var path = AllDownloadedPatches[patch];

            var poolPatches = new List <Pool_patch>(session.Connection.Cache.Pool_patches);
            var poolUpdates = new List <Pool_update>(session.Connection.Cache.Pool_updates);

            var conn   = session.Connection;
            var master = Helpers.GetMaster(conn);

            var existingMapping = mappings.Find(m => m.MasterHost != null && master != null &&
                                                m.MasterHost.uuid == master.uuid && (m.Pool_patch != null || m.Pool_update != null) && m.XenServerPatch.Equals(patch));

            if (existingMapping == null ||
                !(existingMapping.Pool_patch != null && poolPatches.Any(p => string.Equals(p.uuid, existingMapping.Pool_patch.uuid, StringComparison.OrdinalIgnoreCase))) &&
                !(existingMapping.Pool_update != null && poolUpdates.Any(p => string.Equals(p.uuid, existingMapping.Pool_update.uuid, StringComparison.OrdinalIgnoreCase)))
                )
            {
                try
                {
                    if (Helpers.ElyOrGreater(master))
                    {
                        var uploadIsoAction = new UploadSupplementalPackAction(session.Connection, new List <Host>()
                        {
                            master
                        }, path, true);
                        inProgressAction = uploadIsoAction;
                        uploadIsoAction.RunExternal(session);

                        var poolupdate = uploadIsoAction.PoolUpdate;

                        if (poolupdate == null)
                        {
                            log.ErrorFormat("Upload finished successfully, but Pool_update object has not been found for update (uuid={0}) on host (uuid={1}).", patch.Uuid, session.Connection);

                            throw new Exception(Messages.ACTION_UPLOADPATCHTOMASTERPLANACTION_FAILED);
                        }

                        var newMapping = new PoolPatchMapping(patch, poolupdate, Helpers.GetMaster(session.Connection));

                        if (!mappings.Contains(newMapping))
                        {
                            mappings.Add(newMapping);
                        }
                    }
                    else
                    {
                        var checkSpaceForUpload = new CheckDiskSpaceForPatchUploadAction(Helpers.GetMaster(conn), path, true);
                        inProgressAction = checkSpaceForUpload;
                        checkSpaceForUpload.RunExternal(session);

                        var uploadPatchAction = new UploadPatchAction(session.Connection, path, true, false);
                        inProgressAction = uploadPatchAction;
                        uploadPatchAction.RunExternal(session);

                        // this has to be run again to refresh poolPatches (to get the recently uploaded one as well)
                        poolPatches = new List <Pool_patch>(session.Connection.Cache.Pool_patches);

                        var poolPatch = poolPatches.Find(p => string.Equals(p.uuid, patch.Uuid, StringComparison.OrdinalIgnoreCase));
                        if (poolPatch == null)
                        {
                            log.ErrorFormat("Upload finished successfully, but Pool_patch object has not been found for patch (uuid={0}) on host (uuid={1}).", patch.Uuid, session.Connection);

                            throw new Exception(Messages.ACTION_UPLOADPATCHTOMASTERPLANACTION_FAILED);
                        }

                        var newMapping = new PoolPatchMapping(patch, poolPatch, Helpers.GetMaster(session.Connection));

                        if (!mappings.Contains(newMapping))
                        {
                            mappings.Add(newMapping);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Error = ex;
                    throw;
                }
            }
        }