Esempio n. 1
0
File: images.py Progetto: masom/Puck
    def delete(self, id):
        image = Images.first(id=id)
        msg = "The image could not be deleted."
        if image and Images.delete(image):
            msg = "Image deleted"
        cherrypy.session['flash'] = msg

        raise cherrypy.HTTPRedirect('/images')
Esempio n. 2
0
File: images.py Progetto: masom/Puck
    def edit(self, id, **post):
        image = Images.first(id=id)

        if not image:
            cherrypy.session['flash'] = "404 Image Not Found"
            raise cherrypy.HTTPRedirect('/images')

        if post:
            fields = ['name', 'backend_id', 'description']
            data = self._get_data('image', fields, post)
            if image.update(data, fields):
                cherrypy.session['flash'] = "Image successfully updated."
                raise cherrypy.HTTPRedirect('/images')

            cherrypy.session['flash'] = 'Invalid data'

        backend_images = Images.get_backend_images()
        env=dict(image = image, backend_images=backend_images)
        return self.render("/images/edit.html", crumbs=self.crumbs, **env)
Esempio n. 3
0
    def start(self, **post):
        if post:
            self._validate_start_post_data(post)
            creds = cherrypy.session.get('credentials')

            image = Images.first(id=post['image.id'])
            instance_type = self._get_instance_type(post)

            self._validate_start_args(image, instance_type)

            vm = VirtualMachines.new(status="new")

            if VirtualMachines.add(vm):
                if not vm.start_instance(image, instance_type, creds):
                    cherrypy.session['flash'] = 'The virtual machine could not be started.'
                    raise cherrypy.HTTPRedirect("/virtual_machines")
        else:
            cherrypy.session['flash'] = 'Missing image id.'

        raise cherrypy.HTTPRedirect("/virtual_machines")