Esempio n. 1
0
    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(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("steer:engine:access_and_security:floating_ips:associate", args=[1]),
            {
                "instance_id": 1,
                "floating_ip_id": self.floating_ip.id,
                "floating_ip": self.floating_ip.ip,
                "method": "FloatingIpAssociate",
            },
        )

        self.assertRedirects(res, INDEX_URL)
Esempio n. 2
0
    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(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('steer:engine:access_and_security:floating_ips:associate',
                    args=[1]), {
                        'instance_id': 1,
                        'floating_ip_id': self.floating_ip.id,
                        'floating_ip': self.floating_ip.ip,
                        'method': 'FloatingIpAssociate'
                    })

        self.assertRedirects(res, INDEX_URL)
Esempio n. 3
0
    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("steer:engine:access_and_security:floating_ips:associate", args=[1]))
        self.assertTemplateUsed(res, "engine/access_and_security/floating_ips/associate.html")
Esempio n. 4
0
    def test_index(self):
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('steer:engine:instances_and_volumes:index'))

        self.assertTemplateUsed(res,
            'engine/instances_and_volumes/index.html')
        self.assertItemsEqual(res.context['instances'], self.servers)
Esempio n. 5
0
    def test_index_server_list_exception(self):
        self.mox.StubOutWithMock(api, 'server_list')
        self.mox.StubOutWithMock(api, 'volume_list')
        exception = api_exceptions.ApiException('apiException')
        api.server_list(IsA(http.HttpRequest)).AndRaise(exception)
        api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes)

        self.mox.ReplayAll()

        res = self.client.get(
                reverse('steer:engine:instances_and_volumes:index'))

        self.assertTemplateUsed(res,
                'engine/instances_and_volumes/index.html')
        self.assertEqual(len(res.context['instances']), 0)
Esempio n. 6
0
def index(request):
    tenant_id = request.user.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 Exception as e:
        LOG.exception(_('Exception in instance index'))
        if not hasattr(e, 'message'):
            e.message = str(e)
        messages.error(request, _('Unable to get instance list: %s')
                       % e.message)

    # Gather our flavors and correlate our instances to them
    try:
        flavors = api.flavor_list(request)
        full_flavors = SortedDict([(str(flavor.id), flavor) for \
                                    flavor in flavors])
        for instance in instances:
            instance.full_flavor = full_flavors[instance.flavor["id"]]
    except api_exceptions.Unauthorized, e:
        LOG.exception('Unauthorized attempt to access flavor list.')
        messages.error(request, _('Unauthorized.'))
Esempio n. 7
0
    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('steer:engine:access_and_security:floating_ips:associate',
                    args=[1]))
        self.assertTemplateUsed(
            res, 'engine/access_and_security/floating_ips/associate.html')
Esempio n. 8
0
def index(request):
    tenant_id = request.user.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 Exception as e:
        LOG.exception(_('Exception in instance index'))
        if not hasattr(e, 'message'):
            e.message = str(e)
        messages.error(request,
                       _('Unable to get instance list: %s') % e.message)

    # Gather our flavors and correlate our instances to them
    try:
        flavors = api.flavor_list(request)
        full_flavors = SortedDict([(str(flavor.id), flavor) for \
                                    flavor in flavors])
        for instance in instances:
            instance.full_flavor = full_flavors[instance.flavor["id"]]
    except api_exceptions.Unauthorized, e:
        LOG.exception('Unauthorized attempt to access flavor list.')
        messages.error(request, _('Unauthorized.'))
Esempio n. 9
0
 def get_initial(self):
     instances = [(server.id, 'id: %s, name: %s' % (server.id, server.name))
                  for server in api.server_list(self.request)]
     return {
         'floating_ip_id': self.object.id,
         'floating_ip': self.object.ip,
         'instances': instances
     }
Esempio n. 10
0
    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, 'security_group_list')
        api.security_group_list(IsA(http.HttpRequest)).\
                                AndReturn(self.security_groups)
        self.mox.StubOutWithMock(api.engine, 'keypair_list')
        api.engine.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.StubOutWithMock(api, 'server_add_floating_ip')
        api.server_add_floating_ip = self.mox.CreateMockAnything()
        exception = engineclient_exceptions.ClientException(
            'ClientException', message='clientException')
        api.server_add_floating_ip(IsA(http.HttpRequest), IsA(unicode),
                                                          IsA(unicode)).\
                                                          AndRaise(exception)

        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('steer:engine:access_and_security:floating_ips:associate',
                    args=[1]), {
                        'instance_id': 1,
                        'floating_ip_id': self.floating_ip.id,
                        'floating_ip': self.floating_ip.ip,
                        'method': 'FloatingIpAssociate'
                    })
        self.assertRaises(engineclient_exceptions.ClientException)

        self.assertRedirects(res, INDEX_URL)
Esempio n. 11
0
def attach(request, volume_id):
    instances = api.server_list(request)
    attach_form, handled = AttachForm.maybe_handle(request,
                                      initial={'volume_id': volume_id,
                                               'instances': instances})

    if handled:
        return handled

    return shortcuts.render(request,
                            'engine/instances_and_volumes/volumes/attach.html', {
                                'attach_form': attach_form,
                                'volume_id': volume_id})
Esempio n. 12
0
    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, "security_group_list")
        api.security_group_list(IsA(http.HttpRequest)).AndReturn(self.security_groups)
        self.mox.StubOutWithMock(api.engine, "keypair_list")
        api.engine.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs)

        self.mox.StubOutWithMock(api, "server_add_floating_ip")
        api.server_add_floating_ip = self.mox.CreateMockAnything()
        exception = engineclient_exceptions.ClientException("ClientException", message="clientException")
        api.server_add_floating_ip(IsA(http.HttpRequest), IsA(unicode), IsA(unicode)).AndRaise(exception)

        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("steer:engine:access_and_security:floating_ips:associate", args=[1]),
            {
                "instance_id": 1,
                "floating_ip_id": self.floating_ip.id,
                "floating_ip": self.floating_ip.ip,
                "method": "FloatingIpAssociate",
            },
        )
        self.assertRaises(engineclient_exceptions.ClientException)

        self.assertRedirects(res, INDEX_URL)
Esempio n. 13
0
def attach(request, volume_id):
    instances = api.server_list(request)
    attach_form, handled = AttachForm.maybe_handle(request,
                                                   initial={
                                                       'volume_id': volume_id,
                                                       'instances': instances
                                                   })

    if handled:
        return handled

    return shortcuts.render(
        request, 'engine/instances_and_volumes/volumes/attach.html', {
            'attach_form': attach_form,
            'volume_id': volume_id
        })
Esempio n. 14
0
def index(request):
    for f in (TerminateInstance, RebootInstance, DeleteForm, DetachForm):
        form, handled = f.maybe_handle(request)
        if handled:
            return handled

    # Gather our instances
    try:
        instances = api.server_list(request)
    except api_exceptions.ApiException as e:
        instances = []
        LOG.exception(_('Exception in instance index'))
        messages.error(request, _('Unable to fetch instances: %s') % e.message)

    # Gather our volumes
    try:
        volumes = api.volume_list(request)
    except engineclient_exceptions.ClientException, e:
        volumes = []
        LOG.exception("ClientException in volume index")
        messages.error(request, _('Unable to fetch volumes: %s') % e.message)
Esempio n. 15
0
def refresh(request):
    tenant_id = request.user.tenant_id
    instances = []
    try:
        instances = api.server_list(request)
    except Exception as e:
        if not hasattr(e, 'message'):
            e.message = str(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(request,
                        'engine/instances_and_volumes/instances/_list.html', {
                            'instances': instances,
                            'terminate_form': terminate_form,
                            'reboot_form': reboot_form})
Esempio n. 16
0
def refresh(request):
    tenant_id = request.user.tenant_id
    instances = []
    try:
        instances = api.server_list(request)
    except Exception as e:
        if not hasattr(e, 'message'):
            e.message = str(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(
        request, 'engine/instances_and_volumes/instances/_list.html', {
            'instances': instances,
            'terminate_form': terminate_form,
            'reboot_form': reboot_form
        })
Esempio n. 17
0
 def get_initial(self):
     instances = [
         (server.id, "id: %s, name: %s" % (server.id, server.name)) for server in api.server_list(self.request)
     ]
     return {"floating_ip_id": self.object.id, "floating_ip": self.object.ip, "instances": instances}