private void CheckDiskSpace(IXenConnection conn, Session session, string path)
        {
            try
            {
                var checkSpaceForUpload = new CheckDiskSpaceForPatchUploadAction(Helpers.GetMaster(conn), path, true);
                inProgressAction = checkSpaceForUpload;
                checkSpaceForUpload.RunExternal(session);
            }
            catch (NotEnoughSpaceException e)
            {
                if (!e.DiskSpaceRequirements.CanCleanup)
                {
                    throw;
                }

                var dialogResult = Program.Invoke(invokingControl, (Func <DialogResult>)(() =>
                {
                    using (var d = new WarningDialog(e.DiskSpaceRequirements.GetSpaceRequirementsMessage(),
                                                     ThreeButtonDialog.ButtonOK, ThreeButtonDialog.ButtonCancel))
                    {
                        return(d.ShowDialog(invokingControl));
                    }
                }
                                                                                         ), null);

                if (dialogResult is DialogResult dr && dr == DialogResult.OK)
                {
                    new CleanupDiskSpaceAction(e.DiskSpaceRequirements.Host, null, true).RunExternal(session);
                }
예제 #2
0
        protected override void RunWithSession(ref Session session)
        {
            var path = AllDownloadedPatches[patch];

            var poolPatches = new List <Pool_patch>(session.Connection.Cache.Pool_patches);
            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.XenServerPatch.Equals(patch));

            if (existingMapping == null ||
                !poolPatches.Any(p => string.Equals(p.uuid, existingMapping.Pool_patch.uuid, StringComparison.OrdinalIgnoreCase)))
            {
                //free space check for upload:
                try
                {
                    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;
                }
            }
        }
예제 #3
0
        private void TryUploading()
        {
            // reset progress bar and action progress description
            UpdateActionProgress(null);

            // Check if we can upload the patches to the masters if it is necessary.
            // This check is only available for Cream or greater hosts.
            // If we can upload (i.e. there is enough disk space) then start the upload.
            // Otherwise display error.
            canUpload             = true;
            diskSpaceRequirements = null;
            var diskSpaceActions = new List <AsyncAction>();

            foreach (Host master in SelectedMasters.Where(master => Helpers.CreamOrGreater(master.Connection) && !Helpers.ElyOrGreater(master.Connection)))
            {
                AsyncAction action = null;
                switch (SelectedUpdateType)
                {
                case UpdateType.NewRetail:
                    if (CanUploadUpdateOnHost(SelectedNewPatchPath, master))
                    {
                        action = new CheckDiskSpaceForPatchUploadAction(master, SelectedNewPatchPath, true);
                    }
                    break;

                case UpdateType.Existing:
                    if (SelectedExistingPatch != null && !PatchExistsOnPool(SelectedExistingPatch, master))
                    {
                        action = new CheckDiskSpaceForPatchUploadAction(master, SelectedExistingPatch, true);
                    }
                    break;
                }

                if (action != null)
                {
                    action.Changed += delegate
                    {
                        Program.Invoke(Program.MainWindow, () => UpdateActionDescription(action));
                    };
                    diskSpaceActions.Add(action);
                }
            }

            if (diskSpaceActions.Count == 0)
            {
                StartUploading();
                return;
            }

            using (var multipleAction = new MultipleAction(Connection, "", "", "", diskSpaceActions, true, true, true))
            {
                multipleAction.Completed += delegate
                {
                    Program.Invoke(Program.MainWindow, () =>
                    {
                        if (multipleAction.Exception is NotEnoughSpaceException)
                        {
                            canUpload             = false;
                            diskSpaceRequirements = (multipleAction.Exception as NotEnoughSpaceException).DiskSpaceRequirements;
                        }
                        UpdateButtons();
                        OnPageUpdated();
                        if (canUpload)
                        {
                            StartUploading();
                        }
                    });
                };
                multipleAction.RunAsync();
            }
        }
        protected override void RunWithSession(ref Session session)
        {
            var path = AllDownloadedPatches.ContainsKey(patch)
                ? AllDownloadedPatches[patch]
                : patchFromDisk.Key == patch ? patchFromDisk.Value : null;

            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)))
                )
            {
                AddProgressStep(string.Format(Messages.UPDATES_WIZARD_UPLOADING_UPDATE, patch.Name, conn.Name));
                PoolPatchMapping newMapping;

                if (Helpers.ElyOrGreater(master))
                {
                    var uploadIsoAction = new UploadSupplementalPackAction(session.Connection, 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 (uuid={0}) on host (uuid={1}).", patch.Uuid, session.Connection);

                        throw new Exception(Messages.ACTION_UPLOADPATCHTOMASTERPLANACTION_FAILED);
                    }

                    newMapping = new PoolPatchMapping(patch, poolupdate, Helpers.GetMaster(session.Connection));
                }
                else
                {
                    var checkSpaceForUpload = new CheckDiskSpaceForPatchUploadAction(Helpers.GetMaster(conn), path, true);
                    inProgressAction = checkSpaceForUpload;
                    checkSpaceForUpload.RunExternal(session);

                    var uploadPatchAction = new UploadPatchAction(session.Connection, path, true, false);
                    uploadPatchAction.Changed   += uploadAction_Changed;
                    uploadPatchAction.Completed += uploadAction_Completed;
                    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);
                    }

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

                if (!mappings.Contains(newMapping))
                {
                    mappings.Add(newMapping);
                }
            }
        }