def commande_demarrer_application(self, commande: CommandeMonitor):
        self.__logger.info("Demarrer application %s", str(commande))

        mq_properties = commande.mq_properties
        reply_to = mq_properties.reply_to
        correlation_id = mq_properties.correlation_id
        reponse = {'ok': True}
        nom_application = commande.contenu['nom_application']

        try:
            # Tenter de charger la configuration existante
            configuration_existante = self.__gestionnaire_modules_docker.charger_config(
                'app.cfg.' + nom_application)
            configuration_docker = json.loads(
                configuration_existante.decode('utf-8'))
            commande.contenu['configuration'] = configuration_docker
            commande.contenu['configuration_courante'] = True

            self.__service_monitor.generateur_transactions.transmettre_reponse(
                reponse, replying_to=reply_to, correlation_id=correlation_id)

            self.preparer_installation(nom_application, configuration_docker)

            # Transmettre maj
            self.__service_monitor.emettre_presence()
        except Exception as e:
            self.__logger.exception("Erreur demarrer application")
            reponse['ok'] = False
            reponse['err'] = str(e)
            self.__service_monitor.generateur_transactions.transmettre_reponse(
                reponse, replying_to=reply_to, correlation_id=correlation_id)
    def installer_application(self, commande: CommandeMonitor):
        self.__logger.info("Installation application %s", str(commande))

        mq_properties = commande.mq_properties
        reply_to = mq_properties.reply_to
        correlation_id = mq_properties.correlation_id
        reponse = {'ok': True}

        nom_application = commande.contenu['nom_application']
        try:
            configuration_docker = commande.contenu['configuration']

            if configuration_docker is None:
                # Tenter de charger la configuration existante
                configuration_existante = self.__gestionnaire_modules_docker.charger_config(
                    'app.cfg.' + nom_application)
                configuration_docker = json.loads(
                    configuration_existante.decode('utf-8'))
                commande.contenu['configuration'] = configuration_docker
                commande.contenu['configuration_courante'] = True

            self.__service_monitor.generateur_transactions.transmettre_reponse(
                reponse, replying_to=reply_to, correlation_id=correlation_id)

            self.preparer_installation(nom_application, configuration_docker)

            # Transmettre maj
            self.__service_monitor.emettre_presence()
        except Exception as e:
            self.__logger.exception("Erreur installation application")
            reponse['ok'] = False
            reponse['err'] = str(e)
            self.__service_monitor.generateur_transactions.transmettre_reponse(
                reponse, replying_to=reply_to, correlation_id=correlation_id)
        finally:
            # Nettoyer les volumes docker transitifs potentiellement crees
            docker_client = self.__gestionnaire_modules_docker.docker_client
            volumes = ['scripts', 'backup']
            for vol in volumes:
                try:
                    volume = docker_client.volumes.get(vol + '_' +
                                                       nom_application)
                    volume.remove()
                except APIError as apie:
                    if apie.status_code != 404:
                        self.__logger.exception(
                            "Erreur nettoyage volume %s pour application %s" %
                            (vol, nom_application))
Exemple #3
0
    def post_configurer_mq(self, request_data):
        logger = logging.getLogger(__name__ + '.' + self.__class__.__name__)
        if logger.isEnabledFor(logging.DEBUG):
            logger.debug("post_configurer_mq: POST recu\n%s",
                         json.dumps(request_data, indent=2))

        try:
            # Valider input
            if request_data.get('host') and request_data.get(
                    'port') or request_data.get('supprimer_params_mq'):
                request_data[
                    'commande'] = ConstantesServiceMonitor.COMMANDE_CONFIGURER_MQ
                commande = CommandeMonitor(request_data)
                self.service_monitor.gestionnaire_commandes.ajouter_commande(
                    commande)

                self.repondre_json({'ok': True}, status_code=200)
            else:
                self.repondre_json(
                    {
                        'ok': False,
                        'message': 'Params incomplets'
                    },
                    status_code=500)

        except Exception as e:
            self.__logger.exception("post_configurer_mq: Erreur traitement")
            reponse = {'err': str(e)}
            self.repondre_json(reponse, status_code=500)
Exemple #4
0
    def post_configurer_idmg(self, request_data):
        logger = logging.getLogger(__name__ + '.' + self.__class__.__name__)
        if logger.isEnabledFor(logging.DEBUG):
            logger.debug("post_configurer_idmg: POST recu\n%s",
                         json.dumps(request_data, indent=2))

        # S'assurer que le IDMG n'est pas deja configure
        if self.service_monitor.idmg is not None and self.service_monitor.securite is not None:
            logger.error(
                "IDMG et securite deja configure, retourner erreur 403")
            return self.repondre_json(
                {
                    'ok': False,
                    'idmg': self.service_monitor.idmg
                },
                status_code=403)

        try:
            # Valider input
            reponse = {
                'idmg': request_data['idmg'],
                'securite': request_data['securite'],
            }

            request_data[
                'commande'] = ConstantesServiceMonitor.COMMANDE_CONFIGURER_IDMG
            commande = CommandeMonitor(request_data)
            self.service_monitor.gestionnaire_commandes.ajouter_commande(
                commande)

            self.repondre_json(reponse, status_code=200)
        except Exception as e:
            self.__logger.exception("post_configurer_idmg: Erreur traitement")
            reponse = {'err': str(e)}
            self.repondre_json(reponse, status_code=500)
Exemple #5
0
    def post_installer(self, request_data):
        logger = logging.getLogger(__name__ + '.' + self.__class__.__name__)
        logger.debug("post_installer : recu\n%s",
                     json.dumps(request_data, indent=2))

        request_data[
            'commande'] = ConstantesServiceMonitor.COMMANDE_INSTALLER_NOEUD
        commande = CommandeMonitor(request_data)
        self.service_monitor.gestionnaire_commandes.ajouter_commande(commande)

        self.repondre_json(dict(), status_code=200)
Exemple #6
0
    def post_configurer_domaine(self, request_data):
        logger = logging.getLogger(__name__ + '.' + self.__class__.__name__)
        logger.debug("POST recu configuration domaine\n%s",
                     json.dumps(request_data, indent=2))

        request_data[
            'commande'] = ConstantesServiceMonitor.COMMANDE_CONFIGURER_DOMAINE
        commande = CommandeMonitor(request_data)
        self.service_monitor.gestionnaire_commandes.ajouter_commande(commande)

        reponse = {
            'domaine': request_data['domaine'],
        }
        self.repondre_json(reponse, status_code=200)
    def lire_fifo(self):
        self.__logger.info("Demarrage thread FIFO commandes")

        while not self.__fermeture_event.is_set():
            self.__socket_fifo = open(self._path_fifo, 'r')
            try:
                while True:
                    json_commande = json.load(self.__socket_fifo)
                    self.ajouter_commande(CommandeMonitor(json_commande))
            except JSONDecodeError as jse:
                if jse.pos > 0:
                    self.__logger.exception("Erreur decodage commande : %s",
                                            jse.doc)

            self.__action_event.set()
            self.__socket_fifo.close()
            self.__socket_fifo = None

        self.__logger.info("Fermeture thread FIFO commandes")