def detail(request, instance_id): tenant_id = request.user.tenant_id try: instance = api.server_get(request, instance_id) volumes = api.volume_instance_list(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( 'horizon:nova:instances_and_volumes:instances:index') 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( 'horizon:nova:instances_and_volumes:instances:index')
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('horizon:syspanel:instances:index', 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('horizon:syspanel:instances:index', tenant_id)
def detail(request, instance_id): tenant_id = request.user.tenant_id try: instance = api.server_get(request, instance_id) volumes = api.volume_instance_list(request, instance_id) LOG.debug(("KDS: instance-name: %s instance-ip: %s" %(instance.name, instance.ip))) 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( 'horizon:nova:instances_and_volumes:instances:index') 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( 'horizon:nova:instances_and_volumes:instances:index')
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('horizon:nova:instances_and_volumes:instances:vnc', args=[INSTANCE_ID])) self.assertRedirectsNoFollow( res, reverse('horizon:nova:instances_and_volumes:instances:index'))
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('horizon:nova:instances:vnc', args=[INSTANCE_ID])) self.assertRedirectsNoFollow(res, reverse('horizon:nova:instances:index'))
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('horizon:nova:instances_and_volumes:instances:console', args=[INSTANCE_ID])) self.assertIsInstance(res, http.HttpResponse) self.assertContains(res, CONSOLE_OUTPUT)
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('horizon:nova:instances:console', args=[INSTANCE_ID])) self.assertIsInstance(res, http.HttpResponse) self.assertContains(res, CONSOLE_OUTPUT)
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('horizon:nova:instances_and_volumes:instances:console', args=[INSTANCE_ID])) self.assertRedirectsNoFollow( res, reverse('horizon:nova:instances_and_volumes:instances:index'))
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('horizon:nova:instances:console', args=[INSTANCE_ID])) self.assertRedirectsNoFollow(res, reverse('horizon:nova:instances:index'))
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('horizon:nova:instances_and_volumes:instances:vnc', args=[INSTANCE_ID])) self.assertRedirectsNoFollow(res, CONSOLE_OUTPUT + '&title=serverName(1)')
def vnc(request, instance_id): tenant_id = request.user.tenant_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('horizon:nova:instances:index')
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('horizon:nova:instances:vnc', args=[INSTANCE_ID])) self.assertRedirectsNoFollow(res, CONSOLE_OUTPUT + '&title=serverName(1)')
def vnc(request, instance_id): tenant_id = request.user.tenant_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( 'horizon:nova:instances_and_volumes:instances:index')
def console(request, instance_id): tenant_id = request.user.tenant_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('horizon:nova:instances:index')
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('horizon:syspanel:instances:index', 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('horizon:syspanel:instances:index', tenant_id)
def console(request, instance_id): tenant_id = request.user.tenant_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( 'horizon:nova:instances_and_volumes:instances:index')