本文整理汇总了Python中pyanaconda.iutil.execWithCapture函数的典型用法代码示例。如果您正苦于以下问题:Python execWithCapture函数的具体用法?Python execWithCapture怎么用?Python execWithCapture使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execWithCapture函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _build_mpath_topology
def _build_mpath_topology(self):
with open("/etc/multipath.conf") as conf:
log.debug("/etc/multipath.conf contents:")
map(lambda line: log.debug(line.rstrip()), conf)
log.debug("(end of /etc/multipath.conf)")
self._mpath_topology = parseMultipathOutput(
iutil.execWithCapture("multipath", ["-d",]))
self._mpath_topology.update(parseMultipathOutput(
iutil.execWithCapture("multipath", ["-ll",])))
delete_keys = []
for (mp, disks) in self._mpath_topology.items():
# single device mpath is not really an mpath, eliminate them:
if len(disks) < 2:
log.info("MultipathTopology: not a multipath: %s" % disks)
delete_keys.append(mp)
continue
# some usb cardreaders use multiple lun's (for different slots) and
# report a fake disk serial which is the same for all the lun's
# (#517603). find those mpaths and eliminate them:
only_non_usbs = [d for d in disks if
self._devmap[d].get("ID_USB_DRIVER") != "usb-storage"]
if len(only_non_usbs) == 0:
log.info("DeviceToppology: found multi lun usb "
"mass storage device: %s" % disks)
delete_keys.append(mp)
map(lambda key: self._mpath_topology.pop(key), delete_keys)
示例2: testExecCaptureNonZeroFatal
def testExecCaptureNonZeroFatal(self):
import iutil
try:
argv = ["-c", "import sys; sys.exit(3);"]
iutil.execWithCapture(sys.executable, argv, root=None, fatal=True)
except RuntimeError, ex:
self.assertIn("return code: 3", str(ex))
示例3: exec_with_capture_test
def exec_with_capture_test(self):
"""Test execWithCapture."""
# check some output is returned
self.assertGreater(len(iutil.execWithCapture("ls", ["--help"])), 0)
# check no output is returned
self.assertEqual(len(iutil.execWithCapture("true", [])), 0)
示例4: shutdownServer
def shutdownServer():
"""Try to shutdown any running XVNC server
Why is this function on the module level and not in the VncServer class ?
As the server needs to be killed from the exit handler, it would have
to somehow get to the VncServer instance. Like this, it can just kill
it by calling a function of the vnc module.
"""
try:
iutil.execWithCapture("killall", [XVNC_BINARY_NAME])
log.info("The XVNC server has been shut down.")
except OSError as e:
log.error("Shutdown of the XVNC server failed with exception:\n%s", e)
示例5: exec_with_capture_empty_test
def exec_with_capture_empty_test(self):
"""Test execWithCapture with no output"""
# check that the output is an empty string
self.assertEqual(
iutil.execWithCapture("/bin/sh", ["-c", "exit 0"]),
"")
示例6: pvinfo
def pvinfo(device):
"""
If the PV was created with '--metadacopies 0', lvm will do some
scanning of devices to determine from their metadata which VG
this PV belongs to.
pvs -o pv_name,pv_mda_count,vg_name,vg_uuid --config \
'devices { scan = "/dev" filter = ["a/loop0/", "r/.*/"] }'
"""
#cfg = "'devices { scan = \"/dev\" filter = [\"a/%s/\", \"r/.*/\"] }'"
args = ["pvs", "--noheadings"] + \
["--units", "m"] + \
["-o", "pv_name,pv_mda_count,vg_name,vg_uuid"] + \
config_args + \
[device]
rc = iutil.execWithCapture("lvm", args,
stderr = "/dev/tty5")
vals = rc.split()
if not vals:
raise LVMError("pvinfo failed for %s" % device)
# don't raise an exception if pv is not a part of any vg
pv_name = vals[0]
try:
vg_name, vg_uuid = vals[2], vals[3]
except IndexError:
vg_name, vg_uuid = "", ""
info = {'pv_name': pv_name,
'vg_name': vg_name,
'vg_uuid': vg_uuid}
return info
示例7: lvs
def lvs(vg_name):
args = ["lvs", "--noheadings", "--nosuffix"] + \
["--units", "m"] + \
["-o", "lv_name,lv_uuid,lv_size,lv_attr"] + \
config_args + \
[vg_name]
buf = iutil.execWithCapture("lvm",
args,
stderr="/dev/tty5")
lvs = {}
for line in buf.splitlines():
line = line.strip()
if not line:
continue
(name, uuid, size, attr) = line.split()
lvs[name] = {"size": size,
"uuid": uuid,
"attr": attr}
if not lvs:
raise LVMError(_("lvs failed for %s" % vg_name))
return lvs
示例8: minSize
def minSize(self):
""" The minimum filesystem size in megabytes. """
if self._minInstanceSize is None:
# we try one time to determine the minimum size.
size = self._minSize
if self.exists and os.path.exists(self.device):
minSize = None
buf = iutil.execWithCapture(self.resizefsProg,
["-m", self.device],
stderr = "/dev/tty5")
for l in buf.split("\n"):
if not l.startswith("Minsize"):
continue
try:
min = l.split(":")[1].strip()
minSize = int(min) + 250
except Exception, e:
minSize = None
log.warning("Unable to parse output for minimum size on %s: %s" %(self.device, e))
if minSize is None:
log.warning("Unable to discover minimum size of filesystem "
"on %s" %(self.device,))
else:
size = minSize
self._minInstanceSize = size
示例9: exec_with_capture_no_stderr_test
def exec_with_capture_no_stderr_test(self):
"""Test execWithCapture with no stderr"""
with tempfile.NamedTemporaryFile(mode="w+t") as testscript:
testscript.write(
"""#!/bin/sh
echo "output"
echo "error" >&2
"""
)
testscript.flush()
# check that only the output is captured
self.assertEqual(iutil.execWithCapture("/bin/sh", [testscript.name], filter_stderr=True), "output\n")
# check that both output and error are captured
self.assertEqual(iutil.execWithCapture("/bin/sh", [testscript.name]), "output\nerror\n")
示例10: modulesWithPaths
def modulesWithPaths():
mods = []
for modline in open("/proc/modules", "r"):
modName = modline.split(" ", 1)[0]
modInfo = iutil.execWithCapture("modinfo", ["-F", "filename", modName]).splitlines()
modPaths = [line.strip() for line in modInfo if line != ""]
mods.extend(modPaths)
return mods
示例11: ifaceForHostIP
def ifaceForHostIP(host):
route = iutil.execWithCapture("ip", ["route", "get", "to", host])
if not route:
log.error("Could not get interface for route to %s", host)
return ""
routeInfo = route.split()
if routeInfo[0] != host or len(routeInfo) < 5 or "dev" not in routeInfo or routeInfo.index("dev") > 3:
log.error('Unexpected "ip route get to %s" reply: %s', host, routeInfo)
return ""
return routeInfo[routeInfo.index("dev") + 1]
示例12: writeZipl
def writeZipl(self, instRoot, bl, kernelList, chainList,
defaultDev, justConfigFile):
rootDev = self.storage.rootDevice
cf = '/etc/zipl.conf'
self.perms = 0600
if os.access (instRoot + cf, os.R_OK):
self.perms = os.stat(instRoot + cf)[0] & 0777
os.rename(instRoot + cf,
instRoot + cf + '.rpmsave')
f = open(instRoot + cf, "w+")
f.write('[defaultboot]\n')
if self.timeout:
f.write('timeout=%d\n' % self.timeout)
f.write('default=' + kernelList[0][0] + '\n')
f.write('target=%s\n' % (self.kernelLocation))
cfPath = "/boot/"
for (label, longlabel, version) in kernelList:
kernelTag = "-" + version
kernelFile = "%svmlinuz%s" % (cfPath, kernelTag)
initrd = self.makeInitrd(kernelTag, instRoot)
f.write('[%s]\n' % (label))
f.write('\timage=%s\n' % (kernelFile))
if initrd:
f.write('\tramdisk=%s%s\n' %(self.kernelLocation, initrd))
realroot = rootDev.fstabSpec
f.write('\tparameters="root=%s' %(realroot,))
if bl.args.get():
f.write(' %s' % (bl.args.get()))
f.write('"\n')
f.close()
if not justConfigFile:
rc = iutil.execWithCapture("zipl", [], root = instRoot,
stderr = "/dev/stderr")
for line in rc.splitlines():
if line.startswith("Preparing boot device: "):
# Output here may look like:
# Preparing boot device: dasdb (0200).
# Preparing boot device: dasdl.
# We want to extract the device name and pass that.
fields = line[23:].split()
self.setDevice(fields[0].replace('.', ''))
return 0
示例13: _startEDD
def _startEDD(self, intf = None):
rc = iutil.execWithCapture("/usr/libexec/fcoe/fcoe_edd.sh", [ "-i" ],
stderr="/dev/tty5")
if not rc.startswith("NIC="):
log.info("No FCoE EDD info found: %s" % rc.rstrip())
return
(key, val) = rc.strip().split("=", 1)
if val not in isys.getDeviceProperties():
log.error("Unknown FCoE NIC found in EDD: %s, ignoring" % val)
return
log.info("FCoE NIC found in EDD: %s" % val)
self.addSan(val, dcb=True, auto_vlan=True, intf=intf)
示例14: lvorigin
def lvorigin(vg_name, lv_name):
args = ["lvs", "--noheadings", "-o", "origin"] + \
config_args + \
["%s/%s" % (vg_name, lv_name)]
buf = iutil.execWithCapture("lvm",
args,
stderr="/dev/tty5")
try:
origin = buf.splitlines()[0].strip()
except IndexError:
origin = ''
return origin
示例15: vginfo
def vginfo(vg_name):
args = ["vgs", "--noheadings", "--nosuffix"] + \
["--units", "m"] + \
["-o", "uuid,size,free,extent_size,extent_count,free_count,pv_count"] + \
config_args + \
[vg_name]
buf = iutil.execWithCapture("lvm",
args,
stderr="/dev/tty5")
info = buf.split()
if len(info) != 7:
raise LVMError(_("vginfo failed for %s" % vg_name))
d = {}
(d['uuid'],d['size'],d['free'],d['pe_size'],
d['pe_count'],d['pe_free'],d['pv_count']) = info
return d