本文整理汇总了Python中util.pread2函数的典型用法代码示例。如果您正苦于以下问题:Python pread2函数的具体用法?Python pread2怎么用?Python pread2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pread2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _checkVG
def _checkVG(vgname):
try:
cmd = [CMD_VGS, vgname]
util.pread2(cmd)
return True
except:
return False
示例2: _resetDMP
def _resetDMP(sid,explicit_unmap=False,delete_nodes=False):
# If mpath has been turned on since the sr/vdi was attached, we
# might be trying to unmap it before the daemon has been started
# This is unnecessary (and will fail) so just return.
deactivate_MPdev(sid)
if not _is_mpath_daemon_running():
util.SMlog("Warning: Trying to unmap mpath device when multipathd not running")
return
# If the multipath daemon is running, but we were initially plugged
# with multipathing set to no, there may be no map for us in the multipath
# tables. In that case, list_paths will return [], but remove_map might
# throw an exception. Catch it and ignore it.
if explicit_unmap:
util.retry(lambda: util.pread2(['/usr/sbin/multipath', '-f', sid]),
maxretry = 3, period = 4)
util.retry(lambda: util.pread2(['/usr/sbin/multipath', '-W']), maxretry = 3,
period = 4)
else:
mpath_cli.ensure_map_gone(sid)
path = "/dev/mapper/%s" % sid
if not util.wait_for_nopath(path, 10):
util.SMlog("MPATH: WARNING - path did not disappear [%s]" % path)
else:
util.SMlog("MPATH: path disappeared [%s]" % path)
示例3: deactivate
def deactivate():
util.SMlog("MPATH: multipath deactivate called")
# Adjust any HBAs on the host
cmd = [hba_script, "disable"]
util.SMlog(util.pread2(cmd))
cmd = ['ln', '-sf', iscsi_default_file, iscsi_file]
util.pread2(cmd)
# Stop the updatempppathd daemon
if _is_mpp_daemon_running():
cmd = ["/etc/init.d/updatempppathd", "stop"]
util.pread2(cmd)
if _is_mpath_daemon_running():
# Flush the multipath nodes
for sid in mpath_cli.list_maps():
reset(sid,True)
# Disable any active MPP LUN maps (except the root dev)
systemroot = os.path.realpath(util.getrootdev())
for dev in glob.glob(DEVBYMPPPATH + "/*"):
if os.path.realpath(dev) != systemroot:
sid = os.path.basename(dev).split('-')[0]
reset(sid)
else:
util.SMlog("MPP: Found root dev node, not resetting")
# Check the ISCSI daemon doesn't have any active sessions, if not,
# restart in the new mode
if iscsilib.is_iscsi_daemon_running() and not iscsilib._checkAnyTGT():
iscsilib.restart_daemon()
util.SMlog("MPATH: multipath deactivated.")
示例4: create
def create(self, sr_uuid, vdi_uuid, size):
if not self.sr.isMaster:
util.SMlog('vdi_create blocked for non-master')
raise xs_errors.XenError('LVMMaster')
try:
mb = 1024L * 1024L
size_mb = (long(size) + mb - 1L) / mb # round up
# Rather than bailing out for small sizes, just round up to 1 MiB. The
# LVM code will round up to the nearest PE size anyway (probably 4 MiB)
if size_mb == 0:
size_mb = 1
if lvutil._checkLV(self.path):
raise xs_errors.XenError('VDIExists')
# Verify there's sufficient space for the VDI
stats = lvutil._getVGstats(self.sr.vgname)
freespace = stats['physical_size'] - stats['physical_utilisation']
if freespace < long(size):
raise xs_errors.XenError('SRNoSpace')
cmd = ["lvcreate", "-n", self.lvname, "-L", str(size_mb), \
self.sr.vgname]
text = util.pread2(cmd)
cmd = ["lvchange", "-an", self.path]
text = util.pread2(cmd)
self.size = lvutil._getLVsize(self.path)
self.utilisation = self.size
except util.CommandException, inst:
raise xs_errors.XenError('LVMCreate', \
opterr='lv operation failed error is %d' % inst.code)
示例5: _checkPV
def _checkPV(pvname):
try:
cmd = [CMD_PVS, pvname]
util.pread2(cmd)
return True
except:
return False
示例6: _checkLV
def _checkLV(path):
try:
cmd = [CMD_LVDISPLAY, path]
util.pread2(cmd)
return True
except:
return False
示例7: deactivate
def deactivate():
util.SMlog("MPATH: multipath deactivate called")
cmd = ['ln', '-sf', iscsi_default_file, iscsi_file]
if os.path.exists(iscsi_default_file):
# Only do this if using our customized open-iscsi package
util.pread2(cmd)
# Stop the updatempppathd daemon
if _is_mpp_daemon_running():
cmd = ["service", "updatempppathd", "stop"]
util.pread2(cmd)
if _is_mpath_daemon_running():
# Flush the multipath nodes
for sid in mpath_cli.list_maps():
reset(sid,True)
# Disable any active MPP LUN maps (except the root dev)
systemroot = os.path.realpath(util.getrootdev())
for dev in glob.glob(DEVBYMPPPATH + "/*"):
if os.path.realpath(dev) != systemroot:
sid = os.path.basename(dev).split('-')[0]
reset(sid)
else:
util.SMlog("MPP: Found root dev node, not resetting")
# Check the ISCSI daemon doesn't have any active sessions, if not,
# restart in the new mode
if iscsilib.is_iscsi_daemon_running() and not iscsilib._checkAnyTGT():
iscsilib.restart_daemon()
util.SMlog("MPATH: multipath deactivated.")
示例8: createVG
def createVG(root, vgname):
systemroot = util.getrootdev()
rootdev = root.split(',')[0]
# Create PVs for each device
for dev in root.split(','):
if dev in [systemroot, '%s1' % systemroot, '%s2' % systemroot]:
raise xs_errors.XenError('Rootdev', \
opterr=('Device %s contains core system files, ' \
+ 'please use another device') % dev)
if not os.path.exists(dev):
raise xs_errors.XenError('InvalidDev', \
opterr=('Device %s does not exist') % dev)
f = _openExclusive(dev, True)
os.close(f)
try:
# Overwrite the disk header, try direct IO first
cmd = [util.CMD_DD, "if=/dev/zero", "of=%s" % dev, "bs=1M",
"count=10", "oflag=direct"]
util.pread2(cmd)
except util.CommandException, inst:
if inst.code == errno.EPERM:
try:
# Overwrite the disk header, try normal IO
cmd = [util.CMD_DD, "if=/dev/zero", "of=%s" % dev,
"bs=1M", "count=10"]
util.pread2(cmd)
except util.CommandException, inst:
raise xs_errors.XenError('LVMWrite', \
opterr='device %s' % dev)
else:
raise xs_errors.XenError('LVMWrite', \
opterr='device %s' % dev)
示例9: create
def create(name, size, vgname, tag = None, activate = True):
size_mb = size / 1024 / 1024
cmd = [CMD_LVCREATE, "-n", name, "-L", str(size_mb), vgname]
if tag:
cmd.extend(["--addtag", tag])
if not activate:
cmd.extend(["--inactive", "--zero=n"])
util.pread2(cmd)
示例10: activate
def activate():
util.SMlog("MPATH: multipath activate called")
cmd = ['ln', '-sf', iscsi_mpath_file, iscsi_file]
try:
util.pread2(cmd)
except util.CommandException, ce:
if not ce.reason.endswith(': File exists'):
raise
示例11: create
def create(name, size, vgname, tag=None, size_in_percentage=None):
if size_in_percentage:
cmd = [CMD_LVCREATE, "-n", name, "-l", size_in_percentage, vgname]
else:
size_mb = size / 1024 / 1024
cmd = [CMD_LVCREATE, "-n", name, "-L", str(size_mb), vgname]
if tag:
cmd.extend(["--addtag", tag])
util.pread2(cmd)
示例12: detach
def detach(self, sr_uuid):
super(EXTSR, self).detach(sr_uuid)
try:
# deactivate SR
cmd = ["lvchange", "-an", self.remotepath]
util.pread2(cmd)
except util.CommandException, inst:
raise xs_errors.XenError('LVMUnMount', \
opterr='lvm -an failed errno is %d' % inst.code)
示例13: _LUNprint
def _LUNprint(self, sr_uuid):
if self.iscsi.attached:
# Force a rescan on the bus.
self.iscsi.refresh()
# time.sleep(5)
# Now call attach (handles the refcounting + session activa)
self.iscsi.attach(sr_uuid)
util.SMlog("LUNprint: waiting for path: %s" % self.iscsi.path)
if util.wait_for_path("%s/LUN*" % self.iscsi.path, ISCSISR.MAX_TIMEOUT):
try:
adapter=self.iscsi.adapter[self.iscsi.address]
util.SMlog("adapter=%s" % adapter)
# find a scsi device on which to issue a report luns command:
devs=glob.glob("%s/LUN*" % self.iscsi.path)
sgdevs = []
for i in devs:
sgdevs.append(int(i.split("LUN")[1]))
sgdevs.sort()
sgdev = "%s/LUN%d" % (self.iscsi.path,sgdevs[0])
# issue a report luns:
luns=util.pread2(["/usr/bin/sg_luns","-q",sgdev]).split('\n')
nluns=len(luns)-1 # remove the line relating to the final \n
# check if the LUNs are MPP-RDAC Luns
scsi_id = scsiutil.getSCSIid(sgdev)
mpp_lun = False
if (mpp_luncheck.is_RdacLun(scsi_id)):
mpp_lun = True
link=glob.glob('/dev/disk/by-scsibus/%s-*' % scsi_id)
mpp_adapter = link[0].split('/')[-1].split('-')[-1].split(':')[0]
# make sure we've got that many sg devices present
for i in range(0,30):
luns=scsiutil._dosgscan()
sgdevs=filter(lambda r: r[1]==adapter, luns)
if mpp_lun:
sgdevs.extend(filter(lambda r: r[1]==mpp_adapter, luns))
if len(sgdevs)>=nluns:
util.SMlog("Got all %d sg devices" % nluns)
break
else:
util.SMlog("Got %d sg devices - expecting %d" % (len(sgdevs),nluns))
time.sleep(1)
if os.path.exists("/sbin/udevsettle"):
util.pread2(["/sbin/udevsettle"])
else:
util.pread2(["/sbin/udevadm","settle"])
except:
util.SMlog("Generic exception caught. Pass")
pass # Make sure we don't break the probe...
self.iscsi.print_LUNs()
self.iscsi.detach(sr_uuid)
示例14: removeDevMapperEntry
def removeDevMapperEntry(path):
try:
# remove devmapper entry using dmsetup
cmd = [CMD_DMSETUP, "remove", path]
util.pread2(cmd)
return True
except Exception, e:
util.SMlog("removeDevMapperEntry: dmsetup remove failed for file %s " \
"with error %s." % (path, str(e)))
return False
示例15: _flatten_clone
def _flatten_clone(self, clone_uuid):
if not blktap2.VDI.tap_pause(self.session, self.sr.uuid, clone_uuid):
raise util.SMException("failed to pause VDI %s" % clone_uuid)
self._unmap_VHD(clone_uuid)
#--- ?????? CHECK For running VM. What if flattening takes a long time and vdi is paused during this process
clone_name = "%s/%s%s" % (self.sr.CEPH_POOL_NAME, CLONE_PREFIX, clone_uuid)
util.pread2(["rbd", "flatten", clone_name, "--name", self.sr.CEPH_USER])
#--- ??????
self._map_VHD(clone_uuid)
blktap2.VDI.tap_unpause(self.session, self.sr.uuid, clone_uuid, None)