コード例 #1
0
def bulk():
    if request.method == 'POST':
        file = request.files['file']
        filename = secure_filename(file.filename)
        # check if the post request has the file part
        if 'file' not in request.files:
            flash('No file part')
            return render_template('chooser.html')
        # if user does not select file, browser also
        # submit a empty part without filename
        if file.filename == '':
            flash('No selected file')
            return render_template('chooser.html')
        #if file and allowed_file(file.filename):
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        vars = {}
        cr = '\n'
        filex = open(os.path.join(APP_STATIC, 'testdata.txt'), 'w')
        with open(os.path.join(APP_STATIC, filename)) as f:
            line = f.readline().strip('/t')
            while line:
                vars = str.split(line, ',')
                # assign the variables from the linf of the csv file
                dom = vars[0]
                fromzone = vars[1]
                tozone = vars[2]
                direction = vars[3]
                action = vars[4]
                description = vars[5]
                ethertype = vars[6]
                protocol = vars[7]
                sourceport = vars[8]
                destinationport = vars[9]
                dscp = vars[10]
                #Get the domain
                if dom == 'eof':
                    break

                msg = 'In the loop'
                filex.write(line)
                filex.write(cr)

                domain = nuage_user.domains.get_first(filter="name == '%s'" %
                                                      dom)
                domain.fetch()

                from_network = domain.zones.get_first(filter="name == '%s'" %
                                                      fromzone)
                #print from_network.id
                to_network = domain.zones.get_first(filter="name == '%s'" %
                                                    tozone)
                #print to_network.id

                if direction == 'Ingress':
                    for in_acl in domain.ingress_acl_templates.get():
                        db_ingressacl_rule = vsdk.NUIngressACLEntryTemplate(
                            action=action,
                            description=description,
                            ether_type=ethertype,
                            location_type='ZONE',
                            location_id=from_network.id,
                            network_type='ZONE',
                            network_id=to_network.id,
                            protocol=protocol,
                            source_port=sourceport,
                            destination_port=destinationport,
                            dscp=dscp)
                        in_acl.create_child(db_ingressacl_rule)

                if direction == 'Egress':
                    for out_acl in domain.egress_acl_templates.get():
                        db_egressacl_rule = vsdk.NUEgressACLEntryTemplate(
                            action=action,
                            description=description,
                            ether_type=ethertype,
                            location_type='ZONE',
                            location_id=from_network.id,
                            network_type='ZONE',
                            network_id=to_network.id,
                            protocol=protocol,
                            source_port=sourceport,
                            destination_port=destinationport,
                            dscp=dscp)
                        out_acl.create_child(db_egressacl_rule)
                line = f.readline().strip('/t')
                #time.sleep(5)

        f.close()
        filex.close()
        flash('Records processed')
        return render_template('bulk.html')
    return render_template('chooser.html')
コード例 #2
0
def buildaclrule():
    dom = request.form.get('domain')
    fromzone = request.form.get('fromzone')
    tozone = request.form.get('tozone')
    direction = request.form.get('direction')
    action = request.form.get('action')
    description = request.form.get('description')
    ethertype = request.form.get('ethertype')
    protocol = request.form.get('protocol')
    sourceport = request.form.get('sourceport')
    destinationport = request.form.get('destinationport')
    dscp = request.form.get('dscp')
    '''
    return render_template('testvars.html',
    dom = dom,
    fromzone = fromzone,
    tozone = tozone,
    description = description,
    direction = direction,
    action = action,
    ethertype = ethertype,
    sourceport = sourceport,
    destinationport = destinationport,
    dscp = dscp,
    protocol = protocol
    )
    '''
    #Get the domain
    domain = nuage_user.domains.get_first(filter="name == '%s'" % dom)
    domain.fetch()

    from_network = domain.zones.get_first(filter="name == '%s'" % fromzone)
    #print from_network.id
    to_network = domain.zones.get_first(filter="name == '%s'" % tozone)
    #print to_network.id

    if direction == 'Ingress':
        for in_acl in domain.ingress_acl_templates.get():
            db_ingressacl_rule = vsdk.NUIngressACLEntryTemplate(
                action=action,
                description=description,
                ether_type=ethertype,
                location_type='ZONE',
                location_id=from_network.id,
                network_type='ZONE',
                network_id=to_network.id,
                protocol=protocol,
                source_port=sourceport,
                destination_port=destinationport,
                dscp=dscp)
            in_acl.create_child(db_ingressacl_rule)

    if direction == 'Egress':
        for out_acl in domain.egress_acl_templates.get():
            db_egressacl_rule = vsdk.NUEgressACLEntryTemplate(
                action=action,
                description=description,
                ether_type=ethertype,
                location_type='ZONE',
                location_id=from_network.id,
                network_type='ZONE',
                network_id=to_network.id,
                protocol=protocol,
                source_port=sourceport,
                destination_port=destinationport,
                dscp=dscp)
            out_acl.create_child(db_egressacl_rule)

    return render_template('add_acl_success.html')
コード例 #3
0
ファイル: x3.py プロジェクト: veeruds/scriptsonly
        db_ingressacl_rule = vsdk.NUIngressACLEntryTemplate(
            action=action,
            description=description,
            ether_type=ethertype,
            location_type='ZONE',
            location_id=from_network.id,
            network_type='ZONE',
            network_id=to_network.id,
            protocol=protocol,
            source_port=sourceport,
            destination_port=destinationport,
            dscp=dscp)
        in_acl.create_child(db_ingressacl_rule)

if direction == 'Egress':
    for out_acl in domain.egress_acl_templates.get():
        db_ingressacl_rule = vsdk.NUEgressACLEntryTemplate(
            action=action,
            description=description,
            ether_type=ethertype,
            location_type='ZONE',
            location_id=from_network.id,
            network_type='ZONE',
            network_id=to_network.id,
            protocol=protocol,
            source_port=sourceport,
            destination_port=destinationport,
            dscp=dscp)
        egressacl.create_child(db_egressacl_rule)
print 'finsush'