Exemple #1
0
def alter_template(template_name, network, content, user):
    '''Change the contents of the file acl.

    :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.write(template_name, content)

        Git.commit(
            template_name,
            "%s alterou o arquivo %s" % (user.get_username(), template_name))
        Git.push()

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

    except (GITCommandError, FileError, Exception), e:
        logger.error(
            "Erro quando o usuário %s tentou atualizar o arquivo: %s no Git" %
            (user.get_username(), (path + template_name)))
        logger.error(e)
        raise GITCommandError(e)
Exemple #2
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)