############################################################################## # Copyright (c) 2017 ZTE Coreporation and others. # feng.xiaowei@zte.com.cn # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import argparse import os from deploy.config.network import NetworkConfig KOLLA_CONF_PATH = '/etc/kolla/config' DOCTOR_EXTRA_FILE = '/home/kolla_install/kolla-ansible/ansible/roles/ceilometer/templates/event_pipeline.yaml.j2' def _make_dirs(path): if not os.path.isdir(path): os.makedirs(path, mode=0744) def _write_conf_file(conf_file, conf): with open(conf_file, 'w') as f: f.write(conf) f.close() def _config_service(service, subs): def _wrap(func): def _config(*args): conf_path = os.path.join(KOLLA_CONF_PATH, service) _make_dirs(conf_path) for sub in subs: conf_file = os.path.join(conf_path, '{}-{}.conf'.format(service, sub)) _write_conf_file(conf_file, func(*args)) return _config return _wrap @_config_service('nova', ['compute']) def _set_qemu_compute(): return '[libvirt]\n' \ 'virt_type=qemu\n' \ 'cpu_mode=none\n' @_config_service('nova', ['api']) def _set_default_floating_pool(network_file): xnet = NetworkConfig(network_file=network_file).ext_network_name return '[DEFAULT]\n' \ 'default_floating_pool = {}\n'.format(xnet) @_config_service('heat', ['api', 'engine']) def _set_trusts_auth(): return '[DEFAULT]\n' \ 'deferred_auth_method = trusts\n' \ 'trusts_delegated_roles =\n' def _config_doctor_extra_configuration(): with open(DOCTOR_EXTRA_FILE, 'a') as fp: fp.write(' - notifier://?topic=alarm.all\n') def main(): parser = argparse.ArgumentParser() parser.add_argument('-nw', '--network-file', type=str, required=True, help='network configuration file') parser.add_argument('-b', '--is-baremetal', type=str, required=True, help='0 for virtual, 1 for baremetal') parser.add_argument('-d', '--run-doctor', type=str, required=True, help='1 for run doctor, other do not run doctor') args = parser.parse_args() if args.is_baremetal == '0': _set_qemu_compute() if args.run_doctor == '1': _config_doctor_extra_configuration() _set_default_floating_pool(args.network_file) _set_trusts_auth() if __name__ == '__main__': main()