Example #1
0
        public async Task <string> GetTicket(string id)
        {
            await Connect();

            Vm vm = _vmCache[id];

            _logger.LogDebug($"Aquiring mks ticket for vm {vm.Name}");
            var ticket = await _vim.AcquireTicketAsync(vm.AsVim(), "webmks");

            string port = (ticket.portSpecified && ticket.port != 443) ? $":{ticket.port}" : "";

            return($"wss://{ticket.host ?? _config.Host}{port}/ticket/{ticket.ticket}");
        }
Example #2
0
        public async Task <string> GetConsoleUrl(Guid id, ManagedObjectReference vmReference)
        {
            VirtualMachineTicket ticket = null;
            string url = null;

            try
            {
                ticket = await _client.AcquireTicketAsync(vmReference, "webmks");
            }
            catch (Exception ex)
            {
                _logger.LogError(0, ex, $"Failed to get ticket for vm {id}");
                //System.ServiceModel.FaultException: The attempted operation cannot be performed in the current state (Powered off).
                _logger.LogError(0, ex, $"Failed with " + ex.Message);
                return(url);
            }

            string host = string.Empty;

            // ticket.host is null when using esxi instead of vcenter
            if (ticket.host != null)
            {
                host = ticket.host;
            }
            else
            {
                host = _options.Host;
            }

            if (_rewriteHostOptions.RewriteHost)
            {
                url = $"wss://{_rewriteHostOptions.RewriteHostUrl}/ticket/{ticket.ticket}?{_rewriteHostOptions.RewriteHostQueryParam}={host}";
            }
            else
            {
                url = url = $"wss://{host}/ticket/{ticket.ticket}";
            }

            _logger.LogDebug($"Returning url: {url}");

            return(url);
        }