def on_put(self, req, resp, name): """ Handles the creation of a new Cluster. :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 created. :type name: str """ # PUT is idempotent, and since there's no body to this request, # there's nothing to conflict with. The request should always # succeed, even if we didn't actually do anything. if util.etcd_cluster_exists(self.store, name): self.logger.info( 'Creation of already exisiting cluster {0} requested.'.format( name)) else: key = util.etcd_cluster_key(name) cluster = Cluster(status='ok', hostset=[]) etcd_resp = self.store.set(key, cluster.to_json(secure=True)) self.logger.info( 'Created cluster {0} per request.'.format(name)) self.logger.debug('Etcd Response: {0}'.format(etcd_resp)) resp.status = falcon.HTTP_201
def on_get(self, req, resp, name): """ Handles retrieval of an existing Cluster. :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 requested. :type name: str """ key = util.etcd_cluster_key(name) etcd_resp, error = cherrypy.engine.publish('store-get', key)[0] if error: resp.status = falcon.HTTP_404 return cluster = Cluster(**json.loads(etcd_resp.value)) if not cluster: resp.status = falcon.HTTP_404 return self._calculate_hosts(cluster) # Have to set resp.body explicitly to include Hosts. resp.body = cluster.to_json_with_hosts() resp.status = falcon.HTTP_200
def on_put(self, req, resp, name): """ Handles the creation of a new Cluster. :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 created. :type name: str """ # PUT is idempotent, and since there's no body to this request, # there's nothing to conflict with. The request should always # succeed, even if we didn't actually do anything. if util.etcd_cluster_exists(name): self.logger.info( 'Creation of already exisiting cluster {0} requested.'.format( name)) else: key = util.etcd_cluster_key(name) cluster = Cluster(status='ok', hostset=[]) etcd_resp, _ = cherrypy.engine.publish( 'store-save', key, cluster.to_json(secure=True))[0] self.logger.info('Created cluster {0} per request.'.format(name)) self.logger.debug('Etcd Response: {0}'.format(etcd_resp)) resp.status = falcon.HTTP_201
def on_delete(self, req, resp, name): """ Handles the deletion of a Cluster. :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 deleted. :type name: str """ resp.body = '{}' if not util.etcd_cluster_exists(name): self.logger.info( 'Deleting for non-existent cluster {0} requested.'.format( name)) resp.status = falcon.HTTP_404 else: self.store.delete(util.etcd_cluster_key(name)) resp.status = falcon.HTTP_200 self.logger.info('Deleted cluster {0} per request.'.format(name))
def on_delete(self, req, resp, name): """ Handles the deletion of a Cluster. :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 deleted. :type name: str """ resp.body = '{}' if not util.etcd_cluster_exists(self.store, name): self.logger.info( 'Deleting for non-existent cluster {0} requested.'.format( name)) resp.status = falcon.HTTP_404 else: self.store.delete(util.etcd_cluster_key(name)) resp.status = falcon.HTTP_410 self.logger.info( 'Deleted cluster {0} per request.'.format(name))