コード例 #1
0
def hello_edge_hello_edge_page_form():
    form = EdgeForm()

    if form.validate_on_submit():

        edge_session = edge(form.edge.data, form.client.data, form.client_secret.data, app.logger)
        if edge_session.get_session_status() is False:
            app.logger.error("We were unable to contact Edge")
            flash('We were unable to contact Edge')
        else:
            app.logger.error("Contacted the Edge")
            flash('Hello from the Edge!', 'succeed')
            flash('')
            flash('here are your first ten lists', 'succeed')
            flash('')
            flash('')
            count = 0
            for s in edge_session.list_dl():
                flash('%s: %s' %(s['name'], s['domainCount']),'succeed')
                count += 1
                print(count)
                if count >= 9:
                    break



        return redirect(url_for('hello_edgehello_edge_hello_edge_page'))
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template(
            'hello_edge_page.html',
            form=form,
            text=util.get_text(module_path(), config.language),
            options=g.user.get_options(),
        )
コード例 #2
0
    def get_edge_namespaces():
        """
        Exposed endpoint for retrieving networks by hint.
        Used for populating autocomplete fields, does not return all information.
        """
        hint = request.form['namespaces']

        result = {'status': FAIL, 'message': '', 'data': {}}
        try:
            result['status'] = SUCCESS
            result['data']['autocomplete_field'] = []
            result['data']['select_field'] = []
            if hint != '':
                edge_session = edge(edge_create_internal_ns_configuration.edge_url,
                                    edge_create_internal_ns_configuration.client_id,
                                    edge_create_internal_ns_configuration.clientSecret)

                namespaces = edge_session.get_namespaces()
                count = 0
                for namespace in namespaces:
                    if namespace['name'].startswith(hint):

                        result['data']['autocomplete_field'].append({
                            'input': namespace['id'],
                            'value': '%s (%s)' % (namespace['name'], namespace['id'])
                        })
                        result['data']['select_field'].append({
                            'id': namespace['id'],
                            'txt': namespace['name']
                        })
                        if count == 10:
                            break
                        count += 1
        except Exception as e:
            result['status'] = FAIL
            result['message'] = 'Error while searching for Namespaces: %s and hint: %s!' % (util.safe_str(e), hint)
        return result
コード例 #3
0
def edge_create_internal_ns_edge_create_internal_ns_page_form():
    form = GenericFormTemplate()

    if form.validate_on_submit():
        # Login to Edge
        edge_session = edge(edge_create_internal_ns_configuration.edge_url, edge_create_internal_ns_configuration.client_id, edge_create_internal_ns_configuration.clientSecret)
        if edge_session.get_session_status() is False:
            exit()
        else:
            print("Contacted the Edge")

        # Find the domain list ID
        try:
            # Create the Domain List if it doesn't exist
            dl = edge_session.make_new_domain_list(form.domainlist_name.data, form.domainlist_desc.data)
            edge_id = dl['id']
            new_dl = True
        except Exception as e:
            # Find the ID of the Domain List if it already exists
            domain_lists = edge_session.list_dl()
            for dl in domain_lists:
                if dl['name'] == form.domainlist_name.data:
                    edge_id = dl['id']
                    break

        zone_list = []

        #Get all zones (Need to filter out non internal)
        zones = g.user.get_api().get_by_object_types('*', 'Zone')
        for zone in zones:
            # This is to speed up the code.
            zone_list.append(zone)

        zone_file_list = ['',]
        for zone in zone_list:
            if zone.get_property('deployable') == 'true':
                if zone.get_configuration().get_name() == edge_create_internal_ns_configuration.default_configuration:
                    # Trying to get only the correct views zones below
                    parent_type = zone.get_parent()._api_entity['type']
                    parent = zone.get_parent()
                    while parent_type != 'View':
                        parent_type = []
                        parent_type = parent.get_parent()._api_entity['type']
                        parent = parent.get_parent()
                        continue
                    # Need to match the view in the config
                    if parent.get_name() == edge_create_internal_ns_configuration.default_view:
                        zone_file_list.append(zone.get_property('absoluteName'))

        with open(edge_create_internal_ns_configuration.domain_list_file, 'w') as f:
            f.writelines("%s\n" % place for place in zone_file_list)

        new_dl_list = edge_session.push_file(edge_id, edge_create_internal_ns_configuration.domain_list_file)

        if form.namespaces:
            namespaceid_start = form.namespaces.data.rfind('(') + 1
            namespaceid_end = form.namespaces.data.rfind(')', namespaceid_start)
            namespace_id = form.namespaces.data[namespaceid_start:namespaceid_end]

            edge_session.update_namespace_domain_list(namespace_id, [edge_id])

        # Put form processing code here
        if new_dl:
            g.user.logger.info('Created Internal  Namespace: ' + dl['name'] + ' added: ' + str(new_dl_list['numOfValidDomains']) + ' Zones')
            flash('Created Internal  Namespace: ' + dl['name'] + ' added: ' + str(new_dl_list['numOfValidDomains']) + ' Zones' , 'succeed')
        else:
            g.user.logger.info('Updated Internal  Namespace: ' + dl['name'] + ' added: ' + str(new_dl_list['numOfValidDomains']) + ' Zones')
            flash('Updated Internal  Namespace: ' + dl['name'] + ' added: ' + str(new_dl_list['numOfValidDomains']) + ' Zones' , 'succeed')
        return redirect(url_for('edge_create_internal_nsedge_create_internal_ns_edge_create_internal_ns_page'))
    else:
        g.user.logger.info('Form data was not valid.')
        return render_template(
            'edge_create_internal_ns_page.html',
            form=form,
            text=util.get_text(module_path(), config.language),
            options=g.user.get_options(),
        )