private Pool_patch UploadRetailPatch()
        {
            Session session = NewSession();

            Host master = Helpers.GetMaster(Connection);

            log.InfoFormat("Uploading file '{0}' to server '{1}'", _patchName, master.Name());
            this.Description = string.Format(Messages.UPLOAD_PATCH_UPLOADING_DESCRIPTION, _patchName);

            try
            {
                RelatedTask = Task.create(session, "put_pool_patch_upload_task", master.address);
                log.DebugFormat("HTTP PUTTING file from {0} to {1}", retailPatchPath, master.address);

                HTTP_actions.put_pool_patch_upload(UpdateProgress,
                                                   () => XenAdminConfigManager.Provider.ForcedExiting || GetCancelling(),
                                                   XenAdminConfigManager.Provider.GetProxyTimeout(true),
                                                   master.address,
                                                   XenAdminConfigManager.Provider.GetProxyFromSettings(Connection),
                                                   retailPatchPath, RelatedTask.opaque_ref, session.opaque_ref);

                PollToCompletion();
                return(Connection.WaitForCache(new XenRef <Pool_patch>(new XenRef <Pool_patch>(Result))));
            }
            catch (Exception e)
            {
                PollToCompletion(suppressFailures: true);

                if (e is TargetInvocationException ex)
                {
                    if (ex.InnerException == null)
                    {
                        throw;
                    }
                    else
                    {
                        throw ex.InnerException;
                    }
                }

                if (e is CancelledException || e is HTTP.CancelledException || e.InnerException is CancelledException)
                {
                    if (deleteFileOnCancel && File.Exists(retailPatchPath))
                    {
                        File.Delete(retailPatchPath);
                    }
                    throw new CancelledException();
                }

                throw;
            }
        }
Beispiel #2
0
        protected XenRef <Pool_patch> BringPatchToPoolForHost(Host host, Pool_patch patch)
        {
            // Check the patch exists on the pool this host is connected to
            XenRef <Pool_patch> patch_ref = host.Connection.Cache.FindRef(patch);

            if (patch_ref != null)
            {
                return(patch_ref);
            }

            // 1st download patch from the pool that has it (the connection on the xenobject)

            string filename = Path.GetTempFileName();

            try
            {
                Connection = patch.Connection;
                Session    = patch.Connection.DuplicateSession();

                try
                {
                    RelatedTask = Task.create(Session, "get_pool_patch_download_task", patch.Connection.Hostname);
                    log.DebugFormat("HTTP GETTING file from {0} to {1}", patch.Connection.Hostname, filename);

                    HTTP_actions.get_pool_patch_download(
                        bytes =>
                    {
                        PercentComplete = (int)(100 * (double)bytes / patch.size);

                        Description = string.Format(Messages.DOWNLOADING_PATCH_FROM, patch.Connection.Name,
                                                    Util.DiskSizeString(bytes, 1, "F1"), Util.DiskSizeString(patch.size));
                    },
                        () => XenAdminConfigManager.Provider.ForcedExiting || GetCancelling(),
                        XenAdminConfigManager.Provider.GetProxyTimeout(true),
                        patch.Connection.Hostname,
                        XenAdminConfigManager.Provider.GetProxyFromSettings(Connection),
                        filename, RelatedTask.opaque_ref, Session.opaque_ref, patch.uuid);

                    PollToCompletion();
                }
                catch (Exception e)
                {
                    PollToCompletion(suppressFailures: true);

                    if (e is WebException && e.InnerException is IOException ioe && Win32.GetHResult(ioe) == Win32.ERROR_DISK_FULL)
                    {
                        throw new PatchDownloadFailedException(string.Format(Messages.PATCH_DOWNLOAD_FAILED, patch.name_label, patch.Connection.Name), e.InnerException);
                    }

                    if (e is CancelledException || e is HTTP.CancelledException || e.InnerException is CancelledException)
                    {
                        throw new CancelledException();
                    }

                    if (e.InnerException?.Message == "Received error code HTTP/1.1 403 Forbidden\r\n from the server")
                    {
                        // RBAC Failure
                        List <Role> roles = Connection.Session.Roles;
                        roles.Sort();
                        throw new Exception(String.Format(Messages.RBAC_HTTP_FAILURE, roles[0].FriendlyName()), e);
                    }

                    throw new PatchDownloadFailedException(string.Format(Messages.PATCH_DOWNLOAD_FAILED, patch.name_label, patch.Connection.Name), e.InnerException ?? e);
                }
                finally
                {
                    Session    = null;
                    Connection = null;
                }

                // Then, put it on the pool that doesn't have it

                Description = String.Format(Messages.UPLOADING_PATCH_TO, host.Name());
                Connection  = host.Connection;
                Session     = host.Connection.DuplicateSession();

                try
                {
                    RelatedTask = Task.create(Session, "put_pool_patch_upload_task", host.Connection.Hostname);
                    log.DebugFormat("HTTP PUTTING file from {0} to {1}", filename, host.Connection.Hostname);

                    HTTP_actions.put_pool_patch_upload(percent => PercentComplete = percent,
                                                       () => XenAdminConfigManager.Provider.ForcedExiting || GetCancelling(),
                                                       XenAdminConfigManager.Provider.GetProxyTimeout(true),
                                                       host.Connection.Hostname,
                                                       XenAdminConfigManager.Provider.GetProxyFromSettings(Connection),
                                                       filename, RelatedTask.opaque_ref, Session.opaque_ref);

                    PollToCompletion();
                    Description = string.Format(Messages.PATCH_UPLOADED, host.Name());
                    return(new XenRef <Pool_patch>(Result));
                }
                catch (Exception e)
                {
                    PollToCompletion(suppressFailures: true);

                    if (e is CancelledException || e is HTTP.CancelledException || e.InnerException is CancelledException)
                    {
                        throw new CancelledException();
                    }
                    throw;
                }
                finally
                {
                    Session    = null;
                    Connection = null;
                }
            }
            finally
            {
                File.Delete(filename);
            }
        }