Beispiel #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:project:instances:detail', data)
        return data
Beispiel #2
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:
            try:
                console = i_console.get_console(
                    request, console_type, server)[0].lower()
            except exceptions.NotAvailable:
                console = None

            server_data = {'name': server.name,
                           'status': server.status,
                           'task': getattr(server, 'OS-EXT-STS:task_state'),
                           'id': server.id}
            if console:
                server_data['console'] = console
            data.append(server_data)
        self.add_resource_url('horizon:project:instances:detail', data)
        return data
Beispiel #3
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:
            try:
                console = i_console.get_console(request, console_type, server)[0].lower()
            except exceptions.NotAvailable:
                console = None

            server_data = {
                "name": server.name,
                "status": server.status,
                "task": getattr(server, "OS-EXT-STS:task_state"),
                "id": server.id,
            }
            if console:
                server_data["console"] = console
            data.append(server_data)
        self.add_resource_url("horizon:project:instances:detail", data)
        return data
Beispiel #4
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:project:instances:index")
        msg = _('Unable to get RDP console for instance "%s".') % instance_id
        exceptions.handle(request, msg, redirect=redirect)
Beispiel #5
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_url = console.get_console(request, console_type, instance)
        except exceptions.NotAvailable:
            exceptions.handle(request, ignore=True, force_log=True)

        return {'console_url': console_url, 'instance_id': instance.id}
Beispiel #6
0
def auto_console(request, instance_id):
    console_type = getattr(settings, 'CONSOLE_TYPE', 'AUTO')
    try:
        instance = api.nova.server_get(request, instance_id)
        console_url = project_console.get_console(request, console_type,
                                                  instance)[1]
        return shortcuts.redirect(console_url)
    except Exception:
        redirect = reverse("horizon:project:instances:index")
        msg = _('Unable to get console for instance "%s".') % instance_id
        exceptions.handle(request, msg, redirect=redirect)
Beispiel #7
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 parms for title and token
            if console_type == "SERIAL":
                console_url = "/project/instances/%s/serial" % (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}
Beispiel #8
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
    def _test_json_view(self, router_enable=True):
        api.nova.server_list(
            IsA(http.HttpRequest)).AndReturn([self.servers.list(), False])

        tenant_networks = [net for net in self.networks.list()
                           if not net['router:external']]
        external_networks = [net for net in self.networks.list()
                             if net['router:external']]
        api.neutron.network_list_for_tenant(
            IsA(http.HttpRequest),
            self.tenant.id).AndReturn(tenant_networks)

        for server in self.servers.list():
            if server.status != u'BUILD':
                CONSOLE_OUTPUT = '/vncserver'
                CONSOLE_TITLE = '&title=%s' % server.id
                CONSOLE_URL = CONSOLE_OUTPUT + CONSOLE_TITLE

                console_mock = self.mox.CreateMock(api.nova.VNCConsole)
                console_mock.url = CONSOLE_OUTPUT
                console.get_console(IsA(http.HttpRequest), 'AUTO', server) \
                    .AndReturn(('VNC', CONSOLE_URL))

        # router1 : gateway port not in the port list
        # router2 : no gateway port
        # router3 : gateway port included in port list
        routers = self.routers.list() + self.routers_with_rules.list()
        if router_enable:
            api.neutron.router_list(
                IsA(http.HttpRequest),
                tenant_id=self.tenant.id).AndReturn(routers)
        api.neutron.port_list(
            IsA(http.HttpRequest)).AndReturn(self.ports.list())
        if router_enable:
            api.neutron.network_list(
                IsA(http.HttpRequest),
                **{'router:external': True}).AndReturn(external_networks)

        self.mox.ReplayAll()

        res = self.client.get(JSON_URL)

        self.assertEqual('text/json', res['Content-Type'])
        data = jsonutils.loads(res.content)

        # servers
        # result_server_urls = [(server['id'], server['url'])
        #                       for server in data['servers']]
        expect_server_urls = []
        for server in self.servers.list():
            expect_server = {
                'id': server.id,
                'name': server.name,
                'status': server.status.title(),
                'original_status': server.status,
                'task': None,
                'url': '/project/instances/%s/' % server.id
            }
            if server.status != 'BUILD':
                expect_server['console'] = 'vnc'
            expect_server_urls.append(expect_server)
        self.assertEqual(expect_server_urls, data['servers'])

        # routers
        # result_router_urls = [(router['id'], router['url'])
        #                       for router in data['routers']]
        if router_enable:
            expect_router_urls = [
                {'id': router.id,
                 'external_gateway_info':
                 router.external_gateway_info,
                 'name': router.name,
                 'status': router.status.title(),
                 'original_status': router.status,
                 'url': '/project/routers/%s/' % router.id}
                for router in routers]
            self.assertEqual(expect_router_urls, data['routers'])
        else:
            self.assertFalse(data['routers'])

        # networks
        expect_net_urls = []
        if router_enable:
            expect_net_urls += [{'id': net.id,
                                 'url': '/project/networks/%s/detail' % net.id,
                                 'name': net.name,
                                 'router:external': net.router__external,
                                 'status': net.status.title(),
                                 'original_status': net.status,
                                 'subnets': []}
                                for net in external_networks]
        expect_net_urls.extend([{
            'id': net.id,
            'url': '/project/networks/%s/detail' % net.id,
            'name': net.name,
            'router:external': net.router__external,
            'status': net.status.title(),
            'original_status': net.status,
            'subnets': [{
                'cidr': subnet.cidr,
                'id': subnet.id,
                'url': '/project/networks/subnets/%s/detail' % subnet.id}
                for subnet in net.subnets]}
            for net in tenant_networks])
        for exp_net in expect_net_urls:
            if exp_net['url'] is None:
                del exp_net['url']
        self.assertEqual(expect_net_urls, data['networks'])

        # ports
        expect_port_urls = [
            {'id': port.id,
             'device_id': port.device_id,
             'device_owner': port.device_owner,
             'fixed_ips': port.fixed_ips,
             'network_id': port.network_id,
             'status': port.status.title(),
             'original_status': port.status,
             'url': '/project/networks/ports/%s/detail' % port.id}
            for port in self.ports.list()]
        if router_enable:
            # fake port for router1 gateway (router1 on ext_net)
            router1 = routers[0]
            ext_net = external_networks[0]
            expect_port_urls.append(
                {'id': 'gateway%s' % ext_net.id,
                 'device_id': router1.id,
                 'network_id': ext_net.id,
                 'fixed_ips': []})
        self.assertEqual(expect_port_urls, data['ports'])