def install(): #KEYSTONE_ADMIN_PASSWORD print 'Cinder-storage.install start====' # keystone_vip = JSONUtility.getValue('keystone_vip') keystone_admin_password = JSONUtility.getValue('keystone_admin_password') print 'start to install prerequisites=============' script_file_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'cinder-storage', 'cinder_storage_service.sh') ShellCmdExecutor.execCmd('cp -r %s /opt/' % script_file_path) ShellCmdExecutor.execCmd('chmod 777 /opt/cinder_storage_service.sh') FileUtil.replaceFileContent('/opt/cinder_storage_service.sh', '<KEYSTONE_VIP>', keystone_vip) ShellCmdExecutor.execCmd('bash /opt/cinder_storage_service.sh') ShellCmdExecutor.execCmd("systemctl restart lvm2-lvmetad.service") #Default create volume #Create the LVM physical volume /dev/sdb1: # createCmd = 'pvcreate /dev/sdb1' # ShellCmdExecutor.execCmd(createCmd) # createCmd = 'vgcreate cinder-volumes /dev/sdb1' # ShellCmdExecutor.execCmd(createCmd) yumCmd = 'yum install openstack-cinder targetcli python-oslo-db python-oslo-log MySQL-python -y' ShellCmdExecutor.execCmd(yumCmd) print 'Cinder-storage.install done####' pass
def start(): if debug == True : pass else : ceilometer_vip_interface = JSONUtility.getValue("ceilometer_vip_interface") ceilometer_vip = JSONUtility.getValue("ceilometer_vip") CeilometerHA.addVIP(ceilometer_vip, ceilometer_vip_interface) if CeilometerHA.isHAProxyRunning() : ShellCmdExecutor.execCmd('service haproxy restart') else : ShellCmdExecutor.execCmd('service haproxy start') pass if CeilometerHA.isKeepalivedRunning() : ShellCmdExecutor.execCmd('service keepalived restart') else : ShellCmdExecutor.execCmd('service keepalived start') pass ShellCmdExecutor.execCmd('service haproxy restart') isMasterNode = CeilometerHA.isMasterNode() if isMasterNode == True : CeilometerHA.restart() pass else : CeilometerHA.deleteVIP(ceilometer_vip, ceilometer_vip_interface) pass pass ShellCmdExecutor.execCmd('service keepalived restart') pass
def start(): if debug == True : pass else : neutron_vip_interface = JSONUtility.getValue("neutron_vip_interface") neutron_vip = JSONUtility.getValue("neutron_vip") NeutronServerHA.addVIP(neutron_vip, neutron_vip_interface) if NeutronServerHA.isHAProxyRunning() : ShellCmdExecutor.execCmd('service haproxy restart') else : ShellCmdExecutor.execCmd('service haproxy start') pass if NeutronServerHA.isKeepalivedRunning() : ShellCmdExecutor.execCmd('service keepalived restart') else : ShellCmdExecutor.execCmd('service keepalived start') pass isMasterNode = NeutronServerHA.isMasterNode() if isMasterNode == True : NeutronServerHA.restart() pass else : NeutronServerHA.deleteVIP(neutron_vip, neutron_vip_interface) pass pass ShellCmdExecutor.execCmd('service keepalived restart') pass
def confiugureNeutron(): neutronConfTemplateFilePath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'nova-compute', 'neutron.conf') ShellCmdExecutor.execCmd('cp -r %s /etc/neutron/' % neutronConfTemplateFilePath) #configure neutron keystone_vip = JSONUtility.getValue('keystone_vip') # rabbit_host = JSONUtility.getValue("rabbit_host") # rabbit_vip = JSONUtility.getValue("rabbit_vip") rabbit_hosts = JSONUtility.getValue("rabbit_hosts") rabbit_userid = JSONUtility.getValue("rabbit_userid") rabbit_password = JSONUtility.getValue("rabbit_password") #REFACTOR LATER neutron_pass = '******' neutronConfFilePath = '/etc/neutron/neutron.conf' ShellCmdExecutor.execCmd('chmod 777 /etc/neutron/neutron.conf') FileUtil.replaceFileContent(neutronConfFilePath, '<KEYSTONE_VIP>', keystone_vip) FileUtil.replaceFileContent(neutronConfFilePath, '<NEUTRON_PASS>', neutron_pass) # FileUtil.replaceFileContent(neutronConfFilePath, '<RABBIT_HOST>', rabbit_vip) FileUtil.replaceFileContent(neutronConfFilePath, '<RABBIT_HOSTS>', rabbit_hosts) FileUtil.replaceFileContent(neutronConfFilePath, '<RABBIT_USERID>', rabbit_userid) FileUtil.replaceFileContent(neutronConfFilePath, '<RABBIT_PASSWORD>', rabbit_password) ShellCmdExecutor.execCmd('chown -R neutron:neutron /etc/neutron') pass
def initNeutron(): ha_vip1 = JSONUtility.getValue('ha_vip1') ha_vip2 = JSONUtility.getValue('ha_vip2') keystone_admin_password = JSONUtility.getValue('keystone_admin_password') keystone_vip = ha_vip1 keystone_neutron_password = JSONUtility.getValue('keystone_neutron_password') neutron_vip = ha_vip1 initNeutronScriptTemplatePath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'neutron-server', 'initNeutron.sh') ## openstackConfPopertiesFilePath = PropertiesUtility.getOpenstackConfPropertiesFilePath() openstackScriptDirPath = PropertiesUtility.getValue(openstackConfPopertiesFilePath, 'OPENSTACK_SCRIPT_DIR') if os.path.exists(openstackScriptDirPath) : os.system('mkdir -p %s' % openstackScriptDirPath) pass ShellCmdExecutor.execCmd('cp -r %s %s' % (initNeutronScriptTemplatePath, openstackScriptDirPath)) initNeutronScriptPath = os.path.join(openstackScriptDirPath, 'initNeutron.sh') FileUtil.replaceFileContent(initNeutronScriptPath, '<KEYSTONE_ADMIN_PASSWORD>', keystone_admin_password) FileUtil.replaceFileContent(initNeutronScriptPath, '<KEYSTONE_VIP>', keystone_vip) FileUtil.replaceFileContent(initNeutronScriptPath, '<KEYSTONE_NEUTRON_PASSWORD>', keystone_neutron_password) FileUtil.replaceFileContent(initNeutronScriptPath, '<NEUTRON_VIP>', neutron_vip) ShellCmdExecutor.execCmd('bash %s' % initNeutronScriptPath) pass
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(): if debug == True : pass else : keystone_vip_interface = JSONUtility.getValue("keystone_vip_interface") keystone_vip = JSONUtility.getValue("keystone_vip") KeystoneHA.addVIP(keystone_vip, keystone_vip_interface) if KeystoneHA.isHAProxyRunning() : ShellCmdExecutor.execCmd('service haproxy restart') else : ShellCmdExecutor.execCmd('service haproxy start') pass KeystoneHA.deleteVIP(keystone_vip, keystone_vip_interface) if KeystoneHA.isKeepalivedRunning() : ShellCmdExecutor.execCmd('service keepalived restart') else : ShellCmdExecutor.execCmd('service keepalived start') pass #refactor=============== isMasterNode = True if isMasterNode == True : KeystoneHA.addVIP(keystone_vip, keystone_vip_interface) else : KeystoneHA.deleteVIP(keystone_vip, keystone_vip_interface) pass pass pass
def start(): if debug == True : pass else : heat_vip_interface = JSONUtility.getValue("heat_vip_interface") heat_vip = JSONUtility.getValue("heat_vip") HeatHA.addVIP(heat_vip, heat_vip_interface) if HeatHA.isHAProxyRunning() : ShellCmdExecutor.execCmd('service haproxy restart') else : ShellCmdExecutor.execCmd('service haproxy start') pass if HeatHA.isKeepalivedRunning() : ShellCmdExecutor.execCmd('service keepalived restart') else : ShellCmdExecutor.execCmd('service keepalived start') pass ShellCmdExecutor.execCmd('service haproxy restart') isMasterNode = HeatHA.isMasterNode() if isMasterNode == True : HeatHA.restart() pass else : HeatHA.deleteVIP(heat_vip, heat_vip_interface) pass pass ShellCmdExecutor.execCmd('service keepalived restart') pass
def start(): if debug == True : pass else : nova_vip_interface = JSONUtility.getValue("nova_vip_interface") nova_vip = JSONUtility.getValue("nova_vip") NovaHA.addVIP(nova_vip, nova_vip_interface) if NovaHA.isHAProxyRunning() : ShellCmdExecutor.execCmd('service haproxy restart') else : ShellCmdExecutor.execCmd('service haproxy start') pass if NovaHA.isKeepalivedRunning() : ShellCmdExecutor.execCmd('service keepalived restart') else : ShellCmdExecutor.execCmd('service keepalived start') pass #Ensure only one VIP exists. isMasterNode = NovaHA.isMasterNode() if isMasterNode == True : NovaHA.restart() else : NovaHA.deleteVIP(nova_vip, nova_vip_interface) pass ShellCmdExecutor.execCmd('service keepalived restart') pass
def start(): if debug == True : pass else : dashboard_vip_interface = JSONUtility.getValue("dashboard_vip_interface") dashboard_vip = JSONUtility.getValue("dashboard_vip") DashboardHA.addVIP(dashboard_vip, dashboard_vip_interface) if DashboardHA.isHAProxyRunning() : ShellCmdExecutor.execCmd('service haproxy restart') else : ShellCmdExecutor.execCmd('service haproxy start') pass # DashboardHA.deleteVIP(dashboard_vip, dashboard_vip_interface) if DashboardHA.isKeepalivedRunning() : ShellCmdExecutor.execCmd('service keepalived restart') else : ShellCmdExecutor.execCmd('service keepalived start') pass #Ensure only one VIP exists. isMasterNode = DashboardHA.isMasterNode() if isMasterNode == True : DashboardHA.restart() pass else : DashboardHA.deleteVIP(dashboard_vip, dashboard_vip_interface) pass pass ShellCmdExecutor.execCmd('service keepalived restart') pass
def prepareAdminOpenrc(): adminOpenrcTemplateFilePath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'admin-openrc.sh') ShellCmdExecutor.execCmd('cp -r %s /opt/openstack_conf' % adminOpenrcTemplateFilePath) keystone_admin_password = JSONUtility.getValue('keystone_admin_password') keystone_vip = JSONUtility.getValue('keystone_vip') FileUtil.replaceFileContent('/opt/openstack_conf/admin-openrc.sh', '<KEYSTONE_ADMIN_PASSWORD>', keystone_admin_password) FileUtil.replaceFileContent('/opt/openstack_conf/admin-openrc.sh', '<KEYSTONE_VIP>', keystone_vip) pass
def configureKeystoneHAProxy(): dashboard_vip = JSONUtility.getValue("dashboard_vip") openstackConfPopertiesFilePath = PropertiesUtility.getOpenstackConfPropertiesFilePath() HAProxyTemplateFilePath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'haproxy.cfg') haproxyConfFilePath = PropertiesUtility.getValue(openstackConfPopertiesFilePath, 'HAPROXY_CONF_FILE_PATH') print 'haproxyConfFilePath=%s' % haproxyConfFilePath if not os.path.exists('/etc/haproxy') : ShellCmdExecutor.execCmd('sudo mkdir /etc/haproxy') pass if not os.path.exists(haproxyConfFilePath) : ShellCmdExecutor.execCmd('sudo cp -rf %s %s' % (HAProxyTemplateFilePath, haproxyConfFilePath)) pass ShellCmdExecutor.execCmd('sudo chmod 777 %s' % haproxyConfFilePath) dashboardBackendStringTemplate = ''' listen dashboard_cluster bind <DASHBOARD_VIP>:80 balance source option tcpka option httpchk option tcplog <DASHBOARD_SERVER_LIST> ''' ############### dashboardBackendString = dashboardBackendStringTemplate.replace('<DASHBOARD_VIP>', dashboard_vip) ################new dashboard_ips = JSONUtility.getValue("dashboard_ips") dashboard_ip_list = dashboard_ips.strip().split(',') serverDashboardBackendTemplate = 'server dashboard-<INDEX> <SERVER_IP>:8080 weight 3 check inter 2000 rise 2 fall 3' dashboardServerListContent = '' index = 1 for dashboard_ip in dashboard_ip_list: print 'dashboard_ip=%s' % dashboard_ip dashboardServerListContent += serverDashboardBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', dashboard_ip) dashboardServerListContent += '\n' dashboardServerListContent += ' ' index += 1 pass dashboardServerListContent = dashboardServerListContent.strip() print 'dashboardServerListContent=%s--' % dashboardServerListContent dashboardBackendString = dashboardBackendString.replace('<DASHBOARD_SERVER_LIST>', dashboardServerListContent) print 'dashboardBackendString=%s--' % dashboardBackendString #append FileUtil.replaceFileContent(haproxyConfFilePath, '<DASHBOARD_LIST>', dashboardBackendString) ShellCmdExecutor.execCmd('sudo chmod 644 %s' % haproxyConfFilePath)
def configConfFile(): print "configure keystone conf file======" mysql_vip = JSONUtility.getValue("mysql_vip") admin_token = JSONUtility.getValue("admin_token") #memcache service list keystone_ips_string = JSONUtility.getValue("keystone_ips") keystone_ip_list = keystone_ips_string.split(',') memcached_service_list = [] for ip in keystone_ip_list: memcached_service_list.append(ip.strip() + ':11211') pass memcached_service_string = ','.join(memcached_service_list) print 'memcached_service_string=%s--' % memcached_service_string openstackConfPopertiesFilePath = PropertiesUtility.getOpenstackConfPropertiesFilePath() keystoneConfDir = PropertiesUtility.getValue(openstackConfPopertiesFilePath, 'KEYSTONE_CONF_DIR') keystone_conf_file_path = os.path.join(keystoneConfDir, 'keystone.conf') if not os.path.exists(keystoneConfDir) : os.system("sudo mkdir -p %s" % keystoneConfDir) pass ShellCmdExecutor.execCmd("cp -r %s %s" % (SOURCE_KEYSTONE_CONF_FILE_TEMPLATE_PATH, keystoneConfDir)) ShellCmdExecutor.execCmd("sudo chmod 777 %s" % keystone_conf_file_path) # #if exist, remove original conf files # if os.path.exists(keystone_conf_file_path) : # os.system("sudo rm -rf %s" % keystone_conf_file_path) # pass # # ShellCmdExecutor.execCmd('chmod 777 /etc/keystone') # # # os.system("sudo cp -r %s %s" % (SOURCE_KEYSTONE_CONF_FILE_TEMPLATE_PATH, keystoneConfDir)) # ###NEW # ShellCmdExecutor.execCmd('cat %s > /tmp/keystone.conf' % SOURCE_KEYSTONE_CONF_FILE_TEMPLATE_PATH) # ShellCmdExecutor.execCmd('mv /tmp/keystone.conf /etc/keystone/') # # ShellCmdExecutor.execCmd("sudo chmod 777 %s" % keystone_conf_file_path) ###########LOCAL_IP:retrieve it from one file, the LOCAL_IP file is generated when this project inits. localIP = Keystone.getLocalIP() print 'localip=%s--' % localIP # FileUtil.replaceByRegularExpression(keystone_conf_file_path, '<LOCAL_IP>', localIP) # FileUtil.replaceByRegularExpression(keystone_conf_file_path, '<MYSQL_VIP>', mysql_vip) keystoneDbPass = JSONUtility.getValue('keystone_dbpass') FileUtil.replaceFileContent(keystone_conf_file_path, '<ADMIN_TOKEN>', admin_token) FileUtil.replaceFileContent(keystone_conf_file_path, '<LOCAL_MANAGEMENT_IP>', localIP) FileUtil.replaceFileContent(keystone_conf_file_path, '<MYSQL_VIP>', mysql_vip) FileUtil.replaceFileContent(keystone_conf_file_path, '<KEYSTONE_DBPASS>', keystoneDbPass) FileUtil.replaceFileContent(keystone_conf_file_path, '<MEMCACHED_LIST>', memcached_service_string) ShellCmdExecutor.execCmd("chmod 644 %s" % keystone_conf_file_path) print "configure keystone conf file done####" pass
def initKeystone(): admin_token = JSONUtility.getValue('admin_token') keystone_vip = JSONUtility.getValue('ha_vip1') keystone_admin_password = JSONUtility.getValue('keystone_admin_password') if Keystone.getServerIndex() == 0 : output, exitcode = ShellCmdExecutor.execCmd('cat /opt/localip') keystone_ip = output.strip() initKeystoneScriptPath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'keystone', 'initKeystone.sh') if not os.path.exists('/opt/openstack_conf/scripts') : os.system('mkdir -p /opt/openstack_conf/scripts') pass ShellCmdExecutor.execCmd('cp -r %s /opt/openstack_conf/scripts' % initKeystoneScriptPath) try: import pexpect #To make the interact string: Are you sure you want to continue connecting.* always appear if os.path.exists('/root/.ssh/known_hosts') : os.system('rm -rf /root/.ssh/known_hosts') pass # child = pexpect.spawn(scpCmd) cmd = 'bash %s' % initKeystoneScriptPath child = pexpect.spawn(cmd) #When do the first shell cmd execution, this interact message is appeared on shell. child.expect('User Password:'******'Repeat User Password:'******'exit') child.sendcontrol('c') #child.interact() except OSError: print 'Catch exception %s when send tag.' % OSError.strerror sys.exit(0) pass pass
def setMysqlHaproxyString(): ha_vip1 = JSONUtility.getValue('ha_vip1') mysqlBackendApiStringTemplate = ''' listen rdb_mysql bind <HA_VIP1>:3306 balance leastconn mode tcp option mysql-check user haproxy option tcpka option tcplog option clitcpka option srvtcpka timeout client 28801s timeout server 28801s <RDB_MYSQL_SERVER_LIST> ''' mysqlBackendString = mysqlBackendApiStringTemplate.replace('<HA_VIP1>', ha_vip1) mysql_ips = JSONUtility.getValue("mysql_ips") mysql_ip_list = mysql_ips.strip().split(',') #mysql master serverMysqlBacendString1 = 'server mysql1 %s:3306 check inter 2000 rise 2 fall 3' % mysql_ip_list[0] serverMysqlBackendTemplate = 'server mysql<INDEX> <SERVER_IP>:3306 backup check inter 2000 rise 2 fall 3' mysqlServerListContent = '' mysqlServerListContent += serverMysqlBacendString1 mysqlServerListContent += '\n' mysqlServerListContent += ' ' index = 2 if len(mysql_ip_list) > 1 : for mysql_ip in mysql_ip_list[1:] : print 'mysql_ip=%s' % mysql_ip mysqlServerListContent += serverMysqlBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', mysql_ip) mysqlServerListContent += '\n' mysqlServerListContent += ' ' index += 1 pass mysqlServerListContent = mysqlServerListContent.strip() print 'mysqlServerListContent=%s--' % mysqlServerListContent mysqlBackendString = mysqlBackendString.replace('<RDB_MYSQL_SERVER_LIST>', mysqlServerListContent) print 'mysqlBackendString=%s--' % mysqlBackendString HA.appendBackendStringToHaproxyCfg(mysqlBackendString) pass
def configConfFile(): ''' LOCAL_MANAGEMENT_IP KEYSTONE_VIP ''' localSettingsFileTemplatePath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'dashboard', 'local_settings') dashboardConfFileDir = '/etc/openstack-dashboard/' if os.path.exists(Dashboard.DASHBOARD_CONF_FILE_PATH) : ShellCmdExecutor.execCmd("rm -rf %s" % Dashboard.DASHBOARD_CONF_FILE_PATH) pass else : ShellCmdExecutor.execCmd("sudo mkdir %s" % dashboardConfFileDir) pass print 'localSettingsFileTemplatePath=%s--' % localSettingsFileTemplatePath ShellCmdExecutor.execCmd("sudo chmod 777 %s" % dashboardConfFileDir) ####NEW ShellCmdExecutor.execCmd('cat %s > /tmp/local_settings' % localSettingsFileTemplatePath) ShellCmdExecutor.execCmd('cp -r /tmp/local_settings %s' % dashboardConfFileDir) ShellCmdExecutor.execCmd('rm -rf /tmp/local_settings') keystone_vip = JSONUtility.getValue("keystone_vip") print "keystone_vip=%s" % keystone_vip output, exitcode = ShellCmdExecutor.execCmd('cat /opt/localip') localIP = output.strip() dashboard_ips_string = JSONUtility.getValue("dashboard_ips") dashboard_ip_list = dashboard_ips_string.split(',') memcached_service_list = [] for ip in dashboard_ip_list: memcached_service_list.append(ip.strip() + ':11211') pass memcached_service_string = ','.join(memcached_service_list) print 'memcached_service_string=%s--' % memcached_service_string ShellCmdExecutor.execCmd('sudo chmod 777 %s' % Dashboard.DASHBOARD_CONF_FILE_PATH) FileUtil.replaceFileContent(Dashboard.DASHBOARD_CONF_FILE_PATH, '<KEYSTONE_VIP>', keystone_vip) FileUtil.replaceFileContent(Dashboard.DASHBOARD_CONF_FILE_PATH, '<LOCAL_MANAGEMENT_IP>', localIP) ShellCmdExecutor.execCmd('sudo chmod 644 %s' % Dashboard.DASHBOARD_CONF_FILE_PATH) #Assign rights: can be accessed DIR_PATH = '/usr/share/openstack-dashboard/openstack_dashboard/local' if os.path.exists(DIR_PATH) : ShellCmdExecutor.execCmd('sudo chmod 777 %s' % DIR_PATH) pass pass
def install(): print 'Cinder-storage.install start====' keystone_vip = JSONUtility.getValue('keystone_vip') print 'start to install prerequisites=============' script_file_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'cinder-storage', 'cinder_storage_service.sh') ShellCmdExecutor.execCmd('cp -r %s /opt/' % script_file_path) ShellCmdExecutor.execCmd('chmod 777 /opt/cinder_storage_service.sh') FileUtil.replaceFileContent('/opt/cinder_storage_service.sh', '<KEYSTONE_VIP>', keystone_vip) ShellCmdExecutor.execCmd('bash /opt/cinder_storage_service.sh') print 'install prerequisites done####' yumCmd = 'yum install lvm2 -y' ShellCmdExecutor.execCmd(yumCmd) ShellCmdExecutor.execCmd("/etc/init.d/lvm2-lvmetad start") ShellCmdExecutor.execCmd("chkconfig lvm2-lvmetad on") #Default create volume #Create the LVM physical volume /dev/sdb1: # createCmd = 'pvcreate /dev/sdb1' # ShellCmdExecutor.execCmd(createCmd) # createCmd = 'vgcreate cinder-volumes /dev/sdb1' # ShellCmdExecutor.execCmd(createCmd) yumCmd = 'yum install openstack-cinder python-oslo-db MySQL-python -y' ShellCmdExecutor.execCmd(yumCmd) print 'Cinder-storage.install done####' pass
def setNeutronHaproxyString(): neutronServerBackendApiStringTemplate = ''' listen neutron_api bind 0.0.0.0:9696 balance roundrobin option httplog <NEUTRON_SERVER_LIST> ''' neutronServerBackendString = neutronServerBackendApiStringTemplate neutron_ips = JSONUtility.getValue("neutron_ips") neutron_ip_list = neutron_ips.strip().split(',') serverNeutronServerBackendTemplate = 'server coreapi<INDEX> <SERVER_IP>:9696 check inter 2000 rise 2 fall 3' neutronServerListContent = '' index = 1 for ip in neutron_ip_list : neutronServerListContent += serverNeutronServerBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', ip) neutronServerListContent += '\n' neutronServerListContent += ' ' index += 1 pass neutronServerListContent = neutronServerListContent.strip() print 'neutronServerListContent=%s--' % neutronServerListContent neutronServerBackendString = neutronServerBackendString.replace('<NEUTRON_SERVER_LIST>', neutronServerListContent) print 'neutronServerBackendString=%s--' % neutronServerBackendString HA.appendBackendStringToHaproxyCfg(neutronServerBackendString) pass
def setCeilometerHaproxyString(): ceilometerServerBackendString = ''' listen ceilometer_api bind 0.0.0.0:8777 balance roundrobin option httplog <CEILOMETER_SERVER_LIST> ''' ceilometer_ips = JSONUtility.getValue("ceilometer_ips") ceilometer_ip_list = ceilometer_ips.strip().split(',') serverCeilometerBackendTemplate = 'server ceilometer<INDEX> <SERVER_IP>:8777 check inter 2000 rise 2 fall 3' ceilometerServerListContent = '' index = 1 for ip in ceilometer_ip_list : ceilometerServerListContent += serverCeilometerBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', ip) ceilometerServerListContent += '\n' ceilometerServerListContent += ' ' index += 1 pass ceilometerServerListContent = ceilometerServerListContent.strip() print 'ceilometerServerListContent=%s--' % ceilometerServerListContent ceilometerServerBackendString = ceilometerServerBackendString.replace('<CEILOMETER_SERVER_LIST>', ceilometerServerListContent) print 'ceilometerServerBackendString=%s--' % ceilometerServerBackendString HA.appendBackendStringToHaproxyCfg(ceilometerServerBackendString) pass
def configureEnvVar(): ShellCmdExecutor.execCmd('export OS_SERVICE_TOKEN=123456') template_string = 'export OS_SERVICE_ENDPOINT=http://<KEYSTONE_VIP>:35357/v2.0' keystone_vip = JSONUtility.getValue('keystone_vip') cmd = template_string.replace('<KEYSTONE_VIP>', keystone_vip) ShellCmdExecutor.execCmd(cmd) pass
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 configConfFile(): localSettingsFileTemplatePath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'dashboard', 'local_settings') dashboardConfFileDir = '/etc/openstack-dashboard/' if os.path.exists(Dashboard.DASHBOARD_CONF_FILE_PATH) : ShellCmdExecutor.execCmd("rm -rf %s" % Dashboard.DASHBOARD_CONF_FILE_PATH) pass else : ShellCmdExecutor.execCmd("sudo mkdir %s" % dashboardConfFileDir) pass print 'localSettingsFileTemplatePath=%s--' % localSettingsFileTemplatePath ShellCmdExecutor.execCmd("sudo chmod 777 %s" % dashboardConfFileDir) ####NEW ShellCmdExecutor.execCmd('cat %s > /tmp/local_settings' % localSettingsFileTemplatePath) ShellCmdExecutor.execCmd('mv /tmp/local_settings %s' % dashboardConfFileDir) keystone_vip = JSONUtility.getValue("keystone_vip") ShellCmdExecutor.execCmd('sudo chmod 777 %s' % Dashboard.DASHBOARD_CONF_FILE_PATH) FileUtil.replaceFileContent(Dashboard.DASHBOARD_CONF_FILE_PATH, '<KEYSTONE_VIP>', keystone_vip) ShellCmdExecutor.execCmd('sudo chmod 644 %s' % Dashboard.DASHBOARD_CONF_FILE_PATH) #Assign rights: can be accessed DIR_PATH = '/usr/share/openstack-dashboard/openstack_dashboard/local' if os.path.exists(DIR_PATH) : ShellCmdExecutor.execCmd('sudo chmod 777 %s' % DIR_PATH) pass pass
def configureKeepalived(): openstackConfPopertiesFilePath = PropertiesUtility.getOpenstackConfPropertiesFilePath() ###################configure keepalived glanceKeepalivedTemplateFilePath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'keepalived.conf') keepalivedConfFilePath = PropertiesUtility.getValue(openstackConfPopertiesFilePath, 'KEEPALIVED_CONF_FILE_PATH') print 'keepalivedConfFilePath=%s' % keepalivedConfFilePath if not os.path.exists('/etc/keepalived') : ShellCmdExecutor.execCmd('sudo mkdir /etc/keepalived') pass #configure haproxy check script in keepalived checkHAProxyScriptPath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'check_haproxy.sh') print 'checkHAProxyScriptPath=%s===========================---' % checkHAProxyScriptPath ShellCmdExecutor.execCmd('sudo cp -r %s %s' % (checkHAProxyScriptPath, '/etc/keepalived')) if os.path.exists(keepalivedConfFilePath) : ShellCmdExecutor.execCmd("sudo rm -rf %s" % keepalivedConfFilePath) pass ShellCmdExecutor.execCmd('sudo cp -r %s %s' % (glanceKeepalivedTemplateFilePath, '/etc/keepalived')) ShellCmdExecutor.execCmd("sudo chmod 777 %s" % keepalivedConfFilePath) ##configure nova_vip = JSONUtility.getValue("nova_vip") nova_vip_interface = JSONUtility.getValue("nova_vip_interface") weight_counter = 300 if NovaHA.isMasterNode() : weight_counter = 300 state = 'MASTER' pass else : index = NovaHA.getIndex() #get this host index which is indexed by the gid in /etc/astutue.yaml responding with this role weight_counter = 300 - index state = 'SLAVE' + str(index) pass FileUtil.replaceFileContent(keepalivedConfFilePath, '<WEIGHT>', str(weight_counter)) FileUtil.replaceFileContent(keepalivedConfFilePath, '<STATE>', state) FileUtil.replaceFileContent(keepalivedConfFilePath, '<INTERFACE>', nova_vip_interface) FileUtil.replaceFileContent(keepalivedConfFilePath, '<VIRTURL_IPADDR>', nova_vip) ##temporary: if current user is not root ShellCmdExecutor.execCmd("sudo chmod 644 %s" % keepalivedConfFilePath) #If keepalived need to support more VIP: append here pass
def setKeystoneHaproxyString(): keystoneBackendPublicApiStringTemplate = ''' listen keystone_common bind 0.0.0.0:5000 balance roundrobin option httplog <KEYSTONE_PUBLIC_API_SERVER_LIST> ''' keystoneBackendAdminApiStringTemplate = ''' listen keystone_admin bind 0.0.0.0:35357 balance roundrobin option httplog <KEYSTONE_ADMIN_API_SERVER_LIST> ''' keystoneBackendAdminApiString = keystoneBackendAdminApiStringTemplate keystoneBackendPublicApiString = keystoneBackendPublicApiStringTemplate keystone_ips = JSONUtility.getValue("keystone_ips") keystone_ip_list = keystone_ips.strip().split(',') serverKeystoneAdminAPIBackendTemplate = 'server keystone<INDEX> <SERVER_IP>:35357 check inter 2000 rise 2 fall 3' serverKeystonePublicAPIBackendTemplate = 'server keystone<INDEX> <SERVER_IP>:5000 check inter 2000 rise 2 fall 3' keystoneAdminAPIServerListContent = '' keystonePublicAPIServerListContent = '' index = 1 for keystone_ip in keystone_ip_list: print 'keystone_ip=%s' % keystone_ip keystoneAdminAPIServerListContent += serverKeystoneAdminAPIBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', keystone_ip) keystonePublicAPIServerListContent += serverKeystonePublicAPIBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', keystone_ip) keystoneAdminAPIServerListContent += '\n' keystoneAdminAPIServerListContent += ' ' keystonePublicAPIServerListContent += '\n' keystonePublicAPIServerListContent += ' ' index += 1 pass keystoneAdminAPIServerListContent = keystoneAdminAPIServerListContent.strip() keystonePublicAPIServerListContent = keystonePublicAPIServerListContent.strip() print 'keystoneAdminAPIServerListContent=%s--' % keystoneAdminAPIServerListContent print 'keystonePublicAPIServerListContent=%s--' % keystonePublicAPIServerListContent keystoneBackendAdminApiString = keystoneBackendAdminApiString.replace('<KEYSTONE_ADMIN_API_SERVER_LIST>', keystoneAdminAPIServerListContent) keystoneBackendPublicApiString = keystoneBackendPublicApiString.replace('<KEYSTONE_PUBLIC_API_SERVER_LIST>', keystonePublicAPIServerListContent) print 'keystoneBackendAdminApiString=%s--' % keystoneBackendAdminApiString print 'keystoneBackendPublicApiString=%s--' % keystoneBackendPublicApiString HA.appendBackendStringToHaproxyCfg(keystoneBackendPublicApiString) HA.appendBackendStringToHaproxyCfg(keystoneBackendAdminApiString) pass
def setNovaHaproxyString(): novaComputeApiBackendStringTemplate = ''' listen nova_compute_api bind 0.0.0.0:8774 balance roundrobin option httplog <NOVA_COMPUTE_API_SERVER_LIST> ''' novaMetadataApiBackendStringTemplate = ''' listen nova_metadata_api bind 0.0.0.0:8775 balance roundrobin option httplog <NOVA_METADATA_API_SERVER_LIST> ''' nova_api_ips = JSONUtility.getValue("nova_ips") nova_api_ip_list = nova_api_ips.strip().split(',') novaComputeApiBackendString = novaComputeApiBackendStringTemplate novaMetadataApiBackendString = novaMetadataApiBackendStringTemplate ############### serverNovaMetadataAPIBackendTemplate = 'server coreapi<INDEX> <SERVER_IP>:8775 check inter 2000 rise 2 fall 3' serverNovaComputeAPIBackendTemplate = 'server coreapi<INDEX> <SERVER_IP>:8774 check inter 2000 rise 2 fall 3' novaMetadataAPIServerListContent = '' novaComputeAPIServerListContent = '' index = 1 for nova_api_ip in nova_api_ip_list: print 'nova_api_ip=%s' % nova_api_ip novaMetadataAPIServerListContent += serverNovaMetadataAPIBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', nova_api_ip) novaComputeAPIServerListContent += serverNovaComputeAPIBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', nova_api_ip) novaMetadataAPIServerListContent += '\n' novaMetadataAPIServerListContent += ' ' novaComputeAPIServerListContent += '\n' novaComputeAPIServerListContent += ' ' index += 1 pass novaMetadataAPIServerListContent = novaMetadataAPIServerListContent.strip() novaComputeAPIServerListContent = novaComputeAPIServerListContent.strip() print 'novaMetadataAPIServerListContent=%s--' % novaMetadataAPIServerListContent print 'novaComputeAPIServerListContent=%s--' % novaComputeAPIServerListContent novaMetadataApiBackendString = novaMetadataApiBackendString.replace('<NOVA_METADATA_API_SERVER_LIST>', novaMetadataAPIServerListContent) novaComputeApiBackendString = novaComputeApiBackendString.replace('<NOVA_COMPUTE_API_SERVER_LIST>', novaComputeAPIServerListContent) print 'novaMetadataApiBackendString=\n%s\n--' % novaMetadataApiBackendString print 'novaComputeApiBackendString=\n%s\n--' % novaComputeApiBackendString HA.appendBackendStringToHaproxyCfg(novaComputeApiBackendString) HA.appendBackendStringToHaproxyCfg(novaMetadataApiBackendString) pass
def reconfigureNovaCompute(): neutron_vip = JSONUtility.getValue("neutron_vip") keystone_vip = JSONUtility.getValue("keystone_vip") APIsAndDrivers = ''' network_api_class = nova.network.neutronv2.api.API security_group_api = neutron linuxnet_interface_driver = nova.network.linux_net.LinuxOVSInterfaceDriver firewall_driver = nova.virt.firewall.NoopFirewallDriver ''' APIsAndDrivers = APIsAndDrivers.strip() AccessParameters = ''' [neutron] url = http://<NEUTRON_VIP>:9696 auth_strategy = keystone admin_auth_url = http://<KEYSTONE_VIP>:35357/v2.0 admin_tenant_name = service admin_username = neutron admin_password = <NEUTRON_PASS> ''' AccessParameters = AccessParameters.strip() AccessParameters = AccessParameters.replace('<NEUTRON_VIP>', neutron_vip) AccessParameters = AccessParameters.replace('<KEYSTONE_VIP>', keystone_vip) #REFACTOR LATER neutron_pass = '******' AccessParameters = AccessParameters.replace('<NEUTRON_PASS>', neutron_pass) NOVA_CONF_FILE_PATH = '/etc/nova/nova.conf' FileUtil.replaceFileContent(NOVA_CONF_FILE_PATH, '#APIsAndDrivers', APIsAndDrivers) FileUtil.replaceFileContent(NOVA_CONF_FILE_PATH, '#AccessParameters', AccessParameters) ############################## FileUtil.replaceFileContent(NOVA_CONF_FILE_PATH, '#vif_plugging_is_fatal=true', 'vif_plugging_is_fatal=false') FileUtil.replaceFileContent(NOVA_CONF_FILE_PATH, '#vif_plugging_timeout=300', 'vif_plugging_timeout=0') pass
def sshMutualTrust(): fuel_ip = JSONUtility.getValue('fuel_ip') ShellCmdExecutor.execCmd('cp -r /root/.ssh/authorized_keys /root/.ssh/id_rsa.pub') # ShellCmdExecutor.execCmd('mkdir /root/.ssh/') # root_ssh_dir_path = '/root/.ssh' # id_rsa_file_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'ssh', 'id_rsa') # id_rsa_pub_file_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'ssh', 'id_rsa.pub') # authorized_keys_file_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'ssh', 'authorized_keys') #scp key from fuel master: #Why do like this way? #Because this way will not affect the action : on fuel master, ssh to any node without password. scp_cmd = 'scp root@{fuel_ip}:/root/.ssh/id_rsa /root/.ssh/'.format(fuel_ip=fuel_ip) try: import pexpect child = pexpect.spawn(scp_cmd) #When do the first shell cmd execution, this interact message is appeared on shell. child.expect('Are you sure you want to continue connecting.*') child.sendline('yes') expect_pass_string = "root@{fuel_ip}'s password:"******"r00tme" child.expect(expect_pass_string) child.sendline(fuel_root_password) while True : regex = "[\\s\\S]*" #match any index = child.expect([regex , pexpect.EOF, pexpect.TIMEOUT]) if index == 0: break elif index == 1: pass #continue to wait elif index == 2: pass #continue to wait child.sendline('exit') child.sendcontrol('c') #child.interact() except OSError: print 'Catch exception %s when send tag.' % OSError.strerror sys.exit(0) pass sshd_config_file_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'ssh', 'sshd_config') ShellCmdExecutor.execCmd('cp -r %s /etc/ssh/' % sshd_config_file_path) ShellCmdExecutor.execCmd('chmod 700 /root/.ssh/') ShellCmdExecutor.execCmd('chmod 400 /root/.ssh/authorized_keys') ShellCmdExecutor.execCmd('chmod 400 /root/.ssh/id_rsa') ShellCmdExecutor.execCmd('chmod 400 /root/.ssh/id_rsa.pub') ShellCmdExecutor.execCmd('chown -R root:root /root/.ssh/') ShellCmdExecutor.execCmd('/bin/systemctl restart sshd.service') pass
def configMetadataAgent(): if os.path.exists(Network.NEUTRON_METADATA_CONF_FILE_PATH) : ShellCmdExecutor.execCmd("rm -rf %s" % Network.NEUTRON_METADATA_CONF_FILE_PATH) pass neutron_metadata_template_conf_file_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'network', 'metadata_agent.ini') ShellCmdExecutor.execCmd('cat %s > /tmp/metadata_agent.ini' % neutron_metadata_template_conf_file_path) ShellCmdExecutor.execCmd('mv /tmp/metadata_agent.ini /etc/neutron/') keystone_vip = JSONUtility.getValue("keystone_vip") nova_vip = JSONUtility.getValue("nova_vip") keystone_neutron_password = JSONUtility.getValue("keystone_neutron_password") #REFACTOR LATER metadata_secret = '123456'#JSONUtility.getValue("metadata_secret") FileUtil.replaceFileContent(Network.NEUTRON_METADATA_CONF_FILE_PATH, '<KEYSTONE_VIP>', keystone_vip) FileUtil.replaceFileContent(Network.NEUTRON_METADATA_CONF_FILE_PATH, '<NOVA_VIP>', nova_vip) FileUtil.replaceFileContent(Network.NEUTRON_METADATA_CONF_FILE_PATH, '<KEYSTONE_NEUTRON_PASSWORD>', keystone_neutron_password) FileUtil.replaceFileContent(Network.NEUTRON_METADATA_CONF_FILE_PATH, '<METADATA_SECRET>', metadata_secret) pass
def setGlanceHaproxyString(): glanceBackendApiStringTemplate = ''' listen glance_api bind 0.0.0.0:9292 balance roundrobin option httplog <GLANCE_API_SERVER_LIST> ''' glanceBackendRegistryApiStringTemplate = ''' listen glance_registry bind 0.0.0.0:9191 balance roundrobin option httplog <GLANCE_REGISTRY_API_SERVER_LIST> ''' glance_ips = JSONUtility.getValue("glance_ips") glance_ip_list = glance_ips.strip().split(',') glanceBackendApiString = glanceBackendApiStringTemplate glanceBackendRegistryApiString = glanceBackendRegistryApiStringTemplate ############### serverGlanceRegistryAPIBackendTemplate = 'server glance<INDEX> <SERVER_IP>:9191 check inter 2000 rise 2 fall 3' serverGlanceAPIBackendTemplate = 'server glance<INDEX> <SERVER_IP>:9292 check inter 2000 rise 2 fall 3' glanceRegistryAPIServerListContent = '' glanceAPIServerListContent = '' index = 1 for glance_ip in glance_ip_list: print 'glance_ip=%s' % glance_ip glanceRegistryAPIServerListContent += serverGlanceRegistryAPIBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', glance_ip) glanceAPIServerListContent += serverGlanceAPIBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', glance_ip) glanceRegistryAPIServerListContent += '\n' glanceRegistryAPIServerListContent += ' ' glanceAPIServerListContent += '\n' glanceAPIServerListContent += ' ' index += 1 pass glanceRegistryAPIServerListContent = glanceRegistryAPIServerListContent.strip() glanceAPIServerListContent = glanceAPIServerListContent.strip() print 'glanceRegistryAPIServerListContent=%s--' % glanceRegistryAPIServerListContent print 'glanceAPIServerListContent=%s--' % glanceAPIServerListContent glanceBackendRegistryApiString = glanceBackendRegistryApiString.replace('<GLANCE_REGISTRY_API_SERVER_LIST>', glanceRegistryAPIServerListContent) glanceBackendApiString = glanceBackendApiString.replace('<GLANCE_API_SERVER_LIST>', glanceAPIServerListContent) HA.appendBackendStringToHaproxyCfg(glanceBackendApiString) HA.appendBackendStringToHaproxyCfg(glanceBackendRegistryApiString) pass
def sourceAdminOpenRC(): adminOpenRCScriptPath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'admin_openrc.sh') print 'adminOpenRCScriptPath=%s' % adminOpenRCScriptPath ShellCmdExecutor.execCmd('cp -rf %s /opt/' % adminOpenRCScriptPath) keystone_vip = JSONUtility.getValue("keystone_vip") FileUtil.replaceFileContent('/opt/admin_openrc.sh', '<KEYSTONE_VIP>', keystone_vip) time.sleep(2) ShellCmdExecutor.execCmd('source /opt/admin_openrc.sh') pass