def aplicar(rack): try: PATH_TO_CONFIG = get_variable("path_to_config") except ObjectDoesNotExist: raise var_exceptions.VariableDoesNotExistException( "Erro buscando a variável PATH_TO_CONFIG.") path_config = PATH_TO_CONFIG + '*' + rack.nome + '*' arquivos = glob.glob(path_config) for var in arquivos: name_equipaments = var.split('/')[-1][:-4] #Check if file is config relative to this rack for nome in name_equipaments: #Check if file is config relative to this rack if rack.nome in nome: #Apply config only in spines. Leaves already have all necessary config in startup if "DEL" in nome: #Check if equipment in under maintenance. If so, does not aplly on it try: equip = Equipamento.get_by_name(nome) if not equip.maintenance: (erro, result) = commands.getstatusoutput( "/usr/bin/backuper -T acl -b %s -e -i %s -w 300" % (var, nome)) if erro: raise RackAplError( None, None, "Falha ao aplicar as configuracoes: %s" % (result)) except RackAplError, e: raise e except: #Error equipment not found, do nothing pass
def get_core_name(rack): name_core1 = None name_core2 = None try: interfaces2 = Interface.search(rack.id_ilo.id) for interface2 in interfaces2: try: sw = interface2.get_switch_and_router_interface_from_host_interface( None) if sw.equipamento.nome.split('-')[0] == 'OOB': if sw.equipamento.nome.split('-')[2] == '01': name_core1 = sw.equipamento.nome elif sw.equipamento.nome.split('-')[2] == '02': name_core2 = sw.equipamento.nome except InterfaceNotFoundError: next except e: raise RackAplError( None, rack.nome, 'Erro ao buscar os nomes do Core associado ao Switch de gerencia %s' % rack.id_ilo.id) return name_core1, name_core2
def inserir_equip(user, variablestochangecore, rede_id): ip = Ip() ip.descricao = None ip.oct1, ip.oct2, ip.oct3, ip.oct4 = str( variablestochangecore['IPCORE']).split('.') equip = Equipamento.get_by_name(variablestochangecore['EQUIP_NAME']) rede = NetworkIPv4.get_by_pk(rede_id) ip.save_ipv4(equip.id, user, rede) if ip.id is None: raise RackAplError(None, None, 'Erro ao inserir os equipamentos') # Delete vlan's cache destroy_cache_function([rede.vlan_id]) list_id_equip = [] list_id_equip.append(equip.id) destroy_cache_function(list_id_equip, True) return 0
def handle_post(self, request, user, *args, **kwargs): """Treat requests POST to create the configuration file. URL: rack/alocar-config/id_rack """ try: # User permission if not has_perm(user, AdminPermission.SCRIPT_MANAGEMENT, AdminPermission.WRITE_OPERATION): self.log.error( u'User does not have permission to perform the operation.') raise UserNotAuthorizedError(None) rack_id = kwargs.get('id_rack') rack = Rack() rack = rack.get_by_pk(rack_id) # Validar configuracao if not rack.config: raise RackAplError( None, rack.nome, 'Os arquivos de configuracao devem ser gerados antes.') if rack.create_vlan_amb: raise RackAplError( None, rack.nome, 'As vlans, redes e ambientes ja foram criados.') # variaveis name_core1, name_core2 = get_core_name(rack) environment_list = [] variablestochangecore1 = {} variablestochangecore2 = {} variablestochangecore1 = dic_vlan_core(variablestochangecore1, rack.numero, name_core1, rack.nome) variablestochangecore2 = dic_vlan_core(variablestochangecore2, rack.numero, name_core2, rack.nome) # VLAN Gerencia SO ambientes = dict() try: DIVISAODC_MGMT = get_variable('divisaodc_mngt') AMBLOG_MGMT = get_variable('amblog_mngt') GRPL3_MGMT = get_variable('grpl3_mngt') except ObjectDoesNotExist: raise var_exceptions.VariableDoesNotExistException( 'Erro buscando as variáveis <DIVISAODC,AMBLOG,GRPL3>_MGMT.' ) ambientes['DC'] = DIVISAODC_MGMT ambientes['LOG'] = AMBLOG_MGMT ambientes['L3'] = GRPL3_MGMT try: # criar vlan vlan = criar_vlan(user, variablestochangecore1, ambientes) except: raise RackAplError(None, rack.nome, 'Erro ao criar a VLAN_SO.') try: # criar rede network = criar_rede(user, 'Rede invalida equipamentos', variablestochangecore1, vlan) except: raise RackAplError(None, rack.nome, 'Erro ao criar a rede da VLAN_SO') try: # inserir os Core inserir_equip(user, variablestochangecore1, network.id) inserir_equip(user, variablestochangecore2, network.id) except: raise RackAplError(None, rack.nome, 'Erro ao inserir o core 1 e 2') # Ambientes # BE - SPINE - LEAF try: environment_list = ambiente_spn_lf(user, rack, environment_list) except: raise RackAplError( None, rack.nome, 'Erro ao criar os ambientes e alocar as vlans do Spine-leaf.' ) # BE - PRODUCAO try: environment_list = ambiente_prod(user, rack, environment_list) except ObjectDoesNotExist, e: raise var_exceptions.VariableDoesNotExistException(e) except: raise RackAplError(None, rack.nome, 'Erro ao criar os ambientes de produção.') # BE - Hosts - CLOUD try: environment_list = ambiente_cloud(user, rack, environment_list) except: raise RackAplError( None, rack.nome, 'Erro ao criar os ambientes e alocar as vlans da Cloud.') # FE try: environment_list = ambiente_prod_fe(user, rack, environment_list) except ObjectDoesNotExist, e: raise var_exceptions.VariableDoesNotExistException(e)
# BE - Hosts - CLOUD try: environment_list = ambiente_cloud(user, rack, environment_list) except: raise RackAplError( None, rack.nome, 'Erro ao criar os ambientes e alocar as vlans da Cloud.') # FE try: environment_list = ambiente_prod_fe(user, rack, environment_list) except ObjectDoesNotExist, e: raise var_exceptions.VariableDoesNotExistException(e) except: raise RackAplError(None, rack.nome, 'Erro ao criar os ambientes de FE.') # Borda try: environment_list = ambiente_borda(user, rack, environment_list) except ObjectDoesNotExist: raise var_exceptions.VariableDoesNotExistException() except: raise RackAplError(None, rack.nome, 'Erro ao criar os ambientes de Borda.') # Backuper environment_rack(user, environment_list, rack) rack.__dict__.update(id=rack.id, create_vlan_amb=True)