Пример #1
0
def get_template_edit(template_name, network, user):
    '''Retrieves the contents of the file template.

    :param template_name: template name
    :param network: IPv4 or IPv6
    :param user: user

    :raise GITCommandError:  Failed to execute command
    '''

    try:
        ip_version = IP_VERSION.IPv4[0] if network == IP_VERSION.IPv4[
            1] else IP_VERSION.IPv6[0]
        path = "%s%s/%s%s" % (PATH_ACL, ip_version, PATH_ACL_TEMPLATES,
                              template_name)

        chdir(PATH_TYPES.TEMPLATE, ip_version, path)

        Git.synchronization()

        content = File.read(template_name)

        return content

    except (GITCommandError, FileError, Exception), e:
        logger.error("Erro quando o usuário %s tentou sincronizar no Git" %
                     (user.get_username()))
        logger.error(e)
        raise GITCommandError(e)
Пример #2
0
def getAclGit(acl_file_name, environment, network, user):
    '''Retrieves the contents of the file acl.

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

    :raise GITCommandError:  Failed to execute command
    '''
    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)

        Git.synchronization()

        content = File.read(acl)

        return content

    except (GITCommandError, FileError, Exception), e:
        logger.error("Erro quando o usuário %s tentou sincronizar no Git" %
                     (user.get_username()))
        logger.error(e)
        raise GITCommandError(e)
Пример #3
0
def createAclGit(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 GITCommandError:  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)

        Git.synchronization()

        File.create(acl)

        Git.add(acl)

        Git.commit(
            acl, "Criação do Arquivo %s pelo usuário: %s" %
            (acl, user.get_username()))
        Git.push()

        logger.info("%s criou no GIT o arquivo: %s" % (user.get_username(),
                                                       (path + acl)))

    except (GITCommandError, FileError, Exception), e:
        logger.error(
            "Erro quando o usuário %s tentou criar o arquivo: %s no Git" %
            (user.get_username(), (path + acl)))
        logger.error(e)
        raise GITCommandError(e)
Пример #4
0
def create_template(template_name, network, content, user):
    '''Create the file template.

    :param template_name: template name
    :param network: IPv4 or IPv6
    :param content: content
    :param user: user

    :raise GITCommandError:  Failed to execute command
    '''
    try:

        ip_version = IP_VERSION.IPv4[0] if network == IP_VERSION.IPv4[
            1] else IP_VERSION.IPv6[0]

        path = "%s%s/%s%s" % (PATH_ACL, ip_version, PATH_ACL_TEMPLATES,
                              template_name)

        chdir(PATH_TYPES.TEMPLATE, ip_version, path)

        Git.synchronization()

        File.create(template_name)

        Git.add(template_name)

        Git.commit(
            template_name, "Criação do Arquivo %s pelo usuário: %s" %
            (template_name, user.get_username()))
        Git.push()

        logger.info("%s criou no GIT o arquivo: %s" % (user.get_username(),
                                                       (path + template_name)))

        alter_template(template_name, network, content, user)

    except (GITCommandError, FileError, Exception), e:
        logger.error(
            "Erro quando o usuário %s tentou criar o arquivo: %s no Git" %
            (user.get_username(), (path + template_name)))
        logger.error(e)
        raise GITCommandError(e)
Пример #5
0
def check_template(template_name, network, user):
    '''Validates if the file is created template.

    :param template_name: template name
    :param network: IPv4 or IPv6
    :param user: user

    :raise GITCommandError:  Failed to execute command

    :return: True case created
    '''
    try:

        ip_version = IP_VERSION.IPv4[0] if network == IP_VERSION.IPv4[
            1] else IP_VERSION.IPv6[0]

        path = "%s%s/%s%s" % (PATH_ACL, ip_version, PATH_ACL_TEMPLATES,
                              template_name)

        path_net_version = "%s%s" % (PATH_ACL, ip_version)

        if not os.path.isdir(path_net_version + PATH_ACL_TEMPLATES):

            os.chdir(path_net_version)
            os.mkdir('templates')
            Git.add('templates')
            Git.commit('templates', "Criação ")
            Git.push()

        chdir(PATH_TYPES.TEMPLATE, ip_version, path)

        Git.synchronization()

        File.read(template_name)

        return True

    except FileError, e:
        return False
Пример #6
0
def alterAclGit(acl_name, acl_content, environment, comment, network, user):
    '''Change the contents of the file acl.

    :param acl_name: acl name
    :param acl_content: acl content
    :param environment: Environment
    :param comment: comments of user
    :param network: v4 or v6
    :param user: user

    :raise GITCommandError:  Failed to execute command
    '''
    try:

        acl = check_name_file(acl_name)

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

        chdir(PATH_TYPES.ACL, network, path)

        Git.synchronization()

        File.write(acl, acl_content)

        Git.commit(acl, "%s comentou: %s" % (user.get_username(), comment))
        Git.push()

        logger.info(
            "%s alterou no GIT o arquivo: %s Comentário do Usuário: %s" %
            (user.get_username(), (path + acl), comment))

    except (GITCommandError, FileError, Exception), e:
        logger.error(
            "Erro quando o usuário %s tentou atualizar o arquivo: %s no Git" %
            (user.get_username(), (path + acl)))
        logger.error(e)
        raise GITCommandError(e)