def l3_scheduler_patch(op_version): if op_version == 'tecs2.0' and api.check_if_file_exist( '/usr/lib/python2.7/site-packages/neutron/plugins/proxydriver' '/common/rest/znic_l2/config.py'): do_tecs_patch() value = 0 if op_version in ['tecs2.0', 'tecs3.0', 'tecs6.0']: print('This is %s, ignore patch ' 'to l3_router_plugin...\n' % op_version) else: if op_version in ['K', 'bigcloud_K']: value = do_patch('l3_scheduler_k.patch') elif op_version is 'L': value = do_patch('l3_scheduler_l.patch') elif op_version is 'M': value = do_patch('l3_scheduler_m.patch') elif op_version is 'N': value = do_patch('l3_scheduler_n.patch') elif op_version in ['O', 'bigcloud_O']: value = do_patch('l3_scheduler_o.patch') if value not in (0, 256, 1024): api.print_log("patch to l3_router_plugin failed!") return False if op_version == "bigcloud_K": install_openvswitch() return True
def remove_git_code(): full_args = "rpm -qa|grep networking-zte|xargs rpm -e" api.print_log("%s" % full_args) api.excute_command(full_args) full_args = "rm -rf /usr/lib/python2.7/site-packages/networking_zte/" api.excute_command(full_args)
def reset_taas_config(path): try: config_taas = ConfigObj(path, encoding='UTF8') config_taas['service_providers']['service_provider'] = \ 'TAAS:TAAS:neutron_taas.services.taas.service_drivers.' \ 'taas_rpc.TaasRpcDriver:default' config_taas.write() except Exception as e: api.print_log("no taas config found:%s,skip..." % e)
def handle_manual_op_version(op_version, configs): if not l3_scheduler_patch(op_version): return False full_args = "sed -i '/^mechanism_drivers/s/zte_ml2driver,//' " \ "/etc/neutron/plugin.ini" api.excute_command(full_args) config = configs["config_plugin"] mechanism_drivers = config['ml2']['mechanism_drivers'] api.print_log("patched mechanism_drivers is %s" % mechanism_drivers) return restart_neutron_server()
def install_plugin(kwargs, configs): check_service_plugins("install") full_args = "rpm -ivh networking-zte-*" api.print_log("%s" % full_args) api.excute_command(full_args) #api.append_files(copy_files) ret = append_config(kwargs, configs) if not ret: return ret return post_install(kwargs["op_version"])
def do_patch(op_patch): try: full_args = 'patch /usr/lib/python2.7/site-packages/neutron/' \ 'services/l3_router/l3_router_plugin.py ' \ '<%s' % op_patch status, output = api.excute_command(full_args) api.print_log(output) return status except Exception as e: api.print_log("The reason for the failure of patch is %s!" % e)
def update_plugin(kwargs, configs): """update code""" check_service_plugins("update") remove_rpm_folder() recover_old_version() recover_config(configs) full_args = "rpm -Uvh networking-zte-*" api.print_log("%s" % full_args) api.excute_command(full_args) #api.append_files(copy_files) ret = append_config(kwargs, configs) if not ret: return ret return post_install(kwargs["op_version"])
def check_service_plugins(action): full_args = "grep ^service_plugins /etc/neutron/neutron.conf" api.print_log("%s" % full_args) status, output = api.excute_command(full_args) api.print_log("action:%s,service plugins:%s" % (action, output)) full_args = "grep ^mechanism_drivers /etc/neutron/plugin.ini" api.print_log("%s" % full_args) status, output = api.excute_command(full_args) api.print_log("action:%s,mechanism_drivers:%s" % (action, output))
def zenic_plugin_auto_install(auto_install, configs): action = auto_install if action == 'uninstall': if not remove_plugin(configs): return 1 else: return 0 # auto install must have plugin config in plugin.ini if not check_zenic_para(configs): api.print_log("Can not find sdn plugin config in plugin.ini!") return 1 # get op_version and do patch files and restart neutron-server first config_plugin = configs["config_plugin"] if check_op_version(config_plugin): op_version = config_plugin["RESTPROXY"]["op_version"] if not handle_auto_op_version(op_version): return 1 else: api.print_log("Sorry this plugin version does not support auto " "install, please use manual install instead!") return 1 # auto-install only deal with rpm package check_service_plugins(action) remove_rpm_folder() remove_git_code() if action == 'install': full_args = "rpm -ivh networking-zte-*" if action == 'update': full_args = "rpm -Uvh networking-zte-*" api.print_log("%s" % full_args) api.excute_command(full_args) if not post_install(op_version): api.print_log("\33[30mzenic plugin %s failed, please " "fix and try again!!\33[0m" % action) return 1 else: api.print_log("\33[36mzenic plugin %s success!\33[0m" % action) return 0
def do_tecs_patch(): try: import py_compile full_args = 'rm -f /usr/lib/python2.7/site-packages/neutron/plugins' \ '/proxydriver/common/rest/znic_l2/config.py' status, output = api.excute_command(full_args) api.print_log(output) full_args = 'cp -af config.py ' \ '/usr/lib/python2.7/site-packages/neutron/plugins' \ '/proxydriver/common/rest/znic_l2/config.py ' status, output = api.excute_command(full_args) api.print_log(output) py_compile.compile('/usr/lib/python2.7/site-packages/neutron/plugins/' 'proxydriver/common/rest/znic_l2/config.py') return status except Exception as e: api.print_log("The reason for the failure of patch is %s!" % e)
def check_environment_config(): configs = {} try: config_neutron = ConfigObj('/etc/neutron/neutron.conf', encoding='UTF8') except Exception as e: api.print_log("There some errors in the neutron.conf %s!" % e) return configs try: config_plugin = ConfigObj('/etc/neutron/plugin.ini', encoding='UTF8') except Exception as e: api.print_log("There some errors in the plugin.ini %s!" % e) return configs try: config_nova = ConfigObj('/etc/nova/nova.conf', encoding='UTF8') except Exception as e: api.print_log("There some errors in the nova.conf %s!" % e) return configs configs["config_neutron"] = config_neutron configs["config_plugin"] = config_plugin configs["config_nova"] = config_nova return configs
def zenic_plugin_install(configs): welcome() op_version = manual_input_version() if not handle_manual_op_version(op_version, configs): return 1 action = operation_menu() api.print_log("User select to %s plugin...\n" % action) if action == 'install' and check_ml2driver_if_install(configs): api.print_log("zenic plugin has already installed!") return 1 if action == 'update' and not check_ml2driver_if_install(configs): api.print_log("zenic plugin has not installed! " "please install first!") return 1 if action == 'install': all_input_para = get_all_para(configs, op_version) api.print_log("Start to %s plugin...\n" % action) rtn = install_plugin(all_input_para, configs) if rtn: keep_zenic_agent() api.excute_commads(enable_zenic_agent) elif action == 'update' or action == 'update_tecs6.0': all_input_para = get_all_para(configs, op_version) all_input_para = refact_params(all_input_para) if action == 'update_tecs6.0': all_input_para = update_tecs_six(all_input_para) api.print_log("Start to %s plugin...\n" % action) rtn = update_plugin(all_input_para, configs) if rtn: keep_zenic_agent() api.excute_commads(enable_zenic_agent) elif action == 'uninstall': api.print_log("Start to %s plugin...\n" % action) rtn = remove_plugin(configs) else: rtn = True if rtn: api.print_log("\33[36mzenic plugin %s success!\33[0m" % action) return 0 else: api.print_log("\33[30mzenic plugin %s failed, please " "fix and try again!!\33[0m" % action) return 1
def patch_k_qos(qos_patch): full_args = 'patch /usr/lib/python2.7/site-packages/networking_zte/qos/' \ 'zenic_qos_plugin.py <%s' % qos_patch status, output = api.excute_command(full_args) api.print_log(output) return status
def remove_rpm_folder(): full_args = "rm -fr /usr/lib/python2.7/site-packages" \ "/networking_zte-*.egg-info" api.print_log("%s" % full_args) api.excute_command(full_args)
def recover_config(configs): # /etc/neutron/neutron.conf config_neutron = configs["config_neutron"] config_neutron['DEFAULT']['router_scheduler_driver'] = \ 'neutron.scheduler.l3_agent_scheduler.ChanceScheduler' #trunk try: del config_neutron['vlan_trunk']['trunk_drivers'] except Exception as e: api.print_log("There is no key of %s in the neutron.conf" % e) config_neutron.write() # /etc/neutron/plugin.ini # taas config_plugin = configs["config_plugin"] taas_function = get_taas_para(config_plugin) api.save_log("get_taas_para taas_function = %s" % taas_function) if taas_function == 'tecs2.0': reset_taas_config("/etc/neutron/taas_plugin.conf") elif taas_function == 'tecs6.0': reset_taas_config("/etc/neutron/plugin.ini") elif taas_function == 'tecs3.0': reset_taas_config("/etc/neutron/plugin.ini") elif taas_function == 'openstack': reset_taas_config("/etc/neutron/taas_plugin.ini") else: api.save_log("recover config can not find taas function!") if check_op_version(config_plugin): op_version = config_plugin["RESTPROXY"]["op_version"] else: op_version = "False" if op_version != "bigcloud_K": # security_group_api config_nova = configs["config_nova"] config_nova['DEFAULT']['security_group_api'] = 'nova' config_nova.write() full_args = "sed -i '/^\[RESTPROXY/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '/^enable_qos/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '/^enable_M_qos/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '/^enable_bandwidth/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '/^enable_hierarchical_port/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '/^op_version/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '/^server_timeout/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '/^servers/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '/^server_auth/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '/^server_ssl/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '/^no_ssl_validation/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '/^enable_pre_commit/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '/^taas_function/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "grep ^mechanism_drivers[[:space:]]*=.*," \ "[[:space:]]*zte_ml2driver /etc/neutron/plugin.ini" status, output = api.excute_command(full_args) if output != '': full_args = "sed -i '/^mechanism_drivers/s/," \ "[[:space:]]*zte_ml2driver//' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "grep ^mechanism_drivers[[:space:]]*=.*zte_ml2driver" \ "[[:space:]]*, /etc/neutron/plugin.ini" status, output = api.excute_command(full_args) if output != '': full_args = "sed -i '/^mechanism_drivers/s/zte_ml2driver" \ "[[:space:]]*,//' /etc/neutron/plugin.ini" api.excute_command(full_args) # remove l3 router_no_schedule full_args = "sed -i '/^\[L3\]/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '/^router_no_schedule/d' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "grep ^service_plugins[[:space:]]*=.*,[[:space:]]*zte_qos " \ "/etc/neutron/neutron.conf" api.print_log("%s" % full_args) status, output = api.excute_command(full_args) if output != '': full_args = "sed -i '/^service_plugins/s/,[[:space:]]*zte_qos//' " \ "/etc/neutron/neutron.conf" api.print_log("%s" % full_args) api.excute_command(full_args) full_args = "sed -i '/^service_plugins/s/$/,qos/' " \ "/etc/neutron/neutron.conf" api.print_log("%s" % full_args) api.excute_command(full_args) full_args = "grep ^service_plugins[[:space:]]*=.*zte_qos[[:space:]]*, " \ "/etc/neutron/neutron.conf" api.print_log("%s" % full_args) status, output = api.excute_command(full_args) if output != '': full_args = "sed -i '/^service_plugins/s/zte_qos[[:space:]]*,//' " \ "/etc/neutron/neutron.conf" api.print_log("%s" % full_args) api.excute_command(full_args) full_args = "sed -i '/^service_plugins/s/$/,qos/' " \ "/etc/neutron/neutron.conf" api.print_log("%s" % full_args) api.excute_command(full_args)
def welcome(): api.print_log("") api.print_log("================================================") api.print_log(" ZTE SDN Plugin Installation Wizard") api.print_log("================================================")
def append_config(kwargs, configs): config_neutron = ConfigObj('/etc/neutron/neutron.conf', encoding='UTF8') config_neutron['DEFAULT']['router_scheduler_driver'] = \ 'neutron.scheduler.l3_agent_scheduler.ChanceScheduler' # trunk if 'vlan_trunk' in config_neutron.keys(): config_neutron['vlan_trunk']['trunk_drivers'] = 'networking_zte.' \ 'trunk.driver' else: config_neutron['vlan_trunk'] = {} config_neutron['vlan_trunk']['trunk_drivers'] = 'networking_zte.' \ 'trunk.driver' config_neutron.write() #taas if kwargs["taas_function"] == 'tecs2.0': if not set_taas_config("/etc/neutron/taas_plugin.conf"): return False elif kwargs["taas_function"] == 'tecs6.0': if not set_taas_config("/etc/neutron/plugin.ini"): return False elif kwargs["taas_function"] == 'tecs3.0': if not set_taas_config("/etc/neutron/plugin.ini"): return False elif kwargs["taas_function"] == 'openstack': if not api.check_if_file_exist('/etc/neutron/taas_plugin.ini'): api.print_log("use taas funtion of openstack while taas_plugin.ini" " does not exist!") remove_git_code() return False if not set_taas_config("/etc/neutron/taas_plugin.ini"): return False else: api.save_log("append_config can not find taas function!") # plugin.ini full_args = "sed -i '$a \[RESTPROXY]' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '$a \enable_qos=%s' %s" % (kwargs["enable_qos"], "/etc/neutron/plugin.ini") api.excute_command(full_args) full_args = "sed -i '$a \enable_M_qos=%s' %s" % (kwargs["enable_M_qos"], "/etc/neutron/plugin.ini") api.excute_command(full_args) full_args = "sed -i '$a \op_version=%s' %s" % (kwargs["op_version"], "/etc/neutron/plugin.ini") api.excute_command(full_args) full_args = "sed -i '$a \enable_bandwidth=%s' %s" % ( kwargs["enable_bandwidth"], "/etc/neutron/plugin.ini") if kwargs["enable_bandwidth"] is not None: api.excute_command(full_args) full_args = "sed -i '$a \enable_hierarchical_port=%s' %s" % ( kwargs["enable_hierarchical_port"], "/etc/neutron/plugin.ini") if kwargs["enable_hierarchical_port"] is not None: api.excute_command(full_args) full_args = "sed -i '$a \server_timeout=100' %s" % ( "/etc/neutron/plugin.ini") api.excute_command(full_args) full_args = "sed -i '$a \servers=%s' %s" % (kwargs["servers"], "/etc/neutron/plugin.ini") api.excute_command(full_args) full_args = "sed -i '$a \server_auth=%s' %s" % (kwargs["server_auth"], "/etc/neutron/plugin.ini") api.excute_command(full_args) full_args = "sed -i '$a \server_ssl=%s' %s" % (kwargs["ssl"], "/etc/neutron/plugin.ini") api.excute_command(full_args) full_args = "sed -i '$a \\no_ssl_validation=%s' %s" % ( kwargs["ssl_validation"], "/etc/neutron/plugin.ini") api.excute_command(full_args) full_args = "sed -i '$a \\enable_pre_commit=%s' %s" % ( kwargs["pre_commit"], "/etc/neutron/plugin.ini") api.excute_command(full_args) full_args = "sed -i '$a \\taas_function=%s' %s" % ( kwargs["taas_function"], "/etc/neutron/plugin.ini") api.excute_command(full_args) full_args = "sed -i 's/^mechanism_drivers *=/mechanism_drivers " \ "=zte_ml2driver,/g' /etc/neutron/plugin.ini" api.excute_command(full_args) # add l3 router_no_schedule full_args = "sed -i '$a \[L3\]' /etc/neutron/plugin.ini" api.excute_command(full_args) full_args = "sed -i '$a router_no_schedule=True' /etc/neutron/plugin.ini" api.excute_command(full_args) # full_args = "sed -i '/^service_plugins/s/$/,zte_firewall/' #/etc/neutron/neutron.conf" # api.excute_command(full_args) if kwargs["enable_M_qos"] == "True": api.save_log("using M qos!") full_args = "grep ^service_plugins[[:space:]]*=.*,[[:space:]]*qos " \ "/etc/neutron/neutron.conf" status, output = api.excute_command(full_args) if output != '': full_args = "sed -i '/^service_plugins/s/,[[:space:]]*qos//' " \ "/etc/neutron/neutron.conf" api.excute_command(full_args) full_args = "grep ^service_plugins[[:space:]]*=.*qos[[:space:]]*, " \ "/etc/neutron/neutron.conf" status, output = api.excute_command(full_args) if output != '': full_args = "sed -i '/^service_plugins/s/qos[[:space:]]*,//' " \ "/etc/neutron/neutron.conf" api.excute_command(full_args) full_args = "sed -i '/^service_plugins/s/$/,zte_qos/' " \ "/etc/neutron/neutron.conf" api.excute_command(full_args) if kwargs["op_version"] != "bigcloud_K": # security_group_api config_nova = configs["config_nova"] config_nova['DEFAULT']['security_group_api'] = 'neutron' config_nova.write() return True
def menu(): api.print_log("") api.print_log("1. install") api.print_log("2. uninstall") api.print_log("3. update(eg: tecs2.0->tecs2.0)") api.print_log("4. update_tecs6.0(tecs2.0->tecs6.0)") api.print_log("5. exit") api.print_log("")
try: config_nova = ConfigObj('/etc/nova/nova.conf', encoding='UTF8') except Exception as e: api.print_log("There some errors in the nova.conf %s!" % e) return configs configs["config_neutron"] = config_neutron configs["config_plugin"] = config_plugin configs["config_nova"] = config_nova return configs if __name__ == '__main__': configs = check_environment_config() if len(configs) != 0: api.print_log("------------------------------------------------------") version = api.get_version_info('VERSION', 'version') date = api.get_version_info('VERSION', 'date') api.print_log("version: %s = %s" % ('zenic_plugin_version', "%s" % date)) api.backup_old_files() install_type = None if len(sys.argv) > 1: install_type = sys.argv[1] api.print_log("\nRecognizing auto: {} zenic plugin...\n".format( install_type)) rtn = zenic_plugin_auto_install(install_type, configs) else: rtn = zenic_plugin_install(configs) api.set_sys_info('VERSION', 'zenic_version', "kilo_v2.1.%s" % version) api.set_sys_info('VERSION', 'date', date)