Exemple #1
0
def checkAclCvs(acl_file_name, environment, network, user):
    """Validates if the file is created acl.

    @param acl_file_name: acl name
    @param environment: Environment
    @param network: v4 or v6
    @param user: user

    @raise CVSCommandError:  Failed to execute command

    @return: True case created
    """
    try:

        acl = check_name_file(acl_file_name)

        path = path_acl(environment['nome_ambiente_logico'],
                        environment['nome_divisao'], environment['acl_path'])

        mkdir_divison_dc(environment['nome_divisao'], user,
                         environment['acl_path'])

        chdir(PATH_TYPES.ACL, network, path)

        Cvs.synchronization()

        File.read(acl)

        return True

    except FileError, e:
        return False
Exemple #2
0
def checkAclCvs(acl_file_name, environment, network, user):
    """Validates if the file is created acl.

    @param acl_file_name: acl name
    @param environment: Environment
    @param network: v4 or v6
    @param user: user

    @raise CVSCommandError:  Failed to execute command

    @return: True case created
    """
    try:

        acl = check_name_file(acl_file_name)

        path = path_acl(environment['nome_ambiente_logico'], environment['nome_divisao'],
                        environment['acl_path'])

        mkdir_divison_dc(
            environment['nome_divisao'], user, environment['acl_path'])

        chdir(PATH_TYPES.ACL, network, path)

        Cvs.synchronization()

        File.read(acl)

        return True

    except FileError, e:
        return False
Exemple #3
0
def mkdir_divison_dc(divison_dc, user, acl_path=None):
    """Creates the directory division dc in cvs

    @param divison_dc: division dc to be created
    @param user: user

    @raise CVSCommandError: Failed to execute
    """
    try:

        divison_dc = str(divison_dc).upper()

        os.chdir(PATH_ACL)

        if divison_dc == DIVISON_DC.BORDA:
            divison_dc = 'Borda'

        directory = divison_dc

        if acl_path:
            directory = acl_path

        Cvs.synchronization()

        # Set path - Ipv4 - Ipv6
        list_path = []
        list_path.append('%s%s/' % (PATH_ACL, 'v4'))
        list_path.append('%s%s/' % (PATH_ACL, 'v6'))

        for path in list_path:

            os.chdir(path)

            folders = directory.split('/')

            for folder in folders:
                if folder:
                    if not os.path.exists(folder):
                        os.mkdir(folder)
                        Cvs.add(folder)
                        Cvs.commit(
                            folder,
                            'Criação do diretório de divisão dc %s/%s pelo usuário: %s'
                            % (path, folder, user.user))
                        logger.info('%s criou no CVS o diretório: %s/%s' %
                                    (user.user, path, folder))
                        Cvs.synchronization()

                    path = '%s/%s' % (path, folder)
                    os.chdir(path)

    except Exception, e:
        logger.error(
            'Erro quando o usuário %s tentou criar o diretório: %s no Cvs' %
            (user.user, dir))
        logger.error(e)
        raise CVSCommandError(e)
Exemple #4
0
def mkdir_divison_dc(divison_dc, user, acl_path=None):
    """Creates the directory division dc in cvs

    @param divison_dc: division dc to be created
    @param user: user

    @raise CVSCommandError: Failed to execute
    """
    try:

        divison_dc = str(divison_dc).upper()

        os.chdir(PATH_ACL)

        if divison_dc == DIVISON_DC.BORDA:
            divison_dc = 'Borda'

        directory = divison_dc

        if acl_path:
            directory = acl_path

        Cvs.synchronization()

        # Set path - Ipv4 - Ipv6
        list_path = []
        list_path.append('%s%s/' % (PATH_ACL, 'v4'))
        list_path.append('%s%s/' % (PATH_ACL, 'v6'))

        for path in list_path:

            os.chdir(path)

            folders = directory.split('/')

            for folder in folders:
                if folder:
                    if not os.path.exists(folder):
                        os.mkdir(folder)
                        Cvs.add(folder)
                        Cvs.commit(
                            folder, 'Criação do diretório de divisão dc %s/%s pelo usuário: %s' % (path, folder, user.user))
                        logger.info(
                            '%s criou no CVS o diretório: %s/%s' % (user.user, path, folder))
                        Cvs.synchronization()

                    path = '%s/%s' % (path, folder)
                    os.chdir(path)

    except Exception, e:
        logger.error('Erro quando o usuário %s tentou criar o diretório: %s no Cvs' % (
            user.user, dir))
        logger.error(e)
        raise CVSCommandError(e)
Exemple #5
0
def createAclCvs(acl_name, environment, network, user):
    """Create the file acl.

    @param acl_name: acl name
    @param environment: Environment
    @param network: v4 or v6
    @param user: user

    @raise CVSCommandError:  Failed to execute command
    """
    try:

        acl = check_name_file(acl_name)

        path = path_acl(environment['nome_ambiente_logico'],
                        environment['nome_divisao'], environment['acl_path'])

        mkdir_divison_dc(environment['nome_divisao'], user,
                         environment['acl_path'])

        chdir(PATH_TYPES.ACL, network, path)

        Cvs.synchronization()

        File.create(acl)

        Cvs.add(acl)

        Cvs.commit(acl,
                   'Criação do Arquivo %s pelo usuário: %s' % (acl, user.user))

        logger.info('%s criou no CVS o arquivo: %s' % (user.user,
                                                       (path + acl)))

    except (CVSCommandError, FileError, Exception), e:
        logger.error(
            'Erro quando o usuário %s tentou criar o arquivo: %s no Cvs' %
            (user.user, (path + acl)))
        logger.error(e)
        raise CVSCommandError(e)
Exemple #6
0
def createAclCvs(acl_name, environment, network, user):
    """Create the file acl.

    @param acl_name: acl name
    @param environment: Environment
    @param network: v4 or v6
    @param user: user

    @raise CVSCommandError:  Failed to execute command
    """
    try:

        acl = check_name_file(acl_name)

        path = path_acl(environment['nome_ambiente_logico'], environment['nome_divisao'],
                        environment['acl_path'])

        mkdir_divison_dc(
            environment['nome_divisao'], user, environment['acl_path'])

        chdir(PATH_TYPES.ACL, network, path)

        Cvs.synchronization()

        File.create(acl)

        Cvs.add(acl)

        Cvs.commit(acl, 'Criação do Arquivo %s pelo usuário: %s' %
                   (acl, user.user))

        logger.info('%s criou no CVS o arquivo: %s' %
                    (user.user, (path + acl)))

    except (CVSCommandError, FileError, Exception), e:
        logger.error('Erro quando o usuário %s tentou criar o arquivo: %s no Cvs' % (
            user.user, (path + acl)))
        logger.error(e)
        raise CVSCommandError(e)
Exemple #7
0
def scriptAclCvs(acl_name, vlan, environment, network, user, template_name):
    """Generates the acl based on a template

    @param acl_name: acl name
    @param vlan: Vvlan
    @param environment: Environment
    @param network: v4 or v6
    @param user: user
    @param temple_name: Template Name

    @raise CVSCommandError:  Failed to execute command
    """
    try:

        acl = check_name_file(acl_name)
        acl_name = check_name_file(acl_name, extention=False)

        if template_name:

            path_env = environment['acl_path'] if environment[
                'acl_path'] else environment['nome_divisao']

            chdir(PATH_TYPES.ACL, network, path_env)

            Cvs.synchronization()

            arquivo = open('./%s' % acl, 'w')

            chdir(PATH_TYPES.TEMPLATE, network)

            Cvs.synchronization()

            file_template = open(template_name, 'r')

            content_template = file_template.read()

            nova_acl = replace_template(
                acl_name, vlan, content_template, network)

            chdir(PATH_TYPES.ACL, network, path_env)

            arquivo.write('%s' % nova_acl)
            arquivo.close()
            file_template.close()

            Cvs.commit(acl, '%s gerou Script para a acl %s' % (user.user, acl))

            logger.info('%s alterou no CVS o arquivo: %s' % (user.user, acl))

        else:
            if ((environment['nome_divisao'] == 'BE') and (environment['nome_ambiente_logico'] == 'PRODUCAO') and (environment['nome_grupo_l3'] == 'CORE/DENSIDADE')):

                path_env = environment['acl_path'] if environment[
                    'acl_path'] else DIVISON_DC.BE

                chdir(PATH_TYPES.ACL, network, path_env)

                Cvs.synchronization()

                arquivo = open('./%s' % acl, 'w')

                chdir(PATH_TYPES.TEMPLATE, network)

                file_template = open(
                    PREFIX_TEMPLATES + TEMPLATES.BE + EXTENTION_FILE, 'r')

                content_template = file_template.read()

                nova_acl = replace_template(
                    acl_name, vlan, content_template, network)

                chdir(PATH_TYPES.ACL, network, path_env)

                arquivo.write('%s' % nova_acl)
                arquivo.close()
                file_template.close()

                Cvs.commit(acl, '%s gerou Script para a acl %s' %
                           (user.user, acl))

                logger.info('%s alterou no CVS o arquivo: %s' %
                            (user.user, acl))

            if ((environment['nome_divisao'] == DIVISON_DC.FE) and (environment['nome_ambiente_logico'] == ENVIRONMENT_LOGICAL.HOMOLOGACAO) and (environment['nome_grupo_l3'] == 'CORE/DENSIDADE')):

                path_env = environment['acl_path'] if environment[
                    'acl_path'] else DIVISON_DC.DEV_QA_FE

                chdir(PATH_TYPES.ACL, network, path_env)

                Cvs.synchronization()

                arquivo = open('./%s' % acl, 'w')

                chdir(PATH_TYPES.TEMPLATE, network)

                file_template = open(
                    PREFIX_TEMPLATES + TEMPLATES.FE_DEV_QA + EXTENTION_FILE, 'r')

                content_template = file_template.read()

                nova_acl = replace_template(
                    acl_name, vlan, content_template, network)

                chdir(PATH_TYPES.ACL, network, path_env)

                arquivo.write('%s' % nova_acl)
                arquivo.close()
                file_template.close()

                Cvs.commit(acl, '%s gerou Script para a acl %s' %
                           (user.user, acl))

                logger.info('%s alterou no CVS o arquivo: %s' %
                            (user.user, acl))

            if ((environment['nome_divisao'] == DIVISON_DC.FE) and (environment['nome_ambiente_logico'] == ENVIRONMENT_LOGICAL.PORTAL) and (environment['nome_grupo_l3'] == 'CORE/DENSIDADE')):

                path_env = environment['acl_path'] if environment[
                    'acl_path'] else DIVISON_DC.FE

                chdir(PATH_TYPES.ACL, network, path_env)

                Cvs.synchronization()

                arquivo = open('./%s' % acl, 'w')

                chdir(PATH_TYPES.TEMPLATE, network)

                if 'staging' in acl.lower():
                    file_template = open(
                        PREFIX_TEMPLATES + TEMPLATES.FE_STAGING + EXTENTION_FILE, 'r')
                else:
                    file_template = open(
                        PREFIX_TEMPLATES + TEMPLATES.FE_PORTAL + EXTENTION_FILE, 'r')

                content_template = file_template.read()

                nova_acl = replace_template(
                    acl_name, vlan, content_template, network)

                chdir(PATH_TYPES.ACL, network, path_env)

                arquivo.write('%s' % nova_acl)
                arquivo.close()
                file_template.close()

                Cvs.commit(acl, '%s gerou Script para a acl %s' %
                           (user.user, acl))

                logger.info('%s alterou no CVS o arquivo: %s' %
                            (user.user, acl))

            if ((environment['nome_divisao'] == DIVISON_DC.FE) and (environment['nome_ambiente_logico'] == ENVIRONMENT_LOGICAL.APLICATIVOS) and (environment['nome_grupo_l3'] == 'CORE/DENSIDADE')):

                path_env = environment['acl_path'] if environment[
                    'acl_path'] else DIVISON_DC.FE

                chdir(PATH_TYPES.ACL, network, path_env)

                Cvs.synchronization()

                arquivo = open('./%s' % acl, 'w')

                chdir(PATH_TYPES.TEMPLATE, network)

                file_template = open(
                    PREFIX_TEMPLATES + TEMPLATES.FE_APLICATIVOS + EXTENTION_FILE, 'r')

                content_template = file_template.read()

                nova_acl = replace_template(
                    acl_name, vlan, content_template, network)

                chdir(PATH_TYPES.ACL, network, path_env)

                arquivo.write('%s' % nova_acl)
                arquivo.close()
                file_template.close()

                Cvs.commit(acl, '%s gerou Script para a acl %s' %
                           (user.user, acl))

                logger.info('%s alterou no CVS o arquivo: %s' %
                            (user.user, acl))

            if ((environment['nome_divisao'] == DIVISON_DC.BE) and (environment['nome_ambiente_logico'] == ENVIRONMENT_LOGICAL.HOMOLOGACAO) and (environment['nome_grupo_l3'] == 'CORE/DENSIDADE')):

                path_env = environment['acl_path'] if environment[
                    'acl_path'] else DIVISON_DC.DEV_QA

                chdir(PATH_TYPES.ACL, network, path_env)

                Cvs.synchronization()

                arquivo = open('./%s' % acl, 'w')

                chdir(PATH_TYPES.TEMPLATE, network)

                file_template = open(
                    PREFIX_TEMPLATES + TEMPLATES.BEHO + EXTENTION_FILE, 'r')

                content_template = file_template.read()

                nova_acl = replace_template(
                    acl_name, vlan, content_template, network)

                chdir(PATH_TYPES.ACL, network, path_env)

                arquivo.write('%s' % nova_acl)
                arquivo.close()
                file_template.close()

                Cvs.commit(acl, '%s gerou Script para a acl %s' %
                           (user.user, acl))

                logger.info('%s alterou no CVS o arquivo: %s' %
                            (user.user, acl))

    except (CVSCommandError, FileError, Exception), e:
        logger.error(
            'Erro quando o usuário %s tentou gerar o arquivo: %s no Cvs' % (user.user, acl))
        logger.error(e)
        raise CVSCommandError(e)
Exemple #8
0
def scriptAclCvs(acl_name, vlan, environment, network, user, template_name):
    """Generates the acl based on a template

    @param acl_name: acl name
    @param vlan: Vvlan
    @param environment: Environment
    @param network: v4 or v6
    @param user: user
    @param temple_name: Template Name

    @raise CVSCommandError:  Failed to execute command
    """
    try:

        acl = check_name_file(acl_name)
        acl_name = check_name_file(acl_name, extention=False)

        if template_name:

            path_env = environment['acl_path'] if environment[
                'acl_path'] else environment['nome_divisao']

            chdir(PATH_TYPES.ACL, network, path_env)

            Cvs.synchronization()

            arquivo = open('./%s' % acl, 'w')

            chdir(PATH_TYPES.TEMPLATE, network)

            Cvs.synchronization()

            file_template = open(template_name, 'r')

            content_template = file_template.read()

            nova_acl = replace_template(acl_name, vlan, content_template,
                                        network)

            chdir(PATH_TYPES.ACL, network, path_env)

            arquivo.write('%s' % nova_acl)
            arquivo.close()
            file_template.close()

            Cvs.commit(acl, '%s gerou Script para a acl %s' % (user.user, acl))

            logger.info('%s alterou no CVS o arquivo: %s' % (user.user, acl))

        else:
            if ((environment['nome_divisao'] == 'BE')
                    and (environment['nome_ambiente_logico'] == 'PRODUCAO')
                    and (environment['nome_grupo_l3'] == 'CORE/DENSIDADE')):

                path_env = environment['acl_path'] if environment[
                    'acl_path'] else DIVISON_DC.BE

                chdir(PATH_TYPES.ACL, network, path_env)

                Cvs.synchronization()

                arquivo = open('./%s' % acl, 'w')

                chdir(PATH_TYPES.TEMPLATE, network)

                file_template = open(
                    PREFIX_TEMPLATES + TEMPLATES.BE + EXTENTION_FILE, 'r')

                content_template = file_template.read()

                nova_acl = replace_template(acl_name, vlan, content_template,
                                            network)

                chdir(PATH_TYPES.ACL, network, path_env)

                arquivo.write('%s' % nova_acl)
                arquivo.close()
                file_template.close()

                Cvs.commit(acl,
                           '%s gerou Script para a acl %s' % (user.user, acl))

                logger.info('%s alterou no CVS o arquivo: %s' %
                            (user.user, acl))

            if ((environment['nome_divisao'] == DIVISON_DC.FE)
                    and (environment['nome_ambiente_logico']
                         == ENVIRONMENT_LOGICAL.HOMOLOGACAO)
                    and (environment['nome_grupo_l3'] == 'CORE/DENSIDADE')):

                path_env = environment['acl_path'] if environment[
                    'acl_path'] else DIVISON_DC.DEV_QA_FE

                chdir(PATH_TYPES.ACL, network, path_env)

                Cvs.synchronization()

                arquivo = open('./%s' % acl, 'w')

                chdir(PATH_TYPES.TEMPLATE, network)

                file_template = open(
                    PREFIX_TEMPLATES + TEMPLATES.FE_DEV_QA + EXTENTION_FILE,
                    'r')

                content_template = file_template.read()

                nova_acl = replace_template(acl_name, vlan, content_template,
                                            network)

                chdir(PATH_TYPES.ACL, network, path_env)

                arquivo.write('%s' % nova_acl)
                arquivo.close()
                file_template.close()

                Cvs.commit(acl,
                           '%s gerou Script para a acl %s' % (user.user, acl))

                logger.info('%s alterou no CVS o arquivo: %s' %
                            (user.user, acl))

            if ((environment['nome_divisao'] == DIVISON_DC.FE)
                    and (environment['nome_ambiente_logico']
                         == ENVIRONMENT_LOGICAL.PORTAL)
                    and (environment['nome_grupo_l3'] == 'CORE/DENSIDADE')):

                path_env = environment['acl_path'] if environment[
                    'acl_path'] else DIVISON_DC.FE

                chdir(PATH_TYPES.ACL, network, path_env)

                Cvs.synchronization()

                arquivo = open('./%s' % acl, 'w')

                chdir(PATH_TYPES.TEMPLATE, network)

                if 'staging' in acl.lower():
                    file_template = open(
                        PREFIX_TEMPLATES + TEMPLATES.FE_STAGING +
                        EXTENTION_FILE, 'r')
                else:
                    file_template = open(
                        PREFIX_TEMPLATES + TEMPLATES.FE_PORTAL +
                        EXTENTION_FILE, 'r')

                content_template = file_template.read()

                nova_acl = replace_template(acl_name, vlan, content_template,
                                            network)

                chdir(PATH_TYPES.ACL, network, path_env)

                arquivo.write('%s' % nova_acl)
                arquivo.close()
                file_template.close()

                Cvs.commit(acl,
                           '%s gerou Script para a acl %s' % (user.user, acl))

                logger.info('%s alterou no CVS o arquivo: %s' %
                            (user.user, acl))

            if ((environment['nome_divisao'] == DIVISON_DC.FE)
                    and (environment['nome_ambiente_logico']
                         == ENVIRONMENT_LOGICAL.APLICATIVOS)
                    and (environment['nome_grupo_l3'] == 'CORE/DENSIDADE')):

                path_env = environment['acl_path'] if environment[
                    'acl_path'] else DIVISON_DC.FE

                chdir(PATH_TYPES.ACL, network, path_env)

                Cvs.synchronization()

                arquivo = open('./%s' % acl, 'w')

                chdir(PATH_TYPES.TEMPLATE, network)

                file_template = open(
                    PREFIX_TEMPLATES + TEMPLATES.FE_APLICATIVOS +
                    EXTENTION_FILE, 'r')

                content_template = file_template.read()

                nova_acl = replace_template(acl_name, vlan, content_template,
                                            network)

                chdir(PATH_TYPES.ACL, network, path_env)

                arquivo.write('%s' % nova_acl)
                arquivo.close()
                file_template.close()

                Cvs.commit(acl,
                           '%s gerou Script para a acl %s' % (user.user, acl))

                logger.info('%s alterou no CVS o arquivo: %s' %
                            (user.user, acl))

            if ((environment['nome_divisao'] == DIVISON_DC.BE)
                    and (environment['nome_ambiente_logico']
                         == ENVIRONMENT_LOGICAL.HOMOLOGACAO)
                    and (environment['nome_grupo_l3'] == 'CORE/DENSIDADE')):

                path_env = environment['acl_path'] if environment[
                    'acl_path'] else DIVISON_DC.DEV_QA

                chdir(PATH_TYPES.ACL, network, path_env)

                Cvs.synchronization()

                arquivo = open('./%s' % acl, 'w')

                chdir(PATH_TYPES.TEMPLATE, network)

                file_template = open(
                    PREFIX_TEMPLATES + TEMPLATES.BEHO + EXTENTION_FILE, 'r')

                content_template = file_template.read()

                nova_acl = replace_template(acl_name, vlan, content_template,
                                            network)

                chdir(PATH_TYPES.ACL, network, path_env)

                arquivo.write('%s' % nova_acl)
                arquivo.close()
                file_template.close()

                Cvs.commit(acl,
                           '%s gerou Script para a acl %s' % (user.user, acl))

                logger.info('%s alterou no CVS o arquivo: %s' %
                            (user.user, acl))

    except (CVSCommandError, FileError, Exception), e:
        logger.error(
            'Erro quando o usuário %s tentou gerar o arquivo: %s no Cvs' %
            (user.user, acl))
        logger.error(e)
        raise CVSCommandError(e)