def __connectLocalConnection(self, conParams): """ Connect to a storage low level entity. """ conStatus = [] localPath = os.path.join(self.storage_repository, sd.DOMAIN_MNT_POINT) fileUtils.createdir(localPath) for con in conParams: rc = 0 try: if os.path.exists(con['rp']): lnPoint = fileUtils.transformPath(con['rp']) lnPath = os.path.join(localPath, lnPoint) if not os.path.lexists(lnPath): os.symlink(con['rp'], lnPath) else: self.log.error("Path %s does not exists.", con['rp']) rc = se.StorageServerConnectionError.code except se.StorageException, ex: rc = ex.code self.log.error("Error during storage connection: %s", str(ex), exc_info=True) except Exception, ex: rc = se.StorageServerConnectionError.code self.log.error("Error during storage connection: %s", str(ex), exc_info=True)
def __disconnectFileServer(self, conParams, fsType): """ Disconnect from a storage low level entity (server). """ conStatus = [] for con in conParams: try: localPath = os.path.join(self.storage_repository, sd.DOMAIN_MNT_POINT) mntPoint = fileUtils.transformPath(con['rp']) mntPath = os.path.join(localPath, mntPoint) rc = getProcPool().fileUtils.umount(con['rp'], mntPath, fsType) if rc == 0: try: getProcPool().os.rmdir(mntPath) except (OSError, Timeout): # Report the error to the log, but keep going, # afterall we succeeded to disconnect the FS server msg = ("Cannot remove mountpoint after umount()") self.log.warning(msg, exc_info=True) else: self.log.error("Error during storage disconnection: rc=%s", rc, exc_info=True) rc = se.StorageServerDisconnectionError.code # We should return error status instead of exception itself except se.StorageException, ex: rc = ex.code self.log.error("Error during storage disconnection: %s", str(ex), exc_info=True) except Exception, ex: rc = se.StorageException.code self.log.error("Error during storage disconnection: %s", str(ex), exc_info=True)
def __connectFileServer(self, conParams, fsType): """ Connect to a storage low level entity. """ conStatus = [] localPath = os.path.join(self.storage_repository, sd.DOMAIN_MNT_POINT) fileUtils.createdir(localPath) for con in conParams: try: mntPoint = fileUtils.transformPath(con['rp']) mntPath = os.path.join(localPath, mntPoint) if fsType == fileUtils.FSTYPE_NFS: # Stale handle usually resolves itself when doing directory lookups # BUT if someone deletes the export on the servers side. We will keep # getting stale handles and this is unresolvable unless you umount and # remount. if getProcPool().fileUtils.isStaleHandle(mntPath): # A VM might be holding a stale handle, we have to umount # but we can't umount as long as someone is holding a handle # even if it's stale. We use lazy so we can at least recover. # Processes having an open file handle will not recover until # they reopen the files. getProcPool().fileUtils.umount(con['rp'], mntPath, lazy=True) fileUtils.createdir(mntPath) rc = getProcPool().fileUtils.mount(con['rp'], mntPath, fsType) if rc == 0: try: validateDirAccess(mntPath) except se.StorageServerAccessPermissionError, ex: self.log.debug("Unmounting file system %s " "(not enough access permissions)" % con['rp']) getProcPool().fileUtils.umount(con['rp'], mntPath, fsType) raise else: self.log.error("Error during storage connection: rc=%s", rc, exc_info=True) rc = se.StorageServerConnectionError.code
def create(cls, sdUUID, domainName, domClass, remotePath, storageType, version): """ Create new storage domain. 'sdUUID' - Storage Domain UUID 'domainName' - storage domain name ("iso" or "data domain name") 'domClass' - Data/Iso 'remotePath' - /data2 'storageType' - NFS_DOMAIN, LOCALFS_DOMAIN, &etc. 'version' - DOMAIN_VERSIONS """ cls.log.info("sdUUID=%s domainName=%s remotePath=%s " "domClass=%s", sdUUID, domainName, remotePath, domClass) if not misc.isAscii(domainName) and not sd.supportsUnicode(version): raise se.UnicodeArgumentException() # Create local path mntPath = fileUtils.transformPath(remotePath) mntPoint = os.path.join(cls.storage_repository, sd.DOMAIN_MNT_POINT, mntPath) cls._preCreateValidation(sdUUID, mntPoint, remotePath, version) domainDir = os.path.join(mntPoint, sdUUID) cls._prepareMetadata(domainDir, sdUUID, domainName, domClass, remotePath, storageType, version) # create domain images folder imagesDir = os.path.join(domainDir, sd.DOMAIN_IMAGES) fileUtils.createdir(imagesDir) # create special imageUUID for ISO/Floppy volumes # Actually the local domain shouldn't be ISO, but # we can allow it for systems without NFS at all if domClass is sd.ISO_DOMAIN: isoDir = os.path.join(imagesDir, sd.ISO_IMAGE_UUID) fileUtils.createdir(isoDir) fsd = LocalFsStorageDomain(os.path.join(mntPoint, sdUUID)) fsd.initSPMlease() return fsd
def create(cls, sdUUID, domainName, domClass, remotePath, storageType, version): """ Create new storage domain. 'sdUUID' - Storage Domain UUID 'domainName' - storage domain name ("iso" or "data domain name") 'domClass' - Data/Iso 'remotePath' - server:/export_path 'storageType' - NFS_DOMAIN, LOCALFS_DOMAIN, &etc. 'version' - DOMAIN_VERSIONS """ cls.log.info("sdUUID=%s domainName=%s remotePath=%s " "domClass=%s", sdUUID, domainName, remotePath, domClass) if not misc.isAscii(domainName) and not sd.supportsUnicode(version): raise se.UnicodeArgumentException() # Create local path mntPath = fileUtils.transformPath(remotePath) mntPoint = cls.getMountPoint(mntPath) cls._preCreateValidation(sdUUID, mntPoint, remotePath, storageType, version) domainDir = os.path.join(mntPoint, sdUUID) cls._prepareMetadata(domainDir, sdUUID, domainName, domClass, remotePath, storageType, version) # create domain images folder imagesDir = os.path.join(domainDir, sd.DOMAIN_IMAGES) oop.getProcessPool(sdUUID).fileUtils.createdir(imagesDir) # create special imageUUID for ISO/Floppy volumes if domClass is sd.ISO_DOMAIN: isoDir = os.path.join(imagesDir, sd.ISO_IMAGE_UUID) oop.getProcessPool(sdUUID).fileUtils.createdir(isoDir) fsd = cls(os.path.join(mntPoint, sdUUID)) fsd.initSPMlease() return fsd
def __disconnectLocalConnection(self, conParams): """ Disconnect from a storage low level entity (server). """ conStatus = [] localPath = os.path.join(self.storage_repository, sd.DOMAIN_MNT_POINT) for con in conParams: rc = 0 try: lnPoint = fileUtils.transformPath(con['rp']) lnPath = os.path.join(localPath, lnPoint) if os.path.lexists(lnPath): os.unlink(lnPath) except se.StorageException, ex: rc = ex.code self.log.error("Error during storage disconnection: %s", str(ex), exc_info=True) except Exception, ex: rc = se.StorageServerDisconnectionError.code self.log.error("Error during storage disconnection: %s", str(ex), exc_info=True)
def create(cls, sdUUID, domainName, domClass, remotePath, storageType, version): """ Create new storage domain. 'sdUUID' - Storage Domain UUID 'domainName' - storage domain name ("iso" or "data domain name") 'remotePath' - server:/export_path 'domClass' - Data/Iso """ cls.log.info("sdUUID=%s domainName=%s remotePath=%s " "domClass=%s", sdUUID, domainName, remotePath, domClass) # Create local path mntPath = fileUtils.transformPath(remotePath) mntPoint = os.path.join(cls.storage_repository, sd.DOMAIN_MNT_POINT, mntPath) cls._preCreateValidation(sdUUID, mntPoint, remotePath, version) domainDir = os.path.join(mntPoint, sdUUID) cls._prepareMetadata(domainDir, sdUUID, domainName, domClass, remotePath, storageType, version) # create domain images folder imagesDir = os.path.join(domainDir, sd.DOMAIN_IMAGES) oop.getProcessPool(sdUUID).fileUtils.createdir(imagesDir) # create special imageUUID for ISO/Floppy volumes if domClass is sd.ISO_DOMAIN: isoDir = os.path.join(imagesDir, sd.ISO_IMAGE_UUID) oop.getProcessPool(sdUUID).fileUtils.createdir(isoDir) fsd = NfsStorageDomain(os.path.join(mntPoint, sdUUID)) fsd.initSPMlease() return fsd
def _getLocalPath(self): return os.path.join(self.localPathBase, fileUtils.transformPath(self._path))
def _getLocalPath(self): path = fileUtils.transformPath(self._remotePath) return os.path.join(self.localPathBase, self.DIR, path)