def stub_glance_api(self, count=1):
     self.mox.StubOutWithMock(api, "glance_api")
     glance_api = self.mox.CreateMock(glance_client.Client)
     glance_api.token = TEST_TOKEN
     for i in range(count):
         api.glance_api(IsA(http.HttpRequest)).AndReturn(glance_api)
     return glance_api
def index(request, tenant_id):
    tenant = api.get_tenant(request, request.user.tenant)
    all_images = []
    try:
        all_images = api.glance_api(request).get_images_detailed()
        if not all_images:
            messages.info(request, "There are currently no images.")
    except GlanceClientConnectionError, e:
        messages.error(request, "Error connecting to glance: %s" % e.message)
    def test_get_glance_api(self):
        self.mox.StubOutClassWithMocks(glance_client, 'Client')
        glance_client.Client(TEST_HOSTNAME, TEST_PORT)

        self.mox.StubOutWithMock(api, 'url_for')
        api.url_for(IsA(http.HttpRequest), 'glance').AndReturn(TEST_URL)

        self.mox.ReplayAll()

        self.assertIsNotNone(api.glance_api(self.request))

        self.mox.VerifyAll()
    def test_get_glance_api(self):
        self.mox.StubOutClassWithMocks(glance_client, "Client")
        client_instance = glance_client.Client(TEST_HOSTNAME, TEST_PORT, auth_tok=TEST_TOKEN)
        # Normally ``auth_tok`` is set in ``Client.__init__``, but mox doesn't
        # duplicate that behavior so we set it manually.
        client_instance.auth_tok = TEST_TOKEN

        self.mox.StubOutWithMock(api, "url_for")
        api.url_for(IsA(http.HttpRequest), "glance").AndReturn(TEST_URL)

        self.mox.ReplayAll()

        ret_val = api.glance_api(self.request)
        self.assertIsNotNone(ret_val)
        self.assertEqual(ret_val.auth_tok, TEST_TOKEN)

        self.mox.VerifyAll()
def index(request):
    for f in (DeleteImage, ToggleImage):
        _, handled = f.maybe_handle(request)
        if handled:
            return handled

    # We don't have any way of showing errors for these, so don't bother
    # trying to reuse the forms from above
    delete_form = DeleteImage()
    toggle_form = ToggleImage()

    images = []
    try:
        images = api.glance_api(request).get_images_detailed()
        if not images:
            messages.info(request, "There are currently no images.")
    except GlanceClientConnectionError, e:
        messages.error(request, "Error connecting to glance: %s" % e.message)
 def handle(self, request, data):
     try:
         api.glance_api(request).update_image(image_id, image_meta={"is_public": False})
     except GlanceClientConnectionError, e:
         messages.error(request, "Error connecting to glance: %s" % e.message)
 def handle(self, request, data):
     image_id = data["image_id"]
     try:
         api.glance_api(request).delete_image(image_id)
     except GlanceClientConnectionError, e:
         messages.error(request, "Error connecting to glance: %s" % e.message)