Пример #1
0
class RackDeployView(APIView):
    @permission_classes((IsAuthenticated, Write))
    @commit_on_success
    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, e:
                            log.exception(e)
                            raise exceptions.RackAplError(e)

            # Create Foreman entries for rack switches
            facade.api_foreman(rack)

            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, e:
            log.exception(e)
            raise exceptions.NetworkAPIException(e)
Пример #2
0
    def post(self, *args, **kwargs):
        try:
            log.info('RACK Foreman.')

            rack_id = kwargs.get('rack_id')
            rack = facade.get_by_pk(rack_id)
            # Create Foreman entries for rack switches
            facade.api_foreman(rack)
            raise api_exceptions.NetworkAPIException('chegou')
            return Response(datas, status=status.HTTP_201_CREATED)

        except exceptions.RackNumberNotFoundError, e:
            log.exception(e)
            raise exceptions.NetworkAPIException(e)
Пример #3
0
    def post(self, *args, **kwargs):
        log.info('RACK Foreman.')

        try:
            rack_id = kwargs.get('rack_id')
            rack = facade.get_by_pk(rack_id)
            facade.api_foreman(rack)
            return Response({}, 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 ao registrar o Switch no Foreman. Erro: %s' % e)

        except Exception as e:
            log.exception(e)
            raise api_exceptions.NetworkAPIException(e)
Пример #4
0
                            pass

            # Create Foreman entries for rack switches
            facade.api_foreman(rack)

            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, e:
            log.exception(e)
            raise exceptions.NetworkAPIException(e)
        except var_exceptions.VariableDoesNotExistException, 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, e:
            log.exception(e)
            raise api_exceptions.NetworkAPIException(e)


class RackConfigView(APIView):
    @commit_on_success
    def post(self, request, *args, **kwargs):
        try:
            log.info(