def GetFileEntryByPathSpec(self, path_spec): """Retrieves a file entry for a path specification. Args: path_spec (PathSpec): path specification. Returns: LVMFileEntry: a file entry or None if not available. """ volume_index = lvm.LVMPathSpecGetVolumeIndex(path_spec) # The virtual root file has no corresponding volume index but # should have a location. if volume_index is None: location = getattr(path_spec, 'location', None) if location is None or location != self.LOCATION_ROOT: return None return lvm_file_entry.LVMFileEntry(self._resolver_context, self, path_spec, is_root=True, is_virtual=True) if (volume_index < 0 or volume_index >= self._vslvm_volume_group.number_of_logical_volumes): return None return lvm_file_entry.LVMFileEntry(self._resolver_context, self, path_spec)
def _Open(self, mode='rb'): """Opens the file-like object defined by path specification. Args: mode (Optional[str]): file access mode. Raises: AccessError: if the access to open the file was denied. IOError: if the file-like object could not be opened. OSError: if the file-like object could not be opened. PathSpecError: if the path specification is incorrect. """ volume_index = lvm.LVMPathSpecGetVolumeIndex(self._path_spec) if volume_index is None: raise errors.PathSpecError( 'Unable to retrieve volume index from path specification.') self._file_system = resolver.Resolver.OpenFileSystem( self._path_spec, resolver_context=self._resolver_context) vslvm_volume_group = self._file_system.GetLVMVolumeGroup() if (volume_index < 0 or volume_index >= vslvm_volume_group.number_of_logical_volumes): raise errors.PathSpecError(( 'Unable to retrieve LVM logical volume index: {0:d} from path ' 'specification.').format(volume_index)) self._vslvm_logical_volume = vslvm_volume_group.get_logical_volume( volume_index)
def _Open(self, path_spec=None, mode='rb'): """Opens the file-like object defined by path specification. Args: path_spec: optional path specification (instance of PathSpec). mode: optional file access mode. The default is 'rb' read-only binary. Raises: AccessError: if the access to open the file was denied. IOError: if the file-like object could not be opened. PathSpecError: if the path specification is incorrect. ValueError: if the path specification is invalid. """ if not path_spec: raise ValueError(u'Missing path specfication.') volume_index = lvm.LVMPathSpecGetVolumeIndex(path_spec) if volume_index is None: raise errors.PathSpecError( u'Unable to retrieve volume index from path specification.') self._file_system = resolver.Resolver.OpenFileSystem( path_spec, resolver_context=self._resolver_context) vslvm_volume_group = self._file_system.GetLVMVolumeGroup() if (volume_index < 0 or volume_index >= vslvm_volume_group.number_of_logical_volumes): raise errors.PathSpecError(( u'Unable to retrieve LVM logical volume index: {0:d} from path ' u'specification.').format(volume_index)) self._vslvm_logical_volume = vslvm_volume_group.get_logical_volume( volume_index)
def GetParentFileEntry(self): """Retrieves the parent file entry. Returns: LVMFileEntry: parent file entry or None if not available. """ volume_index = lvm.LVMPathSpecGetVolumeIndex(self.path_spec) if volume_index is None: return return self._file_system.GetRootFileEntry()
def GetParentFileEntry(self): """Retrieves the parent file entry. Returns: The parent file entry object (instance of FileEntry) or None. """ volume_index = lvm.LVMPathSpecGetVolumeIndex(self.path_spec) if volume_index is None: return return self._file_system.GetRootFileEntry()
def GetLVMLogicalVolumeByPathSpec(self, path_spec): """Retrieves a LVM logical volume for a path specification. Args: path_spec (PathSpec): path specification. Returns: pyvslvm.logical_volume: a LVM logical volume or None if not available. """ volume_index = lvm.LVMPathSpecGetVolumeIndex(path_spec) if volume_index is not None: return self._vslvm_volume_group.get_logical_volume(volume_index)
def GetLVMLogicalVolume(self): """Retrieves the LVM logical volume object. Returns: A LVM logical volume object (instance of pyvslvm.logical_volume). """ volume_index = lvm.LVMPathSpecGetVolumeIndex(self.path_spec) if volume_index is None: return vslvm_volume_group = self._file_system.GetLVMVolumeGroup() return vslvm_volume_group.get_logical_volume(volume_index)
def FileEntryExistsByPathSpec(self, path_spec): """Determines if a file entry for a path specification exists. Args: path_spec (PathSpec): path specification. Returns: bool: True if the file entry exists. """ volume_index = lvm.LVMPathSpecGetVolumeIndex(path_spec) # The virtual root file has no corresponding volume index but # should have a location. if volume_index is None: location = getattr(path_spec, 'location', None) return location is not None and location == self.LOCATION_ROOT return (0 <= volume_index < self._vslvm_volume_group.number_of_logical_volumes)
def LVM(uco_object, path_spec): volume_index = lvm.LVMPathSpecGetVolumeIndex(path_spec) uco_object.create_property_bundle('LVMVolume', volumeIndex=volume_index)