From e826bfcbc6ca6c16da0941125f7675d49f5a413e Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 23 Apr 2018 12:40:57 +0300 Subject: Add: don't have a PUT for workers, log created worker --- ick2/workerapi.py | 36 ++++++++++++++++++++++++++++++++++++ start_ick | 12 ++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) mode change 100644 => 100755 start_ick diff --git a/ick2/workerapi.py b/ick2/workerapi.py index 5a7e835..bed14b4 100644 --- a/ick2/workerapi.py +++ b/ick2/workerapi.py @@ -21,5 +21,41 @@ class WorkerAPI(ick2.ResourceApiBase): # pragma: no cover def __init__(self, state): super().__init__('workers', state) + def get_routes(self, path): + return [ + { + 'method': 'POST', + 'path': path, + 'callback': self.POST(self.create), + }, + { + 'method': 'GET', + 'path': path, + 'callback': self.GET(self.list), + }, + { + 'method': 'GET', + 'path': '{}/'.format(path), + 'callback': self.GET(self.show), + }, + { + 'method': 'DELETE', + 'path': '{}/'.format(path), + 'callback': self.DELETE(self.delete), + }, + ] + def get_resource_name(self, resource): return resource['worker'] + + def create(self, body, **kwargs): + ick2.log.log( + 'trace', msg_text='create worker', body=body, kwargs=kwargs) + resource = self.mangle_new_resource(body) + name = self.get_resource_name(resource) + try: + self._state.get_resource(self._type_name, name) + except ick2.NotFound: + return self._state.add_resource(self._type_name, name, resource) + else: + raise ick2.ExistsAlready(name) diff --git a/start_ick b/start_ick old mode 100644 new mode 100755 index 96f745c..8c9d50f --- a/start_ick +++ b/start_ick @@ -16,9 +16,17 @@ set -eux -export ICK_CONTROLLER_CONFIG=/etc/ick/controller.yaml +if [ "$#" = 1 ] +then + export ICK_CONTROLLER_CONFIG="$1" + export GUNICORN_LOG=gunicorn3.log +else + export ICK_CONTROLLER_CONFIG=/etc/ick/controller.yaml + export GUNICORN_LOG=/var/log/ick/gunicorn3.log +fi + gunicorn3 \ --bind 127.0.0.1:12765 \ - --log-file /var/log/ick/gunicorn3.log \ + --log-file "$GUNICORN_LOG" \ --log-level debug \ ick_controller:app -- cgit v1.2.1