diff --git a/orm/base_config.py b/orm/base_config.py index 0c0cf561..87dfc875 100644 --- a/orm/base_config.py +++ b/orm/base_config.py @@ -42,7 +42,7 @@ OrmOpts = [ CONF.register_opts(OrmOpts) # Keystone config options in [keystone_autotoken] group -orm_token_group = cfg.OptGroup(name='token', +orm_token_group = cfg.OptGroup(name='keystone_authtoken', title='Orm Keystone Token Options') OrmAuthGroup = [ @@ -58,12 +58,20 @@ OrmAuthGroup = [ cfg.StrOpt('region', default='local', help='Region.'), + cfg.BoolOpt('auth_enabled', + default=False, + help='Auth token Enabled/Disabled.'), + cfg.StrOpt('version', + default='v3', + help='Keystone version number.'), cfg.StrOpt('project_domain_name', default='default', help='Project domain name.'), cfg.StrOpt('user_domain_name', default='default', - help='User domain name.') + help='User domain name.'), + cfg.StrOpt('user_role', + help='token user role.') ] CONF.register_group(orm_token_group) @@ -232,17 +240,17 @@ debug_level = CONF.debug_level protocol = CONF.protocol orm_host = CONF.orm_host ranger_base = CONF.ranger_base -db_user = 'root' -db_pass = 'devstack' -db_host = '127.0.0.1' ssl_verify = CONF.ssl_verify -token_auth_enabled = False -token_auth_user = CONF.token.username -token_auth_pass = CONF.token.password -token_auth_tenant = CONF.token.project_name -token_auth_user_role = 'admin' +token_auth_enabled = CONF.keystone_authtoken.auth_enabled +token_auth_user = CONF.keystone_authtoken.username +token_auth_pass = CONF.keystone_authtoken.password +token_auth_tenant = CONF.keystone_authtoken.project_name +token_auth_user_role = CONF.keystone_authtoken.user_role +conn = CONF.database.connection +db_connect = conn.replace("mysql+pymysql", "mysql") if conn else None +# pass keystone version '2.0' or '3' +token_auth_version = '3' if (CONF.keystone_authtoken.version == 'v3') else '2.0' -db_url = 'mysql://{}:{}@{}:3306/'.format(db_user, db_pass, db_host) uuid = {'port': CONF.uuid.port, 'base_url': '{}://{}:{}/'. diff --git a/orm/cmd/db_setup.py b/orm/cmd/db_setup.py deleted file mode 100644 index 67c080ce..00000000 --- a/orm/cmd/db_setup.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2012 OpenStack Foundation -# All Rights Reserved. -# -# 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. - -import orm.base_config as config -from oslo_config import cfg -from sqlalchemy import * -import sys - - -def main(argv=None): - - if argv is None: - argv = sys.argv - cfg.CONF(argv[1:], project='ranger', validate_default_values=True) - - sql_queries = [] - - orm_dbs = [ - config.ranger_base + '/orm/services/audit_trail_manager/scripts/db_scripts/create_db.sql', - config.ranger_base + '/orm/services/id_generator/scripts/db_scripts/db_create.sql', - config.ranger_base + '/orm/services/resource_distributor/scripts/db_scripts/create_db.sql', - config.ranger_base + '/orm/services/region_manager/scripts/db_scripts/create_db.sql', - config.ranger_base + - '/orm/services/customer_manager/scripts/db_scripts/ranger_cms_create_db.sql', - config.ranger_base + - '/orm/services/customer_manager/scripts/db_scripts/ranger_cms_update_db.sql', - config.ranger_base + - '/orm/services/flavor_manager/scripts/db_scripts/ranger_fms_create_db.sql', - config.ranger_base + '/orm/services/image_manager/scripts/db_scripts/create_db.sql' - ] - - for item in range(len(orm_dbs)): - sql_file = open(orm_dbs[item], "r") - query = sql_file.read() - sql_queries.append(query) - sql_file.close() - - engine = create_engine(config.db_url, echo=False) - - for exec_item in range(len(sql_queries)): - conn = engine.connect() - exec_script = conn.execute(sql_queries[exec_item]) - conn.close() - - print 'Ranger databases setup complete' diff --git a/orm/cmd/db_sync.py b/orm/cmd/db_sync.py index 95d452d7..5ba38f1b 100644 --- a/orm/cmd/db_sync.py +++ b/orm/cmd/db_sync.py @@ -14,7 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. -import db_setup +from orm.services import db_setup def main(): diff --git a/orm/services/audit_trail_manager/config.py b/orm/services/audit_trail_manager/config.py index b0ec6436..0438423d 100644 --- a/orm/services/audit_trail_manager/config.py +++ b/orm/services/audit_trail_manager/config.py @@ -7,9 +7,11 @@ server = { } # DB configurations + +db_url = config.db_connect + database = { - 'url': config.db_url + 'orm_audit?charset=utf8', - # 'url': 'mysql://root:root@127.0.0.1/orm_audit?charset=utf8', + 'url': db_url.endswith('/orm') and db_url.replace("/orm", "/orm_audit") or (db_url + 'orm_audit'), 'echo_statements': True } diff --git a/orm/services/customer_manager/config.py b/orm/services/customer_manager/config.py index 37661855..481ce9db 100755 --- a/orm/services/customer_manager/config.py +++ b/orm/services/customer_manager/config.py @@ -90,8 +90,11 @@ quotas_default_values = { } } +# DB configurations +db_url = config.db_connect + database = { - 'connection_string': config.db_url + 'orm_cms_db' + 'connection_string': db_url.endswith('/orm') and db_url.replace("/orm", "/orm_cms_db") or (db_url + 'orm_cms_db') } api = { @@ -128,8 +131,8 @@ authentication = { # The Keystone collection under which the role was granted. # The key can be either "tenant" (for Keystone v2.0) or "domain" # (for Keystone v3) and the value is the tenant/domain name. - "role_location": {"tenant": "admin"}, + "role_location": {"domain": "admin"}, # The Keystone version currently in use. Can be either "2.0" or "3". - "keystone_version": "2.0", + "keystone_version": config.token_auth_version, "policy_file": config.cms['policy_file'] } diff --git a/orm/services/db_setup.py b/orm/services/db_setup.py new file mode 100644 index 00000000..76c6374d --- /dev/null +++ b/orm/services/db_setup.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +# Copyright (c) 2012 OpenStack Foundation +# All Rights Reserved. +# +# 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 oslo_config import cfg +from sqlalchemy import * +import sys + +CONF = cfg.CONF + + +def main(argv=None): + + if argv is None: + argv = sys.argv + cfg.CONF(argv[1:], project='ranger', validate_default_values=True) + + OrmOpts = [ + cfg.StrOpt('ranger_base', + default='/opt/stack/ranger', + help='Orm base directory.'), + ] + + CONF.register_opts(OrmOpts) + + orm_database_group = cfg.OptGroup(name='database', + title='Orm Database Options') + OrmDatabaseGroup = [ + cfg.StrOpt('connection', + help='The SQLAlchemy connection string to use to connect to ' + 'the ORM database.', + secret=True), + cfg.IntOpt('max_retries', + default=-1, + help='The maximum number of retries for database connection.') + ] + + CONF.register_group(orm_database_group) + CONF.register_opts(OrmDatabaseGroup, orm_database_group) + + sql_queries = [] + + orm_dbs = [ + CONF.ranger_base + '/orm/services/audit_trail_manager/scripts/db_scripts/create_db.sql', + CONF.ranger_base + '/orm/services/id_generator/scripts/db_scripts/db_create.sql', + CONF.ranger_base + '/orm/services/resource_distributor/scripts/db_scripts/create_db.sql', + CONF.ranger_base + '/orm/services/region_manager/scripts/db_scripts/create_db.sql', + CONF.ranger_base + + '/orm/services/customer_manager/scripts/db_scripts/ranger_cms_create_db.sql', + CONF.ranger_base + + '/orm/services/customer_manager/scripts/db_scripts/ranger_cms_update_db.sql', + CONF.ranger_base + + '/orm/services/flavor_manager/scripts/db_scripts/ranger_fms_create_db.sql', + CONF.ranger_base + '/orm/services/image_manager/scripts/db_scripts/create_db.sql' + ] + + for item in range(len(orm_dbs)): + sql_file = open(orm_dbs[item], "r") + query = sql_file.read() + sql_queries.append(query) + sql_file.close() + + db_conn_url = CONF.database.connection + db_conn_url = db_conn_url and db_conn_url.replace("mysql+pymysql", "mysql") or '' + engine = create_engine(db_conn_url, echo=False) + + for exec_item in range(len(sql_queries)): + conn = engine.connect() + exec_script = conn.execute(sql_queries[exec_item]) + conn.close() diff --git a/orm/services/flavor_manager/config.py b/orm/services/flavor_manager/config.py index f6a236bc..ea529a3e 100755 --- a/orm/services/flavor_manager/config.py +++ b/orm/services/flavor_manager/config.py @@ -77,19 +77,13 @@ logging = { } } +# DB configurations +db_url = config.db_connect + database = { - 'host': config.db_host, - 'username': config.db_user, - 'password': config.db_pass, - 'db_name': 'orm_fms_db', - + 'connection_string': db_url.endswith('/orm') and db_url.replace("/orm", "/orm_fms_db") or (db_url + 'orm_fms_db') } -database['connection_string'] = 'mysql://{0}:{1}@{2}:3306/{3}'.format(database['username'], - database['password'], - database['host'], - database['db_name']) - # this table is for calculating default extra specs needed extra_spec_needed_table = { "ns": { @@ -164,7 +158,7 @@ authentication = { "tenant_name": config.token_auth_tenant, "token_role": config.token_auth_user_role, # The Keystone version currently in use. Can be either "2.0" or "3" - "keystone_version": "2.0", + "keystone_version": config.token_auth_version, "policy_file": config.fms['policy_file'], } diff --git a/orm/services/id_generator/config.py b/orm/services/id_generator/config.py index 0a50fb88..97f3b8ae 100755 --- a/orm/services/id_generator/config.py +++ b/orm/services/id_generator/config.py @@ -56,8 +56,12 @@ logging = { } verify = config.ssl_verify + +# DB configurations +db_url = config.db_connect + database = { - 'connection_string': config.db_url + 'orm' + 'connection_string': db_url.endswith('/orm') or (db_url + 'orm') } # Custom Configurations must be in Python dictionary format:: # diff --git a/orm/services/image_manager/config.py b/orm/services/image_manager/config.py index 0516322f..70ec7ca6 100755 --- a/orm/services/image_manager/config.py +++ b/orm/services/image_manager/config.py @@ -68,17 +68,13 @@ logging = { } } -database = { - 'host': config.db_host, - 'username': config.db_user, - 'password': config.db_pass, - 'db_name': 'orm_ims_db', +# DB configurations +db_url = config.db_connect +database = { + 'connection_string': db_url.endswith('/orm') and db_url.replace("/orm", "/orm_ims_db") or (db_url + 'orm_ims_db') } -database['connection_string'] = 'mysql://{0}:{1}@{2}:3306/{3}'.format(database['username'], - database['password'], - database['host'], - database['db_name']) + application_root = config.ims['base_url'] @@ -114,6 +110,6 @@ authentication = { "rms_url": config.rms['base_url'], "tenant_name": config.token_auth_tenant, "token_role": config.token_auth_user_role, - "keystone_version": "2.0", + "keystone_version": config.token_auth_version, "policy_file": config.ims['policy_file'] } diff --git a/orm/services/region_manager/config.py b/orm/services/region_manager/config.py index 1c310576..2ea7c8ea 100755 --- a/orm/services/region_manager/config.py +++ b/orm/services/region_manager/config.py @@ -92,8 +92,10 @@ region_options = { } # DB configurations +db_url = config.db_connect + database = { - 'url': config.db_url + 'orm_rms_db?charset=utf8', + 'url': db_url.endswith('/orm') and db_url.replace("/orm", "/orm_rms_db") or (db_url + 'orm_rms_db'), 'max_retries': 3, 'retries_interval': 10 } @@ -110,7 +112,7 @@ authentication = { "mech_pass": config.token_auth_pass, "tenant_name": config.token_auth_tenant, # The Keystone version currently in use. Can be either "2.0" or "3" - "keystone_version": "2.0", + "keystone_version": config.token_auth_version, "policy_file": config.rms['policy_file'] } diff --git a/orm/services/resource_distributor/config.py b/orm/services/resource_distributor/config.py index 52311560..3550fcc5 100755 --- a/orm/services/resource_distributor/config.py +++ b/orm/services/resource_distributor/config.py @@ -12,8 +12,10 @@ server = { } # DB configurations +db_url = config.db_connect + database = { - 'url': config.db_url + 'orm_rds?charset=utf8' + 'url': db_url.endswith('/orm') and db_url.replace("/orm", "/orm_rds") or (db_url + 'orm_rds') } sot = { @@ -214,5 +216,5 @@ authentication = { "tenant_name": config.token_auth_tenant, "token_role": config.token_auth_user_role, # The Keystone version currently in use. Can be either "2.0" or "3" - "keystone_version": "3" + "keystone_version": config.token_auth_version }