diff --git a/api.py/__init__.py b/api.py/__init__.py new file mode 100644 index 0000000..207fa15 --- /dev/null +++ b/api.py/__init__.py @@ -0,0 +1,13 @@ +# Copyright (c) 2013 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. \ No newline at end of file diff --git a/api.py/v1.py b/api.py/v1.py new file mode 100644 index 0000000..c24d990 --- /dev/null +++ b/api.py/v1.py @@ -0,0 +1,105 @@ + +# Copyright (c) 2013 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from flask import Flask +from flask.ext.restful import reqparse, abort, Api, Resource + +app = Flask(__name__) +api = Api(app) + +TODOS = { + 'todo1': {'task': 'build an API'}, + 'todo2': {'task': '?????'}, + 'todo3': {'task': 'profit!'}, +} + + +def abort_if_todo_doesnt_exist(todo_id): + if todo_id not in TODOS: + abort(404, message="Todo {} doesn't exist".format(todo_id)) + +parser = reqparse.RequestParser() +parser.add_argument('task', type=str) + + +# Todo +# show a single todo item and lets you delete them +class Todo(Resource): + def get(self, todo_id): + abort_if_todo_doesnt_exist(todo_id) + return TODOS[todo_id] + + def delete(self, todo_id): + abort_if_todo_doesnt_exist(todo_id) + del TODOS[todo_id] + return '', 204 + + def put(self, todo_id): + args = parser.parse_args() + task = {'task': args['task']} + TODOS[todo_id] = task + return task, 201 + + +# TodoList +# shows a list of all todos, and lets you POST to add new tasks +class TodoList(Resource): + def get(self): + return TODOS + + def post(self): + args = parser.parse_args() + todo_id = 'todo%d' % (len(TODOS) + 1) + TODOS[todo_id] = {'task': args['task']} + return TODOS[todo_id], 201 + +## +## Actually setup the Api resource routing here +## +api.add_resource(TodoList, '/todos') +api.add_resource(Todo, '/todos/') + + +if __name__ == '__main__': + app.run(debug=True) +# +# @app.route('/client/ui') +# def ui_data(): +# #type - application/z-gzip +# pass +# +# @app.route('/client/ui') +# def conductor_data(): +# #type - application/z-gzip +# pass +# +# @app.route('/client/ui') +# def conductor_data(): +# #type - application/json +# pass +# +# @app.route('/client//') +# def conductor_data(): +# #type - application/json +# pass +# +# @app.route('/client//') +# def conductor_data(): +# #type - application/json +# pass +# +# +# if __name__ == '__main__': +# app.run() \ No newline at end of file diff --git a/archiver.py b/archiver.py index d4c3fb8..808fb80 100644 --- a/archiver.py +++ b/archiver.py @@ -79,13 +79,15 @@ class Archiver(object): "Manifest for {0} service has no file definitions for " "{1}").format(manifest.service_display_name, data_type) - with tarfile.open("service_metadata.tar", "w") as tar: + target_archeve = "service_metadata.tar" + with tarfile.open(target_archeve, "w") as tar: for item in os.listdir(temp_dir): tar.add(os.path.join(temp_dir, item), item) try: shutil.rmtree(temp_dir, ignore_errors=True) except Exception as e: log.error("Unable to delete temp directory: {0}".format(e)) + return target_archeve diff --git a/consts.py b/consts.py index c744aee..1bd10fa 100644 --- a/consts.py +++ b/consts.py @@ -11,9 +11,28 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -UI_FORMS = "ui_forms" -WORKFLOWS = "workflows" -HEAT_TEMPLATES = "heat_templates" -AGENT_TEMPLATES = "agent_templates" -SCRIPTS = "scripts" -DATA_TYPES = [UI_FORMS, WORKFLOWS, HEAT_TEMPLATES, AGENT_TEMPLATES, SCRIPTS] \ No newline at end of file +import os +UI_FORMS = u"ui_forms" +WORKFLOWS = u"workflows" +HEAT_TEMPLATES = u"heat_templates" +AGENT_TEMPLATES = u"agent_templates" +SCRIPTS = u"scripts" + +DATA_TYPES = [UI_FORMS, WORKFLOWS, HEAT_TEMPLATES, AGENT_TEMPLATES, SCRIPTS] + +UI_FORMS_ROOT_DIR = u"ui_forms" +WORKFLOWS_ROOT_DIR = u"workflows" +HEAT_TEMPLATES_ROOT_DIR = u"heat_templates" +AGENT_TEMPLATES_ROOT_DIR = u"agent_templates" +SCRIPTS_ROOT_DIR = u"scripts" +#root directory should contain manifests files +ROOT_DIRECTORY = os.path.join(os.path.dirname(__file__), + u'Services') + +DIRECTORIES_BY_TYPE = {UI_FORMS: UI_FORMS_ROOT_DIR, + WORKFLOWS: WORKFLOWS_ROOT_DIR, + HEAT_TEMPLATES: HEAT_TEMPLATES_ROOT_DIR, + AGENT_TEMPLATES_ROOT_DIR: AGENT_TEMPLATES_ROOT_DIR, + SCRIPTS: SCRIPTS_ROOT_DIR + } + diff --git a/parser.py b/parser.py index 37c6d1f..4e70f43 100644 --- a/parser.py +++ b/parser.py @@ -82,8 +82,8 @@ class ManifestParser(object): exc)) continue - valid_file_info = True for key, value in service_manifest_data.iteritems(): + valid_file_info = True directory_location = self.directory_mapping.get(key) if directory_location: if not isinstance(value, list):