本文整理汇总了Python中ovs.lib.mdsservice.MDSServiceController类的典型用法代码示例。如果您正苦于以下问题:Python MDSServiceController类的具体用法?Python MDSServiceController怎么用?Python MDSServiceController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MDSServiceController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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)
示例2: test_load_calculation
def test_load_calculation(self):
"""
Validates whether the load calculation works
"""
vpools, storagerouters, storagedrivers, services, mds_services, _ = self._build_service_structure(
{'vpools': [1],
'storagerouters': [1],
'storagedrivers': [(1, 1, 1)], # (<id>, <vpool_id>, <sr_id>)
'mds_services': [(1, 1)]} # (<id>, <sd_id>)
)
mds_service = mds_services[1]
self._create_vdisks_for_mds_service(2, 1, mds_service=mds_service)
load, load_plus = MDSServiceController.get_mds_load(mds_service)
self.assertEqual(load, 20, 'There should be a 20% load. {0}'.format(load))
self.assertEqual(load_plus, 30, 'There should be a 30% plus load. {0}'.format(load_plus))
self._create_vdisks_for_mds_service(3, 3, mds_service=mds_service)
load, load_plus = MDSServiceController.get_mds_load(mds_service)
self.assertEqual(load, 50, 'There should be a 50% load. {0}'.format(load))
self.assertEqual(load_plus, 60, 'There should be a 60% plus load. {0}'.format(load_plus))
self._create_vdisks_for_mds_service(5, 6, mds_service=mds_service)
load, load_plus = MDSServiceController.get_mds_load(mds_service)
self.assertEqual(load, 100, 'There should be a 100% load. {0}'.format(load))
self.assertEqual(load_plus, 110, 'There should be a 110% plus load. {0}'.format(load_plus))
mds_service.capacity = -1
mds_service.save()
load, load_plus = MDSServiceController.get_mds_load(mds_service)
self.assertEqual(load, 50, 'There should be a 50% load. {0}'.format(load))
self.assertEqual(load_plus, 50, 'There should be a 50% plus load. {0}'.format(load_plus))
mds_service.capacity = 0
mds_service.save()
load, load_plus = MDSServiceController.get_mds_load(mds_service)
self.assertEqual(load, float('inf'), 'There should be infinite load. {0}'.format(load))
self.assertEqual(load_plus, float('inf'), 'There should be infinite plus load. {0}'.format(load_plus))
示例3: _test_scenario
def _test_scenario(scenario, _vdisks, _mds_services):
"""
Executes a test run for a given scenario
"""
_generate_backend_config(scenario, _vdisks, _mds_services)
for vdisk_id in _vdisks:
MDSServiceController.sync_vdisk_to_reality(_vdisks[vdisk_id])
_validate_scenario(scenario, _vdisks, _mds_services)
示例4: volumedriver_error
def volumedriver_error(code, volumename):
"""
Handles error messages/events from the volumedriver
"""
if code == VolumeDriverEvents.MDSFailover:
disk = VDiskList.get_vdisk_by_volume_id(volumename)
if disk is not None:
MDSServiceController.ensure_safety(disk)
示例5: clone
def clone(diskguid, snapshotid, devicename, pmachineguid, machinename, machineguid=None):
"""
Clone a disk
"""
pmachine = PMachine(pmachineguid)
hypervisor = Factory.get(pmachine)
description = '{} {}'.format(machinename, devicename)
properties_to_clone = ['description', 'size', 'type', 'retentionpolicyguid',
'snapshotpolicyguid', 'autobackup']
vdisk = VDisk(diskguid)
location = hypervisor.get_backing_disk_path(machinename, devicename)
new_vdisk = VDisk()
new_vdisk.copy(vdisk, include=properties_to_clone)
new_vdisk.parent_vdisk = vdisk
new_vdisk.name = '{0}-clone'.format(vdisk.name)
new_vdisk.description = description
new_vdisk.devicename = hypervisor.clean_backing_disk_filename(location)
new_vdisk.parentsnapshot = snapshotid
new_vdisk.vmachine = VMachine(machineguid) if machineguid else vdisk.vmachine
new_vdisk.vpool = vdisk.vpool
new_vdisk.save()
try:
storagedriver = StorageDriverList.get_by_storagedriver_id(vdisk.storagedriver_id)
if storagedriver is None:
raise RuntimeError('Could not find StorageDriver with id {0}'.format(vdisk.storagedriver_id))
mds_service = MDSServiceController.get_preferred_mds(storagedriver.storagerouter, vdisk.vpool)
if mds_service is None:
raise RuntimeError('Could not find a MDS service')
logger.info('Clone snapshot {} of disk {} to location {}'.format(snapshotid, vdisk.name, location))
volume_id = vdisk.storagedriver_client.create_clone(
target_path=location,
metadata_backend_config=MDSMetaDataBackendConfig([MDSNodeConfig(address=str(mds_service.service.storagerouter.ip),
port=mds_service.service.ports[0])]),
parent_volume_id=str(vdisk.volume_id),
parent_snapshot_id=str(snapshotid),
node_id=str(vdisk.storagedriver_id)
)
except Exception as ex:
logger.error('Caught exception during clone, trying to delete the volume. {0}'.format(ex))
new_vdisk.delete()
VDiskController.delete_volume(location)
raise
new_vdisk.volume_id = volume_id
new_vdisk.save()
try:
MDSServiceController.ensure_safety(new_vdisk)
except Exception as ex:
logger.error('Caught exception during "ensure_safety" {0}'.format(ex))
return {'diskguid': new_vdisk.guid,
'name': new_vdisk.name,
'backingdevice': location}
示例6: volumedriver_error
def volumedriver_error(code, volumename, storagedriver_id):
"""
Handles error messages/events from the volumedriver
"""
_ = storagedriver_id # Required for the @log decorator
if code == VolumeDriverEvents.MDSFailover:
disk = VDiskList.get_vdisk_by_volume_id(volumename)
if disk is not None:
MDSServiceController.ensure_safety(disk)
示例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
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
示例8: volumedriver_error
def volumedriver_error(code, volumename, storagedriver_id):
"""
Handles error messages/events from the volumedriver
:param code: Volumedriver error code
:param volumename: Name of the volume throwing the error
:param storagedriver_id: ID of the storagedriver hosting the volume
"""
_ = storagedriver_id # Required for the @log decorator
if code == VolumeDriverEvents.MDSFailover:
disk = VDiskList.get_vdisk_by_volume_id(volumename)
if disk is not None:
MDSServiceController.ensure_safety(disk)
示例9: _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)
)
示例10: volumedriver_error
def volumedriver_error(code, volume_id):
"""
Handles error messages/events from the volumedriver
:param code: Volumedriver error code
:type code: int
:param volume_id: Name of the volume throwing the error
:type volume_id: str
:return: None
"""
if code == VolumeDriverEvents.MDSFailover:
disk = VDiskList.get_vdisk_by_volume_id(volume_id)
if disk is not None:
MDSServiceController.ensure_safety(disk)
示例11: clone
def clone(diskguid, snapshotid, devicename, pmachineguid, machinename, machineguid=None):
"""
Clone a disk
"""
pmachine = PMachine(pmachineguid)
hypervisor = Factory.get(pmachine)
description = "{} {}".format(machinename, devicename)
properties_to_clone = ["description", "size", "type", "retentionpolicyguid", "snapshotpolicyguid", "autobackup"]
vdisk = VDisk(diskguid)
location = hypervisor.get_backing_disk_path(machinename, devicename)
new_vdisk = VDisk()
new_vdisk.copy(vdisk, include=properties_to_clone)
new_vdisk.parent_vdisk = vdisk
new_vdisk.name = "{0}-clone".format(vdisk.name)
new_vdisk.description = description
new_vdisk.devicename = hypervisor.clean_backing_disk_filename(location)
new_vdisk.parentsnapshot = snapshotid
new_vdisk.vmachine = VMachine(machineguid) if machineguid else vdisk.vmachine
new_vdisk.vpool = vdisk.vpool
new_vdisk.save()
storagedriver = StorageDriverList.get_by_storagedriver_id(vdisk.storagedriver_id)
if storagedriver is None:
raise RuntimeError("Could not find StorageDriver with id {0}".format(vdisk.storagedriver_id))
mds_service = MDSServiceController.get_preferred_mds(storagedriver.storagerouter, vdisk.vpool)
if mds_service is None:
raise RuntimeError("Could not find a MDS service")
logger.info("Clone snapshot {} of disk {} to location {}".format(snapshotid, vdisk.name, location))
volume_id = vdisk.storagedriver_client.create_clone(
target_path=location,
metadata_backend_config=MDSMetaDataBackendConfig(
[MDSNodeConfig(address=str(mds_service.service.storagerouter.ip), port=mds_service.service.ports[0])]
),
parent_volume_id=str(vdisk.volume_id),
parent_snapshot_id=str(snapshotid),
node_id=str(vdisk.storagedriver_id),
)
new_vdisk.volume_id = volume_id
new_vdisk.save()
MDSServiceController.ensure_safety(new_vdisk)
return {"diskguid": new_vdisk.guid, "name": new_vdisk.name, "backingdevice": location}
示例12: migrate_from_voldrv
def migrate_from_voldrv(volume_id, new_owner_id):
"""
Triggered when volume has changed owner (Clean migration or stolen due to other reason)
Triggered by volumedriver messages
:param volume_id: Volume ID of the disk
:type volume_id: unicode
:param new_owner_id: ID of the storage driver the volume migrated to
:type new_owner_id: unicode
:returns: None
"""
sd = StorageDriverList.get_by_storagedriver_id(storagedriver_id=new_owner_id)
vdisk = VDiskList.get_vdisk_by_volume_id(volume_id=volume_id)
if vdisk is not None:
logger.info('Migration - Guid {0} - ID {1} - Detected migration for virtual disk {2}'.format(vdisk.guid, vdisk.volume_id, vdisk.name))
if sd is not None:
logger.info('Migration - Guid {0} - ID {1} - Storage Router {2} is the new owner of virtual disk {3}'.format(vdisk.guid, vdisk.volume_id, sd.storagerouter.name, vdisk.name))
MDSServiceController.mds_checkup()
VDiskController.dtl_checkup(vdisk_guid=vdisk.guid)
示例13: _generate_mds_service_load_repr
def _generate_mds_service_load_repr(_mds_service):
"""
Generates a load representing thing for a given mds_service
"""
masters, slaves = 0, 0
for _junction in _mds_service.vdisks:
if _junction.is_master:
masters += 1
else:
slaves += 1
capacity = _mds_service.capacity
if capacity == -1:
capacity = 'infinite'
_load, _ = MDSServiceController.get_mds_load(_mds_service)
if _load == float('inf'):
_load = 'infinite'
else:
_load = round(_load, 2)
return [_mds_service.service.storagerouter.ip, _mds_service.service.ports[0], masters, slaves, capacity, _load]
示例14: create_from_template
def create_from_template(diskguid, machinename, devicename, pmachineguid, machineguid=None, storagedriver_guid=None):
"""
Create a disk from a template
@param devicename: device file name for the disk (eg: mydisk-flat.vmdk)
@param machineguid: guid of the machine to assign disk to
@return diskguid: guid of new disk
"""
pmachine = PMachine(pmachineguid)
hypervisor = Factory.get(pmachine)
disk_path = hypervisor.get_disk_path(machinename, devicename)
description = '{} {}'.format(machinename, devicename)
properties_to_clone = [
'description', 'size', 'type', 'retentionpolicyid',
'snapshotpolicyid', 'vmachine', 'vpool']
vdisk = VDisk(diskguid)
if vdisk.vmachine and not vdisk.vmachine.is_vtemplate:
# Disk might not be attached to a vmachine, but still be a template
raise RuntimeError('The given vdisk does not belong to a template')
if storagedriver_guid is not None:
storagedriver_id = StorageDriver(storagedriver_guid).storagedriver_id
else:
storagedriver_id = vdisk.storagedriver_id
storagedriver = StorageDriverList.get_by_storagedriver_id(storagedriver_id)
if storagedriver is None:
raise RuntimeError('Could not find StorageDriver with id {0}'.format(storagedriver_id))
new_vdisk = VDisk()
new_vdisk.copy(vdisk, include=properties_to_clone)
new_vdisk.vpool = vdisk.vpool
new_vdisk.devicename = hypervisor.clean_backing_disk_filename(disk_path)
new_vdisk.parent_vdisk = vdisk
new_vdisk.name = '{}-clone'.format(vdisk.name)
new_vdisk.description = description
new_vdisk.vmachine = VMachine(machineguid) if machineguid else vdisk.vmachine
new_vdisk.save()
mds_service = MDSServiceController.get_preferred_mds(storagedriver.storagerouter, vdisk.vpool)
if mds_service is None:
raise RuntimeError('Could not find a MDS service')
logger.info('Create disk from template {} to new disk {} to location {}'.format(
vdisk.name, new_vdisk.name, disk_path
))
try:
volume_id = vdisk.storagedriver_client.create_clone_from_template(
target_path=disk_path,
metadata_backend_config=MDSMetaDataBackendConfig([MDSNodeConfig(address=str(mds_service.service.storagerouter.ip),
port=mds_service.service.ports[0])]),
parent_volume_id=str(vdisk.volume_id),
node_id=str(storagedriver_id)
)
new_vdisk.volume_id = volume_id
new_vdisk.save()
MDSServiceController.ensure_safety(new_vdisk)
except Exception as ex:
logger.error('Clone disk on volumedriver level failed with exception: {0}'.format(str(ex)))
new_vdisk.delete()
raise
return {'diskguid': new_vdisk.guid, 'name': new_vdisk.name,
'backingdevice': disk_path}
示例15: update_vmachine_config
def update_vmachine_config(vmachine, vm_object, pmachine=None):
"""
Update a vMachine configuration with a given vMachine configuration
"""
try:
vdisks_synced = 0
if vmachine.name is None:
MessageController.fire(MessageController.Type.EVENT,
{'type': 'vmachine_created',
'metadata': {'name': vm_object['name']}})
elif vmachine.name != vm_object['name']:
MessageController.fire(MessageController.Type.EVENT,
{'type': 'vmachine_renamed',
'metadata': {'old_name': vmachine.name,
'new_name': vm_object['name']}})
if pmachine is not None:
vmachine.pmachine = pmachine
vmachine.name = vm_object['name']
vmachine.hypervisor_id = vm_object['id']
vmachine.devicename = vm_object['backing']['filename']
vmachine.save()
# Updating and linking disks
storagedrivers = StorageDriverList.get_storagedrivers()
datastores = dict([('{}:{}'.format(storagedriver.storage_ip, storagedriver.mountpoint), storagedriver) for storagedriver in storagedrivers])
vdisk_guids = []
for disk in vm_object['disks']:
if disk['datastore'] in vm_object['datastores']:
datastore = vm_object['datastores'][disk['datastore']]
if datastore in datastores:
vdisk = VDiskList.get_by_devicename_and_vpool(disk['filename'], datastores[datastore].vpool)
if vdisk is None:
# The disk couldn't be located, but is in our datastore. We might be in a recovery scenario
vdisk = VDisk()
vdisk.vpool = datastores[datastore].vpool
vdisk.reload_client()
vdisk.devicename = disk['filename']
vdisk.volume_id = vdisk.storagedriver_client.get_volume_id(str(disk['backingfilename']))
vdisk.size = vdisk.info['volume_size']
MDSServiceController.ensure_safety(vdisk)
# Update the disk with information from the hypervisor
if vdisk.vmachine is None:
MessageController.fire(MessageController.Type.EVENT,
{'type': 'vdisk_attached',
'metadata': {'vmachine_name': vmachine.name,
'vdisk_name': disk['name']}})
vdisk.vmachine = vmachine
vdisk.name = disk['name']
vdisk.order = disk['order']
vdisk.save()
vdisk_guids.append(vdisk.guid)
vdisks_synced += 1
for vdisk in vmachine.vdisks:
if vdisk.guid not in vdisk_guids:
MessageController.fire(MessageController.Type.EVENT,
{'type': 'vdisk_detached',
'metadata': {'vmachine_name': vmachine.name,
'vdisk_name': vdisk.name}})
vdisk.vmachine = None
vdisk.save()
logger.info('Updating vMachine finished (name {}, {} vdisks (re)linked)'.format(
vmachine.name, vdisks_synced
))
except Exception as ex:
logger.info('Error during vMachine update: {0}'.format(str(ex)))
raise