First version of murano Api added

This commit is contained in:
efedorova 2013-10-10 14:33:57 +04:00
parent ac04b4e1b7
commit b0c04f614e
5 changed files with 147 additions and 8 deletions

13
api.py/__init__.py Normal file
View File

@ -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.

105
api.py/v1.py Normal file
View File

@ -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/<string:todo_id>')
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/<data_type>/<path>')
# def conductor_data():
# #type - application/json
# pass
#
# @app.route('/client/<data_type>/<file_name>')
# def conductor_data():
# #type - application/json
# pass
#
#
# if __name__ == '__main__':
# app.run()

View File

@ -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

View File

@ -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]
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
}

View File

@ -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):