Support for ASP.NET apps git-based deployment

Change-Id: I1cb47fe1d79d9c4e48e05477c29427324abfccc3
This commit is contained in:
Stan Lagun 2013-05-28 16:11:24 +04:00
parent 0ebc2b8d9e
commit c72b92beb3
8 changed files with 237 additions and 5 deletions

View File

@ -0,0 +1,58 @@
# 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 muranoapi import utils
from muranoapi.db.services.systemservices import SystemServices
from muranoapi.openstack.common import wsgi
from muranoapi.openstack.common import log as logging
log = logging.getLogger(__name__)
class Controller(object):
def index(self, request, environment_id):
log.debug(_('AspNetAppFarms:List <EnvId: {0}>'.format(environment_id)))
session_id = None
if hasattr(request, 'context') and request.context.session:
session_id = request.context.session
get = SystemServices.get_services
services = get(environment_id, 'aspNetAppFarms', session_id)
return {'aspNetAppFarms': services}
@utils.verify_session
def create(self, request, environment_id, body):
log.debug(_('AspNetAppFarms:Create <EnvId: {0}, Body: {1}>'.
format(environment_id, body)))
session_id = request.context.session
create = SystemServices.create_asp_application_farm
return create(body.copy(), session_id, environment_id)
@utils.verify_session
def delete(self, request, environment_id, app_farm_id):
log.debug(_('AspNetAppFarms:Delete <EnvId: {0}, Id: {1}>'.
format(environment_id, app_farm_id)))
session_id = request.context.session
delete = SystemServices.delete_service
delete(app_farm_id, 'aspNetAppFarms', session_id, environment_id)
def create_resource():
return wsgi.Resource(Controller())

View File

@ -10,7 +10,7 @@
# 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
# under the License.
from muranoapi import utils
from muranoapi.db.services.systemservices import SystemServices

View File

@ -19,6 +19,8 @@ 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
from muranoapi.api.v1 import webserverFarms
from muranoapi.api.v1 import aspNetAppFarms
class API(wsgi.Router):
@ -118,4 +120,34 @@ class API(wsgi.Router):
action='delete',
conditions={'method': ['DELETE']})
webServerFarms_resource = webserverFarms.create_resource()
mapper.connect('/environments/{environment_id}/webServerFarms',
controller=webServerFarms_resource,
action='index',
conditions={'method': ['GET']})
mapper.connect('/environments/{environment_id}/webServerFarms',
controller=webServerFarms_resource,
action='create',
conditions={'method': ['POST']})
mapper.connect('/environments/{environment_id}/webServerFarms/'
'{web_server_farm_id}',
controller=webServerFarms_resource,
action='delete',
conditions={'method': ['DELETE']})
aspNetAppFarms_resource = aspNetAppFarms.create_resource()
mapper.connect('/environments/{environment_id}/aspNetAppFarms',
controller=aspNetAppFarms_resource,
action='index',
conditions={'method': ['GET']})
mapper.connect('/environments/{environment_id}/aspNetAppFarms',
controller=aspNetAppFarms_resource,
action='create',
conditions={'method': ['POST']})
mapper.connect('/environments/{environment_id}/aspNetAppFarms/'
'{app_farm_id}',
controller=aspNetAppFarms_resource,
action='delete',
conditions={'method': ['DELETE']})
super(API, self).__init__(mapper)

View File

@ -102,7 +102,7 @@ class Controller(object):
'deployment is in progress'.format(session_id))
raise exc.HTTPForbidden()
SessionServices.deploy(session, request.context.auth_token)
SessionServices.deploy(session, unit, request.context.auth_token)
def reports(self, request, environment_id, session_id):
log.debug(_('Session:Reports <EnvId: {0}, '
@ -129,6 +129,14 @@ class Controller(object):
environment['services']:
services += environment['services']['aspNetApps']
if 'services' in environment and 'webServerFarms' in \
environment['services']:
services += environment['services']['webServerFarms']
if 'services' in environment and 'aspNetAppFarms' in\
environment['services']:
services += environment['services']['aspNetAppFarms']
service = [service for service in services
if service['id'] == service_id][0]

View File

@ -0,0 +1,59 @@
# 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 muranoapi import utils
from muranoapi.db.services.systemservices import SystemServices
from muranoapi.openstack.common import wsgi
from muranoapi.openstack.common import log as logging
log = logging.getLogger(__name__)
class Controller(object):
def index(self, request, environment_id):
log.debug(_('WebServerFarm:List <EnvId: {0}>'.format(environment_id)))
session_id = None
if hasattr(request, 'context') and request.context.session:
session_id = request.context.session
get = SystemServices.get_services
services = get(environment_id, 'webServerFarms', session_id)
return {'webServerFarms': services}
@utils.verify_session
def create(self, request, environment_id, body):
log.debug(_('WebServerFarm:Create <EnvId: {0}, '
'Body: {1}>'.format(environment_id, body)))
session_id = request.context.session
create = SystemServices.create_web_server_farm
return create(body.copy(), session_id, environment_id)
@utils.verify_session
def delete(self, request, environment_id, web_server_farm_id):
log.debug(_('WebServerFarm:Delete <EnvId: {0}, '
'Id: {1}>'.format(environment_id, web_server_farm_id)))
session_id = request.context.session
delete = SystemServices.delete_service
delete(web_server_farm_id, 'webServerFarms', session_id,
environment_id)
def create_resource():
return wsgi.Resource(Controller())

View File

@ -41,7 +41,7 @@ class EnvironmentServices(object):
:return: Returns list of environments
"""
unit = get_session()
environments = unit.query(Environment).filter_by(**filters)
environments = unit.query(Environment).filter_by(**filters).all()
for env in environments:
env['status'] = EnvironmentServices.get_status(env['id'])

View File

@ -108,15 +108,16 @@ class SessionServices(object):
return True
@staticmethod
def deploy(session, token):
def deploy(session, unit, token):
"""
Prepares environment for deployment and send deployment command to
orchestration engine
:param session: session that is going to be deployed
:param unit: SQLalchemy session
:param token: auth token that is going to be used by orchestration
"""
unit = get_session()
#unit = get_session()
#Set X-Auth-Token for conductor
environment = session.description

View File

@ -101,6 +101,12 @@ class SystemServices(object):
if 'aspNetApps' in env_description['services']:
services += env_description['services']['aspNetApps']
if 'webServerFarms' in env_description['services']:
services += env_description['services']['webServerFarms']
if 'aspNetAppFarms' in env_description['services']:
services += env_description['services']['aspNetAppFarms']
services = filter(lambda s: s.id == service_id, services)
if len(services) > 0:
@ -208,6 +214,74 @@ class SystemServices(object):
return aspApp
@staticmethod
def create_web_server_farm(ws_params, session_id, environment_id):
"""
Creates web server farm service and saves it in specified session
:param ws_params: Web Server Farm Params as Dict
:param session_id: Session
"""
env_description = EnvironmentServices.get_environment_description(
environment_id, session_id)
web_server_farm = ws_params
web_server_farm['id'] = uuidutils.generate_uuid()
web_server_farm['created'] = str(timeutils.utcnow())
web_server_farm['updated'] = str(timeutils.utcnow())
unit_count = 0
for unit in web_server_farm['units']:
unit_count += 1
unit['id'] = uuidutils.generate_uuid()
unit['name'] = web_server_farm['name'] + '_instance_' + \
str(unit_count)
if not 'services' in env_description:
env_description['services'] = {}
if not 'webServerFarmss' in env_description['services']:
env_description['services']['webServerFarms'] = []
env_description['services']['webServerFarms'].append(web_server_farm)
EnvironmentServices.save_environment_description(session_id,
env_description)
return web_server_farm
@staticmethod
def create_asp_application_farm(params, session_id, environment_id):
"""
Creates ASP.NET Application Farm service and saves it in
specified session
:param params: Params as Dict
:param session_id: Session
"""
env_description = EnvironmentServices.get_environment_description(
environment_id, session_id)
aspApp_farm = params
aspApp_farm['id'] = uuidutils.generate_uuid()
aspApp_farm['created'] = str(timeutils.utcnow())
aspApp_farm['updated'] = str(timeutils.utcnow())
unit_count = 0
for unit in aspApp_farm['units']:
unit_count += 1
unit['id'] = uuidutils.generate_uuid()
unit['name'] = aspApp_farm['name'] + '_instance_' + str(unit_count)
if not 'services' in env_description:
env_description['services'] = {}
if not 'webServers' in env_description['services']:
env_description['services']['aspNetAppFarms'] = []
env_description['services']['aspNetAppFarms'].append(aspApp_farm)
EnvironmentServices.save_environment_description(session_id,
env_description)
return aspApp_farm
@staticmethod
def delete_service(service_id, service_type, session_id, environment_id):
env_description = EnvironmentServices.get_environment_description(