本文整理汇总了Python中ovs.lib.vdisk.VDiskController.create_volume方法的典型用法代码示例。如果您正苦于以下问题:Python VDiskController.create_volume方法的具体用法?Python VDiskController.create_volume怎么用?Python VDiskController.create_volume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ovs.lib.vdisk.VDiskController
的用法示例。
在下文中一共展示了VDiskController.create_volume方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_volume
# 需要导入模块: from ovs.lib.vdisk import VDiskController [as 别名]
# 或者: from ovs.lib.vdisk.VDiskController import create_volume [as 别名]
def create_volume(self, volume):
"""Creates a volume.
Called on "cinder create ..." or "nova volume-create ..."
:param volume: volume reference (sqlalchemy Model)
"""
_debug_vol_info("CREATE", volume)
hostname = str(volume.host)
name = volume.display_name
if not name:
name = volume.name
mountpoint = self._get_hostname_mountpoint(hostname)
location = '{}/{}.raw'.format(mountpoint, name)
size = volume.size
LOG.info('DO_CREATE_VOLUME %s %s' % (location, size))
VDiskController.create_volume(location = location,
size = size)
volume['provider_location'] = location
try:
ovs_disk = self._find_ovs_model_disk_by_location(location,
hostname)
except RuntimeError:
VDiskController.delete_volume(location = location)
raise
ovs_disk.cinder_id = volume.id
ovs_disk.name = name
ovs_disk.save()
return {'provider_location': volume['provider_location']}
示例2: download_to_vpool
# 需要导入模块: from ovs.lib.vdisk import VDiskController [as 别名]
# 或者: from ovs.lib.vdisk.VDiskController import create_volume [as 别名]
def download_to_vpool(url, path, overwrite_if_exists=False):
"""
Special method to download to vpool because voldrv does not support extending file at write
:param url: URL to download from
:type url: str
:param path: Path to download to
:type path: str
:param overwrite_if_exists: Overwrite if file already exists
:type overwrite_if_exists: bool
:return: None
"""
print url
print path
if os.path.exists(path) and not overwrite_if_exists:
return
u = urllib.urlopen(url)
file_size = u.info()['Content-Length']
bsize = 4096 * 1024
VDiskController.create_volume(path, 0)
with open(path, "wb") as f:
size_written = 0
os.ftruncate(f.fileno(), int(file_size))
while 1:
s = u.read(bsize)
size_written += len(s)
f.write(s)
if len(s) < bsize:
break
u.close()