def on_put(self, req, resp, name): """ Handles PUT (or "initiate") requests for a Cluster restart. :param req: Request instance that will be passed through. :type req: falcon.Request :param resp: Response instance that will be passed through. :type resp: falcon.Response :param name: The name of the Cluster being restarted. :type name: str """ POOLS['clusterexecpool'].spawn( clusterexec.clusterexec, name, 'restart', self.store) key = '/commissaire/cluster/{0}/restart'.format(name) cluster_restart_default = { 'status': 'in_process', 'restarted': [], 'in_process': [], 'started_at': datetime.datetime.utcnow().isoformat(), 'finished_at': None } cluster_restart = ClusterRestart(**cluster_restart_default) self.store.set(key, cluster_restart.to_json()) resp.status = falcon.HTTP_201 req.context['model'] = cluster_restart
def on_put(self, req, resp, name): """ Handles PUT (or "initiate") requests for a Cluster restart. :param req: Request instance that will be passed through. :type req: falcon.Request :param resp: Response instance that will be passed through. :type resp: falcon.Response :param name: The name of the Cluster being restarted. :type name: str """ # Make sure the cluster name is valid. if not util.etcd_cluster_exists(self.store, name): self.logger.info( 'Restart PUT requested for nonexistent cluster {0}'.format( name)) resp.status = falcon.HTTP_404 return # If the operation is already in progress, return the current # status with response code 200 OK. key = '/commissaire/cluster/{0}/restart'.format(name) try: etcd_resp = self.store.get(key) self.logger.debug('Etcd Response: {0}'.format(etcd_resp)) cluster_restart = ClusterRestart(**json.loads(etcd_resp.value)) if not cluster_restart.finished_at: self.logger.debug( 'Cluster {0} restart already in progress'.format(name)) resp.status = falcon.HTTP_200 req.context['model'] = cluster_restart return except etcd.EtcdKeyNotFound: pass POOLS['clusterexecpool'].spawn( clusterexec.clusterexec, name, 'restart', self.store) self.logger.debug('Started restart in clusterexecpool for {0}'.format( name)) cluster_restart_default = { 'status': 'in_process', 'restarted': [], 'in_process': [], 'started_at': datetime.datetime.utcnow().isoformat(), 'finished_at': None } cluster_restart = ClusterRestart(**cluster_restart_default) self.store.set(key, cluster_restart.to_json()) resp.status = falcon.HTTP_201 req.context['model'] = cluster_restart
def on_put(self, req, resp, name): """ Handles PUT (or "initiate") requests for a Cluster restart. :param req: Request instance that will be passed through. :type req: falcon.Request :param resp: Response instance that will be passed through. :type resp: falcon.Response :param name: The name of the Cluster being restarted. :type name: str """ # Make sure the cluster name is valid. if not util.etcd_cluster_exists(name): self.logger.info( 'Restart PUT requested for nonexistent cluster {0}'.format( name)) resp.status = falcon.HTTP_404 return # If the operation is already in progress, return the current # status with response code 200 OK. key = '/commissaire/cluster/{0}/restart'.format(name) etcd_resp, error = cherrypy.engine.publish('store-get', key)[0] if not error: self.logger.debug('Etcd Response: {0}'.format(etcd_resp)) cluster_restart = ClusterRestart(**json.loads(etcd_resp.value)) if not cluster_restart.finished_at: self.logger.debug( 'Cluster {0} restart already in progress'.format(name)) resp.status = falcon.HTTP_200 req.context['model'] = cluster_restart return # TODO: Move to a poll? p = Process(target=clusterexec, args=(name, 'restart')) p.start() self.logger.debug( 'Started restart in clusterexecpool for {0}'.format(name)) cluster_restart_default = { 'status': 'in_process', 'restarted': [], 'in_process': [], 'started_at': datetime.datetime.utcnow().isoformat(), 'finished_at': None } cluster_restart = ClusterRestart(**cluster_restart_default) cherrypy.engine.publish('store-save', key, cluster_restart.to_json()) resp.status = falcon.HTTP_201 req.context['model'] = cluster_restart
def on_put(self, req, resp, name): """ Handles PUT (or "initiate") requests for a Cluster restart. :param req: Request instance that will be passed through. :type req: falcon.Request :param resp: Response instance that will be passed through. :type resp: falcon.Response :param name: The name of the Cluster being restarted. :type name: str """ # Make sure the cluster name is valid. if not util.etcd_cluster_exists(name): self.logger.info( 'Restart PUT requested for nonexistent cluster {0}'.format( name)) resp.status = falcon.HTTP_404 return # If the operation is already in progress, return the current # status with response code 200 OK. key = '/commissaire/cluster/{0}/restart'.format(name) etcd_resp, error = cherrypy.engine.publish('store-get', key)[0] if not error: self.logger.debug('Etcd Response: {0}'.format(etcd_resp)) cluster_restart = ClusterRestart(**json.loads(etcd_resp.value)) if not cluster_restart.finished_at: self.logger.debug( 'Cluster {0} restart already in progress'.format(name)) resp.status = falcon.HTTP_200 req.context['model'] = cluster_restart return # TODO: Move to a poll? p = Process(target=clusterexec, args=(name, 'restart')) p.start() self.logger.debug('Started restart in clusterexecpool for {0}'.format( name)) cluster_restart_default = { 'status': 'in_process', 'restarted': [], 'in_process': [], 'started_at': datetime.datetime.utcnow().isoformat(), 'finished_at': None } cluster_restart = ClusterRestart(**cluster_restart_default) cherrypy.engine.publish('store-save', key, cluster_restart.to_json()) resp.status = falcon.HTTP_201 req.context['model'] = cluster_restart
def on_put(self, req, resp, name): """ Handles PUT (or "initiate") requests for a Cluster restart. :param req: Request instance that will be passed through. :type req: falcon.Request :param resp: Response instance that will be passed through. :type resp: falcon.Response :param name: The name of the Cluster being restarted. :type name: str """ # Make sure the cluster name is valid. if not util.etcd_cluster_exists(self.store, name): self.logger.info( 'Restart PUT requested for nonexistent cluster {0}'.format( name)) resp.status = falcon.HTTP_404 return # If the operation is already in progress, return the current # status with response code 200 OK. key = '/commissaire/cluster/{0}/restart'.format(name) try: etcd_resp = self.store.get(key) self.logger.debug('Etcd Response: {0}'.format(etcd_resp)) cluster_restart = ClusterRestart(**json.loads(etcd_resp.value)) if not cluster_restart.finished_at: self.logger.debug( 'Cluster {0} restart already in progress'.format(name)) resp.status = falcon.HTTP_200 req.context['model'] = cluster_restart return except etcd.EtcdKeyNotFound: pass POOLS['clusterexecpool'].spawn(clusterexec.clusterexec, name, 'restart', self.store) self.logger.debug( 'Started restart in clusterexecpool for {0}'.format(name)) cluster_restart_default = { 'status': 'in_process', 'restarted': [], 'in_process': [], 'started_at': datetime.datetime.utcnow().isoformat(), 'finished_at': None } cluster_restart = ClusterRestart(**cluster_restart_default) self.store.set(key, cluster_restart.to_json()) resp.status = falcon.HTTP_201 req.context['model'] = cluster_restart