Ejemplo n.º 1
0
    def test_generate_keypair_get(self):
        keypair = self.keypairs.first()
        keypair.private_key = "secret"

        self.mox.StubOutWithMock(api, 'keypair_create')
        api.keypair_create(IsA(http.HttpRequest),
                           keypair.name).AndReturn(keypair)
        self.mox.ReplayAll()

        context = {'keypair_name': keypair.name}
        url = reverse('horizon:project:access_and_security:keypairs:generate',
                      kwargs={'keypair_name': keypair.name})
        res = self.client.get(url, context)

        self.assertTrue(res.has_header('content-disposition'))
Ejemplo n.º 2
0
    def test_generate_keypair_exception(self):
        keypair = self.keypairs.first()

        self.mox.StubOutWithMock(api, 'keypair_create')
        api.keypair_create(IsA(http.HttpRequest), keypair.name) \
                        .AndRaise(self.exceptions.nova)
        self.mox.ReplayAll()

        context = {'keypair_name': keypair.name}
        url = reverse('horizon:project:access_and_security:keypairs:generate',
                      kwargs={'keypair_name': keypair.name})
        res = self.client.get(url, context)

        self.assertRedirectsNoFollow(
                res, reverse('horizon:project:access_and_security:index'))
 def handle(self, request, data):
     try:
         LOG.info('Creating keypair "%s"' % data["name"])
         keypair = api.keypair_create(request, data["name"])
         response = http.HttpResponse(mimetype="application/binary")
         response["Content-Disposition"] = "attachment; filename=%s.pem" % keypair.key_name
         response.write(keypair.private_key)
         return response
     except api_exceptions.ApiException, e:
         LOG.error("ApiException in CreateKeyPair", exc_info=True)
         messages.error(request, "Error Creating Keypair: %s" % e.message)
         return shortcuts.redirect(request.build_absolute_uri())
Ejemplo n.º 4
0
    def get(self, request, keypair_name=None):
        try:
            keypair = api.keypair_create(request, keypair_name)
        except:
            redirect = reverse("horizon:project:access_and_security:index")
            exceptions.handle(self.request, _("Unable to create keypair: %(exc)s"), redirect=redirect)

        response = http.HttpResponse(mimetype="application/binary")
        response["Content-Disposition"] = "attachment; filename=%s.pem" % slugify(keypair.name)
        response.write(keypair.private_key)
        response["Content-Length"] = str(len(response.content))
        return response
Ejemplo n.º 5
0
    def get(self, request, keypair_name=None):
        try:
            keypair = api.keypair_create(request, keypair_name)
        except:
            redirect = reverse('horizon:project:access_and_security:index')
            exceptions.handle(self.request,
                              _('Unable to create keypair: %(exc)s'),
                              redirect=redirect)

        response = http.HttpResponse(mimetype='application/binary')
        response['Content-Disposition'] = \
                'attachment; filename=%s.pem' % slugify(keypair.name)
        response.write(keypair.private_key)
        response['Content-Length'] = str(len(response.content))
        return response