diff --git a/muranoapi/api/v1/__init__.py b/muranoapi/api/v1/__init__.py index e2331915d..ca75e772d 100644 --- a/muranoapi/api/v1/__init__.py +++ b/muranoapi/api/v1/__init__.py @@ -77,7 +77,8 @@ def get_env_status(environment_id, session_id): is_inprogress = filter(lambda item: item == 'inprogress', get_statuses('activeDirectories') + - get_statuses('webServers')) + get_statuses('webServers') + + get_statuses('aspNetApps')) if session_state == 'deploying' and is_inprogress > 1: status = 'inprogress' diff --git a/muranoapi/api/v1/aspNetApps.py b/muranoapi/api/v1/aspNetApps.py new file mode 100644 index 000000000..0b483cde1 --- /dev/null +++ b/muranoapi/api/v1/aspNetApps.py @@ -0,0 +1,85 @@ +# 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 oslo.config import cfg + +from muranoapi import utils +from muranoapi.api.v1 import save_draft, get_draft, get_service_status +from muranoapi.common import uuidutils +from muranoapi.openstack.common import wsgi, timeutils +from muranoapi.openstack.common import log as logging + +log = logging.getLogger(__name__) + + +class Controller(object): + def index(self, request, environment_id): + log.debug(_('AspNetApps:List '.format(environment_id))) + + draft = prepare_draft(get_draft(environment_id, + request.context.session)) + + for dc in draft['services']['aspNetApps']: + dc['status'] = get_service_status(environment_id, + request.context.session, dc) + + return {'aspNetApps': draft['services']['aspNetApps']} + + @utils.verify_session + def create(self, request, environment_id, body): + log.debug(_('AspNetApps:Create '. + format(environment_id, body))) + + draft = get_draft(session_id=request.context.session) + + aspNetApp = body.copy() + aspNetApp['id'] = uuidutils.generate_uuid() + aspNetApp['created'] = str(timeutils.utcnow()) + aspNetApp['updated'] = str(timeutils.utcnow()) + + unit_count = 0 + for unit in aspNetApp['units']: + unit_count += 1 + unit['id'] = uuidutils.generate_uuid() + unit['name'] = aspNetApp['name'] + '_instance_' + str(unit_count) + + draft = prepare_draft(draft) + draft['services']['aspNetApps'].append(aspNetApp) + save_draft(request.context.session, draft) + + return aspNetApp + + @utils.verify_session + def delete(self, request, environment_id, app_id): + log.debug(_('AspNetApps:Delete '. + format(environment_id, app_id))) + + draft = get_draft(session_id=request.context.session) + + elements = [service for service in draft['services']['aspNetApps'] if + service['id'] != app_id] + draft['services']['aspNetApps'] = elements + save_draft(request.context.session, draft) + + +def prepare_draft(draft): + if not 'services' in draft: + draft['services'] = {} + + if not 'aspNetApps' in draft['services']: + draft['services']['aspNetApps'] = [] + + return draft + + +def create_resource(): + return wsgi.Resource(Controller()) diff --git a/muranoapi/api/v1/router.py b/muranoapi/api/v1/router.py index be83bb1ce..570db7aee 100644 --- a/muranoapi/api/v1/router.py +++ b/muranoapi/api/v1/router.py @@ -18,6 +18,7 @@ from muranoapi.api.v1 import environments from muranoapi.api.v1 import sessions from muranoapi.api.v1 import active_directories from muranoapi.api.v1 import webservers +from muranoapi.api.v1 import aspNetApps class API(wsgi.Router): @@ -105,4 +106,20 @@ class API(wsgi.Router): controller=webServers_resource, action='delete', conditions={'method': ['DELETE']}) + + aspNetApps_resource = aspNetApps.create_resource() + mapper.connect('/environments/{environment_id}/aspNetApps', + controller=aspNetApps_resource, + action='index', + conditions={'method': ['GET']}) + mapper.connect('/environments/{environment_id}/aspNetApps', + controller=aspNetApps_resource, + action='create', + conditions={'method': ['POST']}) + mapper.connect('/environments/{environment_id}/aspNetApps/' + '{app_id}', + controller=aspNetApps_resource, + action='delete', + conditions={'method': ['DELETE']}) + super(API, self).__init__(mapper) diff --git a/muranoapi/api/v1/sessions.py b/muranoapi/api/v1/sessions.py index 7cae207a8..f92b35661 100644 --- a/muranoapi/api/v1/sessions.py +++ b/muranoapi/api/v1/sessions.py @@ -118,6 +118,10 @@ class Controller(object): environment['services']: services += environment['services']['webServers'] + if 'services' in environment and 'aspNetApps' in\ + environment['services']: + services += environment['services']['aspNetApps'] + service = [service for service in services if service['id'] == service_id][0] diff --git a/muranoapi/db/models.py b/muranoapi/db/models.py index 511f367ee..e0bd34b21 100644 --- a/muranoapi/db/models.py +++ b/muranoapi/db/models.py @@ -79,8 +79,8 @@ class ModelBase(object): def to_dict(self): dictionary = self.__dict__.copy() - return dict((k, v) for k, v in dictionary.iteritems() - if k != '_sa_instance_state') + return dict([(k, v) for k, v in dictionary.iteritems() + if k != '_sa_instance_state']) class JsonBlob(TypeDecorator): diff --git a/muranoapi/tests/sanity_tests.py b/muranoapi/tests/sanity_tests.py index 4d4cc8cf9..16ca36140 100644 --- a/muranoapi/tests/sanity_tests.py +++ b/muranoapi/tests/sanity_tests.py @@ -30,6 +30,7 @@ class SanityUnitTests(unittest2.TestCase): def test_api(self): router.webservers = MagicMock(create_resource=func_mock) + router.aspNetApps = MagicMock(create_resource=func_mock) router.sessions = MagicMock(create_resource=func_mock) router.active_directories = MagicMock(create_resource=func_mock) router.environments = MagicMock(create_resource=func_mock)