basic protection service: Implement a runnable service

As a basic service, it takes a manager and enables
rpc by listening to queues based on topic.

It also periodically runs tasks on the manager and
reports its state to the database services table.

start smaug protection service
python /usr/local/bin/smaug-protection --config-file
/etc/smaug/smaug.conf

Closes-Bug: #1529207
Change-Id: I304a394cac58a4199354f3f54384db703bcc0001
This commit is contained in:
chenying 2015-12-26 10:12:28 +08:00
parent bcaa976c74
commit 02454e92a0
10 changed files with 171 additions and 1 deletions

View File

@ -19,6 +19,7 @@ ENABLED_SERVICES+=,c-api,c-vol,c-sch,c-bak,horizon
#Add the smaug services
enable_service smaug-api
enable_service smaug-operationengine
enable_service smaug-protection
#disable the default services you don't want to use
disable_service n-net

View File

@ -117,6 +117,9 @@ if [[ "$Q_ENABLE_SMAUG" == "True" ]]; then
if is_service_enabled smaug-operationengine; then
run_process smaug-operationengine "$SMAUG_BIN_DIR/smaug-operationengine --config-file $SMAUG_API_CONF"
fi
if is_service_enabled smaug-protection; then
run_process smaug-protection "$SMAUG_BIN_DIR/smaug-protection --config-file $SMAUG_API_CONF"
fi
fi
if [[ "$1" == "unstack" ]]; then
@ -127,5 +130,8 @@ if [[ "$Q_ENABLE_SMAUG" == "True" ]]; then
if is_service_enabled smaug-operationengine; then
stop_process smaug-operationengine
fi
if is_service_enabled smaug-protection; then
stop_process smaug-protection
fi
fi
fi

View File

@ -34,6 +34,7 @@ console_scripts =
smaug-api = smaug.cmd.api:main
smaug-manage = smaug.cmd.manage:main
smaug-operationengine = smaug.cmd.operationengine:main
smaug-protection = smaug.cmd.protection:main
smaug.database.migration_backend =
sqlalchemy = oslo_db.sqlalchemy.migration

42
smaug/cmd/protection.py Normal file
View File

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

View File

@ -55,6 +55,12 @@ global_opts = [
cfg.StrOpt('operationengine_manager',
default='smaug.operationengine.manager.OperationEngineManager',
help='Full class name for the Manager for OperationEngine'),
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. '

View File

@ -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
@ -36,6 +36,7 @@ class OperationEngineManager(manager.Manager):
def __init__(self, service_name=None,
*args, **kwargs):
super(OperationEngineManager, self).__init__(*args, **kwargs)
self.protection_api = protection_api.API()
def create_scheduled_operation(self, context, request_spec=None):
LOG.debug("Received a rpc call from a api service."

View File

33
smaug/protection/api.py Normal file
View File

@ -0,0 +1,33 @@
# 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)

View File

@ -0,0 +1,38 @@
# 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)

View File

@ -0,0 +1,42 @@
# 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 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)