本文整理汇总了Python中ovs.dal.hybrids.vdisk.VDisk类的典型用法代码示例。如果您正苦于以下问题:Python VDisk类的具体用法?Python VDisk怎么用?Python VDisk使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VDisk类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_vdisks_for_mds_service
def _create_vdisks_for_mds_service(self, amount, start_id, mds_service=None, vpool=None):
"""
Generates vdisks and appends them to a given mds_service
"""
vdisks = {}
for i in xrange(start_id, start_id + amount):
disk = VDisk()
disk.name = str(i)
disk.devicename = 'disk_{0}'.format(i)
disk.volume_id = 'disk_{0}'.format(i)
disk.vpool = mds_service.vpool if mds_service is not None else vpool
disk.size = 0
disk.save()
disk.reload_client()
if mds_service is not None:
storagedriver_id = None
for sd in mds_service.vpool.storagedrivers:
if sd.storagerouter_guid == mds_service.service.storagerouter_guid:
storagedriver_id = sd.storagedriver_id
junction = MDSServiceVDisk()
junction.vdisk = disk
junction.mds_service = mds_service
junction.is_master = True
junction.save()
config = type('MDSNodeConfig', (),
{'address': self._generate_nc_function(True, mds_service),
'port': self._generate_nc_function(False, mds_service)})()
mds_backend_config = type('MDSMetaDataBackendConfig', (),
{'node_configs': self._generate_bc_function([config])})()
StorageDriverClient.metadata_backend_config['disk_{0}'.format(i)] = mds_backend_config
StorageDriverClient.catch_up['disk_{0}'.format(i)] = 50
StorageDriverClient.vrouter_id['disk_{0}'.format(i)] = storagedriver_id
vdisks[i] = disk
return vdisks
示例2: check_dtl
def check_dtl(result_handler):
"""
Checks the dtl for all vdisks on the local node
:param result_handler: logging object
:type result_handler: ovs.extensions.healthcheck.result.HCResults
:return: None
:rtype: NoneType
"""
# Fetch vdisks hosted on this machine
local_sr = System.get_my_storagerouter()
if len(local_sr.vdisks_guids) == 0:
return result_handler.skip('No VDisks present in cluster.')
for vdisk_guid in local_sr.vdisks_guids:
vdisk = VDisk(vdisk_guid)
vdisk.invalidate_dynamics(['dtl_status', 'info'])
if vdisk.dtl_status == 'ok_standalone' or vdisk.dtl_status == 'disabled':
result_handler.success('VDisk {0}s DTL is disabled'.format(vdisk.name), code=ErrorCodes.volume_dtl_standalone)
elif vdisk.dtl_status == 'ok_sync':
result_handler.success('VDisk {0}s DTL is enabled and running.'.format(vdisk.name), code=ErrorCodes.volume_dtl_ok)
elif vdisk.dtl_status == 'degraded':
result_handler.warning('VDisk {0}s DTL is degraded.'.format(vdisk.name), code=ErrorCodes.volume_dtl_degraded)
elif vdisk.dtl_status == 'checkup_required':
result_handler.warning('VDisk {0}s DTL should be configured.'.format(vdisk.name), code=ErrorCodes.volume_dtl_checkup_required)
elif vdisk.dtl_status == 'catch_up':
result_handler.warning('VDisk {0}s DTL is enabled but still syncing.'.format(vdisk.name), code=ErrorCodes.volume_dtl_catch_up)
else:
result_handler.warning('VDisk {0}s DTL has an unknown status: {1}.'.format(vdisk.name, vdisk.dtl_status), code=ErrorCodes.volume_dtl_unknown)
示例3: test_set_as_template
def test_set_as_template(self):
"""
Test the set as template functionality
- Create a vDisk
- Set it as template and make some assertions
"""
structure = Helper.build_service_structure(
{'vpools': [1],
'storagerouters': [1],
'storagedrivers': [(1, 1, 1)], # (<id>, <vpool_id>, <storagerouter_id>)
'mds_services': [(1, 1)]} # (<id>, <storagedriver_id>)
)
storagedrivers = structure['storagedrivers']
vdisk = VDisk(VDiskController.create_new(volume_name='vdisk_1', volume_size=1024 ** 4, storagedriver_guid=storagedrivers[1].guid))
metadata = {'is_consistent': True,
'is_automatic': True,
'is_sticky': False}
for x in range(5):
metadata['label'] = 'label{0}'.format(x)
metadata['timestamp'] = int(time.time())
VDiskController.create_snapshot(vdisk_guid=vdisk.guid, metadata=metadata)
self.assertTrue(expr=len(vdisk.snapshots) == 5, msg='Expected to find 5 snapshots')
# Set as template and validate the model
self.assertFalse(expr=vdisk.is_vtemplate, msg='Dynamic property "is_vtemplate" should be False')
VDiskController.set_as_template(vdisk.guid)
vdisk.invalidate_dynamics('snapshots')
self.assertTrue(expr=vdisk.is_vtemplate, msg='Dynamic property "is_vtemplate" should be True')
self.assertTrue(expr=len(vdisk.snapshots) == 1, msg='Expected to find only 1 snapshot after converting to template')
# Try again and verify job succeeds, previously we raised error when setting as template an additional time
VDiskController.set_as_template(vdisk.guid)
self.assertTrue(expr=vdisk.is_vtemplate, msg='Dynamic property "is_vtemplate" should still be True')
示例4: create_volume_from_snapshot
def create_volume_from_snapshot(self, volume, snapshot):
"""Creates a volume from a snapshot.
Called on "cinder create --snapshot-id ..."
:param snapshot: snapshot reference (sqlalchemy Model)
:param volume: volume reference (sqlalchemy Model)
Volume here is just a ModelObject, it doesn't exist physically,
it will be created by OVS.
Diskguid to be passed to the clone method is the ovs diskguid of the
parent of the snapshot with snapshot.id
OVS: Clone from arbitrary volume,
requires volumedriver 3.6 release > 15.08.2014
"""
_debug_vol_info('CLONE_VOL', volume)
_debug_vol_info('CLONE_SNAP', snapshot)
mountpoint = self._get_hostname_mountpoint(str(volume.host))
ovs_snap_disk = self._find_ovs_model_disk_by_snapshot_id(snapshot.id)
OVSVolumeDriver._wait_for_snapshot(ovs_snap_disk, snapshot.id)
devicename = volume.display_name
if not devicename:
devicename = volume.name
pmachineguid = self._find_ovs_model_pmachine_guid_by_hostname(
str(volume.host))
LOG.info('[CLONE FROM SNAP] %s %s %s %s'
% (ovs_snap_disk.guid, snapshot.id, devicename, pmachineguid))
try:
kwargs = dict(diskguid = ovs_snap_disk.guid,
snapshotid = snapshot.id,
devicename = devicename,
pmachineguid = pmachineguid,
machinename = "",
machineguid=None)
LOG.debug('[CLONE FROM SNAP] Executing clone - async')
# Execute "clone" task async, using celery workers
# wait for the result for 30 minutes then raise TimeoutError
disk_meta = VDiskController.clone.apply_async(kwargs = kwargs)\
.get(timeout = 1800)
LOG.debug('[CLONE FROM SNAP] Executing clone - async - DONE')
volume['provider_location'] = '{}{}'.format(
mountpoint, disk_meta['backingdevice'])
LOG.debug('[CLONE FROM SNAP] Meta: %s' % str(disk_meta))
LOG.debug('[CLONE FROM SNAP] New volume %s'
% volume['provider_location'])
vdisk = VDisk(disk_meta['diskguid'])
vdisk.cinder_id = volume.id
vdisk.name = devicename
vdisk.save()
except Exception as ex:
LOG.error('CLONE FROM SNAP: Internal error %s ' % str(ex))
self.delete_volume(volume)
raise
return {'provider_location': volume['provider_location'],
'display_name': volume['display_name']}
示例5: _execute_scrub_work
def _execute_scrub_work(scrub_location, vdisk_guids):
def _verify_mds_config(current_vdisk):
current_vdisk.invalidate_dynamics(['info'])
vdisk_configs = current_vdisk.info['metadata_backend_config']
if len(vdisk_configs) == 0:
raise RuntimeError('Could not load MDS configuration')
return vdisk_configs
ScheduledTaskController._logger.info('Execute Scrub - Started')
ScheduledTaskController._logger.info('Execute Scrub - Scrub location - {0}'.format(scrub_location))
total = len(vdisk_guids)
skipped = 0
storagedrivers = {}
failures = []
for vdisk_guid in vdisk_guids:
vdisk = VDisk(vdisk_guid)
try:
# Load the vDisk's StorageDriver
ScheduledTaskController._logger.info('Execute Scrub - Virtual disk {0} - {1} - Started'.format(vdisk.guid, vdisk.name))
vdisk.invalidate_dynamics(['storagedriver_id'])
if vdisk.storagedriver_id not in storagedrivers:
storagedrivers[vdisk.storagedriver_id] = StorageDriverList.get_by_storagedriver_id(vdisk.storagedriver_id)
storagedriver = storagedrivers[vdisk.storagedriver_id]
# Load the vDisk's MDS configuration
configs = _verify_mds_config(current_vdisk=vdisk)
# Check MDS master is local. Trigger MDS handover if necessary
if configs[0].get('ip') != storagedriver.storagerouter.ip:
ScheduledTaskController._logger.debug('Execute Scrub - Virtual disk {0} - {1} - MDS master is not local, trigger handover'.format(vdisk.guid, vdisk.name))
MDSServiceController.ensure_safety(vdisk)
configs = _verify_mds_config(current_vdisk=vdisk)
if configs[0].get('ip') != storagedriver.storagerouter.ip:
skipped += 1
ScheduledTaskController._logger.info('Execute Scrub - Virtual disk {0} - {1} - Skipping because master MDS still not local'.format(vdisk.guid, vdisk.name))
continue
with vdisk.storagedriver_client.make_locked_client(str(vdisk.volume_id)) as locked_client:
ScheduledTaskController._logger.info('Execute Scrub - Virtual disk {0} - {1} - Retrieve and apply scrub work'.format(vdisk.guid, vdisk.name))
work_units = locked_client.get_scrubbing_workunits()
for work_unit in work_units:
scrubbing_result = locked_client.scrub(work_unit, scrub_location, log_sinks=[SCRUBBER_LOGFILE_LOCATION])
locked_client.apply_scrubbing_result(scrubbing_result)
if work_units:
ScheduledTaskController._logger.info('Execute Scrub - Virtual disk {0} - {1} - Scrub successfully applied'.format(vdisk.guid, vdisk.name))
else:
ScheduledTaskController._logger.info('Execute Scrub - Virtual disk {0} - {1} - No scrubbing required'.format(vdisk.guid, vdisk.name))
except Exception as ex:
failures.append('Failed scrubbing work unit for volume {0} with guid {1}: {2}'.format(vdisk.name, vdisk.guid, ex))
failed = len(failures)
ScheduledTaskController._logger.info('Execute Scrub - Finished - Success: {0} - Failed: {1} - Skipped: {2}'.format((total - failed - skipped), failed, skipped))
if failed > 0:
raise Exception('\n - '.join(failures))
return vdisk_guids
示例6: rollback
def rollback(diskguid, timestamp):
"""
Rolls back a disk based on a given disk snapshot timestamp
"""
disk = VDisk(diskguid)
snapshots = [snap for snap in disk.snapshots if snap['timestamp'] == timestamp]
if not snapshots:
raise ValueError('No snapshot found for timestamp {}'.format(timestamp))
snapshotguid = snapshots[0]['guid']
disk.storagedriver_client.rollback_volume(str(disk.volume_id), snapshotguid)
disk.invalidate_dynamics(['snapshots'])
return True
示例7: _execute_scrub_work
def _execute_scrub_work(scrub_location, vdisk_guids):
def verify_mds_config(current_vdisk):
current_vdisk.invalidate_dynamics(["info"])
vdisk_configs = current_vdisk.info["metadata_backend_config"]
if len(vdisk_configs) == 0:
raise RuntimeError("Could not load MDS configuration")
return vdisk_configs
logger.info("Scrub location: {0}".format(scrub_location))
total = len(vdisk_guids)
skipped = 0
storagedrivers = {}
failures = []
for vdisk_guid in vdisk_guids:
vdisk = VDisk(vdisk_guid)
try:
# Load the vDisk's StorageDriver
logger.info("Scrubbing virtual disk {0} with guid {1}".format(vdisk.name, vdisk.guid))
vdisk.invalidate_dynamics(["storagedriver_id"])
if vdisk.storagedriver_id not in storagedrivers:
storagedrivers[vdisk.storagedriver_id] = StorageDriverList.get_by_storagedriver_id(
vdisk.storagedriver_id
)
storagedriver = storagedrivers[vdisk.storagedriver_id]
# Load the vDisk's MDS configuration
configs = verify_mds_config(current_vdisk=vdisk)
# Check MDS master is local. Trigger MDS handover if necessary
if configs[0].get("ip") != storagedriver.storagerouter.ip:
logger.debug("MDS for volume {0} is not local. Trigger handover".format(vdisk.volume_id))
MDSServiceController.ensure_safety(vdisk)
configs = verify_mds_config(current_vdisk=vdisk)
if configs[0].get("ip") != storagedriver.storagerouter.ip:
skipped += 1
logger.info(
"Skipping scrubbing work unit for volume {0}: MDS master is not local".format(
vdisk.volume_id
)
)
continue
with vdisk.storagedriver_client.make_locked_client(str(vdisk.volume_id)) as locked_client:
work_units = locked_client.get_scrubbing_workunits()
for work_unit in work_units:
scrubbing_result = locked_client.scrub(work_unit, scrub_location)
locked_client.apply_scrubbing_result(scrubbing_result)
if work_units:
logger.info("Scrubbing successfully applied")
except Exception, ex:
failures.append(
"Failed scrubbing work unit for volume {0} with guid {1}: {2}".format(vdisk.name, vdisk.guid, ex)
)
示例8: set_as_template
def set_as_template(diskguid):
"""
Set a disk as template
@param diskguid: guid of the disk
"""
disk = VDisk(diskguid)
if disk.is_vtemplate is True:
raise RuntimeError('Disk {0} is already set as template'.format(disk.name))
logger.info('Setting disk {0} as template'.format(disk.name))
disk.storagedriver_client.set_volume_as_template(str(disk.volume_id))
disk.is_vtemplate = True
disk.save()
示例9: _statistics
def _statistics(self, dynamic):
"""
Aggregates the Statistics (IOPS, Bandwidth, ...) of the vDisks connected to the Storage Driver.
"""
from ovs.dal.hybrids.vdisk import VDisk
statistics = {}
for key in StorageDriverClient.STAT_KEYS:
statistics[key] = 0
statistics['{0}_ps'.format(key)] = 0
for key, value in self.fetch_statistics().iteritems():
statistics[key] += value
statistics['timestamp'] = time.time()
VDisk.calculate_delta(self._key, dynamic, statistics)
return statistics
示例10: _statistics
def _statistics(self, dynamic):
"""
Aggregates the Statistics (IOPS, Bandwidth, ...) of each vDisk served by the vPool.
"""
from ovs.dal.hybrids.vdisk import VDisk
statistics = {}
for key in StorageDriverClient.stat_keys:
statistics[key] = 0
statistics['{0}_ps'.format(key)] = 0
for vdisk in self.vdisks:
for key, value in vdisk.fetch_statistics().iteritems():
statistics[key] += value
statistics['timestamp'] = time.time()
VDisk.calculate_delta(self._key, dynamic, statistics)
return statistics
示例11: delete_snapshot
def delete_snapshot(diskguid, snapshotid):
"""
Delete a disk snapshot
@param diskguid: guid of the disk
@param snapshotid: id of the snapshot
@todo: Check if new volumedriver storagedriver upon deletion
of a snapshot has built-in protection to block it from being deleted
if a clone was created from it.
"""
disk = VDisk(diskguid)
logger.info('Deleting snapshot {} from disk {}'.format(snapshotid, disk.name))
disk.storagedriver_client.delete_snapshot(str(disk.volume_id), str(snapshotid))
disk.invalidate_dynamics(['snapshots'])
示例12: create_snapshot
def create_snapshot(diskguid, metadata, snapshotid=None):
"""
Create a disk snapshot
@param diskguid: guid of the disk
@param metadata: dict of metadata
"""
disk = VDisk(diskguid)
logger.info("Create snapshot for disk {}".format(disk.name))
if snapshotid is None:
snapshotid = str(uuid.uuid4())
metadata = pickle.dumps(metadata)
disk.storagedriver_client.create_snapshot(str(disk.volume_id), snapshot_id=snapshotid, metadata=metadata)
disk.invalidate_dynamics(["snapshots"])
return snapshotid
示例13: _statistics
def _statistics(self, dynamic):
"""
Aggregates the Statistics (IOPS, Bandwidth, ...) of each vDisk of the vMachine.
"""
from ovs.dal.hybrids.vdisk import VDisk
statistics = {}
for key in StorageDriverClient.STAT_KEYS:
statistics[key] = 0
statistics['{0}_ps'.format(key)] = 0
for storagedriver in self.storagedrivers:
for vdisk in storagedriver.vpool.vdisks:
if vdisk.storagedriver_id == storagedriver.storagedriver_id:
for key, value in vdisk.fetch_statistics().iteritems():
statistics[key] += value
statistics['timestamp'] = time.time()
VDisk.calculate_delta(self._key, dynamic, statistics)
return statistics
示例14: resize_from_voldrv
def resize_from_voldrv(volumename, volumesize, volumepath, storagedriver_id):
"""
Resize a disk
Triggered by volumedriver messages on the queue
@param volumepath: path on hypervisor to the volume
@param volumename: volume id of the disk
@param volumesize: size of the volume
"""
pmachine = PMachineList.get_by_storagedriver_id(storagedriver_id)
storagedriver = StorageDriverList.get_by_storagedriver_id(storagedriver_id)
hypervisor = Factory.get(pmachine)
volumepath = hypervisor.clean_backing_disk_filename(volumepath)
mutex = VolatileMutex('{}_{}'.format(volumename, volumepath))
try:
mutex.acquire(wait=30)
disk = VDiskList.get_vdisk_by_volume_id(volumename)
if disk is None:
disk = VDiskList.get_by_devicename_and_vpool(volumepath, storagedriver.vpool)
if disk is None:
disk = VDisk()
finally:
mutex.release()
disk.devicename = volumepath
disk.volume_id = volumename
disk.size = volumesize
disk.vpool = storagedriver.vpool
disk.save()
VDiskController.sync_with_mgmtcenter(disk, pmachine, storagedriver)
MDSServiceController.ensure_safety(disk)
示例15: create_vdisks_for_mds_service
def create_vdisks_for_mds_service(amount, start_id, mds_service=None, storagedriver=None):
"""
Generates vdisks and appends them to a given mds_service
"""
if (mds_service is None and storagedriver is None) or (mds_service is not None and storagedriver is not None):
raise RuntimeError("Either `mds_service` or `storagedriver` should be passed")
vdisks = {}
storagedriver_id = None
vpool = None
mds_services = []
if mds_service is not None:
mds_services.append(mds_service)
for sd in mds_service.vpool.storagedrivers:
if sd.storagerouter_guid == mds_service.service.storagerouter_guid:
storagedriver_id = sd.storagedriver_id
vpool = sd.vpool
if storagedriver_id is None:
raise RuntimeError("The given MDSService is located on a node without StorageDriver")
else:
storagedriver_id = storagedriver.storagedriver_id
vpool = storagedriver.vpool
srclient = StorageRouterClient(vpool.guid, None)
for i in xrange(start_id, start_id + amount):
devicename = "vdisk_{0}".format(i)
mds_backend_config = Helper._generate_mdsmetadatabackendconfig(mds_services)
volume_id = srclient.create_volume(devicename, mds_backend_config, 0, str(storagedriver_id))
if len(mds_services) == 1:
MDSClient.set_catchup(mds_services[0], volume_id, 50)
vdisk = VDisk()
vdisk.name = str(i)
vdisk.devicename = devicename
vdisk.volume_id = volume_id
vdisk.vpool = vpool
vdisk.size = 0
vdisk.save()
vdisk.reload_client("storagedriver")
if mds_service is not None:
junction = MDSServiceVDisk()
junction.vdisk = vdisk
junction.mds_service = mds_service
junction.is_master = True
junction.save()
vdisks[i] = vdisk
return vdisks