コード例 #1
0
ファイル: views.py プロジェクト: woerwin/LuoYunCloud
    def post(self):

        form = NetworkPoolForm(self)
        if form.validate():

            N = NetworkPool(
                name = form.name.data,
                description = form.description.data,
                start = form.start.data,
                end = form.end.data,
                netmask = form.netmask.data,
                gateway = form.gateway.data,
                nameservers = form.nameservers.data,
                exclude_ips = form.exclude_ips.data )

            self.db2.add( N )
            self.db2.commit()

            self.add_to_ippool(N)

            url = self.reverse_url('system:networkpool')
            return self.redirect( url )

        d = { 'title': self.trans(_('Add a new network pool')),  'form': form }
        self.render('system/networkpool_add.html', **d)
コード例 #2
0
    def get(self, ID):

        N = self.db2.query(NetworkPool).get(ID)
        if not N:
            return self.write(
                self.trans(_('Can not find networkpool %s')) % ID)

        form = NetworkPoolForm(self)
        form.name.data = N.name
        form.description.data = N.description
        form.start.data = N.start
        form.end.data = N.end
        form.netmask.data = N.netmask
        form.gateway.data = N.gateway
        if N.nameservers:
            form.nameservers.data = N.nameservers
        else:
            nameservers = self.db2.query(LuoYunConfig).filter_by(
                key='nameservers').first()
            if nameservers:
                form.nameservers.data = nameservers.value
        if N.exclude_ips:
            form.exclude_ips.data = N.exclude_ips

        d = {'title': self.trans(_('Edit network pool')), 'form': form}
        self.render('system/networkpool_edit.html', **d)
コード例 #3
0
    def get(self):

        form = NetworkPoolForm(self)
        NS = self.db2.query(LuoYunConfig).filter_by(key='nameservers').first()
        if NS: form.nameservers.data = NS.value

        d = {'title': self.trans(_('Add a new network pool')), 'form': form}
        self.render('system/networkpool_add.html', **d)
コード例 #4
0
ファイル: views.py プロジェクト: alayasix/LuoYunCloud
    def post(self):

        saved = None
        form = NetworkPoolForm( self.request.arguments )
        if form.validate():

            networkpool = {
                'start': form.start.data,
                'end': form.end.data,
                'netmask': form.netmask.data,
                'gateway': form.gateway.data,
                'nameservers': form.nameservers.data,
                'exclude_ips': form.exclude_ips.data,
                }


            nameservers = form.nameservers.data

            if self.nameservers:
                #self.nameservers.value = nameservers
                pass
            else:
                c = LuoYunConfig('nameservers', nameservers)
                self.db2.add( c )

            networkpool = json.dumps( [networkpool, ] )
            if self.networkpool:
                self.networkpool.value = networkpool
            else:
                c = LuoYunConfig('networkpool', networkpool)
                self.db2.add(c)

            self.db2.commit()
            from tool.network import set_network_pool
            # set settings.NETWORK_POOL
            set_network_pool(self.db2)
            saved = True
            # TODO: redirect to ?
            url = self.reverse_url('system:networkpool')
            self.redirect( url )

        self.render('system/networkpool_edit.html',
                    form = form, saved = saved)
コード例 #5
0
ファイル: views.py プロジェクト: alayasix/LuoYunCloud
    def post(self):

        saved = None
        form = NetworkPoolForm(self.request.arguments)
        if form.validate():

            networkpool = {
                'start': form.start.data,
                'end': form.end.data,
                'netmask': form.netmask.data,
                'gateway': form.gateway.data,
                'nameservers': form.nameservers.data,
                'exclude_ips': form.exclude_ips.data,
            }

            nameservers = form.nameservers.data

            if self.nameservers:
                #self.nameservers.value = nameservers
                pass
            else:
                c = LuoYunConfig('nameservers', nameservers)
                self.db2.add(c)

            networkpool = json.dumps([
                networkpool,
            ])
            if self.networkpool:
                self.networkpool.value = networkpool
            else:
                c = LuoYunConfig('networkpool', networkpool)
                self.db2.add(c)

            self.db2.commit()
            from tool.network import set_network_pool
            # set settings.NETWORK_POOL
            set_network_pool(self.db2)
            saved = True
            # TODO: redirect to ?
            url = self.reverse_url('system:networkpool')
            self.redirect(url)

        self.render('system/networkpool_edit.html', form=form, saved=saved)
コード例 #6
0
    def post(self):

        form = NetworkPoolForm(self)
        if form.validate():

            N = NetworkPool(name=form.name.data,
                            description=form.description.data,
                            start=form.start.data,
                            end=form.end.data,
                            netmask=form.netmask.data,
                            gateway=form.gateway.data,
                            nameservers=form.nameservers.data,
                            exclude_ips=form.exclude_ips.data)

            self.db2.add(N)
            self.db2.commit()

            self.add_to_ippool(N)

            url = self.reverse_url('system:networkpool')
            return self.redirect(url)

        d = {'title': self.trans(_('Add a new network pool')), 'form': form}
        self.render('system/networkpool_add.html', **d)
コード例 #7
0
ファイル: views.py プロジェクト: alayasix/LuoYunCloud
    def get(self):

        form = NetworkPoolForm()
        if self.networkpool:
            networkpool = json.loads(self.networkpool.value)
            if len(networkpool) > 0:
                networkpool = networkpool[0]
                form.start.data = networkpool['start']
                form.end.data = networkpool['end']
                form.netmask.data = networkpool['netmask']
                form.gateway.data = networkpool['gateway']
                if networkpool.has_key('nameservers'):
                    form.nameservers.data = networkpool['nameservers']
                else:
                    nameservers = self.db2.query(LuoYunConfig).filter_by(
                        key='nameservers').first()
                    if nameservers:
                        form.nameservers.data = nameservers
                if networkpool.has_key('exclude_ips'):
                    form.exclude_ips.data = networkpool['exclude_ips']

        self.render('system/networkpool_edit.html', form=form)
コード例 #8
0
ファイル: views.py プロジェクト: woerwin/LuoYunCloud
    def post(self, ID):

        N = self.db2.query(NetworkPool).get(ID)
        if not N: return self.write( self.trans(_('Can not find networkpool %s')) % ID )

        form = NetworkPoolForm(self)
        if form.validate():

            # TODO: a ugly algorithm
            OLD, NEW = [], []
            for x in self.db2.query(IPPool).filter_by(network_id=N.id):
                OLD.append( x.ip )

            start, end = IP( form.start.data ), IP( form.end.data )
            exclude_ips = form.exclude_ips.data

            NETWORK = '%s/%s' % (form.start.data, form.netmask.data)
            for x in IP(NETWORK, make_net=True):
                cur_ip = IP(x)
                if cur_ip > end:
                    break

                if start <= cur_ip:
                    ip_str = x.strNormal()
                    if not exclude_ips.count(ip_str):
                        NEW.append( ip_str )

            OLD_SET, NEW_SET = set(OLD), set(NEW)
            DROP = list(OLD_SET - NEW_SET)

            ERROR, OK = [], []
            for x in DROP:
                find = self.db2.query(IPPool).filter_by(ip=x).first()
                if find.instance_id:
                    ERROR.append( find )
                else:
                    OK.append( find )

            if ERROR:
                d = { 'title': self.trans(_('Edit network pool failed')),
                      'UNABLE_DELETE_IP': ERROR, 'NETWORK': N,
                      'form': form }
                return self.render('system/networkpool_edit.html', **d)

            ADD = list(NEW_SET - OLD_SET)

            N.name = form.name.data
            N.description = form.name.description
            N.start = form.start.data
            N.end = form.end.data
            N.netmask = form.netmask.data
            N.gateway = form.gateway.data
            N.nameservers = form.nameservers.data
            N.exclude_ips = form.exclude_ips.data

            for x in OK:
                self.db2.delete(x)
            for x in ADD:
                self.db2.add( IPPool(x, N) )

            self.db2.commit()

            url = self.reverse_url('system:networkpool')
            return self.redirect( url )

        d = { 'title': self.trans(_('Edit Network Pool')),  'form': form }
        self.render('system/networkpool_edit.html', **d)
コード例 #9
0
    def post(self, ID):

        N = self.db2.query(NetworkPool).get(ID)
        if not N:
            return self.write(
                self.trans(_('Can not find networkpool %s')) % ID)

        form = NetworkPoolForm(self)
        if form.validate():

            # TODO: a ugly algorithm
            OLD, NEW = [], []
            for x in self.db2.query(IPPool).filter_by(network_id=N.id):
                OLD.append(x.ip)

            start, end = IP(form.start.data), IP(form.end.data)
            exclude_ips = form.exclude_ips.data

            NETWORK = '%s/%s' % (form.start.data, form.netmask.data)
            for x in IP(NETWORK, make_net=True):
                cur_ip = IP(x)
                if cur_ip > end:
                    break

                if start <= cur_ip:
                    ip_str = x.strNormal()
                    if not exclude_ips.count(ip_str):
                        NEW.append(ip_str)

            OLD_SET, NEW_SET = set(OLD), set(NEW)
            DROP = list(OLD_SET - NEW_SET)

            ERROR, OK = [], []
            for x in DROP:
                find = self.db2.query(IPPool).filter_by(ip=x).first()
                if find.instance_id:
                    ERROR.append(find)
                else:
                    OK.append(find)

            if ERROR:
                d = {
                    'title': self.trans(_('Edit network pool failed')),
                    'UNABLE_DELETE_IP': ERROR,
                    'NETWORK': N,
                    'form': form
                }
                return self.render('system/networkpool_edit.html', **d)

            ADD = list(NEW_SET - OLD_SET)

            N.name = form.name.data
            N.description = form.name.description
            N.start = form.start.data
            N.end = form.end.data
            N.netmask = form.netmask.data
            N.gateway = form.gateway.data
            N.nameservers = form.nameservers.data
            N.exclude_ips = form.exclude_ips.data

            for x in OK:
                self.db2.delete(x)
            for x in ADD:
                self.db2.add(IPPool(x, N))

            self.db2.commit()

            url = self.reverse_url('system:networkpool')
            return self.redirect(url)

        d = {'title': self.trans(_('Edit Network Pool')), 'form': form}
        self.render('system/networkpool_edit.html', **d)