Region is added part of os_namos

Change-Id: Iff3d743c935e8cc762e3e5ed3eeb2692d1e844da
This commit is contained in:
Kanagaraj Manickam 2016-03-28 14:45:20 +05:30
parent 38476e0ab9
commit 510b6d1b49
5 changed files with 101 additions and 46 deletions

6
config-generator.conf Normal file
View File

@ -0,0 +1,6 @@
[DEFAULT]
output_file = etc/namos/namos.conf.sample
wrap_width = 79
namespace = os_namos
namespace = oslo.messaging
namespace = oslo.log

View File

@ -100,9 +100,15 @@ class ConductorAPI(object):
def stop_me(self):
try:
self.server.stop()
self.server.wait()
except: # noqa
pass
@request_context
def regisgration_ackw(self, context, identification):
self.mgr.regisgration_ackw(identification)
@request_context
def ping_me(self, context, identification):
identification = self.mgr.ping_me(identification)
return identification

View File

@ -16,10 +16,12 @@ import os
import socket
import uuid
from oslo_config import cfg
from oslo_context import context
from oslo_log import log
from os_namos.common import rpcapi
from oslo_utils import netutils
NAMOS_RPCAPI = None
logger = log.getLogger(__name__)
@ -31,6 +33,22 @@ IDENTIFICATION = str(uuid.uuid4())
HEART_BEAT_STARTED = False
NAMOS_RPCSERVER_STARTED = False
cfg_opts = [
cfg.StrOpt('region_name',
default='RegionOne',
help='Keystone Region Name'),
cfg.BoolOpt('enable',
default=True,
help='Enable or Disable'),
]
cfg.CONF.register_opts(cfg_opts, 'os_namos')
def list_opts():
yield 'os_namos', cfg_opts
class RegistrationInfo(object):
def __init__(self,
@ -40,21 +58,24 @@ class RegistrationInfo(object):
fqdn=socket.gethostname(),
pid=os.getpid(),
config_file_list=None,
config_dict=None):
config_list=None,
region_name=None,
i_am_launcher=False):
self.host = host
self.project_name = project_name
self.fqdn = fqdn
self.prog_name = prog_name
self.pid = pid
self.config_file_list = config_file_list or list()
self.config_file_dict = self.get_config_files()
# List of configuration which CONF is already updated with
self.config_dict = config_dict or dict()
self.config_file_dict = self.get_config_files(config_file_list)
self.config_list = config_list or list()
self.identification = IDENTIFICATION
self.region_name = region_name or cfg.CONF.os_namos.region_name
self.i_am_launcher = i_am_launcher
self.ips = [netutils.get_my_ipv4()]
def get_config_files(self):
def get_config_files(self, config_file_list):
files = {}
for f in self.config_file_list:
for f in config_file_list:
files[f] = open(f).read()
return files
@ -84,7 +105,7 @@ class Config(object):
def collect_registration_info():
from oslo_config import cfg
self = cfg.CONF
CFG = cfg.CONF
def normalize_type(type):
try:
@ -98,32 +119,34 @@ def collect_registration_info():
def get_host():
try:
return getattr(self, 'host')
return getattr(CFG, 'host')
except: # noqa
import socket
return socket.gethostname()
reg_info = RegistrationInfo(host=get_host(),
project_name=self.project,
prog_name=self.prog,
config_file_list=self.default_config_files)
project_name=CFG.project,
prog_name=CFG.prog,
config_file_list=CFG.config_file
if CFG.config_file else
CFG.default_config_files)
config_dict = dict()
for opt_name in sorted(self._opts):
opt = self._get_opt_info(opt_name)['opt']
config_list = list()
for opt_name in sorted(CFG._opts):
opt = CFG._get_opt_info(opt_name)['opt']
cfg = Config(name='%s' % opt_name,
type='%s' % normalize_type(opt.type),
value='%s' % getattr(self, opt_name),
value='%s' % getattr(CFG, opt_name),
help='%s' % opt.help,
required=opt.required,
secret=opt.secret,
default_value='%s' % opt.default)
config_dict[cfg.name] = cfg
config_list.append(cfg)
for group_name in self._groups:
group_attr = self.GroupAttr(self, self._get_group(group_name))
for opt_name in sorted(self._groups[group_name]._opts):
opt = self._get_opt_info(opt_name, group_name)['opt']
for group_name in CFG._groups:
group_attr = CFG.GroupAttr(CFG, CFG._get_group(group_name))
for opt_name in sorted(CFG._groups[group_name]._opts):
opt = CFG._get_opt_info(opt_name, group_name)['opt']
cfg = Config(name="%s" % opt_name,
type='%s' % normalize_type(opt.type),
value='%s' % getattr(group_attr, opt_name),
@ -132,20 +155,29 @@ def collect_registration_info():
secret=opt.secret,
default_value='%s' % opt.default,
group='%s' % group_name)
config_dict[cfg.name] = cfg
reg_info.config_dict = config_dict
config_list.append(cfg)
reg_info.config_list = config_list
return reg_info
def register_myself(registration_info=None,
start_heart_beat=True,
start_rpc_server=True):
start_rpc_server=True,
i_am_launcher=False):
if not cfg.CONF.os_namos.enable:
return
if not hasattr(cfg.CONF, 'project'):
logger.info("NOT USING GLOABL OSLO CONF !!!")
return
global NAMOS_RPCAPI
if registration_info is None:
registration_info = collect_registration_info()
registration_info.i_am_launcher = i_am_launcher
import sys
current_module = sys.modules[__name__]
@ -157,24 +189,22 @@ def register_myself(registration_info=None,
mgr=current_module
)
if start_rpc_server:
manage_me()
ctx = context.RequestContext()
NAMOS_RPCAPI.register_myself(ctx, registration_info)
logger.info("*** [%s ]Registeration with Namos started successfully. ***" %
registration_info.identification)
if start_heart_beat:
heart_beat(registration_info.identification)
if start_rpc_server:
manage_me()
return registration_info.identification
def regisgration_ackw(identification):
# TODO(mrkanag) start the heart beat here
logger.info("*** [%s ]Registeration with Namos completed successfully. ***"
% identification)
heart_beat(identification)
def heart_beat(identification):
@ -184,21 +214,24 @@ def heart_beat(identification):
return
HEART_BEAT_STARTED = True
from oslo_service import loopingcall
th = loopingcall.FixedIntervalLoopingCall(NAMOS_RPCAPI.heart_beat,
context=context.RequestContext(),
identification=identification)
# TODO(mrkanag) make this periods configurable
th.start(60, 120)
logger.info("*** [%s] HEART-BEAT with Namos is started successfully. ***" %
identification)
if NAMOS_RPCAPI:
from oslo_service import loopingcall
th = loopingcall.FixedIntervalLoopingCall(
NAMOS_RPCAPI.heart_beat,
context=context.RequestContext(),
identification=identification)
# TODO(mrkanag) make this periods configurable
th.start(60, 120)
logger.info("*** [%s] HEART-BEAT with Namos is started successfully."
" ***" % identification)
# TO(mrkanag) make sure this is called on process exit, hook it to right place
def i_am_dieing():
if NAMOS_RPCAPI:
NAMOS_RPCAPI.heart_beat(context,
NAMOS_RPCAPI,
IDENTIFICATION,
True)
logger.info("*** [%s] HEART-BEAT with Namos is stopping. ***" %
@ -215,13 +248,18 @@ def manage_me():
return
NAMOS_RPCSERVER_STARTED = True
from oslo_service import loopingcall
th = loopingcall.FixedIntervalLoopingCall(NAMOS_RPCAPI.manage_me)
# TODO(mrkanag) make this periods configurable
th.start(60, 0)
logger.info("*** [%s] RPC Server for Namos is started successfully. ***" %
IDENTIFICATION)
if NAMOS_RPCAPI:
NAMOS_RPCAPI.manage_me()
logger.info("*** [%s] RPC Server for Namos is started successfully."
" ***" % IDENTIFICATION)
def ping_me(id_):
logger.info("*** PING [%s] . ***" %
id_)
return id_
def add_config(config):

View File

@ -6,4 +6,5 @@ pbr>=1.6
oslo.context>=0.2.0 # Apache-2.0
oslo.serialization>=1.10.0 # Apache-2.0
oslo.messaging>=4.0.0 # Apache-2.0
oslo.utils>=3.5.0 # Apache-2.0
oslo.utils>=3.5.0 # Apache-2.0
oslo.log>=1.14.0 # Apache-2.0

View File

@ -44,3 +44,7 @@ input_file = os-namos/locale/os-namos.pot
keywords = _ gettext ngettext l_ lazy_gettext
mapping_file = babel.cfg
output_file = os-namos/locale/os-namos.pot
[entry_points]
oslo.config.opts =
os_namos = os_namos.sync:list_opts