本文整理汇总了Python中common.file.FileUtil.FileUtil.writeContent方法的典型用法代码示例。如果您正苦于以下问题:Python FileUtil.writeContent方法的具体用法?Python FileUtil.writeContent怎么用?Python FileUtil.writeContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common.file.FileUtil.FileUtil
的用法示例。
在下文中一共展示了FileUtil.writeContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execCmdWithoutKillTimeout
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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: getMeteringSecret
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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: writeIPList
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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: setHosts
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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: test
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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: test
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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: appendBackendStringToHaproxyCfg
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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: execCmd
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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: configureHAProxy
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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: configureHAProxy
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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: execCmdWithKillTimeout
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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: configureHAProxy
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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: produce
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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) :
#.........这里部分代码省略.........
示例14:
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
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: configureHAProxy
# 需要导入模块: from common.file.FileUtil import FileUtil [as 别名]
# 或者: from common.file.FileUtil.FileUtil import writeContent [as 别名]
#.........这里部分代码省略.........
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