本文整理汇总了Python中twisted.python.filepath.FilePath.realpath方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.realpath方法的具体用法?Python FilePath.realpath怎么用?Python FilePath.realpath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.filepath.FilePath
的用法示例。
在下文中一共展示了FilePath.realpath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_device_path_virtio_blk
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import realpath [as 别名]
def _get_device_path_virtio_blk(self, volume):
"""
The virtio_blk driver allows a serial number to be assigned to virtual
blockdevices.
OpenStack will set a serial number containing the first 20
characters of the Cinder block device ID.
This was introduced in
* https://github.com/openstack/nova/commit/3a47c02c58cefed0e230190b4bcef14527c82709 # noqa
* https://bugs.launchpad.net/nova/+bug/1004328
The udev daemon will read the serial number and create a
symlink to the canonical virtio_blk device path.
We do this because libvirt does not return the correct device path when
additional disks have been attached using a client other than
cinder. This is expected behaviour within Cinder and libvirt See
https://bugs.launchpad.net/cinder/+bug/1387945 and
http://libvirt.org/formatdomain.html#elementsDisks (target section)
:param volume: The Cinder ``Volume`` which is attached.
:returns: ``FilePath`` of the device created by the virtio_blk
driver.
"""
expected_path = FilePath(
"/dev/disk/by-id/virtio-{}".format(volume.id[:20])
)
if expected_path.exists():
return expected_path.realpath()
else:
raise UnattachedVolume(volume.id)
示例2: _get_device_path_virtio_blk
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import realpath [as 别名]
def _get_device_path_virtio_blk(self, volume):
"""
The virtio_blk driver allows a serial number to be assigned to virtual
blockdevices.
OpenStack will set a serial number containing the first 20
characters of the Cinder block device ID.
This was introduced in
* https://github.com/openstack/nova/commit/3a47c02c58cefed0e230190b4bcef14527c82709 # noqa
* https://bugs.launchpad.net/nova/+bug/1004328
The udev daemon will read the serial number and create a
symlink to the canonical virtio_blk device path.
We do this because libvirt does not return the correct device path when
additional disks have been attached using a client other than
cinder. This is expected behaviour within Cinder and libvirt See
https://bugs.launchpad.net/cinder/+bug/1387945 and
http://libvirt.org/formatdomain.html#elementsDisks (target section)
:param volume: The Cinder ``Volume`` which is attached.
:returns: ``FilePath`` of the device created by the virtio_blk
driver.
"""
expected_path = FilePath(
"/dev/disk/by-id/virtio-{}".format(volume.id[:20])
)
# Return the real path instead of the symlink to avoid two problems:
#
# 1. flocker-dataset-agent mounting volumes before udev has populated
# the by-id symlinks.
# 2. Even if we mount with `/dev/disk/by-id/xxx`, the mounted
# filesystems are listed (in e.g. `/proc/mounts`) with the
# **target** (i.e. the real path) of the `/dev/disk/by-id/xxx`
# symlinks. This confuses flocker-dataset-agent (which assumes path
# equality is string equality), causing it to believe that
# `/dev/disk/by-id/xxx` has not been mounted, leading it to
# repeatedly attempt to mount the device.
if expected_path.exists():
return expected_path.realpath()
else:
raise UnattachedVolume(volume.id)
示例3: getDirectory
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import realpath [as 别名]
def getDirectory(self, path='/'):
self.fs = yield FilePath(path)
if not self.fs.getPermissions():
defer.returnValue(False)
files = []
for f in self.fs.listdir():
if f == '/':
continue
fp = path+f
fs = FilePath(fp)
# dont follow symlinks
if fs.realpath().path != fp:
continue
perm = None
isdir = fs.isdir()
size = fs.getsize()
modified = datetime.utcfromtimestamp(fs.getModificationTime())
df = DiscoveredFile(
resource_id=self.data['resource_id'],
file_path=path,
file_name=f,
file_isdir=isdir,
file_size=size,
file_modified=modified,
file_perm=perm
)
print '[%s] LIST %s.' % (self.data['resource_name'], fp if not fp.endswith('.') else fp)
files.append(df)
defer.returnValue(files)