Exemple #1
0
    def post(self, *args, **kwargs):
        try:
            log.info('RACK deploy.')

            rack_id = kwargs.get('rack_id')
            rack = facade.get_by_pk(rack_id)

            try:
                PATH_TO_ADD_CONFIG = get_variable('path_to_add_config')
                REL_PATH_TO_ADD_CONFIG = get_variable('rel_path_to_add_config')
            except ObjectDoesNotExist:
                raise var_exceptions.VariableDoesNotExistException("Erro buscando a variável PATH_TO_ADD_CONFIG ou "
                                                                   "REL_PATH_TO_ADD_CONFIG.")

            path_config = PATH_TO_ADD_CONFIG + '*' + rack.nome + '*'
            arquivos = glob.glob(path_config)

            # Get all files and search for equipments of the rack
            for var in arquivos:
                filename_equipments = var.split('/')[-1]
                rel_filename = REL_PATH_TO_ADD_CONFIG + filename_equipments
                log.debug("rel_filename: %s" % rel_filename)
                # Check if file is config relative to this rack
                if rack.nome in filename_equipments:
                    # Apply config only in spines. Leaves already have all necessary config in startup
                    if "ADD" in filename_equipments:
                        # Check if equipment in under maintenance. If so, does not aplly on it
                        equipment_name = filename_equipments.split('-ADD-')[0]
                        log.debug("equipment_name: %s" % equipment_name)
                        try:
                            equip = Equipamento.get_by_name(equipment_name)
                            if not equip.maintenance:
                                lockvar = LOCK_EQUIPMENT_DEPLOY_CONFIG_USERSCRIPT % (equip.id)
                                output = deploy_facade.deploy_config_in_equipment_synchronous(rel_filename, equip, lockvar)

                                log.debug("equipment output: %s" % (output))
                        except Exception as e:
                            log.exception(e)
                            raise exceptions.RackAplError(e)
            # SEPARAR AQUI!

            datas = dict()
            success_map = dict()

            success_map['rack_conf'] = True
            datas['sucesso'] = success_map

            return Response(datas, status=status.HTTP_201_CREATED)

        except exceptions.RackNumberNotFoundError as e:
            log.exception(e)
            raise exceptions.NetworkAPIException(e)
        except var_exceptions.VariableDoesNotExistException as e:
            log.error(e)
            raise api_exceptions.NetworkAPIException(
                'Erro buscando a variável PATH_TO_ADD_CONFIG ou REL_PATH_TO_ADD_CONFIG. Erro: %s' % e)
        except Exception as e:
            log.exception(e)
            raise api_exceptions.NetworkAPIException(e)
Exemple #2
0
    def post(self, *args, **kwargs):
        try:
            log.info('RACK deploy.')

            rack_id = kwargs.get('rack_id')
            rack = facade.get_by_pk(rack_id)

            try:
                PATH_TO_ADD_CONFIG = get_variable('path_to_add_config')
                REL_PATH_TO_ADD_CONFIG = get_variable('rel_path_to_add_config')
            except ObjectDoesNotExist:
                raise var_exceptions.VariableDoesNotExistException(
                    "Erro buscando a variável PATH_TO_ADD_CONFIG ou "
                    "REL_PATH_TO_ADD_CONFIG.")

            path_config = PATH_TO_ADD_CONFIG + '*' + rack.nome + '*'
            arquivos = glob.glob(path_config)

            # Get all files and search for equipments of the rack
            for var in arquivos:
                filename_equipments = var.split('/')[-1]
                rel_filename = "../../" + REL_PATH_TO_ADD_CONFIG + filename_equipments
                log.debug("rel_filename: %s" % rel_filename)
                # Check if file is config relative to this rack
                if rack.nome in filename_equipments:
                    # Apply config only in spines. Leaves already have all necessary config in startup
                    if "ADD" in filename_equipments:
                        # Check if equipment in under maintenance. If so, does not aplly on it
                        equipment_name = filename_equipments.split('-ADD-')[0]
                        log.debug("equipment_name: %s" % equipment_name)
                        try:
                            equip = Equipamento.get_by_name(equipment_name)
                            if not equip.maintenance:
                                (erro, result) = commands.getstatusoutput(
                                    "/usr/bin/backuper -T acl -b %s -e -i %s -w "
                                    "300" % (rel_filename, equipment_name))
                                log.debug("erro: %s, result: %s" %
                                          (str(erro), str(result)))
                                if erro:
                                    raise exceptions.RackAplError()
                        except exceptions.RackAplError, e:
                            raise e
                        except:
                            # Error equipment not found, do nothing
                            pass
Exemple #3
0
                            if not equip.maintenance:
                                (erro, result) = commands.getstatusoutput("/usr/bin/backuper -T acl -b %s -e -i %s -w 300" % (rel_filename, equipment_name))
                                if erro:
                                    raise exceptions.RackAplError()
                        except exceptions.RackAplError, e:
                            raise e
                        except:
                            #Error equipment not found, do nothing
                            pass

            datas = dict()
            success_map = dict()

            success_map['rack_conf'] = True
            datas['sucesso'] = success_map

            return Response(datas, status=status.HTTP_201_CREATED)

        except exceptions.RackAplError, exception:
            log.exception(exception)
            raise exceptions.RackAplError("Falha ao aplicar as configuracoes: %s" %(result))
        except exceptions.RackNumberNotFoundError, exception:
            log.exception(exception)
            raise exceptions.RackNumberNotFoundError()
        except var_exceptions.VariableDoesNotExistException, exception:
            log.error(exception)
            raise var_exceptions.VariableDoesNotExistException("Erro buscando a variável PATH_TO_ADD_CONFIG ou REL_PATH_TO_ADD_CONFIG.")
        except Exception, exception:
            log.exception(exception)
            raise api_exceptions.NetworkAPIException(exception)