def get_object(self): if not hasattr(self, "_object"): try: self._object = api.image_get(self.request, self.kwargs['image_id']) except: msg = _('Unable to retrieve image.') url = reverse('horizon:project:images_and_snapshots:index') exceptions.handle(self.request, msg, redirect=url) return self._object
def test_image_update_get(self): image = self.images.first() image.disk_format = "ami" image.is_public = True api.image_get(IsA(http.HttpRequest), str(image.id)) \ .AndReturn(image) self.mox.ReplayAll() res = self.client.get( reverse('horizon:project:images_and_snapshots:images:update', args=[image.id])) self.assertTemplateUsed(res, 'project/images_and_snapshots/images/_update.html') self.assertEqual(res.context['image'].name, image.name) # Bug 1076216 - is_public checkbox not being set correctly self.assertContains(res, "<input type='checkbox' id='id_public'" " name='public' checked='checked'>", html=True, msg_prefix="The is_public checkbox is not checked")
def test_image_update_get(self): image = self.images.first() image.disk_format = "ami" image.is_public = True api.image_get(IsA(http.HttpRequest), str(image.id)) \ .AndReturn(image) self.mox.ReplayAll() res = self.client.get( reverse('horizon:project:images_and_snapshots:images:update', args=[image.id])) self.assertTemplateUsed( res, 'project/images_and_snapshots/images/_update.html') self.assertEqual(res.context['image'].name, image.name) # Bug 1076216 - is_public checkbox not being set correctly self.assertContains(res, "<input type='checkbox' id='id_public'" " name='public' checked='checked'>", html=True, msg_prefix="The is_public checkbox is not checked")
def launch(request, tenant_id, image_id): def flavorlist(): try: fl = api.flavor_list(request) # TODO add vcpu count to flavors sel = [(f.id, "%s (%svcpu / %sGB Disk / %sMB Ram )" % (f.name, f.vcpus, f.disk, f.ram)) for f in fl] return sorted(sel) except api_exceptions.ApiException: LOG.error("Unable to retrieve list of instance types", exc_info=True) return [(1, "m1.tiny")] def keynamelist(): try: fl = api.keypair_list(request) sel = [(f.key_name, f.key_name) for f in fl] return sel except api_exceptions.ApiException: LOG.error("Unable to retrieve list of keypairs", exc_info=True) return [] def securitygrouplist(): try: fl = api.security_group_list(request) sel = [(f.name, f.name) for f in fl] return sel except api_exceptions.ApiException: LOG.error("Unable to retrieve list of security groups", exc_info=True) return [] # TODO(mgius): Any reason why these can't be after the launchform logic? # If The form is valid, we've just wasted these two api calls image = api.image_get(request, image_id) tenant = api.token_get_tenant(request, request.user.tenant) quotas = api.tenant_quota_get(request, request.user.tenant) try: quotas.ram = int(quotas.ram) / 100 except Exception, e: messages.error(request, "Error parsing quota for %s: %s" % (image_id, e.message)) return redirect(topbar + "/instances", tenant_id)
def handle(self, request, data): image_id = data["image_id"] tenant_id = data["tenant_id"] try: image = api.image_get(request, image_id) flavor = api.flavor_get(request, data["flavor"]) api.server_create( request, data["name"], image, flavor, data.get("key_name"), data.get("user_data"), data.get("security_groups"), ) msg = "Instance was successfully launched" LOG.info(msg) messages.success(request, msg) return redirect(topbar + "/instances", tenant_id) except api_exceptions.ApiException, e: LOG.error('ApiException while creating instances of image "%s"' % image_id, exc_info=True) messages.error(request, "Unable to launch instance: %s" % e.message)
def get_data(self, request, image_id): image = api.image_get(request, image_id) return image
def update(request, image_id): try: image = api.image_get(request, image_id) except glance_exception.ClientConnectionError, e: LOG.error("Error connecting to glance", exc_info=True) messages.error(request, "Error connecting to glance: %s" % e.message)