def test_associate_post(self): server = self.server self.mox.StubOutWithMock(api, 'server_list') api.server_list = self.mox.CreateMockAnything() api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers) self.mox.StubOutWithMock(api, 'tenant_floating_ip_list') api.tenant_floating_ip_list(IsA(http.HttpRequest)).\ AndReturn(self.floating_ips) self.mox.StubOutWithMock(api, 'server_add_floating_ip') api.server_add_floating_ip = self.mox.CreateMockAnything() api.server_add_floating_ip(IsA(http.HttpRequest), IsA(unicode), IsA(unicode)).\ AndReturn(None) self.mox.StubOutWithMock(messages, 'info') messages.info(IsA(http.HttpRequest), IsA(unicode)) self.mox.StubOutWithMock(api, 'tenant_floating_ip_get') api.tenant_floating_ip_get = self.mox.CreateMockAnything() api.tenant_floating_ip_get(IsA(http.HttpRequest), str(1)).\ AndReturn(self.floating_ip) self.mox.ReplayAll() res = self.client.post(reverse('dash_floating_ips_associate', args=[self.TEST_TENANT, 1]), {'instance_id': 1, 'floating_ip_id': self.floating_ip.id, 'floating_ip': self.floating_ip.ip, 'method': 'FloatingIpAssociate'}) self.assertRedirects(res, reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.mox.VerifyAll()
def test_index(self): self.mox.StubOutWithMock(api, 'server_list') api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers) self.mox.ReplayAll() res = self.client.get(reverse('dash_instances', args=[self.TEST_TENANT])) self.assertTemplateUsed(res, 'dash_instances.html') self.assertItemsEqual(res.context['instances'], self.servers) self.mox.VerifyAll()
def test_index_server_list_exception(self): self.mox.StubOutWithMock(api, 'server_list') exception = api_exceptions.ApiException('apiException') api.server_list(IsA(http.HttpRequest)).AndRaise(exception) self.mox.ReplayAll() res = self.client.get(reverse('dash_instances', args=[self.TEST_TENANT])) self.assertTemplateUsed(res, 'dash_instances.html') self.assertEqual(len(res.context['instances']), 0) self.mox.VerifyAll()
def test_index(self): self.mox.StubOutWithMock(api, 'server_list') api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers) self.mox.ReplayAll() res = self.client.get(reverse('dash_instances', args=[self.TEST_TENANT])) self.assertTemplateUsed(res, 'django_openstack/dash/instances/index.html') self.assertItemsEqual(res.context['instances'], self.servers) self.mox.VerifyAll()
def test_index_server_list_exception(self): self.mox.StubOutWithMock(api, 'server_list') exception = api_exceptions.ApiException('apiException') api.server_list(IsA(http.HttpRequest)).AndRaise(exception) self.mox.ReplayAll() res = self.client.get(reverse('dash_instances', args=[self.TEST_TENANT])) self.assertTemplateUsed(res, 'django_openstack/dash/instances/index.html') self.assertEqual(len(res.context['instances']), 0) self.mox.VerifyAll()
def test_associate(self): self.mox.StubOutWithMock(api, 'server_list') api.server_list = self.mox.CreateMockAnything() api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers) self.mox.StubOutWithMock(api, 'tenant_floating_ip_get') api.tenant_floating_ip_get = self.mox.CreateMockAnything() api.tenant_floating_ip_get(IsA(http.HttpRequest), str(1)).\ AndReturn(self.floating_ip) self.mox.ReplayAll() res = self.client.get( reverse('dash_floating_ips_associate', args=[self.TEST_TENANT, 1])) self.assertTemplateUsed( res, 'django_openstack/dash/floating_ips/associate.html') self.mox.VerifyAll()
def index(request, tenant_id): for f in (TerminateInstance, RebootInstance): _, handled = f.maybe_handle(request) if handled: return handled instances = [] try: image_dict = api.image_all_metadata(request) instances = api.server_list(request) for instance in instances: # FIXME - ported this over, but it is hacky instance._info['attrs']['image_name'] =\ image_dict.get(int(instance.attrs['image_id']),{}).get('name') except Exception as e: messages.error(request, 'Unable to get instance list: %s' % e.message) # We don't have any way of showing errors for these, so don't bother # trying to reuse the forms from above terminate_form = TerminateInstance() reboot_form = RebootInstance() return render_to_response('dash_instances.html', { 'instances': instances, 'terminate_form': terminate_form, 'reboot_form': reboot_form, }, context_instance=template.RequestContext(request))
def index(request, tenant_id): for f in (TerminateInstance, RebootInstance): form, handled = f.maybe_handle(request) if handled: return handled instances = [] try: instances = api.server_list(request) except api_exceptions.ApiException as e: LOG.exception(_('Exception in instance index')) messages.error(request, _('Unable to get instance list: %s') % e.message) # We don't have any way of showing errors for these, so don't bother # trying to reuse the forms from above terminate_form = TerminateInstance() reboot_form = RebootInstance() return shortcuts.render_to_response( 'django_openstack/dash/instances/index.html', { 'instances': instances, 'terminate_form': terminate_form, 'reboot_form': reboot_form, }, context_instance=template.RequestContext(request))
def test_associate(self): self.mox.StubOutWithMock(api, 'server_list') api.server_list = self.mox.CreateMockAnything() api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers) self.mox.StubOutWithMock(api, 'tenant_floating_ip_get') api.tenant_floating_ip_get = self.mox.CreateMockAnything() api.tenant_floating_ip_get(IsA(http.HttpRequest), str(1)).\ AndReturn(self.floating_ip) self.mox.ReplayAll() res = self.client.get(reverse('dash_floating_ips_associate', args=[self.TEST_TENANT, 1])) self.assertTemplateUsed(res, 'django_openstack/dash/floating_ips/associate.html') self.mox.VerifyAll()
def test_associate_post_with_exception(self): server = self.server self.mox.StubOutWithMock(api, 'server_list') api.server_list = self.mox.CreateMockAnything() api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers) self.mox.StubOutWithMock(api, 'tenant_floating_ip_list') api.tenant_floating_ip_list(IsA(http.HttpRequest)).\ AndReturn(self.floating_ips) self.mox.StubOutWithMock(api, 'server_add_floating_ip') api.server_add_floating_ip = self.mox.CreateMockAnything() exception = novaclient_exceptions.ClientException( 'ClientException', message='clientException') api.server_add_floating_ip(IsA(http.HttpRequest), IsA(unicode), IsA(unicode)).\ AndRaise(exception) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(str)) self.mox.StubOutWithMock(api, 'tenant_floating_ip_get') api.tenant_floating_ip_get = self.mox.CreateMockAnything() api.tenant_floating_ip_get(IsA(http.HttpRequest), IsA(unicode)).\ AndReturn(self.floating_ip) self.mox.ReplayAll() res = self.client.post( reverse('dash_floating_ips_associate', args=[self.TEST_TENANT, 1]), { 'instance_id': 1, 'floating_ip_id': self.floating_ip.id, 'floating_ip': self.floating_ip.ip, 'method': 'FloatingIpAssociate' }) self.assertRaises(novaclient_exceptions.ClientException) self.assertRedirects( res, reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.mox.VerifyAll()
def test_associate_post_with_exception(self): server = self.server self.mox.StubOutWithMock(api, 'server_list') api.server_list = self.mox.CreateMockAnything() api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers) self.mox.StubOutWithMock(api, 'tenant_floating_ip_list') api.tenant_floating_ip_list(IsA(http.HttpRequest)).\ AndReturn(self.floating_ips) self.mox.StubOutWithMock(api, 'server_add_floating_ip') api.server_add_floating_ip = self.mox.CreateMockAnything() exception = novaclient_exceptions.ClientException('ClientException', message='clientException') api.server_add_floating_ip(IsA(http.HttpRequest), IsA(unicode), IsA(unicode)).\ AndRaise(exception) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(basestring)) self.mox.StubOutWithMock(api, 'tenant_floating_ip_get') api.tenant_floating_ip_get = self.mox.CreateMockAnything() api.tenant_floating_ip_get(IsA(http.HttpRequest), IsA(unicode)).\ AndReturn(self.floating_ip) self.mox.ReplayAll() res = self.client.post(reverse('dash_floating_ips_associate', args=[self.TEST_TENANT, 1]), {'instance_id': 1, 'floating_ip_id': self.floating_ip.id, 'floating_ip': self.floating_ip.ip, 'method': 'FloatingIpAssociate'}) self.assertRaises(novaclient_exceptions.ClientException) self.assertRedirects(res, reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.mox.VerifyAll()
def test_associate_post(self): server = self.server self.mox.StubOutWithMock(api, 'server_list') api.server_list = self.mox.CreateMockAnything() api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers) self.mox.StubOutWithMock(api, 'tenant_floating_ip_list') api.tenant_floating_ip_list(IsA(http.HttpRequest)).\ AndReturn(self.floating_ips) self.mox.StubOutWithMock(api, 'server_add_floating_ip') api.server_add_floating_ip = self.mox.CreateMockAnything() api.server_add_floating_ip(IsA(http.HttpRequest), IsA(unicode), IsA(unicode)).\ AndReturn(None) self.mox.StubOutWithMock(messages, 'info') messages.info(IsA(http.HttpRequest), IsA(unicode)) self.mox.StubOutWithMock(api, 'tenant_floating_ip_get') api.tenant_floating_ip_get = self.mox.CreateMockAnything() api.tenant_floating_ip_get(IsA(http.HttpRequest), str(1)).\ AndReturn(self.floating_ip) self.mox.ReplayAll() res = self.client.post( reverse('dash_floating_ips_associate', args=[self.TEST_TENANT, 1]), { 'instance_id': 1, 'floating_ip_id': self.floating_ip.id, 'floating_ip': self.floating_ip.ip, 'method': 'FloatingIpAssociate' }) self.assertRedirects( res, reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.mox.VerifyAll()
def associate(request, tenant_id, ip_id): instancelist = [(server.id, 'id: %s, name: %s' % (server.id, server.name)) for server in api.server_list(request)] form, handled = FloatingIpAssociate().maybe_handle(request, initial={ 'floating_ip_id': ip_id, 'floating_ip': api.tenant_floating_ip_get(request, ip_id).ip, 'instances': instancelist}) if handled: return handled return shortcuts.render_to_response( 'django_openstack/dash/floating_ips/associate.html', { 'associate_form': form, }, context_instance=template.RequestContext(request))
def refresh(request, tenant_id): instances = [] try: instances = api.server_list(request) except Exception as e: messages.error(request, _("Unable to get instance list: %s") % e.message) # We don't have any way of showing errors for these, so don't bother # trying to reuse the forms from above terminate_form = TerminateInstance() reboot_form = RebootInstance() return shortcuts.render_to_response( "django_openstack/dash/instances/_instance_list.html", {"instances": instances, "terminate_form": terminate_form, "reboot_form": reboot_form}, context_instance=template.RequestContext(request), )
def refresh(request, tenant_id): instances = [] try: instances = api.server_list(request) except Exception as e: messages.error(request, 'Unable to get instance list: %s' % e.message) # We don't have any way of showing errors for these, so don't bother # trying to reuse the forms from above terminate_form = TerminateInstance() reboot_form = RebootInstance() return shortcuts.render_to_response('_instance_list.html', { 'instances': instances, 'terminate_form': terminate_form, 'reboot_form': reboot_form, }, context_instance=template.RequestContext(request))
def test_server_list(self): servers = (TEST_RETURN, TEST_RETURN + "2") extras_api = self.stub_extras_api() extras_api.servers = self.mox.CreateMockAnything() extras_api.servers.list().AndReturn(servers) self.mox.ReplayAll() ret_val = api.server_list(self.request) self.assertEqual(len(ret_val), len(servers)) for server in ret_val: self.assertIsInstance(server, api.Server) self.assertIn(server._apiresource, servers) self.mox.VerifyAll()
def refresh(request, tenant_id): instances = [] try: instances = api.server_list(request) except Exception as e: messages.error(request, 'Unable to get instance list: %s' % e.message) # We don't have any way of showing errors for these, so don't bother # trying to reuse the forms from above terminate_form = TerminateInstance() reboot_form = RebootInstance() return shortcuts.render_to_response( 'django_openstack/dash/instances/_instance_list.html', { 'instances': instances, 'terminate_form': terminate_form, 'reboot_form': reboot_form, }, context_instance=template.RequestContext(request))
def refresh(request): for f in (TerminateInstance, RebootInstance): _, handled = f.maybe_handle(request) if handled: return handled instances = [] try: instances = api.server_list(request) except Exception as e: messages.error(request, 'Unable to get instance list: %s' % e.message) # We don't have any way of showing errors for these, so don't bother # trying to reuse the forms from above terminate_form = TerminateInstance() reboot_form = RebootInstance() return render_to_response('_syspanel_instance_list.html', { 'instances': instances, 'terminate_form': terminate_form, 'reboot_form': reboot_form, }, context_instance=template.RequestContext(request))
def index(request, tenant_id): for f in (TerminateInstance, RebootInstance): _, handled = f.maybe_handle(request) if handled: return handled instances = [] try: instances = api.server_list(request) except api_exceptions.ApiException as e: LOG.error('Exception in instance index', exc_info=True) messages.error(request, 'Unable to get instance list: %s' % e.message) # We don't have any way of showing errors for these, so don't bother # trying to reuse the forms from above terminate_form = TerminateInstance() reboot_form = RebootInstance() return shortcuts.render_to_response('dash_instances.html', { 'instances': instances, 'terminate_form': terminate_form, 'reboot_form': reboot_form, }, context_instance=template.RequestContext(request))
def index(request, tenant_id): for f in (TerminateInstance, RebootInstance): form, handled = f.maybe_handle(request) if handled: return handled instances = [] try: instances = api.server_list(request) except api_exceptions.ApiException as e: LOG.exception("Exception in instance index") messages.error(request, _("Unable to get instance list: %s") % e.message) # We don't have any way of showing errors for these, so don't bother # trying to reuse the forms from above terminate_form = TerminateInstance() reboot_form = RebootInstance() return shortcuts.render_to_response( "django_openstack/dash/instances/index.html", {"instances": instances, "terminate_form": terminate_form, "reboot_form": reboot_form}, context_instance=template.RequestContext(request), )
def instances(): insts = api.server_list(request) return [(inst.id, '%s (Instance %s)' % (inst.name, inst.id)) for inst in insts]
def associate(request, tenant_id, ip_id): instancelist = [(server.id, "id: %s, name: %s" % (server.id, server.name)) for server in api.server_list(request)] form, handled = FloatingIpAssociate().maybe_handle( request, initial={ "floating_ip_id": ip_id, "floating_ip": api.tenant_floating_ip_get(request, ip_id).ip, "instances": instancelist, }, ) if handled: return handled return shortcuts.render_to_response( "django_openstack/dash/floating_ips/associate.html", {"associate_form": form}, context_instance=template.RequestContext(request), )