本文整理汇总了Python中common.file.FileUtil.FileUtil类的典型用法代码示例。如果您正苦于以下问题:Python FileUtil类的具体用法?Python FileUtil怎么用?Python FileUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: install
def install():
print 'Cinder-storage.install start===='
keystone_vip = JSONUtility.getValue('keystone_vip')
print 'start to install prerequisites============='
script_file_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR,
'cinder-storage',
'cinder_storage_service.sh')
ShellCmdExecutor.execCmd('cp -r %s /opt/' % script_file_path)
ShellCmdExecutor.execCmd('chmod 777 /opt/cinder_storage_service.sh')
FileUtil.replaceFileContent('/opt/cinder_storage_service.sh', '<KEYSTONE_VIP>', keystone_vip)
ShellCmdExecutor.execCmd('bash /opt/cinder_storage_service.sh')
print 'install prerequisites done####'
yumCmd = 'yum install lvm2 -y'
ShellCmdExecutor.execCmd(yumCmd)
ShellCmdExecutor.execCmd("/etc/init.d/lvm2-lvmetad start")
ShellCmdExecutor.execCmd("chkconfig lvm2-lvmetad on")
#Default create volume
#Create the LVM physical volume /dev/sdb1:
# createCmd = 'pvcreate /dev/sdb1'
# ShellCmdExecutor.execCmd(createCmd)
# createCmd = 'vgcreate cinder-volumes /dev/sdb1'
# ShellCmdExecutor.execCmd(createCmd)
yumCmd = 'yum install openstack-cinder python-oslo-db MySQL-python -y'
ShellCmdExecutor.execCmd(yumCmd)
print 'Cinder-storage.install done####'
pass
示例2: confiugureNeutron
def confiugureNeutron():
neutronConfTemplateFilePath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'nova-compute', 'neutron.conf')
ShellCmdExecutor.execCmd('cp -r %s /etc/neutron/' % neutronConfTemplateFilePath)
#configure neutron
keystone_vip = JSONUtility.getValue('keystone_vip')
# rabbit_host = JSONUtility.getValue("rabbit_host")
# rabbit_vip = JSONUtility.getValue("rabbit_vip")
rabbit_hosts = JSONUtility.getValue("rabbit_hosts")
rabbit_userid = JSONUtility.getValue("rabbit_userid")
rabbit_password = JSONUtility.getValue("rabbit_password")
#REFACTOR LATER
neutron_pass = '123456'
neutronConfFilePath = '/etc/neutron/neutron.conf'
ShellCmdExecutor.execCmd('chmod 777 /etc/neutron/neutron.conf')
FileUtil.replaceFileContent(neutronConfFilePath, '<KEYSTONE_VIP>', keystone_vip)
FileUtil.replaceFileContent(neutronConfFilePath, '<NEUTRON_PASS>', neutron_pass)
# FileUtil.replaceFileContent(neutronConfFilePath, '<RABBIT_HOST>', rabbit_vip)
FileUtil.replaceFileContent(neutronConfFilePath, '<RABBIT_HOSTS>', rabbit_hosts)
FileUtil.replaceFileContent(neutronConfFilePath, '<RABBIT_USERID>', rabbit_userid)
FileUtil.replaceFileContent(neutronConfFilePath, '<RABBIT_PASSWORD>', rabbit_password)
ShellCmdExecutor.execCmd('chown -R neutron:neutron /etc/neutron')
pass
示例3: install
def install():
#KEYSTONE_ADMIN_PASSWORD
print 'Cinder-storage.install start===='
#
keystone_vip = JSONUtility.getValue('keystone_vip')
keystone_admin_password = JSONUtility.getValue('keystone_admin_password')
print 'start to install prerequisites============='
script_file_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR,
'cinder-storage',
'cinder_storage_service.sh')
ShellCmdExecutor.execCmd('cp -r %s /opt/' % script_file_path)
ShellCmdExecutor.execCmd('chmod 777 /opt/cinder_storage_service.sh')
FileUtil.replaceFileContent('/opt/cinder_storage_service.sh', '<KEYSTONE_VIP>', keystone_vip)
ShellCmdExecutor.execCmd('bash /opt/cinder_storage_service.sh')
ShellCmdExecutor.execCmd("systemctl restart lvm2-lvmetad.service")
#Default create volume
#Create the LVM physical volume /dev/sdb1:
# createCmd = 'pvcreate /dev/sdb1'
# ShellCmdExecutor.execCmd(createCmd)
# createCmd = 'vgcreate cinder-volumes /dev/sdb1'
# ShellCmdExecutor.execCmd(createCmd)
yumCmd = 'yum install openstack-cinder targetcli python-oslo-db python-oslo-log MySQL-python -y'
ShellCmdExecutor.execCmd(yumCmd)
print 'Cinder-storage.install done####'
pass
示例4: configOVS
def configOVS():
output, exitcode = ShellCmdExecutor.execCmd('systemctl enable openvswitch.service')
output, exitcode = ShellCmdExecutor.execCmd('systemctl start openvswitch.service')
time.sleep(3)
#Add the external bridge:
ShellCmdExecutor.execCmd('ovs-vsctl add-br br-ex')
time.sleep(2)
#Add a port to the external bridge that connects to the physical external network interface:
#Replace INTERFACE_NAME with the actual interface name. For example, eth2 or ens256.
#REFACTOR LATER:on physical, the below is bond1 or bond2
physical_external_network_interface = 'eth2'
# addExternalBridgeCmd = 'ovs-vsctl add-port br-ex %s' % physical_external_network_interface
addExternalBridgeTemplateScriptPath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'network', 'addExternalBridge.sh')
ShellCmdExecutor.execCmd('cp -r %s /opt/' % addExternalBridgeTemplateScriptPath)
FileUtil.replaceFileContent('/opt/addExternalBridge.sh',
'<PHYSICAL_EXTERNAL_NETWORK_INTERFACE>',
physical_external_network_interface)
# output, exitcode = ShellCmdExecutor.execCmd('cat /opt/localip')
# localIP = output.strip()
# FileUtil.replaceFileContent('/opt/addExternalBridge.sh',
# '<LOCAL_IP>',
# localIP)
ShellCmdExecutor.execCmd('bash /opt/addExternalBridge.sh')
pass
示例5: configConfFile
def configConfFile():
localSettingsFileTemplatePath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'dashboard', 'local_settings')
dashboardConfFileDir = '/etc/openstack-dashboard/'
if os.path.exists(Dashboard.DASHBOARD_CONF_FILE_PATH) :
ShellCmdExecutor.execCmd("rm -rf %s" % Dashboard.DASHBOARD_CONF_FILE_PATH)
pass
else :
ShellCmdExecutor.execCmd("sudo mkdir %s" % dashboardConfFileDir)
pass
print 'localSettingsFileTemplatePath=%s--' % localSettingsFileTemplatePath
ShellCmdExecutor.execCmd("sudo chmod 777 %s" % dashboardConfFileDir)
####NEW
ShellCmdExecutor.execCmd('cat %s > /tmp/local_settings' % localSettingsFileTemplatePath)
ShellCmdExecutor.execCmd('mv /tmp/local_settings %s' % dashboardConfFileDir)
keystone_vip = JSONUtility.getValue("keystone_vip")
ShellCmdExecutor.execCmd('sudo chmod 777 %s' % Dashboard.DASHBOARD_CONF_FILE_PATH)
FileUtil.replaceFileContent(Dashboard.DASHBOARD_CONF_FILE_PATH, '<KEYSTONE_VIP>', keystone_vip)
ShellCmdExecutor.execCmd('sudo chmod 644 %s' % Dashboard.DASHBOARD_CONF_FILE_PATH)
#Assign rights: can be accessed
DIR_PATH = '/usr/share/openstack-dashboard/openstack_dashboard/local'
if os.path.exists(DIR_PATH) :
ShellCmdExecutor.execCmd('sudo chmod 777 %s' % DIR_PATH)
pass
pass
示例6: configureML2
def configureML2():
ml2ConfTemplatePath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'nova-compute', 'ml2_conf.ini')
ShellCmdExecutor.execCmd('cp -r %s /etc/neutron/plugins/ml2/' % ml2ConfTemplatePath)
output, exitcode = ShellCmdExecutor.execCmd('cat /opt/localip')
localIP = output.strip()
FileUtil.replaceFileContent('/etc/neutron/plugins/ml2/ml2_conf.ini', '<INSTANCE_TUNNELS_INTERFACE_IP_ADDRESS>', localIP)
pass
示例7: execCmdWithoutKillTimeout
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)
示例8: prepareAdminOpenrc
def prepareAdminOpenrc():
adminOpenrcTemplateFilePath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'admin-openrc.sh')
ShellCmdExecutor.execCmd('cp -r %s /opt/openstack_conf' % adminOpenrcTemplateFilePath)
keystone_admin_password = JSONUtility.getValue('keystone_admin_password')
keystone_vip = JSONUtility.getValue('keystone_vip')
FileUtil.replaceFileContent('/opt/openstack_conf/admin-openrc.sh', '<KEYSTONE_ADMIN_PASSWORD>', keystone_admin_password)
FileUtil.replaceFileContent('/opt/openstack_conf/admin-openrc.sh', '<KEYSTONE_VIP>', keystone_vip)
pass
示例9: configureKeystoneHAProxy
def configureKeystoneHAProxy():
dashboard_vip = JSONUtility.getValue("dashboard_vip")
openstackConfPopertiesFilePath = PropertiesUtility.getOpenstackConfPropertiesFilePath()
HAProxyTemplateFilePath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'haproxy.cfg')
haproxyConfFilePath = PropertiesUtility.getValue(openstackConfPopertiesFilePath, 'HAPROXY_CONF_FILE_PATH')
print 'haproxyConfFilePath=%s' % haproxyConfFilePath
if not os.path.exists('/etc/haproxy') :
ShellCmdExecutor.execCmd('sudo mkdir /etc/haproxy')
pass
if not os.path.exists(haproxyConfFilePath) :
ShellCmdExecutor.execCmd('sudo cp -rf %s %s' % (HAProxyTemplateFilePath, haproxyConfFilePath))
pass
ShellCmdExecutor.execCmd('sudo chmod 777 %s' % haproxyConfFilePath)
dashboardBackendStringTemplate = '''
listen dashboard_cluster
bind <DASHBOARD_VIP>:80
balance source
option tcpka
option httpchk
option tcplog
<DASHBOARD_SERVER_LIST>
'''
###############
dashboardBackendString = dashboardBackendStringTemplate.replace('<DASHBOARD_VIP>', dashboard_vip)
################new
dashboard_ips = JSONUtility.getValue("dashboard_ips")
dashboard_ip_list = dashboard_ips.strip().split(',')
serverDashboardBackendTemplate = 'server dashboard-<INDEX> <SERVER_IP>:8080 weight 3 check inter 2000 rise 2 fall 3'
dashboardServerListContent = ''
index = 1
for dashboard_ip in dashboard_ip_list:
print 'dashboard_ip=%s' % dashboard_ip
dashboardServerListContent += serverDashboardBackendTemplate.replace('<INDEX>', str(index)).replace('<SERVER_IP>', dashboard_ip)
dashboardServerListContent += '\n'
dashboardServerListContent += ' '
index += 1
pass
dashboardServerListContent = dashboardServerListContent.strip()
print 'dashboardServerListContent=%s--' % dashboardServerListContent
dashboardBackendString = dashboardBackendString.replace('<DASHBOARD_SERVER_LIST>', dashboardServerListContent)
print 'dashboardBackendString=%s--' % dashboardBackendString
#append
FileUtil.replaceFileContent(haproxyConfFilePath, '<DASHBOARD_LIST>', dashboardBackendString)
ShellCmdExecutor.execCmd('sudo chmod 644 %s' % haproxyConfFilePath)
示例10: configConfFile
def configConfFile():
print "configure keystone conf file======"
mysql_vip = JSONUtility.getValue("mysql_vip")
admin_token = JSONUtility.getValue("admin_token")
#memcache service list
keystone_ips_string = JSONUtility.getValue("keystone_ips")
keystone_ip_list = keystone_ips_string.split(',')
memcached_service_list = []
for ip in keystone_ip_list:
memcached_service_list.append(ip.strip() + ':11211')
pass
memcached_service_string = ','.join(memcached_service_list)
print 'memcached_service_string=%s--' % memcached_service_string
openstackConfPopertiesFilePath = PropertiesUtility.getOpenstackConfPropertiesFilePath()
keystoneConfDir = PropertiesUtility.getValue(openstackConfPopertiesFilePath, 'KEYSTONE_CONF_DIR')
keystone_conf_file_path = os.path.join(keystoneConfDir, 'keystone.conf')
if not os.path.exists(keystoneConfDir) :
os.system("sudo mkdir -p %s" % keystoneConfDir)
pass
ShellCmdExecutor.execCmd("cp -r %s %s" % (SOURCE_KEYSTONE_CONF_FILE_TEMPLATE_PATH, keystoneConfDir))
ShellCmdExecutor.execCmd("sudo chmod 777 %s" % keystone_conf_file_path)
# #if exist, remove original conf files
# if os.path.exists(keystone_conf_file_path) :
# os.system("sudo rm -rf %s" % keystone_conf_file_path)
# pass
#
# ShellCmdExecutor.execCmd('chmod 777 /etc/keystone')
#
# # os.system("sudo cp -r %s %s" % (SOURCE_KEYSTONE_CONF_FILE_TEMPLATE_PATH, keystoneConfDir))
# ###NEW
# ShellCmdExecutor.execCmd('cat %s > /tmp/keystone.conf' % SOURCE_KEYSTONE_CONF_FILE_TEMPLATE_PATH)
# ShellCmdExecutor.execCmd('mv /tmp/keystone.conf /etc/keystone/')
#
# ShellCmdExecutor.execCmd("sudo chmod 777 %s" % keystone_conf_file_path)
###########LOCAL_IP:retrieve it from one file, the LOCAL_IP file is generated when this project inits.
localIP = Keystone.getLocalIP()
print 'localip=%s--' % localIP
# FileUtil.replaceByRegularExpression(keystone_conf_file_path, '<LOCAL_IP>', localIP)
# FileUtil.replaceByRegularExpression(keystone_conf_file_path, '<MYSQL_VIP>', mysql_vip)
keystoneDbPass = JSONUtility.getValue('keystone_dbpass')
FileUtil.replaceFileContent(keystone_conf_file_path, '<ADMIN_TOKEN>', admin_token)
FileUtil.replaceFileContent(keystone_conf_file_path, '<LOCAL_MANAGEMENT_IP>', localIP)
FileUtil.replaceFileContent(keystone_conf_file_path, '<MYSQL_VIP>', mysql_vip)
FileUtil.replaceFileContent(keystone_conf_file_path, '<KEYSTONE_DBPASS>', keystoneDbPass)
FileUtil.replaceFileContent(keystone_conf_file_path, '<MEMCACHED_LIST>', memcached_service_string)
ShellCmdExecutor.execCmd("chmod 644 %s" % keystone_conf_file_path)
print "configure keystone conf file done####"
pass
示例11: sourceAdminOpenRC
def sourceAdminOpenRC():
adminOpenRCScriptPath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'admin_openrc.sh')
print 'adminOpenRCScriptPath=%s' % adminOpenRCScriptPath
ShellCmdExecutor.execCmd('cp -rf %s /opt/' % adminOpenRCScriptPath)
keystone_vip = JSONUtility.getValue("keystone_vip")
FileUtil.replaceFileContent('/opt/admin_openrc.sh', '<KEYSTONE_VIP>', keystone_vip)
time.sleep(2)
ShellCmdExecutor.execCmd('source /opt/admin_openrc.sh')
pass
示例12: getMeteringSecret
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
示例13: writeIPList
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
示例14: configureOVS
def configureOVS():
ShellCmdExecutor.execCmd("service openvswitch start")
ShellCmdExecutor.execCmd("chkconfig openvswitch on")
scriptPath = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'nova-compute', 'addBridgeAndInterface.sh')
ShellCmdExecutor.execCmd('cp -r %s /opt/' % scriptPath)
output, exitcode = ShellCmdExecutor.execCmd('cat /opt/localip')
localIP = output.strip()
FileUtil.replaceFileContent('/opt/addBridgeAndInterface.sh', '<LOCAL_IP>', localIP)
ShellCmdExecutor.execCmd('bash /opt/addBridgeAndInterface.sh')
pass
示例15: configKeepalived
def configKeepalived():
ha_vip1 = JSONUtility.getValue('ha_vip1')
ha_vip2 = JSONUtility.getValue('ha_vip2')
ha_vip1_interface = JSONUtility.getValue('ha_vip1_interface')
ha_vip2_interface = JSONUtility.getValue('ha_vip2_interface')
keepalived_conf_1_template_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'ha', 'keepalived.conf.1')
keepalived_conf_2_template_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'ha', 'keepalived.conf.2')
keepalived_conf_dest_path = '/etc/keepalived/keepalived.conf'
haproxy_keepalived_ips = JSONUtility.getValue('haproxy_keepalived_ips')
haproxy_keepalived_ip_list = haproxy_keepalived_ips.split(',')
output, exitcode = ShellCmdExecutor.execCmd('cat /opt/localip')
local_management_ip = output.strip()
serverIndex = ServerSequence.getIndex(haproxy_keepalived_ip_list, local_management_ip)
if serverIndex == 0 :
ShellCmdExecutor.execCmd('cp -r %s %s' % (keepalived_conf_1_template_path, keepalived_conf_dest_path))
FileUtil.replaceFileContent(keepalived_conf_dest_path, '<HA_VIP1>', ha_vip1)
FileUtil.replaceFileContent(keepalived_conf_dest_path, '<HA_VIP1_INTERFACE>', ha_vip1_interface)
pass
if serverIndex == 1 :
ShellCmdExecutor.execCmd('cp -r %s %s' % (keepalived_conf_2_template_path, keepalived_conf_dest_path))
FileUtil.replaceFileContent(keepalived_conf_dest_path, '<HA_VIP2>', ha_vip2)
FileUtil.replaceFileContent(keepalived_conf_dest_path, '<HA_VIP1_INTERFACE>', ha_vip2_interface)
pass
haproxy_check_script_path = os.path.join(OPENSTACK_CONF_FILE_TEMPLATE_DIR, 'ha', 'haproxy_check.sh')
ShellCmdExecutor.execCmd('cp -r %s /etc/keepalived/' % haproxy_check_script_path)
ShellCmdExecutor.execCmd('chmod 644 %s' % keepalived_conf_dest_path)
ShellCmdExecutor.execCmd('chmod 644 /etc/keepalived/haproxy_check.sh')
pass