本文整理汇总了Python中util.ioretry函数的典型用法代码示例。如果您正苦于以下问题:Python ioretry函数的具体用法?Python ioretry怎么用?Python ioretry使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ioretry函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lock
def lock(self, sr_uuid, vdi_uuid, force, l_uuid):
util.ioretry(lambda: self._lockt(force, l_uuid))
if self.status < 0:
oktosteal = util.ioretry(lambda: self._checklock(l_uuid))
if oktosteal:
util.ioretry(lambda: self._lockt("1", l_uuid))
return super(NFSVDI, self).lock(sr_uuid, vdi_uuid, force, l_uuid)
示例2: mount
def mount(self, mountpoint=None):
"""Mount the remote CIFS export at 'mountpoint'"""
if mountpoint == None:
mountpoint = self.mountpoint
elif not util.is_string(mountpoint) or mountpoint == "":
raise CifsException("mountpoint not a string object")
missing_params = set()
if not self.dconf.has_key('username'):
missing_params.add('username')
if not (self.dconf.has_key('password') or
self.dconf.has_key('password_secret')):
missing_params.add('password')
if missing_params:
errstr = 'device-config is missing the following parameters: ' + \
', '.join([param for param in missing_params])
raise xs_errors.XenError('ConfigParamsMissing', opterr=errstr)
try:
if not util.ioretry(lambda: util.isdir(mountpoint)):
util.ioretry(lambda: util.makedirs(mountpoint))
except util.CommandException, inst:
raise CifsException("Failed to make directory: code is %d" %
inst.code)
示例3: _find_path_with_retries
def _find_path_with_retries(self, vdi_uuid, maxretry=5, period=2.0):
vhd_path = os.path.join(self.sr.path, "%s.%s" % \
(vdi_uuid, self.PARAM_VHD))
raw_path = os.path.join(self.sr.path, "%s.%s" % \
(vdi_uuid, self.PARAM_RAW))
cbt_path = os.path.join(self.sr.path, "%s.%s" %
(vdi_uuid, CBTLOG_TAG))
found = False
tries = 0
while tries < maxretry and not found:
tries += 1
if util.ioretry(lambda: util.pathexists(vhd_path)):
self.vdi_type = vhdutil.VDI_TYPE_VHD
self.path = vhd_path
found = True
elif util.ioretry(lambda: util.pathexists(raw_path)):
self.vdi_type = vhdutil.VDI_TYPE_RAW
self.path = raw_path
self.hidden = False
found = True
elif util.ioretry(lambda: util.pathexists(cbt_path)):
self.vdi_type = CBTLOG_TAG
self.path = cbt_path
self.hidden = False
found = True
if not found:
util.SMlog("VHD %s not found, retry %s of %s" % (vhd_path, tries, maxretry))
time.sleep(period)
return found
示例4: delete
def delete(self, sr_uuid):
self.attach(sr_uuid)
cleanup.gc_force(self.session, self.uuid)
# check to make sure no VDIs are present; then remove old
# files that are non VDI's
try:
if util.ioretry(lambda: util.pathexists(self.path)):
#Load the VDI list
self._loadvdis()
for uuid in self.vdis:
if not self.vdis[uuid].deleted:
raise xs_errors.XenError('SRNotEmpty', \
opterr='VDIs still exist in SR')
# remove everything else, there are no vdi's
for name in util.ioretry(lambda: util.listdir(self.path)):
fullpath = os.path.join(self.path,name)
try:
util.ioretry(lambda: os.unlink(fullpath))
except util.CommandException, inst:
if inst.code != errno.ENOENT and \
inst.code != errno.EISDIR:
raise xs_errors.XenError('FileSRDelete', \
opterr='failed to remove %s error %d' \
% (fullpath, inst.code))
self.detach(sr_uuid)
示例5: create
def create(self, sr_uuid, size):
if util.ioretry(lambda: self._checkmount()):
raise xs_errors.XenError('NFSAttached')
# Set the target path temporarily to the base dir
# so that we can create the target SR directory
self.remotepath = self.dconf['serverpath']
try:
self.attach(sr_uuid)
except:
try:
os.rmdir(self.path)
except:
pass
raise xs_errors.XenError('NFSMount')
newpath = os.path.join(self.path, sr_uuid)
if util.ioretry(lambda: util.pathexists(newpath)):
if len(util.ioretry(lambda: util.listdir(newpath))) != 0:
self.detach(sr_uuid)
raise xs_errors.XenError('SRExists')
else:
try:
util.ioretry(lambda: util.makedirs(newpath))
except util.CommandException, inst:
if inst.code != errno.EEXIST:
self.detach(sr_uuid)
raise xs_errors.XenError('NFSCreate', \
opterr='remote directory creation error is %d' \
% inst.code)
示例6: scan_srlist
def scan_srlist(path, dconf):
"""Scan and report SR, UUID."""
dom = xml.dom.minidom.Document()
element = dom.createElement("SRlist")
dom.appendChild(element)
for val in filter(util.match_uuid, util.ioretry(
lambda: util.listdir(path))):
fullpath = os.path.join(path, val)
if not util.ioretry(lambda: util.isdir(fullpath)):
continue
entry = dom.createElement('SR')
element.appendChild(entry)
subentry = dom.createElement("UUID")
entry.appendChild(subentry)
textnode = dom.createTextNode(val)
subentry.appendChild(textnode)
from NFSSR import PROBEVERSION
if dconf.has_key(PROBEVERSION):
util.SMlog("Add supported nfs versions to sr-probe")
supported_versions = get_supported_nfs_versions(dconf.get('server'))
supp_ver = dom.createElement("SupportedVersions")
element.appendChild(supp_ver)
for ver in supported_versions:
version = dom.createElement('Version')
supp_ver.appendChild(version)
textnode = dom.createTextNode(ver)
version.appendChild(textnode)
return dom.toprettyxml()
示例7: create
def create(self, sr_uuid, vdi_uuid, size):
if util.ioretry(lambda: util.pathexists(self.path)):
raise xs_errors.XenError('VDIExists')
overhead = 0
if self.vdi_type == vhdutil.VDI_TYPE_VHD:
overhead = vhdutil.calcOverheadFull(long(size))
# Test the amount of actual disk space
if ENFORCE_VIRT_ALLOC:
self.sr._loadvdis()
reserved = self.sr.virtual_allocation
sr_size = self.sr._getsize()
if (sr_size - reserved) < (long(size) + overhead):
raise xs_errors.XenError('SRNoSpace')
if self.vdi_type == vhdutil.VDI_TYPE_VHD:
try:
size = vhdutil.validate_and_round_vhd_size(long(size))
mb = 1024L * 1024L
size_mb = long(size) / mb
util.ioretry(lambda: self._create(str(size_mb), self.path))
self.size = util.ioretry(lambda: self._query_v(self.path))
except util.CommandException, inst:
raise xs_errors.XenError('VDICreate',
opterr='error %d' % inst.code)
示例8: delete
def delete(self, sr_uuid):
if not self._checkpath(self.path):
raise xs_errors.XenError("SRUnavailable", opterr="no such directory %s" % self.path)
cleanup.gc_force(self.session, self.uuid)
# check to make sure no VDIs are present; then remove old
# files that are non VDI's
try:
if util.ioretry(lambda: util.pathexists(self.path)):
# Load the VDI list
self._loadvdis()
for uuid in self.vdis:
if not self.vdis[uuid].deleted:
raise xs_errors.XenError("SRNotEmpty", opterr="VDIs still exist in SR")
# remove everything else, there are no vdi's
for name in util.ioretry(lambda: util.listdir(self.path)):
fullpath = os.path.join(self.path, name)
try:
util.ioretry(lambda: os.unlink(fullpath))
except util.CommandException, inst:
if inst.code != errno.ENOENT and inst.code != errno.EISDIR:
raise xs_errors.XenError(
"FileSRDelete", opterr="failed to remove %s error %d" % (fullpath, inst.code)
)
except util.CommandException, inst:
raise xs_errors.XenError("FileSRDelete", opterr="error %d" % inst.code)
示例9: load
def load(self, vdi_uuid):
self.vdi_type = SR.DEFAULT_TAP
self.path = os.path.join(self.sr.path, "%s.%s" % \
(vdi_uuid,self.vdi_type))
if util.ioretry(lambda: util.pathexists(self.path)):
try:
st = util.ioretry(lambda: os.stat(self.path))
self.utilisation = long(st.st_size)
except util.CommandException, inst:
if inst.code == errno.EIO:
raise xs_errors.XenError('VDILoad', \
opterr='Failed load VDI information %s' % self.path)
else:
raise xs_errors.XenError('VDIType', \
opterr='Invalid VDI type %s' % self.vdi_type)
try:
diskinfo = util.ioretry(lambda: self._query_info(self.path))
if diskinfo.has_key('parent'):
self.parent = diskinfo['parent']
else:
self.parent = ''
self.size = long(diskinfo['size']) * 1024 * 1024
self.hidden = long(diskinfo['hidden'])
except util.CommandException, inst:
raise xs_errors.XenError('VDILoad', \
opterr='Failed load VDI information %s' % self.path)
示例10: create
def create(self, sr_uuid, vdi_uuid, size):
if util.ioretry(lambda: util.pathexists(self.path)):
raise xs_errors.XenError('VDIExists')
overhead = 0
if self.vdi_type == vhdutil.VDI_TYPE_VHD:
overhead = vhdutil.calcOverheadFull(long(size))
# Test the amount of actual disk space
if ENFORCE_VIRT_ALLOC:
self.sr._loadvdis()
reserved = self.sr.virtual_allocation
sr_size = self.sr._getsize()
if (sr_size - reserved) < (long(size) + overhead):
raise xs_errors.XenError('SRNoSpace')
if self.vdi_type == vhdutil.VDI_TYPE_VHD:
try:
mb = 1024L * 1024L
size_mb = util.roundup(VHD_SIZE_INC, long(size)) / mb
if size_mb < 1 or (size_mb + (overhead / mb)) >= MAX_DISK_MB:
raise xs_errors.XenError('VDISize', opterr='VDI size ' + \
'must be between 1 MB and %d MB' % \
((MAX_DISK_MB - MAX_DISK_METADATA) - 1))
util.ioretry(lambda: self._create(str(size_mb), self.path))
self.size = util.ioretry(lambda: self._query_v(self.path))
except util.CommandException, inst:
raise xs_errors.XenError('VDICreate',
opterr='error %d' % inst.code)
示例11: soft_mount
def soft_mount(mountpoint, remoteserver, remotepath, transport):
"""Mount the remote NFS export at 'mountpoint'"""
try:
if not util.ioretry(lambda: util.isdir(mountpoint)):
util.ioretry(lambda: util.makedirs(mountpoint))
except util.CommandException, inst:
raise NfsException("Failed to make directory: code is %d" %
inst.code)
示例12: _checkpath
def _checkpath(self, path):
try:
if util.ioretry(lambda: util.pathexists(path)):
if util.ioretry(lambda: util.isdir(path)):
return True
return False
except util.CommandException, inst:
raise xs_errors.XenError("EIO", opterr="IO error checking path %s" % path)
示例13: soft_mount
def soft_mount(mountpoint, remoteserver, remotepath, transport, timeout=0,
nfsversion=DEFAULT_NFSVERSION):
"""Mount the remote NFS export at 'mountpoint'.
The 'timeout' param here is in seconds"""
try:
if not util.ioretry(lambda: util.isdir(mountpoint)):
util.ioretry(lambda: util.makedirs(mountpoint))
except util.CommandException, inst:
raise NfsException("Failed to make directory: code is %d" %
inst.code)
示例14: check_server_tcp
def check_server_tcp(server):
"""Make sure that NFS over TCP/IP V3 is supported on the server.
Returns True if everything is OK, False otherwise."""
try:
util.ioretry(lambda: util.pread([RPCINFO_BIN,"-t",
"%s" % server, "nfs","3"]),
errlist=[errno.EPERM], maxretry=2, nofail=True)
except util.CommandException, inst:
raise NfsException("rpcinfo failed or timed out: return code %d" %
inst.code)
示例15: _load
def _load(self, vdi_uuid):
self.vdi_type = SR.DEFAULT_TAP
self.path = os.path.join(self.sr.path, "%s.%s" % \
(vdi_uuid,self.vdi_type))
if self.sr.__dict__.get("vhds") and self.sr.vhds.get(vdi_uuid):
# VHD info already preloaded: use it instead of querying directly
vhdInfo = self.sr.vhds[vdi_uuid]
self.utilisation = vhdInfo.sizePhys
self.size = vhdInfo.sizeVirt
self.hidden = vhdInfo.hidden
if self.hidden:
self.managed = False
self.parent = vhdInfo.parentUuid
if self.parent:
self.sm_config_override = {'vhd-parent':self.parent}
else:
self.sm_config_override = {'vhd-parent':None}
return
try:
# Change to the SR directory in case parent
# locator field path has changed
os.chdir(self.sr.path)
except:
raise xs_errors.XenError('SRUnavailable')
if util.ioretry(lambda: util.pathexists(self.path)):
try:
st = util.ioretry(lambda: os.stat(self.path))
self.utilisation = long(st.st_size)
except util.CommandException, inst:
if inst.code == errno.EIO:
raise xs_errors.XenError('VDILoad', \
opterr='Failed load VDI information %s' % self.path)
else:
raise xs_errors.XenError('VDIType', \
opterr='Invalid VDI type %s' % self.vdi_type)
try:
diskinfo = util.ioretry(lambda: self._query_info(self.path))
if diskinfo.has_key('parent'):
self.parent = diskinfo['parent']
self.sm_config_override = {'vhd-parent':self.parent}
else:
self.sm_config_override = {'vhd-parent':None}
self.parent = ''
self.size = long(diskinfo['size']) * 1024 * 1024
self.hidden = long(diskinfo['hidden'])
if self.hidden:
self.managed = False
self.exists = True
except util.CommandException, inst:
raise xs_errors.XenError('VDILoad', \
opterr='Failed load VDI information %s' % self.path)