Exemple #1
0
    def post_resource(self, I):
        form = ResourceForm(self)
        if form.validate():

            # TODO: resource limit
            RUNNING_INST_LIST = self.db2.query(Instance).filter( and_(
                    Instance.status.in_( settings.INSTANCE_SLIST_RUNING ),
                    Instance.user_id == I.user_id ) )

            USED_CPUS, USED_MEMORY = 0, 0
            for instance in RUNNING_INST_LIST:
                if instance.is_running:
                    USED_CPUS += instance.cpus
                    USED_MEMORY += instance.memory

            profile = I.user.profile
            if (form.cpus.data + USED_CPUS) > profile.cpus:
                form.cpus.errors.append( self.trans(_('cpus can not greater than %s')) % (profile.cpus - USED_CPUS) )
            if (form.memory.data + USED_MEMORY) > profile.memory:
                form.memory.errors.append( self.trans(_('memory can not greater than %s')) % (profile.memory - USED_MEMORY) )
            if not (form.cpus.errors or form.memory.errors):

                I.cpus = form.cpus.data
                I.memory = form.memory.data
                if I.is_running:
                    I.ischanged = True
                self.db2.commit()

                url = self.reverse_url('myun:instance:view', I.id)
                url += '?tab=resource'
                return self.redirect( url )


        self.d['form'] = form
        self.render( 'myun/instance/edit_resource.html', **self.d)
Exemple #2
0
    def post(self, id):

        inst = self.get_instance(id, isowner=True)
        if not inst: return

        form = ResourceForm( self.request.arguments )
        if form.validate():

            # TODO: resource limit
            RUNNING_INST_LIST = self.db2.query(Instance).filter( and_(
                    Instance.status.in_( settings.INSTANCE_SLIST_RUNING ),
                    Instance.user_id == inst.user_id ) )

            USED_CPUS, USED_MEMORY = 0, 0
            for I in RUNNING_INST_LIST:
                if I.is_running:
                    USED_CPUS += I.cpus
                    USED_MEMORY += I.memory

            profile = inst.user.profile
            if (form.cpus.data + USED_CPUS) > profile.cpus:
                form.cpus.errors.append( _('cpus can not greater than %s') % (profile.cpus - USED_CPUS) )
            if (form.memory.data + USED_MEMORY) > profile.memory:
                form.memory.errors.append( _('memory can not greater than %s') % (profile.memory - USED_MEMORY) )
            if form.cpus.errors or form.memory.errors:
                d = { 'title': _('Edit Resource'),
                      'instance': inst, 'form': form }
                self.render('instance/resource_edit.html', **d)
                

            inst.cpus = form.cpus.data
            inst.memory = form.memory.data
            if inst.is_running:
                inst.ischanged = True
            self.db2.commit()

            url = self.reverse_url('instance:view', id)
            url += '?view=resource'
            return self.redirect( url )

        # Get error
        d = { 'title': _('Edit Resource'),
              'instance': inst, 'form': form }
        self.render('instance/resource_edit.html', **d)
Exemple #3
0
    def post(self, id):

        inst = self.get_instance(id, isowner=True)
        if not inst: return

        form = ResourceForm( self.request.arguments )
        if form.validate():

            # TODO: resource limit
            RUNNING_INST_LIST = self.db2.query(Instance).filter( and_(
                    Instance.status.in_( settings.INSTANCE_SLIST_RUNING ),
                    Instance.user_id == inst.user_id ) )

            USED_CPUS, USED_MEMORY = 0, 0
            for I in RUNNING_INST_LIST:
                if I.is_running:
                    USED_CPUS += I.cpus
                    USED_MEMORY += I.memory

            profile = inst.user.profile
            if (form.cpus.data + USED_CPUS) > profile.cpus:
                form.cpus.errors.append( _('cpus can not greater than %s') % (profile.cpus - USED_CPUS) )
            if (form.memory.data + USED_MEMORY) > profile.memory:
                form.memory.errors.append( _('memory can not greater than %s') % (profile.memory - USED_MEMORY) )
            if form.cpus.errors or form.memory.errors:
                d = { 'title': _('Edit Resource'),
                      'instance': inst, 'form': form }
                self.render('instance/resource_edit.html', **d)
                

            inst.cpus = form.cpus.data
            inst.memory = form.memory.data
            if inst.is_running:
                inst.ischanged = True
            self.db2.commit()

            url = self.reverse_url('instance:view', id)
            url += '?view=resource'
            return self.redirect( url )

        # Get error
        d = { 'title': _('Edit Resource'),
              'instance': inst, 'form': form }
        self.render('instance/resource_edit.html', **d)
Exemple #4
0
    def get(self, id):

        inst = self.get_instance(id, isowner=True)
        if not inst: return

        form = ResourceForm()
        form.cpus.data = inst.cpus
        form.memory.data = inst.memory

        d = { 'title': _('Edit Resource'),
              'instance': inst, 'form': form }

        self.render('instance/resource_edit.html', **d)