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)
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)
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
def deleteAclGit(acl_name, environment, network, user): '''Delete acl file :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"]) os.chdir(PATH_ACL) Git.synchronization() path_to_acl = "%s/%s/%s" % (network, path, acl) Git.remove(path_to_acl) Git.commit( path_to_acl, "Exclusão do Arquivo %s pelo usuário:%s" % (acl, user.get_username())) Git.push() logger.info("%s excluiu no GIT o arquivo: %s" % (user.get_username(), (path + acl))) except (GITCommandError, FileError, Exception), e: logger.error( "Erro quando o usuário %s tentou excluiu o arquivo: %s no Git" % (user.get_username(), (path + acl))) logger.error(e) raise GITCommandError(e)
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)
def scriptAclGit(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 GITCommandError: 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) Git.synchronization() arquivo = open("./%s" % acl, "w") chdir(PATH_TYPES.TEMPLATE, network) 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() Git.commit( acl, "%s gerou Script para a acl %s" % (user.get_username(), acl)) Git.push() logger.info("%s alterou no GIT o arquivo: %s" % (user.get_username(), 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) Git.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() Git.commit( acl, "%s gerou Script para a acl %s" % (user.get_username(), acl)) Git.push() logger.info("%s alterou no GIT o arquivo: %s" % (user.get_username(), 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) Git.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() Git.commit( acl, "%s gerou Script para a acl %s" % (user.get_username(), acl)) Git.push() logger.info("%s alterou no GIT o arquivo: %s" % (user.get_username(), 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) Git.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() Git.commit( acl, "%s gerou Script para a acl %s" % (user.get_username(), acl)) Git.push() logger.info("%s alterou no GIT o arquivo: %s" % (user.get_username(), 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) Git.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() Git.commit( acl, "%s gerou Script para a acl %s" % (user.get_username(), acl)) Git.push() logger.info("%s alterou no GIT o arquivo: %s" % (user.get_username(), 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) Git.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() Git.commit( acl, "%s gerou Script para a acl %s" % (user.get_username(), acl)) Git.push() logger.info("%s alterou no GIT o arquivo: %s" % (user.get_username(), acl)) except (GITCommandError, FileError, Exception), e: logger.error( "Erro quando o usuário %s tentou gerar o arquivo: %s no Git" % (user.get_username(), acl)) logger.error(e) raise GITCommandError(e)