diff --git a/script/README.md b/script/README.md new file mode 100755 index 00000000..bc6a5e45 --- /dev/null +++ b/script/README.md @@ -0,0 +1,44 @@ +Tricircle Configuration Options Updating Module +=============================================== + +In Tricircle Project, we added many options in the *.conf files for cascading, these options +among nova, glance, neutron, cinder. When deploy the cascading environment, these options should +be modified based on the deployment context(IP, tenant, user, password etc.), so we have to +modify each install scripts(/installation) every time for deployment because the options is +configured by these scripts. It is inconvenient. + +This script module is created in order to managing the options in *.conf with a centralized way. +It is independent of the installation scripts, but the scripts can invoke the function in it to +finish the options' configuration. + +Composition +------ +* **config.py**: the implementation to execute options updating, using python build-in lib:ConfigParser. +* **tricircle.cfg**: the options you want to update are stored here. +* **exec.sh**: a very simple shell commend to invoke the python code. + +Usage +------- +- Format of the tricircle.cfg + + The tricircle.cfg is standard python config file(like nova.conf in /etc/nova), it contains + sections and options in each section like what the *.conf is in it. The only difference is + the **Naming Conventions** of the section: + + + Every section name start with the openstack service config-file name + (nova/neutron/glance-api/cinder); + + + If the option to be updated needs in a special section in *.conf, the special section + (keystone_authtoken e.g) should be added to the end of the section name with '_' ahead of + it. For example, if the 'auth_host' option in nova.conf need be updated, it should in + 'nova_keystone_authtoken' section in the tricircle.cfg. + +- Execution + + After you configured the options in tricircle.cfg, run the commend: + ```python config.py [openstack-service-name]``` + If you want update all services' options in tricircle.cfg, run ```python config.py all```. + + + **Note**: you can execute multiple times for an option with different value and do + not worry about it appears multiple times in *.conf, only the latest value in the conf + file. diff --git a/script/__init__.py b/script/__init__.py new file mode 100755 index 00000000..4a7de129 --- /dev/null +++ b/script/__init__.py @@ -0,0 +1 @@ +__author__ = 'openstack' diff --git a/script/config.py b/script/config.py new file mode 100755 index 00000000..b8bc5c7e --- /dev/null +++ b/script/config.py @@ -0,0 +1,113 @@ +# Copyright (c) 2014 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. +# +# @author: Jia Dong, HuaWei + +import ConfigParser +import os +import sys + +DEFAULT_CFG_FILE_PATHS = { + 'nova': {'nova': '/etc/nova/nova.conf'}, + 'glance': { + 'api': '/etc/glance/glance-api.conf', + 'registry': '/etc/glance/glance-registry.conf', + 'sync': '/etc/glance/glance-sync.conf' + }, + 'cinder': {'cinder': '/etc/cinder/cinder.conf'} +} + + +class TricircleConfig(object): + CFG_FILE = "tricircle.cfg" + + def __init__(self): + self.cf = ConfigParser.ConfigParser() + self.cf.read(self.CFG_FILE) + + def update_options(self, module_name, module_cfg_file_paths=None): + """ + module_name like 'nova', 'glance-api' etc. + """ + cfg_mapping = module_cfg_file_paths if module_cfg_file_paths \ + else DEFAULT_CFG_FILE_PATHS.get(module_name, None) + + if not cfg_mapping: + print 'Abort, no cfg_file for module %s' \ + ' has configured.' % module_name + return + options = {} + for cfg_mod in cfg_mapping: + + sub_mod = cfg_mod + sub_file_path = cfg_mapping[sub_mod] + sub_module_name = module_name + '-' + sub_mod if module_name != sub_mod \ + else module_name + options[sub_module_name] = {} + + sections = filter(lambda x: x.startswith(sub_module_name), + self.cf.sections()) + for section in sections: + module_section = section[len(sub_module_name):] or 'DEFAULT' + module_section = module_section[1:] \ + if module_section[0] == '_' else module_section + + _options = {} + module_options = self.cf.items(section, raw=True) + for pair in module_options: + _options[pair[0]] = pair[1] + options[sub_module_name][module_section] = _options + + if options[sub_module_name]: + print '>>> Start updating %s config: ' % sub_module_name + TricircleConfig._replace_cfg(options[sub_module_name], sub_file_path) + print 'Finish updating %s config. <<< ' % sub_module_name + + @staticmethod + def _replace_cfg(options, file_path): + if not (file_path and os.path.isfile(file_path)): + print 'file_path %s not exists or not a file' % file_path + mod_cf = ConfigParser.SafeConfigParser() + mod_cf.read(file_path) + sections = mod_cf.sections() + for _section in options: + if _section not in sections and _section != 'DEFAULT': + mod_cf.add_section(_section) + + for option in options[_section]: + mod_cf.set(_section, option, options[_section][option]) + + mod_cf.write(open(file_path, 'w')) + print 'Done' + + +def main(): + module = sys.argv[1] + print module + if not module: + print 'The input parameters not exists.' + try: + config = TricircleConfig() + if module.upper() == 'ALL': + for mod in ('nova', 'glance', 'cinder', 'neutron'): + config.update_options(mod) + else: + config.update_options(module) + except Exception as e: + print e + print 'Update tricircle %s config options fails' % module + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/script/exec.sh b/script/exec.sh new file mode 100755 index 00000000..35cfcc07 --- /dev/null +++ b/script/exec.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +python config.py all \ No newline at end of file diff --git a/script/tricircle.cfg b/script/tricircle.cfg new file mode 100755 index 00000000..d38d99e4 --- /dev/null +++ b/script/tricircle.cfg @@ -0,0 +1,72 @@ +[glance-api] +sync_enabled=True +sync_server_port=9595 +sync_server_host=127.0.0.1 +show_multiple_locations=True + +[glance-api_keystone_authtoken] +service_host=127.0.0.1 +auth_host=127.0.0.1 +auth_uri=http://127.0.0.1:5000/ +admin_tenant_name=service +admin_user=glance +admin_password=openstack + +[glance-sync] +sync_strategy=All +cascading_endpoint_url=http:/// +snapshot_region_names= + +[glance-sync_keystone_authtoken] +auth_host=127.0.0.1 +admin_tenant_name=service +admin_user=glance +admin_password=openstack + +[nova] +vif_plugging_timeout=0 +vif_plugging_is_fatal=False +nova_admin_username=admin +nova_admin_password=openstack +nova_admin_tenant_name=admin +proxy_region_name= +cascading_nova_url=http://127.0.0.1:8774/v2 +cascaded_nova_url=http://127.0.0.1:8774/v2 +cascaded_neutron_url=http://127.0.0.1:9696 +cascaded_glance_flag=True +cascaded_glance_url=http://127.0.0.1:9292 +os_region_name= +keystone_auth_url=http://127.0.0.1:5000/v2.0/ +cinder_endpoint_template=http://127.0.0.1:8776/v2/%(project_id)s +compute_manager=nova.compute.manager_proxy.ComputeManager +image_copy_dest_location_url=file:///var/lib/glance/images +image_copy_dest_host=127.0.0.1 +image_copy_dest_user=glance +image_copy_dest_password=openstack +image_copy_source_location_url=file:///var/lib/glance/images +image_copy_source_host=127.0.0.1 +image_copy_source_user=glance +image_copy_source_password=openstack + +[nova_keystone_authtoken] +auth_uri = http://127.0.0.1:5000 +auth_host = 127.0.0.1 +admin_tenant_name = service +admin_user = nova +admin_password = openstack + +[cinder] +volume_manager=cinder.volume.cinder_proxy.CinderProxy +volume_sync_interval=5 +voltype_sync_interval=3600 +periodic_interval=5 +cinder_tenant_name=admin +cinder_username=admin +cinder_password=1234 +keystone_auth_url=http://127.0.0.1:5000/v2.0/ +glance_cascading_flag=False +cascading_glance_url=127.0.0.1:9292 +cascaded_glance_url=http://127.0.0.1:9292 +cascaded_cinder_url=http://127.0.0.1:8776/v2/%(project_id)s +cascaded_region_name=Region_AZ +cascaded_available_zone=AZ \ No newline at end of file