diff --git a/setup.cfg b/setup.cfg index 10d6c162..58a78a3e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -34,6 +34,7 @@ console_scripts = smaug-api = smaug.cmd.api:main smaug-manage = smaug.cmd.manage:main smaug-scheduler = smaug.cmd.scheduler:main + smaug-protection = smaug.cmd.protection:main smaug.database.migration_backend = sqlalchemy = oslo_db.sqlalchemy.migration diff --git a/smaug/cmd/protection.py b/smaug/cmd/protection.py new file mode 100644 index 00000000..b6d7b555 --- /dev/null +++ b/smaug/cmd/protection.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +# 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. + +"""Starter script for smaug protection service.""" + +import eventlet +eventlet.monkey_patch() + +import sys + +from oslo_config import cfg +from oslo_log import log as logging + +from smaug import i18n +i18n.enable_lazy() + +# Need to register global_opts +from smaug.common import config # noqa +from smaug import service +from smaug import version + + +CONF = cfg.CONF + + +def main(): + CONF(sys.argv[1:], project='smaug', + version=version.version_string()) + logging.setup(CONF, "smaug") + server = service.Service.create(binary='smaug-protection') + service.serve(server) + service.wait() diff --git a/smaug/common/config.py b/smaug/common/config.py index d6abef01..c8e6af1b 100644 --- a/smaug/common/config.py +++ b/smaug/common/config.py @@ -55,6 +55,12 @@ global_opts = [ cfg.StrOpt('scheduler_manager', default='smaug.scheduler.manager.SchedulerManager', help='Full class name for the Manager for scheduler'), + cfg.StrOpt('protection_topic', + default='smaug-protection', + help='The topic that protection nodes listen on'), + cfg.StrOpt('protection_manager', + default='smaug.protection.manager.ProtectionManager', + help='Full class name for the Manager for Protection'), cfg.StrOpt('host', default=socket.gethostname(), help='Name of this node. This can be an opaque identifier. ' diff --git a/smaug/protection/__init__.py b/smaug/protection/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/smaug/protection/api.py b/smaug/protection/api.py new file mode 100644 index 00000000..be417057 --- /dev/null +++ b/smaug/protection/api.py @@ -0,0 +1,37 @@ +# 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. + +"""Handles all requests relating to protection service.""" + + +from oslo_config import cfg +from oslo_log import log as logging + +from smaug.db import base +from smaug.protection import rpcapi as protection_rpcapi + + +CONF = cfg.CONF + +LOG = logging.getLogger(__name__) + + +class API(base.Base): + """API for interacting with the protection manager.""" + + def __init__(self, db_driver=None): + self.protection_rpcapi = protection_rpcapi.ProtectionAPI() + super(API, self).__init__(db_driver) + + def create_test_protection(self, context, request_spec): + + self.protection_rpcapi.create_test_protection(context, request_spec) diff --git a/smaug/protection/manager.py b/smaug/protection/manager.py new file mode 100644 index 00000000..7a6036f9 --- /dev/null +++ b/smaug/protection/manager.py @@ -0,0 +1,42 @@ +# 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. + +""" +Protection Service +""" + +from oslo_config import cfg +from oslo_log import log as logging +import oslo_messaging as messaging + +from smaug import manager + + +CONF = cfg.CONF + +LOG = logging.getLogger(__name__) + + +class ProtectionManager(manager.Manager): + """Smaug Protection Manager.""" + + RPC_API_VERSION = '1.0' + + target = messaging.Target(version=RPC_API_VERSION) + + def __init__(self, service_name=None, + *args, **kwargs): + super(ProtectionManager, self).__init__(*args, **kwargs) + + def create_test_protection(self, context, request_spec=None): + LOG.debug("Received a rpc call from a scheduler service." + "request_spec:%s", request_spec) diff --git a/smaug/protection/rpcapi.py b/smaug/protection/rpcapi.py new file mode 100644 index 00000000..c6870da9 --- /dev/null +++ b/smaug/protection/rpcapi.py @@ -0,0 +1,51 @@ +# Copyright 2012, Red Hat, 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. + +""" +Client side of the protection manager RPC API. +""" + +from oslo_config import cfg +import oslo_messaging as messaging +from oslo_serialization import jsonutils + +from smaug import rpc + + +CONF = cfg.CONF + + +class ProtectionAPI(object): + """Client side of the protection rpc API. + + API version history: + + 1.0 - Initial version. + """ + + RPC_API_VERSION = '1.0' + + def __init__(self): + super(ProtectionAPI, self).__init__() + target = messaging.Target(topic=CONF.protection_topic, + version=self.RPC_API_VERSION) + self.client = rpc.get_client(target, version_cap=None) + + def create_test_protection(self, ctxt, request_spec=None): + request_spec_p = jsonutils.to_primitive(request_spec) + cctxt = self.client.prepare(version='1.0') + return cctxt.cast( + ctxt, + 'create_test_protection', + request_spec=request_spec_p) diff --git a/smaug/scheduler/manager.py b/smaug/scheduler/manager.py index 927f9f96..23fb19d6 100644 --- a/smaug/scheduler/manager.py +++ b/smaug/scheduler/manager.py @@ -19,7 +19,7 @@ from oslo_log import log as logging import oslo_messaging as messaging from smaug import manager - +from smaug.protection import api as protection_api CONF = cfg.CONF @@ -35,8 +35,10 @@ class SchedulerManager(manager.Manager): def __init__(self, service_name=None, *args, **kwargs): + self.protection_api = protection_api.API() super(SchedulerManager, self).__init__(*args, **kwargs) def create_test_scheduler(self, context, request_spec=None): LOG.debug("Received a rpc call from a api service." "request_spec:%s", request_spec) + self.protection_api.create_test_protection(context, request_spec)