Coverage for drivers/NFSSR : 37%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/python # # Copyright (C) Citrix Systems Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation; version 2.1 only. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # FileSR: local-file storage repository
"VDI_CREATE","VDI_DELETE","VDI_ATTACH","VDI_DETACH", "VDI_UPDATE", "VDI_CLONE","VDI_SNAPSHOT","VDI_RESIZE", "VDI_GENERATE_CONFIG","VDI_MIRROR", "VDI_RESET_ON_BOOT/2", "ATOMIC_PAUSE", "VDI_CONFIG_CBT", "VDI_ACTIVATE", "VDI_DEACTIVATE", "THIN_PROVISIONING", "VDI_READ_CACHING"]
['serverpath', 'path on remote server (required)'], nfs.NFS_VERSION]
'name': 'NFS VHD', 'description': 'SR plugin which stores disks as VHD files on a remote NFS filesystem', 'vendor': 'Citrix Systems Inc', 'copyright': '(C) 2008 Citrix Systems Inc', 'driver_version': '1.0', 'required_api_version': '1.0', 'capabilities': CAPABILITIES, 'configuration': CONFIGURATION }
# The mountpoint for the directory when performing an sr_probe. All probes # are guaranteed to be serialised by xapi, so this single mountpoint is fine.
"""NFS file-based storage repository"""
raise xs_errors.XenError('ConfigServerMissing') self.sm_config = self.session.xenapi.SR.get_sm_config(self.sr_ref) self.other_config = self.session.xenapi.SR.get_other_config(self.sr_ref) else: serverpath, not self.nosubdir and sr_uuid or "" ).encode('utf-8')
# Handle optional dconf attributes self.transport = "udp" else:
if scan: try: self.scan_exports(self.dconf['server']) except: pass raise xs_errors.XenError('ConfigServerPathMissing') raise xs_errors.XenError('ConfigServerPathBad', \ opterr='serverpath is %s' % self.dconf['serverpath'])
sv = nfs.get_supported_nfs_versions(self.remoteserver) if len(sv): self.nfsversion = sv[0] else: except nfs.NfsException, exc: raise xs_errors.XenError('NFSVersion', opterr=exc.errstr)
mountpoint, self.remoteserver, remotepath, self.transport, useroptions=self.options, timeout=timeout, nfsversion=self.nfsversion, retrans=retrans) except nfs.NfsException, exc: raise xs_errors.XenError('NFSMount', opterr=exc.errstr)
#Extract timeout and retrans values, if any retrans=io_retrans)
# FIXME: What is the purpose of this check_server? # It doesn't stop us from continuing if the server # doesn't support the requested version. We fail # in mount instead timeout=timeout, retrans=retrans)
# Verify NFS target and port util._testHost(self.dconf['server'], NFSPORT, 'NFSTarget')
self.validate_remotepath(True) self.check_server()
temppath = os.path.join(SR.MOUNT_BASE, PROBE_MOUNTPOINT)
self.mount(temppath, self.remotepath) try: return nfs.scan_srlist(temppath, self.dconf) finally: try: nfs.unmount(temppath, True) except: pass
"""Detach the SR: Unmounts and removes the mountpoint""" if not self._checkmount(): return util.SMlog("Aborting GC/coalesce") cleanup.abort(self.uuid)
# Change directory to avoid unmount conflicts os.chdir(SR.MOUNT_BASE)
try: nfs.unmount(self.path, True) except nfs.NfsException, exc: raise xs_errors.XenError('NFSUnMount', opterr=exc.errstr)
self.attached = False
util._testHost(self.dconf['server'], NFSPORT, 'NFSTarget') self.validate_remotepath(True) if 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'].encode('utf-8') try: self.mount_remotepath(sr_uuid) except Exception, exn: try: os.rmdir(self.path) except: pass raise exn
if not self.nosubdir: 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) self.detach(sr_uuid)
# try to remove/delete non VDI contents first super(NFSSR, self).delete(sr_uuid) try: if self._checkmount(): self.detach(sr_uuid)
# Set the target path temporarily to the base dir # so that we can remove the target SR directory self.remotepath = self.dconf['serverpath'].encode('utf-8') self.mount_remotepath(sr_uuid) if not self.nosubdir: newpath = os.path.join(self.path, sr_uuid) if util.ioretry(lambda: util.pathexists(newpath)): util.ioretry(lambda: os.rmdir(newpath)) self.detach(sr_uuid) except util.CommandException, inst: self.detach(sr_uuid) if inst.code != errno.ENOENT: raise xs_errors.XenError('NFSDelete')
if not loadLocked: return NFSFileVDI(self, uuid) return NFSFileVDI(self, uuid)
util.SMlog("scanning2 (target=%s)" % target) dom = nfs.scan_exports(target) print >>sys.stderr,dom.toprettyxml()
if not hasattr(self,'xenstore_data'): self.xenstore_data = {}
self.xenstore_data["storage-type"]="nfs"
return super(NFSFileVDI, self).attach(sr_uuid, vdi_uuid)
util.SMlog("NFSFileVDI.generate_config") if not util.pathexists(self.path): raise xs_errors.XenError('VDIUnavailable') resp = {} resp['device_config'] = self.sr.dconf resp['sr_uuid'] = sr_uuid resp['vdi_uuid'] = vdi_uuid resp['sr_sm_config'] = self.sr.sm_config resp['sr_other_config'] = self.sr.other_config resp['command'] = 'vdi_attach_from_config' # Return the 'config' encoded within a normal XMLRPC response so that # we can use the regular response/error parsing code. config = xmlrpclib.dumps(tuple([resp]), "vdi_attach_from_config") return xmlrpclib.dumps((config,), "", True)
"""Used for HA State-file only. Will not just attach the VDI but also start a tapdisk on the file""" util.SMlog("NFSFileVDI.attach_from_config") try: self.sr.attach(sr_uuid) except: util.logException("NFSFileVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', \ opterr='Unable to attach from config')
SRCommand.run(NFSSR, DRIVER_INFO) else: |