From b24d260524d16dce96a682fd32629951e2ac17ee Mon Sep 17 00:00:00 2001 From: efedorova Date: Tue, 15 Oct 2013 18:47:27 +0400 Subject: [PATCH] Update api --- .gitignore | 1 + muranorepository/api/__init__.py | 13 +++ muranorepository/api/v1.py | 137 ++++++++++++++++++++++++++ "muranorepository/config.example\\" | 0 muranorepository/service_metadata.tar | Bin 0 -> 51200 bytes 5 files changed, 151 insertions(+) create mode 100644 muranorepository/api/__init__.py create mode 100644 muranorepository/api/v1.py create mode 100644 "muranorepository/config.example\\" create mode 100644 muranorepository/service_metadata.tar diff --git a/.gitignore b/.gitignore index a2e9ce9..f76f900 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ nosetests.xml .project .pydevproject .idea +etc/murano-repository.conf diff --git a/muranorepository/api/__init__.py b/muranorepository/api/__init__.py new file mode 100644 index 0000000..207fa15 --- /dev/null +++ b/muranorepository/api/__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/muranorepository/api/v1.py b/muranorepository/api/v1.py new file mode 100644 index 0000000..0ad610b --- /dev/null +++ b/muranorepository/api/v1.py @@ -0,0 +1,137 @@ +# 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. + +import os +from flask import Blueprint, make_response, send_file +from flask import jsonify, request, abort +from werkzeug import secure_filename + +from muranorepository.utils.parser import ManifestParser +from muranorepository.utils.archiver import Archiver +from muranorepository.consts import DATA_TYPES, MANIFEST +from oslo.config import cfg +CONF = cfg.CONF + +v1_api = Blueprint('v1', __name__) + + +@v1_api.route('/client/ui') +def get_ui_data(): + parser = ManifestParser(CONF.manifests) + manifests = parser.parse() + archive_name = Archiver().create(manifests, "ui") + + return send_file(archive_name) + + +@v1_api.route('/client/conductor') +def get_conductor_data(): + parser = ManifestParser(CONF.manifests) + manifests = parser.parse() + archive_name = Archiver().create(manifests, + "heat", + "agent", + "scripts") + return send_file(archive_name) + + +@v1_api.route('/admin/', methods=['GET', 'POST']) +def get_data_type_locations(data_type): + ####### validation ######## + if data_type not in DATA_TYPES: + abort(404) + result_path = os.path.join(CONF.manifests, getattr(CONF, data_type)) + ####### end validation ######## + if request.method == 'GET': + locations = [] + + for path, subdirs, files in os.walk(result_path): + for name in files: + locations.append(name) + result = {data_type: locations} + return jsonify(result) + + if request.method == 'POST': + try: + file_to_upload = request.files['files'] + if file_to_upload: + filename = secure_filename(file_to_upload.filename) + file_to_upload.save(os.path.join(result_path, filename)) + return jsonify(result="success") + except: + abort(403) + + +@v1_api.route('/admin//', methods=['GET', 'POST']) +def get_data_type_locations_by_path_or_get_file(data_type, path): + if data_type not in DATA_TYPES: + abort(404) + result_path = os.path.join(os.path.join(CONF.manifests, + getattr(CONF, data_type), + path)) + if not os.path.exists(result_path): + abort(404) + + if request.method == 'GET': + locations = [] + if os.path.isfile(result_path): + return send_file(result_path) + else: + for file in os.listdir(result_path): + locations.append(file) + result = {data_type: locations} + return jsonify(result) + + if request.method == 'POST': + file_to_upload = request.files.get('files') + if file_to_upload: + filename = secure_filename(file_to_upload.filename) + file_to_upload.save(os.path.join(result_path, filename)) + return jsonify(result="success") + else: + abort(403) + + +@v1_api.route('/admin//', methods=['PUT', 'DELETE']) +def create_dirs(data_type, path): + if data_type not in DATA_TYPES: + abort(404) + result_path = os.path.join(CONF.manifests, getattr(CONF, data_type), path) + if request.method == 'PUT': + resp = make_response() + if os.path.exists(result_path): + return resp + if data_type == MANIFEST: + abort(403) + try: + os.makedirs(result_path) + except Exception as e: + abort(403) + return resp + + if request.method == 'DELETE': + if not os.path.exists(result_path): + abort(404) + if os.path.isfile(result_path): + try: + os.remove(result_path) + except Exception as e: + abort(404) + else: + try: + os.rmdir(result_path) + except Exception as e: + abort(403) + resp = make_response() + return resp diff --git "a/muranorepository/config.example\\" "b/muranorepository/config.example\\" new file mode 100644 index 0000000..e69de29 diff --git a/muranorepository/service_metadata.tar b/muranorepository/service_metadata.tar new file mode 100644 index 0000000000000000000000000000000000000000..33903f8978921ab74af47794897c8f384281f6b0 GIT binary patch literal 51200 zcmeHQZCBhzvi4{HiryvX00}cN#K2x|Zgyu)Ubx3^$#{3quHoj0kpN{i(nQi2v$^^2 z`&4(ARNbSQfi-p<+?KK)zwu}zD~!<59dWWskR@ylb;>@931RDz^}o< z-j4iDujuE&V0U--VE579&H>&J@ayvjYVV!&#;bHz)lsR`gL4of$!qUz`_EPH%{cVn z^nluuAM{_9GyhMk(NEdq3^Yl~5fP;9Uq_SdEk{7~*x!F7=biZgZ+3V04j#GlzdP95 zA3RVyZ`tmRihtzupGTAAP(2-~(RWXjnQ~axf$zEm$S6Rz&-D9sA+5Lc+a*ygX&9Lp}tDutp?({Wi;#d)p!FjvTQ>fys# zp4Kmu$ux`Vq&h^oo=U5y5wYr_s>@k|M+%Qd*ZEjHFauoAi#X}6t$W4JqpZ4{a&1js zgAcW2HT|`V?QxNxrx&v_()82aR_Z)WvRIFchC!n<71e2-nJ${=W>P@MG{3M#=|!3R zG)v1QK2&W_Oo7WZjuT8%Ln8Ays!_$+tWKVR1FHFA&JM7idnQVU3yMQ2HNsF@x+pdvbmLeBU#i?==hDo6V&Quu~wu4hVN zp7F>|abNu}1dAH>{;{Q^-oLigPVc|A6b(~Fc}!g2{><_?DY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