Ejemplo n.º 1
0
def list_all(request):
    try:

        lists = dict()
        lists['form'] = DeleteForm()

        auth = AuthSession(request.session)
        client = auth.get_clientFactory()

        column_index_name_map = {
            0: '',
            1: 'id',
            2: 'divisao_dc__nome',
            3: 'vrf',
            4: 'dcroom__dc__dcname',
            5: ''
        }

        dtp = DataTablePaginator(request, column_index_name_map)

        dtp.build_server_side_list()

        dtp.searchable_columns = [
            'grupo_l3__nome', 'ambiente_logico__nome', 'divisao_dc__nome',
            'vrf', 'dcroom__dc__dcname', 'dcroom__name'
        ]

        dtp.end_record = 10000

        pagination = Pagination(dtp.start_record, dtp.end_record,
                                dtp.asorting_cols, dtp.searchable_columns,
                                dtp.custom_search)

        extends_search = dict()
        extends_search["father_environment__isnull"] = True

        data = dict()
        data["start_record"] = pagination.start_record
        data["end_record"] = pagination.end_record
        data["asorting_cols"] = [
            'divisao_dc__nome', 'ambiente_logico__nome', 'grupo_l3__nome'
        ]
        data["searchable_columns"] = pagination.searchable_columns
        data["custom_search"] = pagination.custom_search or ""
        data["extends_search"] = [extends_search] if extends_search else []

        environment = client.create_api_environment().search(fields=[
            'id', 'children__basic', 'vrf', 'name', 'configs__details',
            'dcroom__details'
        ],
                                                             search=data)

        lists['envs'] = json.dumps(environment.get("environments"))

    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, e)
Ejemplo n.º 2
0
def search_environment(request):
    """
    Function to list all environments.
    """

    auth = AuthSession(request.session)
    client = auth.get_clientFactory()
    lists = dict()
    try:
        if request.method == 'GET':
            column_index_name_map = {
                0: '',
                1: 'id',
                2: 'divisao_dc__nome',
                3: 'vrf',
                4: 'dcroom__dc__dcname',
                5: ''
            }

            dtp = DataTablePaginator(request, column_index_name_map)

            dtp.build_server_side_list()

            dtp.searchable_columns = [
                'grupo_l3__nome', 'ambiente_logico__nome', 'divisao_dc__nome',
                'vrf', 'dcroom__dc__dcname', 'dcroom__name'
            ]

            dtp.end_record = 10000

            pagination = Pagination(dtp.start_record, dtp.end_record,
                                    dtp.asorting_cols, dtp.searchable_columns,
                                    dtp.custom_search)

            data = dict()
            data["start_record"] = pagination.start_record
            data["end_record"] = pagination.end_record
            data["asorting_cols"] = [
                'divisao_dc__nome', 'ambiente_logico__nome', 'grupo_l3__nome'
            ]
            data["searchable_columns"] = pagination.searchable_columns
            data["custom_search"] = pagination.custom_search or ""
            data["extends_search"] = []

            fields = [
                'id', 'children__basic', 'vrf', 'name', 'father_environment',
                'configs__details'
            ]

            envs = client.create_api_environment().search(search=data,
                                                          fields=fields)

            lists["envs"] = yaml.safe_load(json.dumps(
                envs.get('environments')))

    except NetworkAPIClientError as e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, e)
    except BaseException as e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, e)

    return render_to_response(templates.ENVIRONMENT_LIST_V3,
                              lists,
                              context_instance=RequestContext(request))
Ejemplo n.º 3
0
def ajax_list_all(request, search_term=None):
    try:

        lists = dict()
        lists['form'] = DeleteForm()

        auth = AuthSession(request.session)
        client = auth.get_clientFactory()

        column_index_name_map = {
            0: '',
            1: 'id',
            2: 'divisao_dc__nome',
            3: 'vrf',
            4: 'dcroom__dc__dcname',
            5: ''
        }

        dtp = DataTablePaginator(request, column_index_name_map)

        dtp.build_server_side_list()

        dtp.searchable_columns = [
            'grupo_l3__nome',
            'ambiente_logico__nome',
            'divisao_dc__nome',
            'vrf',
            'dcroom__dc__dcname',
            'dcroom__name'
        ]

        dtp.end_record = 10000

        fields = [
            "divisao_dc__nome__icontains",
            "ambiente_logico__nome__icontains",
            "grupo_l3__nome__icontains"
        ]

        extends_search_dict = dict()

        if search_term:
            term = search_term.split("+")
            term_len = len(term)
            if term_len > 1:
                for i in xrange(len(term)):
                    extends_search_dict.update({fields[i]: term[i]})
            else:
                dtp.custom_search = term[0]

        pagination = Pagination(
            dtp.start_record,
            dtp.end_record,
            dtp.asorting_cols,
            dtp.searchable_columns,
            dtp.custom_search
        )

        data = dict()
        data["start_record"] = pagination.start_record
        data["end_record"] = pagination.end_record
        data["asorting_cols"] = ['divisao_dc__nome','ambiente_logico__nome','grupo_l3__nome']
        data["searchable_columns"] = pagination.searchable_columns
        data["custom_search"] = pagination.custom_search or ""
        data["extends_search"] = [extends_search_dict] if extends_search_dict else []

        environment = client.create_api_environment().search(fields=['id',
                                                                     'children__basic',
                                                                     'vrf',
                                                                     'name',
                                                                     'configs__details',
                                                                     'dcroom__details'],
                                                             search=data)

        lists['envs'] = json.dumps(environment.get("environments"))

        return render_to_response(ENVIRONMENT_LIST, lists, context_instance=RequestContext(request))

    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, e)
Ejemplo n.º 4
0
def ajax_list_all(request, search_term=None):
    try:

        lists = dict()
        lists['form'] = DeleteForm()

        auth = AuthSession(request.session)
        client = auth.get_clientFactory()

        column_index_name_map = {
            0: '',
            1: 'id',
            2: 'divisao_dc__nome',
            3: 'vrf',
            4: 'dcroom__dc__dcname',
            5: ''
        }

        dtp = DataTablePaginator(request, column_index_name_map)

        dtp.build_server_side_list()

        dtp.searchable_columns = [
            'grupo_l3__nome',
            'ambiente_logico__nome',
            'divisao_dc__nome',
            'vrf',
            'dcroom__dc__dcname',
            'dcroom__name'
        ]

        dtp.end_record = 10000

        fields = [
            "divisao_dc__nome__icontains",
            "ambiente_logico__nome__icontains",
            "grupo_l3__nome__icontains"
        ]

        extends_search_dict = dict()

        if search_term:
            term = search_term.split("+")
            term_len = len(term)
            if term_len > 1:
                for i in xrange(len(term)):
                    extends_search_dict.update({fields[i]: term[i]})
            else:
                dtp.custom_search = term[0]

        pagination = Pagination(
            dtp.start_record,
            dtp.end_record,
            dtp.asorting_cols,
            dtp.searchable_columns,
            dtp.custom_search
        )

        data = dict()
        data["start_record"] = pagination.start_record
        data["end_record"] = pagination.end_record
        data["asorting_cols"] = ['divisao_dc__nome','ambiente_logico__nome','grupo_l3__nome']
        data["searchable_columns"] = pagination.searchable_columns
        data["custom_search"] = pagination.custom_search or ""
        data["extends_search"] = [extends_search_dict] if extends_search_dict else []

        environment = client.create_api_environment().search(fields=['id',
                                                                     'children__basic',
                                                                     'vrf',
                                                                     'name',
                                                                     'configs__details',
                                                                     'dcroom__details'],
                                                             search=data)

        lists['envs'] = json.dumps(environment.get("environments"))

        return render_to_response(ENVIRONMENT_LIST, lists, context_instance=RequestContext(request))

    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, e)
Ejemplo n.º 5
0
def list_all(request):
    try:

        lists = dict()
        lists['form'] = DeleteForm()

        auth = AuthSession(request.session)
        client = auth.get_clientFactory()

        column_index_name_map = {
            0: '',
            1: 'id',
            2: 'divisao_dc__nome',
            3: 'vrf',
            4: 'dcroom__dc__dcname',
            5: ''
        }

        dtp = DataTablePaginator(request, column_index_name_map)

        dtp.build_server_side_list()

        dtp.searchable_columns = [
            'grupo_l3__nome',
            'ambiente_logico__nome',
            'divisao_dc__nome',
            'vrf',
            'dcroom__dc__dcname',
            'dcroom__name'
        ]

        dtp.end_record = 10000

        pagination = Pagination(
            dtp.start_record,
            dtp.end_record,
            dtp.asorting_cols,
            dtp.searchable_columns,
            dtp.custom_search
        )

        extends_search = dict()
        extends_search["father_environment__isnull"] = True

        data = dict()
        data["start_record"] = pagination.start_record
        data["end_record"] = pagination.end_record
        data["asorting_cols"] = ['divisao_dc__nome','ambiente_logico__nome','grupo_l3__nome']
        data["searchable_columns"] = pagination.searchable_columns
        data["custom_search"] = pagination.custom_search or ""
        data["extends_search"] = [extends_search] if extends_search else []

        environment = client.create_api_environment().search(fields=['id',
                                                                     'children__basic',
                                                                     'vrf',
                                                                     'name',
                                                                     'configs__details',
                                                                     'dcroom__details'],
                                                             search=data)

        lists['envs'] = json.dumps(environment.get("environments"))

    except NetworkAPIClientError, e:
        logger.error(e)
        messages.add_message(request, messages.ERROR, e)