Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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