generate_config.py 3.6 KB
Newer Older
R
Rongfeng Fu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# coding: utf-8
# OceanBase Deploy.
# Copyright (C) 2021 OceanBase
#
# This file is part of OceanBase Deploy.
#
# OceanBase Deploy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OceanBase Deploy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OceanBase Deploy.  If not, see <https://www.gnu.org/licenses/>.


from __future__ import absolute_import, division, print_function


F
v1.6.0  
frf12 已提交
24
def generate_config(plugin_context, deploy_config, auto_depend=False, *args, **kwargs):
R
Rongfeng Fu 已提交
25 26 27 28 29 30 31 32 33 34 35 36
    cluster_config = plugin_context.cluster_config
    clients = plugin_context.clients
    stdio = plugin_context.stdio
    success = True
    stdio.start_loading('Generate obproxy configuration')

    for server in cluster_config.servers:
        server_config = cluster_config.get_server_conf(server)
        if not server_config.get('home_path'):
            stdio.error("obproxy %s: missing configuration 'home_path' in configuration file" % server)
            success = False
            continue
R
Rongfeng Fu 已提交
37
        cluster_config.update_server_conf(server, 'enable_cluster_checkout', False)
R
Rongfeng Fu 已提交
38 39 40 41
    if not success:
        stdio.stop_loading('fail')
        return

R
Rongfeng Fu 已提交
42 43 44 45 46
    global_config = cluster_config.get_original_global_conf()
    if 'skip_proxy_sys_private_check' not in global_config:
        cluster_config.update_global_conf('skip_proxy_sys_private_check', True, False)
    if 'enable_strict_kernel_release' not in global_config:
        cluster_config.update_global_conf('enable_strict_kernel_release', False, False)
F
v1.6.0  
frf12 已提交
47 48 49 50
    
    if getattr(plugin_context.options, 'mini', False):
        if 'proxy_mem_limited' not in global_config:
            cluster_config.update_global_conf('proxy_mem_limited', '200M', False)
R
Rongfeng Fu 已提交
51

F
v1.6.0  
frf12 已提交
52
    ob_comps = ['oceanbase', 'oceanbase-ce']
R
Rongfeng Fu 已提交
53
    ob_cluster_config = None
F
v1.6.0  
frf12 已提交
54 55 56 57
    for comp in ob_comps:
        if comp in cluster_config.depends:
            stdio.stop_loading('succeed')
            return plugin_context.return_true()
R
Rongfeng Fu 已提交
58
        if comp in deploy_config.components:
R
Rongfeng Fu 已提交
59
            ob_cluster_config = deploy_config.components[comp]
F
v1.6.0  
frf12 已提交
60 61 62 63 64 65

    if auto_depend:
        for depend in ['oceanbase', 'oceanbase-ce']:
            if cluster_config.add_depend_component(depend):
                stdio.stop_loading('succeed')
                return plugin_context.return_true()
R
Rongfeng Fu 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

    if ob_cluster_config:
        root_servers = {}
        cluster_name = ob_cluster_config.get_global_conf().get('appname')
        for server in ob_cluster_config.servers:
            config = ob_cluster_config.get_server_conf_with_default(server)
            zone = config['zone']
            cluster_name = cluster_name if cluster_name else config.get('appname')
            if zone not in root_servers:
                root_servers[zone] = '%s:%s' % (server.ip, config['mysql_port'])
        rs_list = ';'.join([root_servers[zone] for zone in root_servers])

        cluster_name = cluster_name if cluster_name else 'obcluster'
        if not global_config.get('rs_list'):
            cluster_config.update_global_conf('rs_list', rs_list, False)
        if not global_config.get('cluster_name'):
            cluster_config.update_global_conf('cluster_name', cluster_name, False)
R
Rongfeng Fu 已提交
83 84 85
    
    stdio.stop_loading('succeed')
    return plugin_context.return_true()