def getServerIndex(): output, exitcode = ShellCmdExecutor.execCmd('cat /opt/localip') local_management_ip = output.strip() glance_ips = JSONUtility.getValue('glance_ips') glance_ip_list = glance_ips.split(',') index = ServerSequence.getIndex(glance_ip_list, local_management_ip) return index
def configKeepalived(): ha_vip1 = JSONUtility.getValue('ha_vip1') ha_vip2 = JSONUtility.getValue('ha_vip2') ha_vip1_interface = JSONUtility.getValue('ha_vip1_interface') ha_vip2_interface = JSONUtility.getValue('ha_vip2_interface') keepalived_conf_1_template_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'ha', 'keepalived.conf.1') keepalived_conf_2_template_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'ha', 'keepalived.conf.2') keepalived_conf_dest_path = '/etc/keepalived/keepalived.conf' haproxy_keepalived_ips = JSONUtility.getValue('haproxy_keepalived_ips') haproxy_keepalived_ip_list = haproxy_keepalived_ips.split(',') output, exitcode = ShellCmdExecutor.execCmd('cat /opt/localip') local_management_ip = output.strip() serverIndex = ServerSequence.getIndex(haproxy_keepalived_ip_list, local_management_ip) if serverIndex == 0 : ShellCmdExecutor.execCmd('cp -r %s %s' % (keepalived_conf_1_template_path, keepalived_conf_dest_path)) FileUtil.replaceFileContent(keepalived_conf_dest_path, '<HA_VIP1>', ha_vip1) FileUtil.replaceFileContent(keepalived_conf_dest_path, '<HA_VIP1_INTERFACE>', ha_vip1_interface) pass if serverIndex == 1 : ShellCmdExecutor.execCmd('cp -r %s %s' % (keepalived_conf_2_template_path, keepalived_conf_dest_path)) FileUtil.replaceFileContent(keepalived_conf_dest_path, '<HA_VIP2>', ha_vip2) FileUtil.replaceFileContent(keepalived_conf_dest_path, '<HA_VIP1_INTERFACE>', ha_vip2_interface) pass haproxy_check_script_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'ha', 'haproxy_check.sh') ShellCmdExecutor.execCmd('cp -r %s /etc/keepalived/' % haproxy_check_script_path) ShellCmdExecutor.execCmd('chmod 644 %s' % keepalived_conf_dest_path) ShellCmdExecutor.execCmd('chmod 644 /etc/keepalived/haproxy_check.sh') pass
def start(): from openstack.common.serverSequence import ServerSequence mysql_ips = JSONUtility.getValue("mysql_ips") print 'mysql_ips=%s---' % mysql_ips mysql_ip_list = mysql_ips.strip().split(',') print 'mysql_ip_list=%s--' % mysql_ip_list output, exitcode = ShellCmdExecutor.execCmd('cat /opt/localip') local_management_ip = output.strip() index = ServerSequence.getIndex(mysql_ip_list, local_management_ip) print 'mysql index=%s--' % str(index) #Judge master if not os.path.exists('/opt/openstack_conf/tag/') : ShellCmdExecutor.execCmd('mkdir -p /opt/openstack_conf/tag/') pass from openstack.kilo.ssh.SSH import SSH if index == 0 : print 'start to launch mysql master===============' start_cmd = '/opt/bcrdb/support-files/mysql.server bootstrap' ShellCmdExecutor.execCmd(start_cmd) #Mutual trust has been established when execute prerequisites.py, then send tag to the rest bcrdb servers #to mark that the first bcrdb server has been launched. tag_file_name = 'bcrdb_0' #The first server of bcrdb cluster #mark master mark_cmd = 'touch /opt/openstack_conf/tag/{file}'.format(file=tag_file_name) os.system(mark_cmd) #mark slave slave_mysql_server_list = mysql_ip_list[1:] for slave_ip in slave_mysql_server_list : SSH.sendTagTo(slave_ip, tag_file_name) pass keystone_ips = JSONUtility.getValue("keystone_ips") keystone_ip_list = keystone_ips.strip().split(',') #send tag to first server of keystone cluster SSH.sendTagTo(keystone_ip_list[0], tag_file_name) pass else : print 'start to launch mysql slave================' #wait bcrdb first server launched file_path = '/opt/openstack_conf/tag/bcrdb_0' time_count = 0 while True: flag = os.path.exists(file_path) if flag == True : print 'wait time: %s second(s).' % time_count print 'If first mysql is launched,then start mysql slave=========' start_cmd = '/opt/bcrdb/support-files/mysql.server start' ShellCmdExecutor.execCmd(start_cmd) print 'done to start mysql slave######' break else : step = 1 # print 'wait %s second(s)......' % step time_count += step time.sleep(1) pass if time_count == BCRDB.TIMEOUT : print 'Do nothing!timeout=%s.' % BCRDB.TIMEOUT break pass #send tag to the first server of keystone cluster: #when all servers are launched,keystone is used to register info to RDB. index = ServerSequence.getIndex(mysql_ip_list, local_management_ip) tag_file_name = 'bcrdb_{index}'.format(index=str(index)) print 'slave mysql tag_file_name=%s' % tag_file_name SSH.sendTagTo(keystone_ip_list[0], tag_file_name) print 'send tag to first mysql====' SSH.sendTagTo(mysql_ip_list[0], tag_file_name) print 'done to send tag to first mysql####' pass pass
# Prerequisites.prepare() NeutronServer.install() NeutronServer.configConfFile() #import neutron server db schema output, exitcode = ShellCmdExecutor.execCmd('cat /opt/localip') localIP = output.strip() neutron_ips = JSONUtility.getValue("neutron_ips") neutron_ip_list = neutron_ips.split(',') first_neutron_launched_mark_file = '/opt/openstack_conf/tag/neutronserver0_launched' TIMEOUT = 1800 #0.5 hour for test if ServerSequence.getIndex(neutron_ip_list, localIP) == 0: firstKeystoneLaunchedTag = '/opt/openstack_conf/tag/keystone0_launched' timeout = TIMEOUT time_count = 0 print 'test timeout===' while True: #all mysql are launched. flag = os.path.exists(firstKeystoneLaunchedTag) if flag == True : print 'wait time: %s second(s).' % time_count NeutronServer.importNeutronDBSchema() break else : step = 1 # print 'wait %s second(s)......' % step
else: Nova.install() Nova.configConfFile() ########### # import nova db schema output, exitcode = ShellCmdExecutor.execCmd("cat /opt/localip") localIP = output.strip() nova_ips = JSONUtility.getValue("nova_ips") nova_ip_list = nova_ips.strip().split(",") first_nova_launched_mark_file = "/opt/openstack_conf/tag/nova0_launched" TIMEOUT = 1800 # 0.5 hour for test if ServerSequence.getIndex(nova_ip_list, localIP) == 0: firstKeystoneLaunchedTag = "/opt/openstack_conf/tag/keystone0_launched" timeout = TIMEOUT time_count = 0 print "test timeout===" while True: # all mysql are launched. flag = os.path.exists(firstKeystoneLaunchedTag) if flag == True: print "wait time: %s second(s)." % time_count Nova.importNovaDBSchema() break else: step = 1 # print 'wait %s second(s)......' % step
print 'exit====' pass else : Cinder.install() Cinder.configConfFile() #import cinder db schema output, exitcode = ShellCmdExecutor.execCmd('cat /opt/localip') localIP = output.strip() cinder_ips = JSONUtility.getValue("cinder_ips") cinder_ip_list = cinder_ips.strip().split(',') first_cinder_launched_mark_file = '/opt/openstack_conf/tag/cinder0_launched' TIMEOUT = 1800 #0.5 hour for test if ServerSequence.getIndex(cinder_ip_list, localIP) == 0: firstKeystoneLaunchedTag = '/opt/openstack_conf/tag/keystone0_launched' timeout = TIMEOUT time_count = 0 print 'test timeout===' while True: #all mysql are launched. flag = os.path.exists(firstKeystoneLaunchedTag) if flag == True : print 'wait time: %s second(s).' % time_count Cinder.importCinderDBSchema() break else : step = 1 # print 'wait %s second(s)......' % step time_count += step