示例#1
0
 def execCmdWithoutKillTimeout(cmd, ifPrint=None, env=None):
     if not cmd:
         return
     
     print('Executing cmd without timeout : %s' % cmd)
     output = None
     error = None
     outputFile = None
     outputFilePath = ""
     try :
         strTime = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
         strUUID = commands.getoutput('uuidgen')
         outputFileName = "output%s.%s.log" % (strTime, strUUID)
         if not os.path.exists(ShellCmdExecutor.OPENSTACK_INSTALL_LOG_TEMP_DIR) :
             os.system("mkdir -p %s" % ShellCmdExecutor.OPENSTACK_INSTALL_LOG_TEMP_DIR)
             pass
         
         outputFilePath = "%s/%s" % (ShellCmdExecutor.OPENSTACK_INSTALL_LOG_TEMP_DIR, outputFileName)
         print("OutputFileName=%s" % outputFilePath)
         outputFile=open(outputFilePath, 'w')
         
         if env != None :
             try:
                 import inspect
                 import json
                 stack = inspect.stack()
                 the_class = stack[2][0].f_locals["self"].__class__.__name__
                 if not os.path.exists("/var/log/autoops_env.json"):
                     record_env = {the_class: env}
                     content = json.dumps(record_env, sort_keys=True, indent=4)
                 else:
                     content_data = json.load(file("/var/log/autoops_env.json"))
                     content_data[the_class] = env
                     content = json.dumps(content_data, sort_keys=True, indent=4)
                 FileUtil.writeContent("/var/log/autoops_env.json", content)
             except Exception as ex:
                 print("Save parsed Env params Failed")
                 print(ex)
             env = dict(os.environ.items() + env.items())
             pass
         p = subprocess.Popen(cmd, shell=True, close_fds=True, stdout=outputFile, stderr=subprocess.PIPE, env=env)
         output, error = p.communicate()
         
         output = FileUtil.readContent(outputFilePath)
         
         if ifPrint :
             print("cmd output=%s---" % output)
         elif not ifPrint or ifPrint == None :
             pass
         
         if error!=None and error!="" :
             print("cmd error=%s---" % error)
             pass
         
         if error!=None and error!="" and cmd.find(".sh") > -1:
             error = "SOE: " + str(error)
     except Exception, e :
         print(e)
示例#2
0
 def getMeteringSecret():
     if not os.path.exists(Ceilometer.METERING_SECRET_FILE_PATH) :
         output, exitcode = ShellCmdExecutor.execCmd("openssl rand -hex 10")
         meteringSecret = output.strip()
         FileUtil.writeContent(Ceilometer.METERING_SECRET_FILE_PATH, meteringSecret)
         pass
     
     output, exitcode = ShellCmdExecutor.execCmd('cat %s' % Ceilometer.METERING_SECRET_FILE_PATH)
     
     meteringSecret = output.strip()
     
     return meteringSecret
示例#3
0
 def writeIPList(role):
     #Default, in /opt/{role}_ip_list
     ipList = YAMLUtil.getRoleIPList(role)
     ipListContent = ','.join(ipList)
     ip_list_file_path = '/opt/{role}_ip_list'.format(role=role).replace('-', '_')
     
     if os.path.exists(ip_list_file_path) :
         ShellCmdExecutor.execCmd('rm -rf %s' % ip_list_file_path)
         pass
     
     FileUtil.writeContent(ip_list_file_path, ipListContent)
     pass
示例#4
0
 def setHosts():
     nodes_dict = {}
     host="127.0.0.1 localhost\n"
     nodesMap = YAMLUtil.getNodesMap()
     for node in nodesMap:
         if nodes_dict.has_key(node['ip']) == False:
             nodes_dict[node['ip']]=node['name']
             host = host + node['ip'] + " " + node['name'] + "\n"
             pass
         pass
      
     print host
     FileUtil.writeContent("/etc/hosts",host)
     pass    
示例#5
0
文件: Test.py 项目: zbwzy/fuel-python
    def test():
        haproxyConfFilePath = "/etc/haproxy/haproxy.cfg"
        if os.path.exists(haproxyConfFilePath):
            output, exitcode = ShellCmdExecutor.execCmd("cat %s" % haproxyConfFilePath)
        else:
            output = """
global
  daemon
  group haproxy
  log /dev/log local0
  maxconn 16000
  pidfile /var/run/haproxy.pid
  stats socket /var/lib/haproxy/stats
  user haproxy

defaults
  log global
  maxconn 8000
  mode http
  retries 3
  stats enable
  timeout http-request 10s
  timeout queue 1m
  timeout connect 10s
  timeout client 1m
  timeout server 1m
  timeout check 10s

            """
            pass

        print "nativecontent=%s-----" % output
        haproxyNativeContent = output.strip()

        haproxyContent = ""
        haproxyContent += haproxyNativeContent
        haproxyContent += "\n\n"

        haproxyContent += "hello"
        haproxyContent += "\n"
        haproxyContent += "world"

        FileUtil.writeContent("/tmp/haproxy.cfg", haproxyContent)
        ShellCmdExecutor.execCmd("sudo cp -rf /tmp/haproxy.cfg /etc/haproxy")

        ShellCmdExecutor.execCmd("sudo chmod 644 %s" % haproxyConfFilePath)
        pass
示例#6
0
文件: Test.py 项目: zbwzy/fuel-python
    def test():
        haproxyConfFilePath = '/etc/haproxy/haproxy.cfg'
        if os.path.exists(haproxyConfFilePath) :
            output, exitcode = ShellCmdExecutor.execCmd('cat %s' % haproxyConfFilePath)
        else :
            output = '''
global
  daemon
  group haproxy
  log /dev/log local0
  maxconn 16000
  pidfile /var/run/haproxy.pid
  stats socket /var/lib/haproxy/stats
  user haproxy

defaults
  log global
  maxconn 8000
  mode http
  retries 3
  stats enable
  timeout http-request 10s
  timeout queue 1m
  timeout connect 10s
  timeout client 1m
  timeout server 1m
  timeout check 10s

            '''
            pass
        
        print 'nativecontent=%s-----' % output
        haproxyNativeContent = output.strip()
        
        haproxyContent = ''
        haproxyContent += haproxyNativeContent
        haproxyContent += '\n\n'
        
        haproxyContent += 'hello'
        haproxyContent += '\n'
        haproxyContent += 'world'
        
        FileUtil.writeContent('/tmp/haproxy.cfg', haproxyContent)
        ShellCmdExecutor.execCmd('sudo cp -rf /tmp/haproxy.cfg /etc/haproxy')
        
        ShellCmdExecutor.execCmd('sudo chmod 644 %s' % haproxyConfFilePath)
        pass
示例#7
0
    def appendBackendStringToHaproxyCfg(backendString):
        output, exitcode = ShellCmdExecutor.execCmd('cat %s' % HA.HaproxyConfFilePath)
        haproxyNativeContent = output.strip()

        haproxyContent = ''
        haproxyContent += haproxyNativeContent
        haproxyContent += '\n\n'
        haproxyContent += backendString
        FileUtil.writeContent('/tmp/haproxy.cfg', haproxyContent)
        
        if os.path.exists(HA.HaproxyConfFilePath):
            ShellCmdExecutor.execCmd("rm -rf %s" % HA.HaproxyConfFilePath)
            pass
        
        ShellCmdExecutor.execCmd('mv /tmp/haproxy.cfg /etc/haproxy/')
        ShellCmdExecutor.execCmd('sudo chmod 644 %s' % HA.HaproxyConfFilePath)
        pass
示例#8
0
 def execCmd(cmd, ifPrint=None, exitcodeSwitch=None, timeout=None, env=None):
     if timeout == None :
         timeout = ShellCmdExecutor.DEFAULT_TIMEOUT
         pass
     
     if exitcodeSwitch == None:
         exitcodeSwitch = False
         pass
     
     if not cmd:
         return
     #write cmd to a temp file in order to support multiple shell commands execution
     msg = 'Executing cmd with timeout(timeout=%s s): %s' % (timeout, cmd)
     print(msg)
     
     strTime = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
     strUUID = commands.getoutput('uuidgen')
     bashFileName = "bashfile-%s-%s.sh" % (strTime, strUUID)
     if not os.path.exists(ShellCmdExecutor.OPENSTACK_INSTALL_LOG_TEMP_DIR) :
         os.system("mkdir -p %s" % ShellCmdExecutor.OPENSTACK_INSTALL_LOG_TEMP_DIR)
         pass
     bashFilePath = "%s/%s" % (ShellCmdExecutor.OPENSTACK_INSTALL_LOG_TEMP_DIR, bashFileName)
     FileUtil.writeContent(bashFilePath, cmd)
     bash_cmd = "bash %s" % bashFilePath
     output = None
     exitcode = -1
     
     try :
         output, exitcode = ShellCmdExecutor.execCmdWithKillTimeout(bash_cmd, ifPrint=ifPrint, kill_timeout=timeout, env=env)
         if exitcodeSwitch :
             if exitcode != 0 :
                 print("otuput=%s" % output)
                 print("exitcode=%s" % exitcode)
                 pass
             else :
                 print("otuput=%s" % output)
                 print("exitcode=%s" % exitcode)
                 pass
             pass
         pass
     except Exception, e:
         print("Write content exception:" + str(e))
示例#9
0
    def configureHAProxy():
        ####################configure haproxy
        #server heat-01 192.168.1.137:8004 check inter 10s
        ceilometer_vip = JSONUtility.getValue("ceilometer_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('cat %s > /tmp/haproxy.cfg' % HAProxyTemplateFilePath)
            ShellCmdExecutor.execCmd('mv /tmp/haproxy.cfg /etc/haproxy/')
            ShellCmdExecutor.execCmd('rm -rf /tmp/haproxy.cfg')
            pass
        
        ShellCmdExecutor.execCmd('sudo chmod 777 %s' % haproxyConfFilePath)
        
        #############
        ceilometerBackendApiStringTemplate = '''
listen ceilometer_api_cluster
  bind <CEILOMETER_VIP>:8777
  balance source
  <CEILOMETER_API_SERVER_LIST>
  '''
        ceilometerBackendApiString = ceilometerBackendApiStringTemplate.replace('<CEILOMETER_VIP>', ceilometer_vip)
        
        ################new
        ceilometer_ips = JSONUtility.getValue("ceilometer_ips")
        ceilometer_ip_list = ceilometer_ips.strip().split(',')
        
        serverCeilometerAPIBackendTemplate   = 'server ceilometer-<INDEX> <SERVER_IP>:8777 check inter 2000 rise 2 fall 5'
        
        ceilometerAPIServerListContent = ''
        
        index = 1
        for ip in ceilometer_ip_list:
            print 'ceilometer_ip=%s' % ip
            ceilometerAPIServerListContent += serverCeilometerAPIBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', ip)
            
            ceilometerAPIServerListContent += '\n'
            ceilometerAPIServerListContent += '  '
            
            index += 1
            pass
        
        ceilometerAPIServerListContent = ceilometerAPIServerListContent.strip()
        print 'ceilometerAPIServerListContent=%s--' % ceilometerAPIServerListContent
        
        ceilometerBackendApiString = ceilometerBackendApiString.replace('<CEILOMETER_API_SERVER_LIST>', ceilometerAPIServerListContent)
        
        print 'ceilometerBackendApiString=%s--' % ceilometerBackendApiString
        
        #append
#         ShellCmdExecutor.execCmd('sudo echo "%s" >> %s' % (heatBackendApiString, haproxyConfFilePath))

        if os.path.exists(haproxyConfFilePath) :
            output, exitcode = ShellCmdExecutor.execCmd('cat %s' % haproxyConfFilePath)
        else :
            output, exitcode = ShellCmdExecutor.execCmd('cat %s' % HAProxyTemplateFilePath)
            pass
        
        haproxyNativeContent = output.strip()

        haproxyContent = ''
        haproxyContent += haproxyNativeContent
        haproxyContent += '\n\n'
        haproxyContent += ceilometerBackendApiString
        FileUtil.writeContent('/tmp/haproxy.cfg', haproxyContent)
        if os.path.exists(haproxyConfFilePath):
            ShellCmdExecutor.execCmd("sudo rm -rf %s" % haproxyConfFilePath)
            pass
        ShellCmdExecutor.execCmd('mv /tmp/haproxy.cfg /etc/haproxy/')
        ShellCmdExecutor.execCmd('rm -rf /tmp/haproxy.cfg')
        
        ShellCmdExecutor.execCmd('sudo chmod 644 %s' % haproxyConfFilePath)
        pass
示例#10
0
    def configureHAProxy():
        ####################configure haproxy
        neutron_vip = JSONUtility.getValue("neutron_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 -r %s %s' % (HAProxyTemplateFilePath, '/etc/haproxy'))
            pass
        
        ShellCmdExecutor.execCmd('sudo chmod 777 %s' % haproxyConfFilePath)
        
        ####
        ##############new
        neutronApiBackendStringTemplate = '''
listen neutron_api_cluster
  bind <NEUTRON_VIP>:9696
  balance source
  <NEUTRON_API_SERVER_LIST>
  '''

        neutronApiBackendString = neutronApiBackendStringTemplate.replace('<NEUTRON_VIP>', neutron_vip)
        
        ################new
        neutron_ips = JSONUtility.getValue("neutron_ips")
        neutron_ip_list = neutron_ips.strip().split(',')
        
        serverNeutronAPIBackendTemplate   = 'server neutron-<INDEX> <SERVER_IP>:9696 check inter 2000 rise 2 fall 5'
        neutronAPIServerListContent = ''
        index = 1
        for ip in neutron_ip_list:
            print 'neutron_ip=%s' % ip
            neutronAPIServerListContent += serverNeutronAPIBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', ip)
            
            neutronAPIServerListContent += '\n'
            neutronAPIServerListContent += '  '
            index += 1
            pass
        
        neutronAPIServerListContent = neutronAPIServerListContent.strip()
        print 'neutronAPIServerListContent=%s--' % neutronAPIServerListContent
        
        neutronApiBackendString = neutronApiBackendString.replace('<NEUTRON_API_SERVER_LIST>', neutronAPIServerListContent)
        
        print 'neutronApiBackendString=%s--' % neutronApiBackendString
        
        #append
        if os.path.exists(haproxyConfFilePath) :
            output, exitcode = ShellCmdExecutor.execCmd('cat %s' % haproxyConfFilePath)
        else :
            output, exitcode = ShellCmdExecutor.execCmd('cat %s' % HAProxyTemplateFilePath)
            pass
        
        haproxyNativeContent = output.strip()
        
        haproxyContent = ''
        haproxyContent += haproxyNativeContent
        haproxyContent += '\n\n'
        
        haproxyContent += neutronApiBackendString
        
        FileUtil.writeContent('/tmp/haproxy.cfg', haproxyContent)
        if os.path.exists(haproxyConfFilePath):
            ShellCmdExecutor.execCmd("sudo rm -rf %s" % haproxyConfFilePath)
            pass
        ShellCmdExecutor.execCmd('mv /tmp/haproxy.cfg /etc/haproxy/')
        #############
        ShellCmdExecutor.execCmd('sudo chmod 644 %s' % haproxyConfFilePath)
        pass
示例#11
0
    def execCmdWithKillTimeout(cmd, ifPrint=None, kill_timeout=600, env=None):
        if not cmd:
            return
        
        output = None
        outputFile = None
        exitcode = -1
        outputFilePath = ""
        content = ""
        try :
            if kill_timeout == None :
                kill_timeout = ShellCmdExecutor.DEFAULT_TIMEOUT
                pass
            strTime = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
            strUUID = commands.getoutput('uuidgen')
            outputFileName = "output%s.%s.log" % (strTime, strUUID)
            
            ######################################
            cmd = cmd.strip()
            if cmd.startswith("bash") :
                scriptPath = cmd.strip().lstrip("bash").strip()
                content = FileUtil.readContent(scriptPath)
                #get script name
                content = content.strip()
                if content.startswith("bash") or content.startswith("sh") or content.startswith("python") or content.startswith("ruby"):
                    strCmd = content.strip()
                    elements = strCmd.split(" ")
                    scriptName = elements[1].split("/")[-1]
                    outputFileName = "%s-%s-%s.log" % (scriptName, strTime, strUUID)
                    pass
                elif content.startswith("./"):
                    pass
                pass
            ######################################
            outputDir = "/var/log/autoopsscriptslog"
            if not os.path.exists(outputDir) :
                os.system("mkdir -p %s" % outputDir)
                pass
            
            outputFilePath = "%s/%s" % (outputDir, outputFileName)
            print("OutputFileName=%s" % outputFilePath)
            print(content)
            outputFile=open(outputFilePath, 'w')
            
            current_dir = os.path.dirname(__file__)
            print "current_dir=%s" % current_dir
            timeout3ScriptPath= "%s/timeout3.sh" % current_dir
            timeoutCmd = "bash %s -t %s -i 1 -d 1 %s" % (timeout3ScriptPath, kill_timeout, cmd)
            #print("you can check the cmd %s logs @ %s if the cmd execution time is long" % (cmd, outputFilePath))
            if env != None :
                try:
                    import inspect
                    import json
                    stack = inspect.stack()
                    the_class = stack[2][0].f_locals["self"].__class__.__name__
                    if not os.path.exists("/var/log/autoops_env.json"):
                        record_env = {the_class: env}
                        content = json.dumps(record_env, sort_keys=True, indent=4)
                    else:
                        content_data = json.load(file("/var/log/autoops_env.json"))
                        content_data[the_class] = env
                        content = json.dumps(content_data, sort_keys=True, indent=4)
                    FileUtil.writeContent("/var/log/autoops_env.json", content)
                except Exception as ex:
                    print("Save parsed Env params Failed")
                    print(ex)

                env = dict(os.environ.items() + env.items())
                pass
            p = subprocess.Popen(timeoutCmd, shell=True, close_fds=True, stdout=outputFile, stderr=subprocess.STDOUT, env=env)
            #ToDo: start a thread to print the logs to log file
            output, error = p.communicate()
            exitcode = p.returncode
            
            output = FileUtil.readContent(outputFilePath)
            
            if ifPrint :
                print("cmd output=%s---" % output)
                print("The returncode is : %s" % exitcode)
                pass
            elif not ifPrint or ifPrint == None :
                pass
        except Exception, e :
            print(e)
示例#12
0
    def configureHAProxy():
        ####################configure haproxy
        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
        
        ShellCmdExecutor.execCmd('sudo chmod 777 /etc/haproxy')
        
        if not os.path.exists(haproxyConfFilePath) :
#             ShellCmdExecutor.execCmd('sudo cp -r %s %s' % (HAProxyTemplateFilePath, '/etc/haproxy'))
            
            ShellCmdExecutor.execCmd('cat %s > /tmp/haproxy.cfg' % HAProxyTemplateFilePath)
            ShellCmdExecutor.execCmd('mv /tmp/haproxy.cfg /etc/haproxy/')
            pass
        
        ShellCmdExecutor.execCmd('sudo chmod 777 %s' % haproxyConfFilePath)
        
        ####
        ##############new
#         dashboardBackendStringTemplate = '''
# listen  localhost <DASHBOARD_VIP>:80
#   mode http
#   stats   uri  /haproxy
#   balance roundrobin
#   cookie  JSESSIONID prefix
#   stats   hide-version
#   option  httpclose
#   <DASHBOARD_SERVER_LIST>
#   '''
        
        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
        if os.path.exists(haproxyConfFilePath) :
            output, exitcode = ShellCmdExecutor.execCmd('cat %s' % haproxyConfFilePath)
        else :
            output, exitcode = ShellCmdExecutor.execCmd('cat %s' % HAProxyTemplateFilePath)
            pass
        
        haproxyNativeContent = output.strip()
        
        haproxyContent = ''
        haproxyContent += haproxyNativeContent
        haproxyContent += '\n\n'
        
        haproxyContent += dashboardBackendString
        
        FileUtil.writeContent('/tmp/haproxy.cfg', haproxyContent)
        if os.path.exists(haproxyConfFilePath):
            ShellCmdExecutor.execCmd("sudo rm -rf %s" % haproxyConfFilePath)
            pass
        ShellCmdExecutor.execCmd('mv /tmp/haproxy.cfg /etc/haproxy/')
        #############
        
        ShellCmdExecutor.execCmd('sudo chmod 644 %s' % haproxyConfFilePath)
        pass
示例#13
0
 def produce():
     print 'produe role ip list in /opt/{role}_ip_list======='
     for role in ParamsProducer.OPENSTACK_ROLES :
         if YAMLUtil.hasRoleInNodes(role) :
             YAMLUtil.writeIPList(role)
             pass
         pass
     
     print 'produce local ip in /opt/localip'
     localIPPath = '/opt/localip'
     FileUtil.writeContent(localIPPath, YAMLUtil.getLocalIP())    
     
     print 'produce all params in /opt/openstack_conf/openstack_params.json'
     paramsMap = {}
     #global variables
     print 'global==========================='
     admin_token = YAMLUtil.getValue('global', 'admin_token')
     paramsMap['admin_token'] = admin_token
     
     cinder_dbpass = YAMLUtil.getValue('global', 'cinder_dbpass')
     paramsMap['cinder_dbpass'] = cinder_dbpass
     
     keystone_heat_password = YAMLUtil.getValue('global', 'keystone_heat_password')
     paramsMap['keystone_heat_password'] = keystone_heat_password
     
     keystone_neutron_password = YAMLUtil.getValue('global', 'keystone_neutron_password')
     paramsMap['keystone_neutron_password'] = keystone_neutron_password
     
     keystone_admin_password = YAMLUtil.getValue('global', 'keystone_admin_password')
     paramsMap['keystone_admin_password'] = keystone_admin_password
     
     keystone_glance_password = YAMLUtil.getValue('global', 'keystone_glance_password')
     paramsMap['keystone_glance_password'] = keystone_glance_password
     
     neutron_dbpass = YAMLUtil.getValue('global', 'neutron_dbpass')
     paramsMap['neutron_dbpass'] = neutron_dbpass
     
     keystone_cinder_password = YAMLUtil.getValue('global', 'keystone_cinder_password')
     paramsMap['keystone_cinder_password'] = keystone_cinder_password
     
     nova_dbpass = YAMLUtil.getValue('global', 'nova_dbpass')
     paramsMap['nova_dbpass'] = nova_dbpass
     
     keystone_nova_password = YAMLUtil.getValue('global', 'keystone_nova_password')
     paramsMap['keystone_nova_password'] = keystone_nova_password
     
     ceilometer_dbpass = YAMLUtil.getValue('global', 'ceilometer_dbpass')
     paramsMap['ceilometer_dbpass'] = ceilometer_dbpass
     
     heat_dbpass = YAMLUtil.getValue('global', 'heat_dbpass')
     paramsMap['heat_dbpass'] = heat_dbpass
     
     bclinux_repo_url = YAMLUtil.getValue('global', 'bclinux_repo_url')
     paramsMap['bclinux_repo_url'] = bclinux_repo_url
     
     glance_dbpass = YAMLUtil.getValue('global', 'glance_dbpass')
     paramsMap['glance_dbpass'] = glance_dbpass
     
     keystone_dbpass = YAMLUtil.getValue('global', 'keystone_dbpass')
     paramsMap['keystone_dbpass'] = keystone_dbpass
     
     keystone_ceilometer_password = YAMLUtil.getValue('global', 'keystone_ceilometer_password')
     paramsMap['keystone_ceilometer_password'] = keystone_ceilometer_password
     
     cluster_id = YAMLUtil.getValue('global', 'cluster_id')
     paramsMap['cluster_id'] = cluster_id
     
     fuel_master_ip = YAMLUtil.getValue('global', 'fuel_master_ip')
     paramsMap['fuel_master_ip'] = fuel_master_ip
     
     print 'mysql============================'
     #Judge whether current host is mysql role
     role = 'mysql'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         key = 'mysql_vip'
         mysql_vip = YAMLUtil.getValue(role, key)
         
         key = 'mysql_vip_interface'
         mysql_vip_interface = YAMLUtil.getValue(role, key)
         
         key = 'root_password'
         mysql_root_password = YAMLUtil.getValue(role, key)
         print 'mysql_vip=%s--' % mysql_vip
         print 'mysql_vip_interface=%s--' % mysql_vip_interface
         print 'mysql_password=%s--' % mysql_root_password
         
         mysql_ips_list = YAMLUtil.getRoleIPList(role)
         #Judge mysql master ip
         mysql_master_ip = mysql_ips_list[0]
         FileUtil.writeContent('/opt/mysql_master_ip', mysql_master_ip)
         
         mysql_ips = ','.join(mysql_ips_list)
         print 'mysql_ips=%s' % mysql_ips
         paramsMap['mysql_vip'] = mysql_vip
         paramsMap['mysql_vip_interface'] = mysql_vip_interface
         paramsMap['mysql_password'] = mysql_root_password
         paramsMap['mysql_ips'] = mysql_ips
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), mysql_ips_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
             pass
 #         else:
 #             FileUtil.writeContent(is_mysql_role_file_path, 'false')
 #             pass
 #         pass
 #     else :
 #         FileUtil.writeContent(is_mysql_role_file_path, 'false')
 #         pass
         
     print 'rabbitmq========================'
     role = 'rabbitmq'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         key = 'rabbit_userid'
         rabbit_userid = YAMLUtil.getValue(role, key)
         
         key = 'rabbit_password'
         rabbit_password = YAMLUtil.getValue(role, key)
         
         key = 'rabbit_vip'
         rabbit_vip = YAMLUtil.getValue(role, key)
         
         key = 'rabbit_vip_interface'
         rabbit_vip_interface = YAMLUtil.getValue(role, key)
         
         rabbit_ips_list = YAMLUtil.getRabbitRoleIPList(role)
         rabbit_ips = ','.join(rabbit_ips_list)
         
         #Judge rabbitmq master ip
         rabbit_master_ip = rabbit_ips_list[0]
         FileUtil.writeContent('/opt/rabbitmq_master_ip', rabbit_master_ip)
         
         print 'rabbit_userid=%s--' % rabbit_userid
         print 'rabbit_vip=%s--' % rabbit_vip
         print 'rabbit_vip_interface=%s--' % rabbit_vip_interface
         print 'rabbit_password=%s--' % rabbit_password
         print 'rabbit_ips=%s--' % rabbit_ips
         
         rabbit_hosts_list = [] #rabbit_ip1:5672,rabbit_ip2:5672
         
         for ip in rabbit_ips_list :
             rabbit_with_port = '%s:5672' % ip
             rabbit_hosts_list.append(rabbit_with_port)
             pass
         paramsMap['rabbit_hosts'] = ','.join(rabbit_hosts_list)
         paramsMap['rabbit_host'] = rabbit_ips_list[0]
         paramsMap['rabbit_vip'] = rabbit_vip
         paramsMap['rabbit_vip_interface'] = rabbit_vip_interface
         paramsMap['rabbit_userid'] = rabbit_userid
         paramsMap['rabbit_password'] = rabbit_password
         paramsMap['rabbitmq_ips'] = rabbit_ips
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), rabbit_ips_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
             pass
         pass
     
     print 'keystone========================='
     role = 'keystone'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         key = 'keystone_vip'
         keystone_vip = YAMLUtil.getValue(role, key)
         
         key = 'keystone_vip_interface'
         keystone_vip_interface = YAMLUtil.getValue(role, key)
         
         key = 'keystone_mysql_user'
         keystone_mysql_user = YAMLUtil.getValue(role, key)
         
         key = 'keystone_mysql_password'
         keystone_mysql_password = YAMLUtil.getValue(role, key)
         
         keystone_ips_list = YAMLUtil.getRoleIPList(role)
         keystone_ips = ','.join(keystone_ips_list)
         
         print 'keystone_vip=%s--' % keystone_vip
         print 'keystone_vip_interface=%s--' % keystone_vip_interface
         print 'keystone_mysql_user=%s--' % keystone_mysql_user 
         print 'keystone_ips=%s--' % keystone_ips
         
         paramsMap['keystone_vip'] = keystone_vip
         paramsMap['keystone_vip_interface'] = keystone_vip_interface
         paramsMap['keystone_mysql_user'] = keystone_mysql_user
         paramsMap['keystone_mysql_password'] = keystone_mysql_password
         paramsMap['keystone_ips'] = keystone_ips
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), keystone_ips_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
             pass
 #         else:
 #             FileUtil.writeContent(is_keystone_role_file_path, 'false')
 #             pass
 #         pass
 #     else :
 #         FileUtil.writeContent(is_keystone_role_file_path, 'false')
 #         pass
     
     print 'glance====================================='
     role = 'glance'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         key = 'glance_vip'
         glance_vip = YAMLUtil.getValue(role, key)
         
         key = 'glance_vip_interface'
         glance_vip_interface = YAMLUtil.getValue(role, key)
         
         key = 'glance_mysql_user'
         glance_mysql_user = YAMLUtil.getValue(role, key)
         
         key = 'glance_mysql_password'
         glance_mysql_password = YAMLUtil.getValue(role, key)
         
         glance_ips_list = YAMLUtil.getRoleIPList(role)
         glance_ips = ','.join(glance_ips_list)
         
         print 'glance_vip=%s--' % glance_vip
         print 'glance_vip_interface=%s--' % glance_vip_interface
         print 'glance_mysql_user=%s--' % glance_mysql_user
         print 'glance_mysql_password=%s--' % glance_mysql_password 
         print 'glance_ips=%s--' % glance_ips
         paramsMap['glance_vip'] = glance_vip
         paramsMap['glance_vip_interface'] = glance_vip_interface
         paramsMap['glance_mysql_user'] = glance_mysql_user
         paramsMap['glance_mysql_password'] = glance_mysql_password
         paramsMap['glance_ips'] = glance_ips
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), glance_ips_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
             pass
         pass
 
     print 'neutron-server========================================='
     role = 'neutron-server'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         key = 'neutron_vip'
         neutron_vip = YAMLUtil.getValue(role, key)
         
         key = 'neutron_vip_interface'
         neutron_vip_interface = YAMLUtil.getValue(role, key)
         
         key = 'neutron_network_mode'
         neutron_network_mode = YAMLUtil.getValue(role, key)
         
         key = 'neutron_mysql_user'
         neutron_mysql_user = YAMLUtil.getValue(role, key)
         key = 'neutron_mysql_password'
         neutron_mysql_password = YAMLUtil.getValue(role, key)
         
         neutron_ip_list = YAMLUtil.getRoleIPList(role)
         neutron_ips = ','.join(neutron_ip_list)
         
         print 'neutron_vip=%s--' % neutron_vip
         print 'neutron_vip_interface=%s--' % neutron_vip_interface
         print 'neutron_network_mode=%s--' % neutron_network_mode
         
         print 'neutron_mysql_user=%s--' % neutron_mysql_user
         print 'neutron_mysql_user_password=%s--' % neutron_mysql_password
         
         print 'neutron_ips=%s--' % neutron_ips
         paramsMap['neutron_vip'] = neutron_vip
         paramsMap['neutron_vip_interface'] = neutron_vip_interface
         paramsMap['neutron_mysql_user'] = neutron_mysql_user
         paramsMap['neutron_mysql_password'] = neutron_mysql_password
         paramsMap['neutron_network_mode'] = neutron_network_mode
         paramsMap['neutron_ips'] = neutron_ips
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), neutron_ip_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
             pass
         pass
     
     print 'nova-api========================================='
     role = 'nova-api'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         key = 'nova_vip'
         nova_vip = YAMLUtil.getValue(role, key)
         
         key = 'nova_vip_interface'
         nova_vip_interface = YAMLUtil.getValue(role, key)
         
         key = 'nova_mysql_user'
         nova_mysql_user = YAMLUtil.getValue(role, key)
         
         key = 'nova_mysql_password'
         nova_mysql_password = YAMLUtil.getValue(role, key)
         
         nova_ip_list = YAMLUtil.getRoleIPList(role)
         nova_ips = ','.join(nova_ip_list)
         
         print 'nova_vip=%s--' % nova_vip
         print 'nova_vip_interface=%s--' % nova_vip_interface
         print 'nova_mysql_user=%s--' % nova_mysql_user
         print 'nova_mysql_password=%s--' % nova_mysql_password
         
         print 'nova_ips=%s--' % nova_ips
         print YAMLUtil.hasRoleInNodes('nova-api')
         paramsMap['nova_vip'] = nova_vip
         paramsMap['nova_vip_interface'] = nova_vip_interface
         paramsMap['nova_mysql_user'] = nova_mysql_user
         paramsMap['nova_mysql_password'] = nova_mysql_password
         paramsMap['nova_ips'] = nova_ips
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), nova_ip_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
             pass
         pass
     
     print 'nova-compute============================================='
     role = 'nova-compute'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         key = 'virt_type'
         virt_type= YAMLUtil.getValue(role, key)
         print 'virt_type=%s' % virt_type
         
         nova_compute_ip_list = YAMLUtil.getRoleIPList(role)
         nova_compute_ips = ','.join(nova_compute_ip_list)
         print 'nova_compute_ips=%s--' % nova_compute_ips
         paramsMap['virt_type'] = virt_type
         paramsMap['nova_compute_ips'] = nova_compute_ips
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), nova_compute_ip_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
             pass
         pass
     
     role = 'horizon'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         key = 'dashboard_vip'
         dashboard_vip= YAMLUtil.getValue(role, key)
         key = 'dashboard_vip_interface'
         dashboard_vip_interface = YAMLUtil.getValue(role, key)
         
         dashboard_ips_list = YAMLUtil.getRoleIPList(role)
         dashboard_ips = ','.join(dashboard_ips_list)
         print 'dashboard_vip=%s--' % dashboard_vip
         print 'dashboard_vip_interface=%s--' % dashboard_vip_interface
         print 'dashboard_ips=%s--' % dashboard_ips
         paramsMap['dashboard_vip'] = dashboard_vip
         paramsMap['dashboard_vip_interface'] = dashboard_vip_interface
         paramsMap['dashboard_ips'] = dashboard_ips
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), dashboard_ips_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
             pass
         pass
         
     print 'cinder============================================'
     role = 'cinder-api'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         key = 'cinder_vip'
         cinder_vip = YAMLUtil.getValue(role, key)
         
         key = 'cinder_vip_interface'
         cinder_vip_interface = YAMLUtil.getValue(role, key)
         
         key = 'cinder_mysql_user'
         cinder_mysql_user = YAMLUtil.getValue(role, key)
         
         key = 'cinder_mysql_password'
         cinder_mysql_password = YAMLUtil.getValue(role, key)
         
         cinder_ips_list = YAMLUtil.getRoleIPList(role)
         cinder_ips = ','.join(cinder_ips_list)
         print 'cinder_vip=%s-' % cinder_vip
         print 'cinder_vip_interface=%s--' % cinder_vip_interface
         print 'cinder_mysql_user=%s--' % cinder_mysql_user
         print 'cinder_mysql_password=%s--' % cinder_mysql_password
         print 'cinder_ips=%s--' % cinder_ips
         paramsMap['cinder_vip'] = cinder_vip
         paramsMap['cinder_vip_interface'] = cinder_vip_interface
         paramsMap['cinder_mysql_user'] = cinder_mysql_user
         paramsMap['cinder_mysql_password'] = cinder_mysql_password
         paramsMap['cinder_ips'] = cinder_ips
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), cinder_ips_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
             pass
         pass
     
     print 'cinder-storage============================================'
     role = 'cinder-storage'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         cinder_storage_ips_list = YAMLUtil.getRoleIPList(role)
         cinder_storage_ips = ','.join(cinder_storage_ips_list)
         paramsMap['cinder_storage_ips'] = cinder_storage_ips
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), cinder_storage_ips_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
             pass
         pass
     
     print 'heat============================================'
     role = 'heat'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         heat_ips_list = YAMLUtil.getRoleIPList(role)
         heat_ips = ','.join(heat_ips_list)
         print 'heat_ips=%s--' % heat_ips
         
         key = 'heat_vip'
         heat_vip = YAMLUtil.getValue(role, key)
         
         key = 'heat_vip_interface'
         heat_vip_interface = YAMLUtil.getValue(role, key)
         
         key = 'heat_mysql_user'
         heat_mysql_user = YAMLUtil.getValue(role, key)
         
         key = 'heat_mysql_password'
         heat_mysql_password = YAMLUtil.getValue(role, key)
         
         paramsMap['heat_ips'] = heat_ips
         paramsMap['heat_vip'] = heat_vip
         paramsMap['heat_vip_interface'] = heat_vip_interface
         paramsMap['heat_mysql_user'] = heat_mysql_user
         paramsMap['heat_mysql_password'] = heat_mysql_password
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), heat_ips_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
             pass
         pass
     
     print 'neutron-agent============================================'
     role = 'neutron-agent'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         neutron_service_ips_list = YAMLUtil.getRoleIPList(role)
         neutron_service_ips = ','.join(neutron_service_ips_list)
         print 'neutron_service_ips=%s--' % neutron_service_ips
         paramsMap['neutron_service_ips'] = neutron_service_ips
         
         #REFACTOR LATER
         paramsMap['metadata_secret'] = '123456'
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), neutron_service_ips_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
             pass
         pass
     
     print 'mongodb==========================================='
     role = 'mongodb'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         #refactor later
 #         key = 'mongodb_vip'
 #         mongodb_vip = YAMLUtil.getValue(role, key)
 #         
 #         key = 'mongodb_vip_interface'
 #         mongodb_vip_interface = YAMLUtil.getValue(role, key)
         
         mongodb_ips_list = YAMLUtil.getRoleIPList(role)
         mongodb_ips = ','.join(mongodb_ips_list)
         
         #refactor later
         mongodb_vip = mongodb_ips_list[0]
         mongodb_vip_interface = 'eth0'
         print 'mongodb_vip=%s-' % mongodb_vip
         print 'mongodb_vip_interface=%s--' % mongodb_vip_interface
         paramsMap['mongodb_vip'] = mongodb_vip
         paramsMap['mongodb_vip_interface'] = mongodb_vip_interface
         paramsMap['mongodb_ips'] = mongodb_ips
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), mongodb_ips_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
             pass
         pass
     
     print 'ceilometer==========================================='
     role = 'ceilometer'
     is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
     if YAMLUtil.hasRoleInNodes(role):
         key = 'ceilometer_vip'
         ceilometer_vip = YAMLUtil.getValue(role, key)
         
         key = 'ceilometer_vip_interface'
         ceilometer_vip_interface = YAMLUtil.getValue(role, key)
         
         key = 'ceilometer_mongo_user'
         ceilometer_mongo_user = YAMLUtil.getValue(role, key)
         
         key = 'ceilometer_mongo_password'
         ceilometer_mongo_password = YAMLUtil.getValue(role, key)
         
         ceilometer_ips_list = YAMLUtil.getRoleIPList(role)
         ceilometer_ips = ','.join(ceilometer_ips_list)
         print 'ceilometer_vip=%s-' % ceilometer_vip
         print 'ceilometer_vip_interface=%s--' % ceilometer_vip_interface
         print 'ceilometer_mongo_user=%s--' % ceilometer_mongo_user
         print 'ceilometer_mongo_password=%s--' % ceilometer_mongo_password
         print 'ceilometer_ips=%s--' % ceilometer_ips
         paramsMap['ceilometer_vip'] = ceilometer_vip
         paramsMap['ceilometer_vip_interface'] = ceilometer_vip_interface
         paramsMap['ceilometer_mongo_user'] = ceilometer_mongo_user
         paramsMap['ceilometer_mongo_password'] = ceilometer_mongo_password
         paramsMap['ceilometer_ips'] = ceilometer_ips
         
         #REFACTOR LATER
         ceilometer_metering_secret = '7c1edcdfc1b2841c21ff'
         paramsMap['ceilometer_metering_secret'] = ceilometer_metering_secret
         
         if ParamsProducer.isExistElementInArray(YAMLUtil.getLocalIP(), ceilometer_ips_list) :
             FileUtil.writeContent(is_role_file_path, 'true')
         pass
     
     print 'get global var==========================================='
     role = 'global'
     neutron_dbpass = YAMLUtil.getValue(role, 'neutron_dbpass')
     nova_dbpass = YAMLUtil.getValue(role, 'nova_dbpass')
     
     paramsMap['neutron_dbpass'] = YAMLUtil.getValue(role, 'neutron_dbpass')
     paramsMap['nova_dbpass'] =  YAMLUtil.getValue(role, 'nova_dbpass')
         
     #HA: only 2,master-backup mutually
     print 'haproxy-keepalived=================='
     role = 'haproxy-keepalived'
     if YAMLUtil.hasRoleInNodes(role):
         ha_vip1 = YAMLUtil.getValue(role, 'haproxy_vip1')
         ha_vip2 = YAMLUtil.getValue(role, 'haproxy_vip2')
         ha_vip1_interface = YAMLUtil.getValue(role, 'haproxy_vipinterface1')
         ha_vip2_interface = YAMLUtil.getValue(role, 'haproxy_vipinterface2')
         
         paramsMap['ha_vip1'] = ha_vip1
         paramsMap['ha_vip2'] = ha_vip2
         paramsMap['ha_vip1_interface'] = ha_vip1_interface
         paramsMap['ha_vip2_interface'] = ha_vip2_interface
         
         #dispatch vip
         paramsMap['mysql_vip'] = ha_vip1
         paramsMap['rabbit_vip'] = ha_vip1
         paramsMap['keystone_vip'] = ha_vip1
         paramsMap['glance_vip'] = ha_vip1
         paramsMap['neutron_vip'] = ha_vip1
         paramsMap['nova_vip'] = ha_vip1
         paramsMap['dashboard_vip'] = ha_vip1
         paramsMap['cinder_vip'] = ha_vip1
         paramsMap['heat_vip'] = ha_vip1
         paramsMap['mongodb_vip'] = ha_vip2
         paramsMap['ceilometer_vip'] = ha_vip2
         pass
     
     openstackConfPopertiesFilePath = PropertiesUtility.getOpenstackConfPropertiesFilePath()
     admin_email = PropertiesUtility.getValue(openstackConfPopertiesFilePath, 'ADMIN_EMAIL')
     
     paramsMap['admin_email'] = admin_email
     
     import json
     jsonParams = json.dumps(paramsMap,indent=4)
     print jsonParams
     print type(jsonParams)
     
     openstackConfPopertiesFilePath = PropertiesUtility.getOpenstackConfPropertiesFilePath()
     openstackConfBaseDir = PropertiesUtility.getValue(openstackConfPopertiesFilePath, 'OPENSTACK_CONF_BASE_DIR')
     if not os.path.exists(openstackConfBaseDir) :
         ShellCmdExecutor.execCmd("mkdir %s" % openstackConfBaseDir)
         pass
     openstackParamsFilePath = os.path.join(openstackConfBaseDir, 'openstack_params.json')
     FileUtil.writeContent(openstackParamsFilePath, jsonParams)
     
     print 'produce role list done#######'
     
     ###zgf add
     YAMLUtil.setHosts()
示例#14
0
    print 'Keep one vip for each role: delete non-master role vip========================'
    
    for role in VIPHandler.OPENSTACK_ROLES :
        is_role_file_path = '/opt/is_{rolename}_role'.format(rolename=role).replace('-', '_')
        #judge role
        if os.path.exists(is_role_file_path) :
            #judge master
            if not VIPHandler.isMaster(role) :
                #delete VIP
                VIPHandler.deleteRoleVIP(role)
                
                #restart keepalived
                ShellCmdExecutor.execCmd('service keepalived restart')
                
                print 'delete role vip done##########'
                pass
            else :
                xx = 'This is %s master.Do not need to delete VIP.####' % role
                print xx
                file_path = '/tmp/{rolename}_vip_handle.log'.format(rolename=role).replace('-', '_')
                FileUtil.writeContent(file_path, xx)
            pass
        pass
    
    pass

    
    
        
        
    
示例#15
0
文件: nova.py 项目: zbwzy/fuel-python
    def configureHAProxy():
        ####################configure haproxy
        nova_vip = JSONUtility.getValue("nova_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
        
        ShellCmdExecutor.execCmd('sudo chmod 777 %s' % haproxyConfFilePath)
        
        nova_ips = JSONUtility.getValue("nova_ips")
        nova_ip_list = nova_ips.strip().split(',')
        
        novaEC2ApiBackendStringTemplate = '''
listen nova_ec2_api_cluster
  bind <NOVA_VIP>:8773
  balance source
  <NOVA_EC2_API_SERVER_LIST>
  '''
        novaComputeApiBackendStringTemplate = '''
listen nova_compute_api_cluster
  bind <NOVA_VIP>:8774
  balance source
  <NOVA_COMPUTE_API_SERVER_LIST>
        '''
        
        novaMetadataApiBackendStringTemplate = '''
listen nova_metadata_api_cluster
  bind <NOVA_VIP>:8775
  balance source
  <NOVA_METADATA_API_SERVER_LIST>
        '''
        
        vncBackendStringTemplate = '''
listen vnc_cluster
  bind <NOVA_VIP>:6080
  balance source
  option tcpka
  option tcplog
  <VNC_SERVER_LIST>
        '''
        
        novaEC2ApiBackendString = novaEC2ApiBackendStringTemplate.replace('<NOVA_VIP>', nova_vip)
        novaComputeApiBackendString = novaComputeApiBackendStringTemplate.replace('<NOVA_VIP>', nova_vip)
        novaMetadataApiBackendString = novaMetadataApiBackendStringTemplate.replace('<NOVA_VIP>', nova_vip)
        vncBackendString = vncBackendStringTemplate.replace('<NOVA_VIP>', nova_vip)
        ###############
        
        serverNovaEC2APIBackendTemplate = 'server nova-<INDEX> <SERVER_IP>:8773 check inter 2000 rise 2 fall 5'
        serverNovaComputeAPIBackendTemplate = 'server nova-<INDEX> <SERVER_IP>:8774 check inter 2000 rise 2 fall 5'
        serverNovaMetadataAPIBackendTemplate = 'server nova-<INDEX> <SERVER_IP>:8775 check inter 2000 rise 2 fall 5'
        serverVNCBackendTemplate = 'server nova-<INDEX> <SERVER_IP>:6080 check inter 2000 rise 2 fall 5'
        
        novaEC2APIServerListContent = ''
        novaComputeAPIServerListContent = ''
        novaMetadataAPIServerListContent = ''
        vncServerListContent = ''
        
        index = 1
        for ip in nova_ip_list:
            print 'nova_ip=%s' % ip
            novaEC2APIServerListContent += serverNovaEC2APIBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', ip)
            novaComputeAPIServerListContent += serverNovaComputeAPIBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', ip)
            novaMetadataAPIServerListContent += serverNovaMetadataAPIBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', ip)
            vncServerListContent += serverVNCBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', ip)
            
            novaEC2APIServerListContent += '\n'
            novaEC2APIServerListContent += '  '
            
            novaComputeAPIServerListContent += '\n'
            novaComputeAPIServerListContent += '  '
            
            novaMetadataAPIServerListContent += '\n'
            novaMetadataAPIServerListContent += '  '
            
            vncServerListContent += '\n'
            vncServerListContent += '  '
            
            index += 1
            pass
        
        novaEC2APIServerListContent = novaEC2APIServerListContent.strip()
        novaComputeAPIServerListContent = novaComputeAPIServerListContent.strip()
        novaMetadataAPIServerListContent = novaMetadataAPIServerListContent.strip()
        
        novaEC2ApiBackendString = novaEC2ApiBackendString.replace('<NOVA_EC2_API_SERVER_LIST>', novaEC2APIServerListContent)
        novaComputeApiBackendString = novaComputeApiBackendString.replace('<NOVA_COMPUTE_API_SERVER_LIST>', novaComputeAPIServerListContent)
        novaMetadataApiBackendString = novaMetadataApiBackendString.replace('<NOVA_METADATA_API_SERVER_LIST>', novaMetadataAPIServerListContent)
        vncBackendString = vncBackendString.replace('<VNC_SERVER_LIST>', vncServerListContent)
        
        #append to haproxy.cfg
        if os.path.exists(haproxyConfFilePath) :
            output, exitcode = ShellCmdExecutor.execCmd('cat %s' % haproxyConfFilePath)
        else :
            output, exitcode = ShellCmdExecutor.execCmd('cat %s' % HAProxyTemplateFilePath)
            pass
        
        haproxyNativeContent = output.strip()
        
        haproxyContent = ''
        haproxyContent += haproxyNativeContent
        haproxyContent += '\n\n'
        
        haproxyContent += novaEC2ApiBackendString
        haproxyContent += novaComputeApiBackendString
        haproxyContent += novaMetadataApiBackendString
        haproxyContent += vncBackendString
        
        FileUtil.writeContent('/tmp/haproxy.cfg', haproxyContent)
        if os.path.exists(haproxyConfFilePath):
            ShellCmdExecutor.execCmd("sudo rm -rf %s" % haproxyConfFilePath)
            pass
        ShellCmdExecutor.execCmd('mv /tmp/haproxy.cfg /etc/haproxy/')
        
        ShellCmdExecutor.execCmd('sudo chmod 644 %s' % haproxyConfFilePath)
        pass
示例#16
0
    def configureHAProxy():
        ####################configure haproxy
        #server keystone-01 192.168.1.137:35357 check inter 10s
        keystone_vip = JSONUtility.getValue("keystone_vip")
        
        openstackConfPopertiesFilePath = PropertiesUtility.getOpenstackConfPropertiesFilePath()
        keystoneHAProxyTemplateFilePath = 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 -r %s %s' % (keystoneHAProxyTemplateFilePath, '/etc/haproxy'))
            pass
        
        ShellCmdExecutor.execCmd('sudo chmod 777 %s' % haproxyConfFilePath)
        
        ####
        ##############new
        keystoneBackendAdminApiStringTemplate = '''
listen keystone_admin_cluster
  bind <KEYSTONE_VIP>:35357
  balance source
  <KEYSTONE_ADMIN_API_SERVER_LIST>
  '''
        keystoneBackendPublicApiStringTemplate = '''
listen keystone_public_internal_cluster
  bind <KEYSTONE_VIP>:5000
  balance source
  <KEYSTONE_PUBLIC_API_SERVER_LIST>
  '''
        keystoneBackendAdminApiString = keystoneBackendAdminApiStringTemplate.replace('<KEYSTONE_VIP>', keystone_vip)
        keystoneBackendPublicApiString = keystoneBackendPublicApiStringTemplate.replace('<KEYSTONE_VIP>', keystone_vip)
        
        ################new
        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 5'
        serverKeystonePublicAPIBackendTemplate  = 'server keystone-<INDEX> <SERVER_IP>:5000 check inter 2000 rise 2 fall 5'
        
        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
        
        #append
        if os.path.exists(haproxyConfFilePath) :
            output, exitcode = ShellCmdExecutor.execCmd('cat %s' % haproxyConfFilePath)
        else :
            output, exitcode = ShellCmdExecutor.execCmd('cat %s' % keystoneHAProxyTemplateFilePath)
            pass
        
        haproxyNativeContent = output.strip()
        
        haproxyContent = ''
        haproxyContent += haproxyNativeContent
        haproxyContent += '\n\n'
        
        haproxyContent += keystoneBackendAdminApiString
        haproxyContent += keystoneBackendPublicApiString
        
        FileUtil.writeContent('/tmp/haproxy.cfg', haproxyContent)
        if os.path.exists(haproxyConfFilePath):
            ShellCmdExecutor.execCmd("sudo rm -rf %s" % haproxyConfFilePath)
            pass
        ShellCmdExecutor.execCmd('mv /tmp/haproxy.cfg /etc/haproxy/')
        #############
        ShellCmdExecutor.execCmd('sudo chmod 644 %s' % haproxyConfFilePath)
        pass
示例#17
0
 for ip in mysqlIPList :
     server_list += backendServerTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', ip)
     server_list += '\n'
     server_list += '  '
     index += 1
     pass
 content = content.replace("<SERVER_LIST>", server_list)
 if not os.path.exists(haproxy_conf_file_path) :
     ShellCmdExecutor.execCmd('yum -y install haproxy')
     haproxy_templete = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'haproxy.cfg')
     ShellCmdExecutor.execCmd('cp -f %s %s' % (haproxy_templete, haproxy_conf))
     haproxyContent = FileUtil.readContent(haproxy_conf_file_path)
     content = haproxyContent + content
     ShellCmdExecutor.execCmd('sudo chmod 777 %s' % haproxy_conf_file_path)
     # FileUtil.replaceFileContent(haproxy_conf_file_path, '#RABBIT_SERVER_LIST', content)
     FileUtil.writeContent(haproxy_conf_file_path, content)
     ShellCmdExecutor.execCmd('sudo chmod 644 %s' % haproxy_conf_file_path)
     ##############install keepalived
     ShellCmdExecutor.execCmd('yum -y install keepalived')
     keepalived_template = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'keepalived.conf')
     ShellCmdExecutor.execCmd('cp -f %s %s' % (keepalived_template, keepalived_conf))
     keep_sh_template = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'check_haproxy.sh')
     ShellCmdExecutor.execCmd('cp -f %s %s' % (keep_sh_template, keepalived_conf))
     FileUtil.replaceFileContent(keepalived_conf_file_path,'<WEIGHT>','99')
     FileUtil.replaceFileContent(keepalived_conf_file_path,'<STATE>','MASTER')
     FileUtil.replaceFileContent(keepalived_conf_file_path,'<INTERFACE>','eth0')
     FileUtil.replaceFileContent(keepalived_conf_file_path,'<VIRTURL_IPADDR>',mysql_vip)
 else :
     haproxyContent = FileUtil.readContent(haproxy_conf_file_path)
     content = haproxyContent + content
     ShellCmdExecutor.execCmd('sudo chmod 777 %s' % haproxy_conf_file_path)
示例#18
0
    def configureHAProxy():
        ####################configure haproxy
        glance_vip = JSONUtility.getValue("glance_vip")
        
        openstackConfPopertiesFilePath = PropertiesUtility.getOpenstackConfPropertiesFilePath()
        glanceHAProxyTemplateFilePath = 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 -r %s %s' % (glanceHAProxyTemplateFilePath, '/etc/haproxy'))
            pass
        
        ShellCmdExecutor.execCmd('sudo chmod 777 %s' % haproxyConfFilePath)
        
        glance_ips = JSONUtility.getValue("glance_ips")
        glance_ip_list = glance_ips.strip().split(',')
        
        glanceBackendApiStringTemplate = '''
listen glance_api_cluster
  bind <GLANCE_VIP>:9292
  balance source
  <GLANCE_API_SERVER_LIST>
  '''
        glanceBackendRegistryApiStringTemplate = '''
listen glance_registry_cluster
  bind <GLANCE_VIP>:9191
  balance source
  <GLANCE_REGISTRY_API_SERVER_LIST>
        '''
        
        glanceBackendApiString = glanceBackendApiStringTemplate.replace('<GLANCE_VIP>', glance_vip)
        
        glanceBackendRegistryApiString = glanceBackendRegistryApiStringTemplate.replace('<GLANCE_VIP>', glance_vip)
        ###############
        
        serverGlanceRegistryAPIBackendTemplate = 'server glance-<INDEX> <SERVER_IP>:9191 check inter 2000 rise 2 fall 5'
        serverGlanceAPIBackendTemplate         = 'server glance-<INDEX> <SERVER_IP>:9292 check inter 2000 rise 2 fall 5'
        
        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)
        #append to haproxy.cfg
        if os.path.exists(haproxyConfFilePath) :
            output, exitcode = ShellCmdExecutor.execCmd('cat %s' % haproxyConfFilePath)
        else :
            output, exitcode = ShellCmdExecutor.execCmd('cat %s' % glanceHAProxyTemplateFilePath)
            pass
        
        haproxyNativeContent = output.strip()
        
        haproxyContent = ''
        haproxyContent += haproxyNativeContent
        haproxyContent += '\n\n'
        
        haproxyContent += glanceBackendRegistryApiString
        haproxyContent += glanceBackendApiString
        
        FileUtil.writeContent('/tmp/haproxy.cfg', haproxyContent)
        if os.path.exists(haproxyConfFilePath):
            ShellCmdExecutor.execCmd("sudo rm -rf %s" % haproxyConfFilePath)
            pass
        ShellCmdExecutor.execCmd('mv /tmp/haproxy.cfg /etc/haproxy/')
        ##############

        #Default: glance-api & glance-registry-api use the same vip
        ShellCmdExecutor.execCmd('sudo chmod 644 %s' % haproxyConfFilePath)
        pass