Added config file foreignkey ref in config
Change-Id: Ia37b538ad7fa8a9b377e796dbf4e005370e723cd
This commit is contained in:
parent
ce9913a9e5
commit
59a3041e70
|
@ -167,6 +167,29 @@ class ServiceProcessor(object):
|
||||||
def __init__(self, registration_info):
|
def __init__(self, registration_info):
|
||||||
self.registration_info = registration_info
|
self.registration_info = registration_info
|
||||||
|
|
||||||
|
def file_to_configs(self, file_content):
|
||||||
|
tmp_file_path = '/tmp/sample-namos-config.conf'
|
||||||
|
with open(tmp_file_path, 'w') as file:
|
||||||
|
file.write(file_content)
|
||||||
|
|
||||||
|
with open(tmp_file_path, 'r') as file:
|
||||||
|
section = ''
|
||||||
|
conf_dict = dict()
|
||||||
|
|
||||||
|
for line in file:
|
||||||
|
if line.strip().startswith('['):
|
||||||
|
section = line.replace('[', '').replace(']', '').strip()
|
||||||
|
continue
|
||||||
|
if section:
|
||||||
|
kv = line.strip().split('=')
|
||||||
|
conf_dict[
|
||||||
|
'%s::%s' % (section, kv[0].strip())] = None
|
||||||
|
|
||||||
|
import os
|
||||||
|
os.remove(tmp_file_path)
|
||||||
|
|
||||||
|
return conf_dict
|
||||||
|
|
||||||
def process_service(self, context):
|
def process_service(self, context):
|
||||||
# Service Node
|
# Service Node
|
||||||
try:
|
try:
|
||||||
|
@ -225,34 +248,6 @@ class ServiceProcessor(object):
|
||||||
service_component)
|
service_component)
|
||||||
# TODO(mrkanag) what to do when service_components size is > 1
|
# TODO(mrkanag) what to do when service_components size is > 1
|
||||||
|
|
||||||
# config file
|
|
||||||
for cfg_f in self.registration_info['config_file_list']:
|
|
||||||
try:
|
|
||||||
config_file = db_api.config_file_create(
|
|
||||||
context,
|
|
||||||
dict(name=cfg_f,
|
|
||||||
file=self.registration_info[
|
|
||||||
'config_file_dict'][cfg_f],
|
|
||||||
service_component_id=service_component.id,
|
|
||||||
service_node_id=node.id))
|
|
||||||
LOG.info('Oslo config file %s is created' % config_file)
|
|
||||||
except exception.AlreadyExist:
|
|
||||||
config_files = \
|
|
||||||
db_api.config_file_get_by_name_for_service_node(
|
|
||||||
context,
|
|
||||||
service_node_id=node.id,
|
|
||||||
name=cfg_f
|
|
||||||
)
|
|
||||||
if len(config_files) == 1:
|
|
||||||
config_file = \
|
|
||||||
db_api.config_file_update(
|
|
||||||
context,
|
|
||||||
config_files[0].id,
|
|
||||||
dict(file=self.registration_info[
|
|
||||||
'config_file_dict'][cfg_f]))
|
|
||||||
LOG.info('Oslo config file %s is existing and is updated'
|
|
||||||
% config_file)
|
|
||||||
|
|
||||||
# Service Worker
|
# Service Worker
|
||||||
try:
|
try:
|
||||||
service_worker = db_api.service_worker_create(
|
service_worker = db_api.service_worker_create(
|
||||||
|
@ -293,6 +288,41 @@ class ServiceProcessor(object):
|
||||||
|
|
||||||
# TODO(mrkanag) what to do when service_workers size is > 1
|
# TODO(mrkanag) what to do when service_workers size is > 1
|
||||||
|
|
||||||
|
# config file
|
||||||
|
conf_files = dict()
|
||||||
|
for cfg_f in self.registration_info['config_file_list']:
|
||||||
|
try:
|
||||||
|
config_file = db_api.config_file_create(
|
||||||
|
context,
|
||||||
|
dict(name=cfg_f,
|
||||||
|
file=self.registration_info[
|
||||||
|
'config_file_dict'][cfg_f],
|
||||||
|
service_component_id=service_component.id,
|
||||||
|
service_node_id=node.id))
|
||||||
|
LOG.info('Oslo config file %s is created' % config_file)
|
||||||
|
except exception.AlreadyExist:
|
||||||
|
config_files = \
|
||||||
|
db_api.config_file_get_by_name_for_service_node(
|
||||||
|
context,
|
||||||
|
service_node_id=node.id,
|
||||||
|
name=cfg_f
|
||||||
|
)
|
||||||
|
if len(config_files) == 1:
|
||||||
|
config_file = \
|
||||||
|
db_api.config_file_update(
|
||||||
|
context,
|
||||||
|
config_files[0].id,
|
||||||
|
dict(file=self.registration_info[
|
||||||
|
'config_file_dict'][cfg_f]))
|
||||||
|
LOG.info('Oslo config file %s is existing and is updated'
|
||||||
|
% config_file)
|
||||||
|
|
||||||
|
config_dict = self.file_to_configs(
|
||||||
|
self.registration_info['config_file_dict'][cfg_f]
|
||||||
|
)
|
||||||
|
|
||||||
|
conf_files[config_file.id] = config_dict
|
||||||
|
|
||||||
# Config
|
# Config
|
||||||
# TODO(mrkanag) Optimize the config like per service_component
|
# TODO(mrkanag) Optimize the config like per service_component
|
||||||
# or per service_worker,
|
# or per service_worker,
|
||||||
|
@ -338,11 +368,20 @@ class ServiceProcessor(object):
|
||||||
LOG.debug("Config Schema %s is existing and is updated" %
|
LOG.debug("Config Schema %s is existing and is updated" %
|
||||||
cfg_sche)
|
cfg_sche)
|
||||||
|
|
||||||
|
# is it part of config file
|
||||||
|
cfg_name = "%s::%s" % (cfg_obj['group'], cfg_name)
|
||||||
|
file_id = None
|
||||||
|
for f_id, conf_keys in conf_files.items():
|
||||||
|
if cfg_name in conf_keys.keys():
|
||||||
|
file_id = f_id
|
||||||
|
break
|
||||||
|
|
||||||
cfg_obj_ = dict(
|
cfg_obj_ = dict(
|
||||||
service_worker_id=service_worker.id,
|
service_worker_id=service_worker.id,
|
||||||
name="%s.%s" % (cfg_obj['group'], cfg_name),
|
name=cfg_name,
|
||||||
value=cfg_obj['value'],
|
value=cfg_obj['value'],
|
||||||
oslo_config_schema_id=cfg_sche.id
|
oslo_config_schema_id=cfg_sche.id,
|
||||||
|
oslo_config_file_id=file_id
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -177,8 +177,8 @@ def upgrade():
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
op.drop_table('oslo_config_file')
|
|
||||||
op.drop_table('oslo_config')
|
op.drop_table('oslo_config')
|
||||||
|
op.drop_table('oslo_config_file')
|
||||||
op.drop_table('oslo_config_schema')
|
op.drop_table('oslo_config_schema')
|
||||||
op.drop_table('device_driver')
|
op.drop_table('device_driver')
|
||||||
op.drop_table('service_worker')
|
op.drop_table('service_worker')
|
||||||
|
|
|
@ -357,8 +357,9 @@ class OsloConfig(BASE,
|
||||||
value = sqlalchemy.Column(
|
value = sqlalchemy.Column(
|
||||||
sqlalchemy.Text
|
sqlalchemy.Text
|
||||||
)
|
)
|
||||||
file = sqlalchemy.Column(
|
oslo_config_file_id = sqlalchemy.Column(
|
||||||
sqlalchemy.String(512)
|
Uuid,
|
||||||
|
sqlalchemy.ForeignKey('oslo_config_file.id')
|
||||||
)
|
)
|
||||||
oslo_config_schema_id = sqlalchemy.Column(
|
oslo_config_schema_id = sqlalchemy.Column(
|
||||||
Uuid,
|
Uuid,
|
||||||
|
|
Loading…
Reference in New Issue