Example #1
0
def detail(request, instance_id):
    try:
        instance = api.server_get(request, instance_id)
        try:
            console = api.console_create(request, instance_id, 'vnc')
            vnc_url = "%s&title=%s(%s)" % (console.output, instance.name,
                                           instance_id)
        except api_exceptions.ApiException, e:
            LOG.exception('ApiException while fetching instance vnc \
                           connection')
            messages.error(
                request,
                _('Unable to get vnc console for instance %(inst)s: %(message)s'
                  ) % {
                      "inst": instance_id,
                      "message": e.message
                  })
            return redirect('dash_instances', tenant_id)
    except api_exceptions.ApiException, e:
        LOG.exception('ApiException while fetching instance info')
        messages.error(
            request,
            _('Unable to get information for instance %(inst)s: %(message)s') %
            {
                "inst": instance_id,
                "message": e.message
            })
        return redirect('dash_instances', tenant_id)
    def test_console_create(self):
        extras_api = self.stub_extras_api(count=2)
        extras_api.consoles = self.mox.CreateMockAnything()
        extras_api.consoles.create(TEST_INSTANCE_ID, TEST_CONSOLE_KIND).AndReturn(TEST_RETURN)
        extras_api.consoles.create(TEST_INSTANCE_ID, "text").AndReturn(TEST_RETURN + "2")

        self.mox.ReplayAll()

        ret_val = api.console_create(self.request, TEST_INSTANCE_ID, TEST_CONSOLE_KIND)
        self.assertIsInstance(ret_val, api.Console)
        self.assertEqual(ret_val._apiresource, TEST_RETURN)

        ret_val = api.console_create(self.request, TEST_INSTANCE_ID)
        self.assertIsInstance(ret_val, api.Console)
        self.assertEqual(ret_val._apiresource, TEST_RETURN + "2")

        self.mox.VerifyAll()
def vnc(request, tenant_id, instance_id):
    try:
        console = api.console_create(request, instance_id, 'vnc')
        return redirect(console.output)
    except api_exceptions.ApiException, e:
        messages.error(request,
                   'Unable to get vnc console for instance %s: %s' %
                   (instance_id, e.message))
        return redirect('dash_instances', tenant_id)
Example #4
0
def console(request, tenant_id, instance_id):
    try:
        console = api.console_create(request, instance_id, "text")
        response = http.HttpResponse(mimetype="text/plain")
        response.write(console.output)
        response.flush()
        return response
    except api_exceptions.ApiException, e:
        LOG.exception("ApiException while fetching instance console")
        messages.error(request, "Unable to get log for instance %s: %s" % (instance_id, e.message))
        return shortcuts.redirect("dash_instances", tenant_id)
Example #5
0
    def test_instance_vnc_exception(self):
        INSTANCE_ID = self.servers[0].id

        exception = api_exceptions.ApiException('apiException',
                                                message='apiException')

        self.mox.StubOutWithMock(api, 'console_create')
        api.console_create(IsA(http.HttpRequest),
                           unicode(INSTANCE_ID),
                           'vnc').AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_instances_vnc',
                                      args=[self.TEST_TENANT, INSTANCE_ID]))

        self.assertRedirectsNoFollow(res, reverse('dash_instances',
                                                  args=[self.TEST_TENANT]))

        self.mox.VerifyAll()
Example #6
0
    def test_instance_console(self):
        CONSOLE_OUTPUT = 'output'
        INSTANCE_ID = self.servers[0].id

        console_mock = self.mox.CreateMock(api.Console)
        console_mock.output = CONSOLE_OUTPUT

        self.mox.StubOutWithMock(api, 'console_create')
        api.console_create(IgnoreArg(),
                           unicode(INSTANCE_ID),
                           IgnoreArg()).AndReturn(console_mock)

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_instances_console',
                                      args=[self.TEST_TENANT, INSTANCE_ID]))

        self.assertIsInstance(res, http.HttpResponse)
        self.assertContains(res, CONSOLE_OUTPUT)

        self.mox.VerifyAll()
def console(request, tenant_id, instance_id):
    try:
        console = api.console_create(request, instance_id)
        response = http.HttpResponse(mimetype='text/plain')
        response.write(console.output)
        response.flush()
        return response
    except api_exceptions.ApiException, e:
        messages.error(request,
                   'Unable to get log for instance %s: %s' %
                   (instance_id, e.message))
        return redirect('dash_instances', tenant_id)
Example #8
0
def vnc(request, tenant_id, instance_id):
    try:
        console = api.console_create(request, instance_id, 'vnc')
        instance = api.server_get(request, instance_id)
        return shortcuts.redirect(console.output +
                ("&title=%s(%s)" % (instance.name, instance_id)))
    except api_exceptions.ApiException, e:
        LOG.exception(_('ApiException while fetching instance vnc connection'))
        messages.error(request,
            _('Unable to get vnc console for instance %(inst)s: %(message)s') %
            {"inst": instance_id, "message": e.message})
        return shortcuts.redirect('dash_instances', tenant_id)
Example #9
0
def vnc(request, tenant_id, instance_id):
    try:
        console = api.console_create(request, instance_id, 'vnc')
        instance = api.server_get(request, instance_id)
        return shortcuts.redirect(console.output +
                                  ("&title=%s(%s)" %
                                   (instance.name, instance_id)))
    except api_exceptions.ApiException, e:
        LOG.exception('ApiException while fetching instance vnc connection')
        messages.error(
            request, 'Unable to get vnc console for instance %s: %s' %
            (instance_id, e.message))
        return shortcuts.redirect('dash_instances', tenant_id)
Example #10
0
def console(request, tenant_id, instance_id):
    try:
        console = api.console_create(request, instance_id, 'text')
        response = http.HttpResponse(mimetype='text/plain')
        response.write(console.output)
        response.flush()
        return response
    except api_exceptions.ApiException, e:
        LOG.exception('ApiException while fetching instance console')
        messages.error(
            request,
            'Unable to get log for instance %s: %s' % (instance_id, e.message))
        return shortcuts.redirect('dash_instances', tenant_id)
def vnc(request, tenant_id, instance_id):
    try:
        console = api.console_create(request, instance_id, 'vnc')
        instance = api.server_get(request, instance_id)
        return shortcuts.redirect(console.output + ("&title=%s(%s)" % (instance.name, instance_id)))
    except api_exceptions.ApiException, e:
        LOG.error('ApiException while fetching instance vnc connection',
                  exc_info=True)

        messages.error(request,
                   'Unable to get vnc console for instance %s: %s' %
                   (instance_id, e.message))
        return shortcuts.redirect('dash_instances', tenant_id)
Example #12
0
    def test_instance_console_exception(self):
        INSTANCE_ID = self.servers[0].id

        exception = api_exceptions.ApiException('apiException',
                                                message='apiException')

        self.mox.StubOutWithMock(api, 'console_create')
        api.console_create(IgnoreArg(),
                           unicode(INSTANCE_ID),
                           IgnoreArg()).AndRaise(exception)

        self.mox.StubOutWithMock(messages, 'error')
        messages.error(IgnoreArg(), IsA(unicode))

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_instances_console',
                                      args=[self.TEST_TENANT, INSTANCE_ID]))

        self.assertRedirectsNoFollow(res, reverse('dash_instances',
                                                  args=[self.TEST_TENANT]))

        self.mox.VerifyAll()
    def test_instance_vnc(self):
        INSTANCE_ID = self.servers[0].id
        CONSOLE_OUTPUT = '/vncserver'

        console_mock = self.mox.CreateMock(api.Console)
        console_mock.output = CONSOLE_OUTPUT

        self.mox.StubOutWithMock(api, 'console_create')
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                       str(self.servers[0].id)).AndReturn(self.servers[0])
        api.console_create(IgnoreArg(),
                           unicode(INSTANCE_ID),
                           'vnc').AndReturn(console_mock)

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_instances_vnc',
                                      args=[self.TEST_TENANT, INSTANCE_ID]))

        self.assertRedirectsNoFollow(res, CONSOLE_OUTPUT + '&title=serverName(1)')

        self.mox.VerifyAll()
def console(request, tenant_id, instance_id):
    try:
        console = api.console_create(request, instance_id, 'text')
        response = http.HttpResponse(mimetype='text/plain')
        response.write(console.output)
        response.flush()
        return response
    except api_exceptions.ApiException, e:
        LOG.error('ApiException while fetching instance console',
                  exc_info=True)

        messages.error(request,
                   'Unable to get log for instance %s: %s' %
                   (instance_id, e.message))
        return shortcuts.redirect('dash_instances', tenant_id)
Example #15
0
    def test_instance_vnc(self):
        INSTANCE_ID = self.servers[0].id
        CONSOLE_OUTPUT = '/vncserver'

        console_mock = self.mox.CreateMock(api.Console)
        console_mock.output = CONSOLE_OUTPUT

        self.mox.StubOutWithMock(api, 'console_create')
        self.mox.StubOutWithMock(api, 'server_get')
        api.server_get(IsA(http.HttpRequest),
                       str(self.servers[0].id)).AndReturn(self.servers[0])
        api.console_create(IgnoreArg(),
                           unicode(INSTANCE_ID),
                           'vnc').AndReturn(console_mock)

        self.mox.ReplayAll()

        res = self.client.get(reverse('dash_instances_vnc',
                                      args=[self.TEST_TENANT, INSTANCE_ID]))

        self.assertRedirectsNoFollow(res,
                CONSOLE_OUTPUT + '&title=serverName(1)')

        self.mox.VerifyAll()
Example #16
0
def console(request, tenant_id, instance_id):
    try:
        # TODO(jakedahn): clean this up once the api supports tailing.
        length = request.GET.get('length', '')
        console = api.console_create(request, instance_id, 'text')
        response = http.HttpResponse(mimetype='text/plain')
        if length:
            response.write('\n'.join(console.output.split('\n')[-int(length):]))
        else:
            response.write(console.output)
        response.flush()
        return response
    except api_exceptions.ApiException, e:
        LOG.exception(_('ApiException while fetching instance console'))
        messages.error(request,
                   _('Unable to get log for instance %(inst)s: %(msg)s') %
                    {"inst": instance_id, "msg": e.message})
        return shortcuts.redirect('dash_instances', tenant_id)
Example #17
0
def detail(request, tenant_id, instance_id):
    try:
        instance = api.server_get(request, instance_id)
        try:
            console = api.console_create(request, instance_id, 'vnc')
            vnc_url =  "%s&title=%s(%s)" % (console.output,
                                            instance.name,
                                            instance_id)
        except api_exceptions.ApiException, e:
            LOG.exception(_('ApiException while fetching instance vnc \
                           connection'))
            messages.error(request,
                _('Unable to get vnc console for instance %(inst)s: %(msg)s') %
                {"inst": instance_id, "msg": e.message})
            return shortcuts.redirect('dash_instances', tenant_id)
    except api_exceptions.ApiException, e:
        LOG.exception(_('ApiException while fetching instance info'))
        messages.error(request,
            _('Unable to get information for instance %(inst)s: %(msg)s') %
            {"inst": instance_id, "msg": e.message})
        return shortcuts.redirect('dash_instances', tenant_id)
Example #18
0
def detail(request, instance_id):
    try:
        instance = api.server_get(request, instance_id)
        try:
            console = api.console_create(request, instance_id, 'vnc')
            vnc_url =  "%s&title=%s(%s)" % (console.output,
                                            instance.name,
                                            instance_id)
        except api_exceptions.ApiException, e:
            LOG.exception('ApiException while fetching instance vnc \
                           connection')
            messages.error(request,
                       'Unable to get vnc console for instance %s: %s' %
                       (instance_id, e.message))
            return redirect('dash_instances', tenant_id)
    except api_exceptions.ApiException, e:
        LOG.exception('ApiException while fetching instance info')
        messages.error(request,
                   'Unable to get information for instance %s: %s' %
                   (instance_id, e.message))
        return redirect('dash_instances', tenant_id)
Example #19
0
def console(request, tenant_id, instance_id):
    try:
        # TODO(jakedahn): clean this up once the api supports tailing.
        length = request.GET.get('length', '')
        console = api.console_create(request, instance_id, 'text')
        response = http.HttpResponse(mimetype='text/plain')
        if length:
            response.write('\n'.join(
                console.output.split('\n')[-int(length):]))
        else:
            response.write(console.output)
        response.flush()
        return response
    except api_exceptions.ApiException, e:
        LOG.exception(_('ApiException while fetching instance console'))
        messages.error(
            request,
            _('Unable to get log for instance %(inst)s: %(msg)s') % {
                "inst": instance_id,
                "msg": e.message
            })
        return shortcuts.redirect('dash_instances', tenant_id)