Esempio n. 1
0
    def _get_servers(self, request):
        # Get nova data
        try:
            servers, more = api.nova.server_list(request)
        except Exception:
            servers = []
        data = []
        console_type = getattr(settings, 'CONSOLE_TYPE', 'AUTO')
        # lowercase of the keys will be used at the end of the console URL.
        for server in servers:
            server_data = {'name': server.name,
                           'status': self.trans.instance[server.status],
                           'original_status': server.status,
                           'task': getattr(server, 'OS-EXT-STS:task_state'),
                           'id': server.id}
            # Avoid doing extra calls for console if the server is in
            # a invalid status for console connection
            if server.status.lower() not in console_invalid_status:
                try:
                    console = i_console.get_console(
                        request, console_type, server)[0].lower()
                    server_data['console'] = console
                except exceptions.NotAvailable:
                    pass

            data.append(server_data)
        self.add_resource_url('horizon:admin:instances:detail', data)
        return data
Esempio n. 2
0
def rdp(request, instance_id):
    try:
        instance = api.nova.server_get(request, instance_id)
        console_url = project_console.get_console(request, 'RDP', instance)[1]
        return shortcuts.redirect(console_url)
    except Exception:
        redirect = reverse("horizon:admin:instances:index")
        msg = _('Unable to get RDP console for instance "%s".') % instance_id
        exceptions.handle(request, msg, redirect=redirect)
Esempio n. 3
0
    def get(self, request, *args, **kwargs):

        try:
            if kwargs.get('remote_id') and hasattr(request.user,'token'):
                instance_id, password = kwargs['remote_id'].split('_')
                instance = api.nova.server_get(request, instance_id)
                console_type = getattr(settings, 'CONSOLE_TYPE', 'VNC')
                _type, console_url = console.get_console(request, 
                              console_type, instance, password=password)
                callback = request.GET['callback']
                data = ''.join([callback, '({"success":"%s"})' % console_url])
                return HttpResponse(data, 
                       content_type="text/plain")
            else:
                return HttpResponse('token is invalid',\
                    content_type="text/plain")
        except Exception:
            return HttpResponse('Handle Remote Error!',\
                content_type="text/plain")
Esempio n. 4
0
    def get_context_data(self, request):
        instance = self.tab_group.kwargs['instance']
        console_type = getattr(settings, 'CONSOLE_TYPE', 'AUTO')
        console_url = None
        try:
            console_type, console_url = console.get_console(
                request, console_type, instance)
            # For serial console, the url is different from VNC, etc.
            # because it does not include params for title and token
            if console_type == "SERIAL":
                console_url = reverse('horizon:admin:instances:serial',
                                      args=[instance.id])
        except exceptions.NotAvailable:
            exceptions.handle(request, ignore=True, force_log=True)

        return {
            'console_url': console_url,
            'instance_id': instance.id,
            'console_type': console_type
        }
Esempio n. 5
0
 def get_context_data(self, **kwargs):
     context = super(SerialConsoleView, self).get_context_data(**kwargs)
     context['instance_id'] = self.kwargs['instance_id']
     instance = None
     try:
         instance = api.nova.server_get(self.request,
                                        self.kwargs['instance_id'])
     except Exception:
         context["error_message"] = _(
             "Cannot find instance %s.") % self.kwargs['instance_id']
         # name is unknown, so leave it blank for the window title
         # in full-screen mode, so only the instance id is shown.
         context['instance_name'] = ''
         return context
     context['instance_name'] = instance.name
     try:
         console_url = project_console.get_console(self.request, "SERIAL",
                                                   instance)[1]
         context["console_url"] = console_url
     except exceptions.NotAvailable:
         context["error_message"] = _("Cannot get console for instance %s."
                                      ) % self.kwargs['instance_id']
     return context