本文整理汇总了Python中utilities.bash函数的典型用法代码示例。如果您正苦于以下问题:Python bash函数的具体用法?Python bash怎么用?Python bash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bash函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: addBridge
def addBridge(self, br, dev):
bash("ifdown %s"%dev.name)
for line in file(self.netCfgFile).readlines():
match = re.match("^ *iface %s.*"%dev.name, line)
if match is not None:
dev.method = self.getNetworkMethod(match.group(0))
cfo = configFileOps(self.netCfgFile, self)
if self.syscfg.env.bridgeType == "openvswitch":
bridgeCfg = "\n".join(("",
"iface {device} inet manual",
" ovs_type OVSPort",
" ovs_bridge {bridge}",
"",
"auto {bridge}",
"allow-ovs {bridge}",
"iface {bridge} inet {device_method}",
" ovs_type OVSBridge",
" ovs_ports {device}",
"")).format(bridge=br, device=dev.name, device_method=dev.method)
cfo.replace_line("^ *auto %s.*" % dev.name,
"allow-{bridge} {device}".format(bridge=br, device=dev.name))
elif self.syscfg.env.bridgeType == "native":
bridgeCfg = "\niface %s inet manual\n \
auto %s\n \
iface %s inet %s\n \
bridge_ports %s\n"%(dev.name, br, br, dev.method, dev.name)
else:
raise CloudInternalException("Unknown network.bridge.type %s" % self.syscfg.env.bridgeType)
cfo.replace_line("^ *iface %s.*"%dev.name, bridgeCfg)
开发者ID:ikarin,项目名称:cloudstack,代码行数:29,代码来源:serviceConfig.py
示例2: restore
def restore(self):
try:
bash("setenforce 1")
return True
except:
logging.debug(formatExceptionInfo())
return False
开发者ID:adamdc,项目名称:CloudStack,代码行数:7,代码来源:serviceConfig.py
示例3: configAgent
def configAgent(self):
try:
cfo = configFileOps("/etc/cloudstack/agent/agent.properties", self)
cfo.addEntry("host", self.syscfg.env.mgtSvr)
cfo.addEntry("zone", self.syscfg.env.zone)
cfo.addEntry("pod", self.syscfg.env.pod)
cfo.addEntry("cluster", self.syscfg.env.cluster)
cfo.addEntry("hypervisor.type", self.syscfg.env.hypervisor)
cfo.addEntry("port", "8250")
cfo.addEntry("private.network.device", self.syscfg.env.nics[0])
cfo.addEntry("public.network.device", self.syscfg.env.nics[1])
cfo.addEntry("guest.network.device", self.syscfg.env.nics[2])
cfo.addEntry("guid", str(self.syscfg.env.uuid))
if cfo.getEntry("local.storage.uuid") == "":
cfo.addEntry("local.storage.uuid", str(bash("uuidgen").getStdout()))
if cfo.getEntry("resource") == "":
cfo.addEntry("resource", "com.cloud.hypervisor.kvm.resource.LibvirtComputingResource")
cfo.save()
self.syscfg.svo.stopService("cloudstack-agent")
bash("sleep 30")
self.syscfg.svo.enableService("cloudstack-agent")
return True
except:
raise
开发者ID:ustcweizhou,项目名称:cloudstack,代码行数:25,代码来源:serviceConfig.py
示例4: allowPort
def allowPort(self, port):
status = False
try:
status = bash("iptables-save|grep INPUT|grep -w %s"%port).isSuccess()
except:
pass
if not status:
bash("iptables -I INPUT -p tcp -m tcp --dport %s -j ACCEPT"%port)
开发者ID:adamdc,项目名称:CloudStack,代码行数:9,代码来源:serviceConfig.py
示例5: config
def config(self):
try:
for port in self.ports:
self.allowPort(port)
#FIXME: urgly make /root writable
bash("sudo chmod 0777 /root")
return True
except:
raise
开发者ID:adamdc,项目名称:CloudStack,代码行数:11,代码来源:serviceConfig.py
示例6: addBridge
def addBridge(self, br, dev):
bash("ifdown %s"%dev.name)
for line in file(self.netCfgFile).readlines():
match = re.match("^ *iface %s.*"%dev.name, line)
if match is not None:
dev.method = self.getNetworkMethod(match.group(0))
bridgeCfg = "\niface %s inet manual\n \
auto %s\n \
iface %s inet %s\n \
bridge_ports %s\n"%(dev.name, br, br, dev.method, dev.name)
cfo = configFileOps(self.netCfgFile, self)
cfo.replace_line("^ *iface %s.*"%dev.name, bridgeCfg)
开发者ID:adamdc,项目名称:CloudStack,代码行数:12,代码来源:serviceConfig.py
示例7: executeFromFile
def executeFromFile(self, file):
if not os.path.exists(file):
return False
cmdLine = "mysql --host=" + self.host + " --port=" + str(self.port) + " --user=" + self.username
if self.password is not None:
cmdLine += " --password=" + self.password
cmdLine += " < " + file
try:
bash(cmdLine)
except:
raise CloudRuntimeException("Failed to execute " + cmdLine)
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:14,代码来源:db.py
示例8: getDevInfo
def getDevInfo(dev):
if not networkConfig.isNetworkDev(dev):
logging.debug("dev: " + dev + " is not a network device")
raise CloudInternalException("dev: " + dev + " is not a network device")
netmask = None
ipAddr = None
macAddr = None
cmd = bash("ifconfig " + dev)
if not cmd.isSuccess():
logging.debug("Failed to get address from ifconfig")
raise CloudInternalException("Failed to get network info by ifconfig %s"%dev)
for line in cmd.getLines():
if line.find("HWaddr") != -1:
macAddr = line.split("HWaddr ")[1].strip(" ")
elif line.find("inet ") != -1:
m = re.search("addr:(.*)\ *Bcast:(.*)\ *Mask:(.*)", line)
if m is not None:
ipAddr = m.group(1).rstrip(" ")
netmask = m.group(3).rstrip(" ")
if networkConfig.isBridgePort(dev):
type = "brport"
elif networkConfig.isBridge(dev):
type = "bridge"
else:
type = "dev"
return networkConfig.devInfo(macAddr, ipAddr, netmask, None, type, dev)
开发者ID:BillTheBest,项目名称:CloudStack,代码行数:31,代码来源:networkConfig.py
示例9: getDefaultNetwork
def getDefaultNetwork():
cmd = bash("route -n|awk \'/^0.0.0.0/ {print $2,$8}\'")
if not cmd.isSuccess():
logging.debug("Failed to get default route")
raise CloudRuntimeException("Failed to get default route")
result = cmd.getStdout().split(" ")
gateway = result[0]
dev = result[1]
pdi = networkConfig.getDevInfo(dev)
logging.debug("Found default network device:%s"%pdi.name)
pdi.gateway = gateway
return pdi
开发者ID:BillTheBest,项目名称:CloudStack,代码行数:14,代码来源:networkConfig.py
示例10: createBridge
def createBridge(dev, brName):
if not networkConfig.isBridgeSupported():
logging.debug("bridge is not supported")
return False
if networkConfig.isBridgeEnslavedWithDevices(brName):
logging.debug("bridge: %s has devices enslaved"%brName)
return False
cmds = ""
if not networkConfig.isBridge(brName):
cmds = "brctl addbr %s ;"%brName
cmds += "ifconfig %s up;"%brName
cmds += "brctl addif %s %s"%(brName, dev)
return bash(cmds).isSuccess()
开发者ID:BillTheBest,项目名称:CloudStack,代码行数:15,代码来源:networkConfig.py
示例11: configMyCloud
def configMyCloud(self):
try:
cfo = configFileOps("/etc/cosmic/agent/agent.properties", self)
cfo.addEntry("host", self.syscfg.env.mgtSvr)
cfo.addEntry("zone", self.syscfg.env.zone)
cfo.addEntry("port", "443")
if cfo.getEntry("local.storage.uuid") == "":
cfo.addEntry("local.storage.uuid", str(bash("uuidgen").getStdout()))
cfo.addEntry("guid", str(self.syscfg.env.uuid))
cfo.addEntry("mount.path", "/mnt")
cfo.addEntry("resource", "com.cloud.storage.resource.LocalSecondaryStorageResource|com.cloud.agent.resource.computing.CloudZonesComputingResource")
cfo.save()
#self.syscfg.svo.stopService("cloud-agent")
#self.syscfg.svo.enableService("cloud-agent")
return True
except:
raise
开发者ID:EdwardBetts,项目名称:blackhole,代码行数:18,代码来源:serviceConfig.py
示例12: allowPort
def allowPort(self, port):
status = False
try:
status = bash("iptables-save|grep INPUT|grep -w %s"%port).isSuccess()
except:
pass
if not status:
redo = False
result = True
try:
result = bash("iptables -I INPUT -p tcp -m tcp --dport %s -j ACCEPT"%port).isSuccess()
except:
redo = True
if not result or redo:
bash("sleep 30")
bash("iptables -I INPUT -p tcp -m tcp --dport %s -j ACCEPT"%port)
开发者ID:ikarin,项目名称:cloudstack,代码行数:18,代码来源:serviceConfig.py
示例13: isBridgeSupported
def isBridgeSupported():
if os.path.exists("/proc/sys/net/bridge"):
return True
return bash("modprobe bridge").isSucess()
开发者ID:BillTheBest,项目名称:CloudStack,代码行数:5,代码来源:networkConfig.py
示例14: bash
try:
statement = """ UPDATE configuration SET value='%s' WHERE name='%s'"""
db.execute(statement%('true','use.local.storage'))
db.execute(statement%('20','max.template.iso.size'))
statement = """ UPDATE vm_template SET url='%s',checksum='%s' WHERE id='%s' """
db.execute(statement%('https://rightscale-cloudstack.s3.amazonaws.com/kvm/RightImage_CentOS_5.4_x64_v5.6.28.qcow2.bz2', '90fcd2fa4d3177e31ff296cecb9933b7', '4'))
statement="""UPDATE disk_offering set use_local_storage=1"""
db.execute(statement)
except:
raise e
#add DNAT 443 to 8250
if not bash("iptables-save |grep PREROUTING | grep 8250").isSuccess():
bash("iptables -A PREROUTING -t nat -p tcp --dport 443 -j REDIRECT --to-port 8250 ")
elif self.syscfg.env.svrMode == "HttpsServer":
if not bash("iptables-save |grep PREROUTING | grep 8443").isSuccess():
bash("iptables -A PREROUTING -t nat -p tcp --dport 443 -j REDIRECT --to-port 8443")
bash("touch /var/run/cloudstack-management.pid")
bash("chown cloud.cloud /var/run/cloudstack-management.pid")
checkHostName()
bash("mkdir -p /var/lib/cloudstack/")
bash("chown cloud:cloud -R /var/lib/cloudstack/")
#set max process per account is unlimited
if os.path.exists("/etc/security/limits.conf"):
cfo = configFileOps("/etc/security/limits.conf")
cfo.add_lines("cloud soft nproc -1\n")
cfo.add_lines("cloud hard nproc -1\n")
cfo.save()
开发者ID:Accelerite,项目名称:cloudstack,代码行数:31,代码来源:serviceConfigServer.py
示例15: bash
try:
statement = """ UPDATE configuration SET value='%s' WHERE name='%s'"""
db.execute(statement%('true','use.local.storage'))
db.execute(statement%('20','max.template.iso.size'))
statement = """ UPDATE vm_template SET url='%s',checksum='%s' WHERE id='%s' """
db.execute(statement%('https://rightscale-cloudstack.s3.amazonaws.com/kvm/RightImage_CentOS_5.4_x64_v5.6.28.qcow2.bz2', '90fcd2fa4d3177e31ff296cecb9933b7', '4'))
statement="""UPDATE disk_offering set use_local_storage=1"""
db.execute(statement)
except:
raise e
#add DNAT 443 to 8250
if not bash("iptables-save |grep PREROUTING | grep 8250").isSuccess():
bash("iptables -A PREROUTING -t nat -p tcp --dport 443 -j REDIRECT --to-port 8250 ")
#generate keystore
keyPath = "/var/lib/cloud/management/web.keystore"
if not os.path.exists(keyPath):
cmd = bash("keytool -genkey -keystore %s -storepass \"cloud.com\" -keypass \"cloud.com\" -validity 3650 -dname cn=\"Cloudstack User\",ou=\"mycloud.cloud.com\",o=\"mycloud.cloud.com\",c=\"Unknown\""%keyPath)
if not cmd.isSuccess():
raise CloudInternalException(cmd.getErrMsg())
cfo = configFileOps("/etc/cloud/management/tomcat6.conf", self)
cfo.add_lines("JAVA_OPTS+=\" -Djavax.net.ssl.trustStore=%s \""%keyPath)
try:
self.syscfg.svo.disableService("tomcat6")
开发者ID:pigxiang,项目名称:CloudStack,代码行数:31,代码来源:serviceConfigServer.py
示例16: bash
try:
statement = """ UPDATE configuration SET value='%s' WHERE name='%s'"""
db.execute(statement % ('true', 'use.local.storage'))
db.execute(statement % ('20', 'max.template.iso.size'))
statement = """ UPDATE vm_template SET url='%s',checksum='%s' WHERE id='%s' """
db.execute(statement % ('https://rightscale-cloudstack.s3.amazonaws.com/kvm/RightImage_CentOS_5.4_x64_v5.6.28.qcow2.bz2', '90fcd2fa4d3177e31ff296cecb9933b7', '4'))
statement = """UPDATE disk_offering set use_local_storage=1"""
db.execute(statement)
except:
raise e
# add DNAT 443 to 8250
if not bash("iptables-save |grep PREROUTING | grep 8250").isSuccess():
bash("iptables -A PREROUTING -t nat -p tcp --dport 443 -j REDIRECT --to-port 8250 ")
# generate keystore
keyPath = "/var/cloudstack/management/web.keystore"
if not os.path.exists(keyPath):
cmd = bash(
"keytool -genkeypair -keystore %s -storepass \"cloud.com\" -keypass \"cloud.com\" -validity 3650 -dname cn=\"Cloudstack User\",ou=\"mycloud.cloud.com\",o=\"mycloud.cloud.com\",c=\"Unknown\"" % keyPath)
if not cmd.isSuccess():
raise CloudInternalException(cmd.getErrMsg())
if not self.syscfg.env.svrConf == "Tomcat7":
cfo = configFileOps("/etc/cloudstack/management/tomcat6.conf", self)
cfo.add_lines("JAVA_OPTS+=\" -Djavax.net.ssl.trustStore=%s \"" % keyPath)
elif self.syscfg.env.svrMode == "HttpsServer":
if self.syscfg.env.svrConf == "Tomcat7":
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:31,代码来源:serviceConfigServer.py
注:本文中的utilities.bash函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论