本文整理汇总了Python中ovs.dal.lists.vdisklist.VDiskList.get_vdisks方法的典型用法代码示例。如果您正苦于以下问题:Python VDiskList.get_vdisks方法的具体用法?Python VDiskList.get_vdisks怎么用?Python VDiskList.get_vdisks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ovs.dal.lists.vdisklist.VDiskList
的用法示例。
在下文中一共展示了VDiskList.get_vdisks方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_event_resize_from_volumedriver
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def test_event_resize_from_volumedriver(self):
"""
Test resize from volumedriver event
- Create a vDisk using the resize event
- Resize the created vDisk using the same resize event
"""
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>)
)
vpools = structure['vpools']
storagedrivers = structure['storagedrivers']
mds_service = structure['mds_services'][1]
# Create volume using resize from voldrv
device_name = '/vdisk.raw'
srclient = StorageRouterClient(vpools[1].guid, None)
mds_backend_config = Helper._generate_mdsmetadatabackendconfig([mds_service])
volume_id = srclient.create_volume(device_name, mds_backend_config, 1024 ** 4, str(storagedrivers[1].storagedriver_id))
VDiskController.resize_from_voldrv(volume_id=volume_id,
volume_size=1024 ** 4,
volume_path=device_name,
storagedriver_id=storagedrivers[1].storagedriver_id)
vdisks = VDiskList.get_vdisks()
self.assertTrue(expr=len(vdisks) == 1,
msg='Expected to find 1 vDisk in model')
self.assertEqual(first=vdisks[0].name,
second='vdisk',
msg='Volume name should be vdisk')
self.assertEqual(first=vdisks[0].volume_id,
second=volume_id,
msg='Volume ID should be {0}'.format(volume_id))
self.assertEqual(first=vdisks[0].devicename,
second=device_name,
msg='Device name should be {0}'.format(device_name))
self.assertEqual(first=vdisks[0].size,
second=1024 ** 4,
msg='Size should be 1 TiB')
# Resize volume using resize from voldrv
VDiskController.resize_from_voldrv(volume_id=volume_id,
volume_size=2 * 1024 ** 4,
volume_path=device_name,
storagedriver_id=storagedrivers[1].storagedriver_id)
vdisks = VDiskList.get_vdisks()
self.assertTrue(expr=len(vdisks) == 1,
msg='Expected to find 1 vDisk in model')
self.assertEqual(first=vdisks[0].name,
second='vdisk',
msg='Volume name should be vdisk')
self.assertEqual(first=vdisks[0].size,
second=2 * 1024 ** 4,
msg='Size should be 2 TiB')
示例2: _find_ovs_model_disk_by_location
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def _find_ovs_model_disk_by_location(self, location, hostname, retry=3,
timeout=3):
"""Find OVS disk object based on location and hostname
:return VDisk: OVS DAL model object
"""
hostname = self._get_real_hostname(hostname)
LOG.debug('[_FIND OVS DISK] Location %s, hostname %s'
% (location, hostname))
attempt = 0
while attempt <= retry:
for vd in VDiskList.get_vdisks():
if vd.vpool:
for vsr in vd.vpool.storagedrivers:
if vsr.storagerouter.name == hostname:
_location = "{0}/{1}".format(vsr.mountpoint,
vd.devicename)
if _location == location:
LOG.info('Location %s Disk found %s'
% (location, vd.guid))
disk = VDisk(vd.guid)
return disk
msg = ' NO RESULT Attempt %s timeout %s max attempts %s'
LOG.debug(msg % (attempt, timeout, retry))
if timeout:
time.sleep(timeout)
attempt += 1
raise RuntimeError('No disk found for location %s' % location)
示例3: list
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def list(self, vpoolguid=None, storagerouterguid=None, query=None):
"""
Overview of all vDisks
:param vpoolguid: Guid of the vPool to retrieve its disks
:type vpoolguid: str
:param storagerouterguid: Guid of the StorageRouter to retrieve its disks
:type storagerouterguid: str
:param query: A query to be executed if required
:type query: DataQuery
"""
if vpoolguid is not None:
vpool = VPool(vpoolguid)
vdisks = vpool.vdisks
elif storagerouterguid is not None:
storagerouter = StorageRouter(storagerouterguid)
vdisks = DataList(
VDisk,
{
"type": DataList.where_operator.AND,
"items": [("guid", DataList.operator.IN, storagerouter.vdisks_guids)],
},
)
else:
vdisks = VDiskList.get_vdisks()
if query is not None:
query_vdisk_guids = DataList(VDisk, query).guids
vdisks = [vdisk for vdisk in vdisks if vdisk.guid in query_vdisk_guids]
return vdisks
示例4: _snapshot_has_children
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def _snapshot_has_children(self, snapshotid):
"""Find if snapshot has children, in OVS Model
:return True/False
"""
LOG.debug('[_FIND CHILDREN OF SNAPSHOT] Snapshotid %s' % snapshotid)
for vdisk in VDiskList.get_vdisks():
if vdisk.parentsnapshot == snapshotid:
return True
return False
示例5: _find_ovs_model_disk_by_snapshot_id
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def _find_ovs_model_disk_by_snapshot_id(self, snapshotid):
"""Find OVS disk object based on snapshot id
:return VDisk: OVS DAL model object
"""
LOG.debug("[_FIND OVS DISK] Snapshotid %s" % snapshotid)
for disk in VDiskList.get_vdisks():
snaps_guid = [s["guid"] for s in disk.snapshots]
if str(snapshotid) in snaps_guid:
LOG.info("[_FIND OVS DISK] Snapshot id %s Disk found %s" % (snapshotid, disk.name))
return disk
raise RuntimeError("No disk found for snapshotid %s" % snapshotid)
示例6: test_list_volumes
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def test_list_volumes(self):
"""
Test the list volumes functionality
- Create 1 vDisk on vPool1 and create 3 vDisks on vPool2
- List all volumes
- List the volumes on vPool1
- List the volumes on vPool2
"""
structure = Helper.build_service_structure(
{'vpools': [1, 2],
'storagerouters': [1],
'storagedrivers': [(1, 1, 1), (2, 2, 1)], # (<id>, <vpool_id>, <storagerouter_id>)
'mds_services': [(1, 1), (2, 2)]} # (<id>, <storagedriver_id>)
)
vpools = structure['vpools']
storagedrivers = structure['storagedrivers']
vpool1 = vpools[1]
vpool2 = vpools[2]
VDiskController.create_new(volume_name='vdisk_1', volume_size=1024 ** 4, storagedriver_guid=storagedrivers[1].guid)
VDiskController.create_new(volume_name='vdisk_1', volume_size=1024 ** 4, storagedriver_guid=storagedrivers[2].guid)
VDiskController.create_new(volume_name='vdisk_2', volume_size=1024 ** 4, storagedriver_guid=storagedrivers[2].guid)
VDiskController.create_new(volume_name='vdisk_3', volume_size=1024 ** 4, storagedriver_guid=storagedrivers[2].guid)
all_vdisks = VDiskList.get_vdisks()
# List all volumes
sd_volume_ids = set(VDiskController.list_volumes())
model_volume_ids = set([vdisk.volume_id for vdisk in all_vdisks])
self.assertEqual(first=len(sd_volume_ids),
second=4,
msg='Expected to retrieve all 4 volumes')
self.assertEqual(first=sd_volume_ids,
second=model_volume_ids,
msg='Volume IDs from Storage Driver not identical to volume IDs in model. SD: {0} - Model: {1}'.format(sd_volume_ids, model_volume_ids))
# List all volumes of vpools[1]
sd_vpool1_volume_ids = set(VDiskController.list_volumes(vpool_guid=vpool1.guid))
model_vpool1_volume_ids = set([vdisk.volume_id for vdisk in all_vdisks if vdisk.vpool == vpool1])
self.assertEqual(first=len(sd_vpool1_volume_ids),
second=1,
msg='Expected to retrieve 1 volume')
self.assertEqual(first=sd_vpool1_volume_ids,
second=model_vpool1_volume_ids,
msg='Volume IDs for vPool1 from Storage Driver not identical to volume IDs in model. SD: {0} - Model: {1}'.format(sd_vpool1_volume_ids, model_vpool1_volume_ids))
# List all volumes of vpools[2]
sd_vpool2_volume_ids = set(VDiskController.list_volumes(vpool_guid=vpool2.guid))
model_vpool2_volume_ids = set([vdisk.volume_id for vdisk in all_vdisks if vdisk.vpool == vpool2])
self.assertEqual(first=len(sd_vpool2_volume_ids),
second=3,
msg='Expected to retrieve 3 volumes')
self.assertEqual(first=sd_vpool2_volume_ids,
second=model_vpool2_volume_ids,
msg='Volume IDs for vPool2 from Storage Driver not identical to volume IDs in model. SD: {0} - Model: {1}'.format(sd_vpool2_volume_ids, model_vpool2_volume_ids))
示例7: list
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def list(self, vmachineguid=None, vpoolguid=None):
"""
Overview of all vDisks
"""
if vmachineguid is not None:
vmachine = VMachine(vmachineguid)
return vmachine.vdisks
elif vpoolguid is not None:
vpool = VPool(vpoolguid)
return vpool.vdisks
return VDiskList.get_vdisks()
示例8: _ovs_snapshot_id_in_vdisklist_snapshots
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def _ovs_snapshot_id_in_vdisklist_snapshots(self, snapshot_id, retry=10):
attempt = 0
while attempt <= int(retry):
snap_map = dict((vd.guid, vd.snapshots) for vd in VDiskList.get_vdisks())
for guid, snapshots in snap_map.items():
snaps = [snap['guid'] for snap in snapshots if snap['guid'] == snapshot_id]
if len(snaps) == 1:
return True
attempt += 1
time.sleep(2)
return False
示例9: get_vdisks_stats
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def get_vdisks_stats():
"""
Send vdisks statistics to InfluxDB
"""
vdisks = VDiskList.get_vdisks()
if len(vdisks) == 0:
StatsmonkeyScheduledTaskController._logger.info("No vdisks found")
return None
for vdisk in vdisks:
try:
points = []
metrics = StatsmonkeyScheduledTaskController._pop_realtime_info(vdisk.statistics)
disk_name = vdisk.name
failover_mode = vdisk.info['failover_mode']
if failover_mode in ['OK_STANDALONE', 'OK_SYNC']:
failover_status = 0
elif failover_mode == 'CATCHUP':
failover_status = 1
elif failover_mode == 'DEGRADED':
failover_status = 2
else:
failover_status = 3
metrics['failover_mode_status'] = failover_status
if vdisk.vmachine:
vm_name = vdisk.vmachine.name
else:
vm_name = None
vpool_name = VPool(vdisk.vpool_guid).name
entry = {
'measurement': 'vdisk_stats',
'tags': {
'disk_name': disk_name,
'vm_name': vm_name,
'storagerouter_name': StorageRouter(vdisk.storagerouter_guid).name,
'vpool_name': vpool_name,
'failover_mode': vdisk.info['failover_mode']
},
'fields': metrics
}
points.append(entry)
StatsmonkeyScheduledTaskController._send_stats(points)
return points
except Exception as ex:
StatsmonkeyScheduledTaskController._logger.error(ex.message)
return None
return None
示例10: list
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def list(self, vmachineguid=None, vpoolguid=None):
"""
Overview of all vDisks
:param vmachineguid: Guid of the virtual machine to retrieve its disks
:param vpoolguid: Guid of the vPool to retrieve its disks
"""
if vmachineguid is not None:
vmachine = VMachine(vmachineguid)
return vmachine.vdisks
elif vpoolguid is not None:
vpool = VPool(vpoolguid)
return vpool.vdisks
return VDiskList.get_vdisks()
示例11: teardown
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def teardown():
"""
Teardown for VirtualDisk package, will be executed when all started tests in this package have ended
Removal actions of possible things left over after the test-run
:return: None
"""
vpool_name = General.get_config().get("vpool", "name")
vpool = GeneralVPool.get_vpool_by_name(vpool_name)
for vd in VDiskList.get_vdisks():
GeneralVDisk.delete_volume(vd, vpool, loop_device='loop0')
if vpool is not None:
GeneralVPool.remove_vpool(vpool)
alba_backend = GeneralAlba.get_by_name(General.get_config().get('backend', 'name'))
if alba_backend is not None:
GeneralAlba.unclaim_disks_and_remove_alba_backend(alba_backend=alba_backend)
示例12: test_delete
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def test_delete(self):
"""
Test the delete of a vDisk
- Create 2 vDisks with identical names on 2 different vPools
- Delete 1st vDisk and verify other still remains on correct vPool
- Delete 2nd vDisk and verify no more volumes left
"""
structure = Helper.build_service_structure(
{'vpools': [1, 2],
'domains': [1],
'storagerouters': [1],
'storagedrivers': [(1, 1, 1), (2, 2, 1)], # (<id>, <vpool_id>, <storagerouter_id>)
'mds_services': [(1, 1), (2, 2)]} # (<id>, <storagedriver_id>)
)
domains = structure['domains']
storagedrivers = structure['storagedrivers']
vdisk1 = VDisk(VDiskController.create_new(volume_name='vdisk_1', volume_size=1024 ** 3, storagedriver_guid=storagedrivers[1].guid))
vdisk2 = VDisk(VDiskController.create_new(volume_name='vdisk_1', volume_size=1024 ** 3, storagedriver_guid=storagedrivers[2].guid))
vdisk_domain = VDiskDomain()
vdisk_domain.domain = domains[1]
vdisk_domain.vdisk = vdisk1
vdisk_domain.save()
# Delete vDisk1 and make some assertions
VDiskController.delete(vdisk_guid=vdisk1.guid)
with self.assertRaises(ObjectNotFoundException):
VDisk(vdisk1.guid)
self.assertEqual(first=len(VDiskController.list_volumes()),
second=1,
msg='Expected to find only 1 volume in Storage Driver list_volumes')
self.assertIn(member=vdisk2,
container=VDiskList.get_vdisks(),
msg='vDisk2 should still be modeled')
# Delete vDisk2 and make some assertions
VDiskController.delete(vdisk_guid=vdisk2.guid)
with self.assertRaises(ObjectNotFoundException):
VDisk(vdisk2.guid)
self.assertEqual(first=len(VDiskController.list_volumes()),
second=0,
msg='Expected to find no more volumes in Storage Driver list_volumes')
示例13: snapshot_all_vdisks
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def snapshot_all_vdisks():
"""
Snapshots all vDisks
"""
ScheduledTaskController._logger.info('[SSA] started')
success = []
fail = []
for vdisk in VDiskList.get_vdisks():
try:
metadata = {'label': '',
'is_consistent': False,
'timestamp': str(int(time.time())),
'is_automatic': True,
'is_sticky': False}
VDiskController.create_snapshot(vdisk_guid=vdisk.guid,
metadata=metadata)
success.append(vdisk.guid)
except Exception:
ScheduledTaskController._logger.exception('Error taking snapshot for vDisk {0}'.format(vdisk.guid))
fail.append(vdisk.guid)
ScheduledTaskController._logger.info('[SSA] Snapshot has been taken for {0} vDisks, {1} failed.'.format(len(success), len(fail)))
示例14: get_vdisks
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def get_vdisks():
"""
Retrieve all Virtual Disks
:return: Virtual Disk data-object list
"""
return VDiskList.get_vdisks()
示例15: dtl_checkup
# 需要导入模块: from ovs.dal.lists.vdisklist import VDiskList [as 别名]
# 或者: from ovs.dal.lists.vdisklist.VDiskList import get_vdisks [as 别名]
def dtl_checkup(vpool_guid=None, vdisk_guid=None, storagerouters_to_exclude=None):
"""
Check DTL for all volumes
:param vpool_guid: vPool to check the DTL configuration of all its disks
:type vpool_guid: String
:param vdisk_guid: Virtual Disk to check its DTL configuration
:type vdisk_guid: String
:param storagerouters_to_exclude: Storage Routers to exclude from possible targets
:type storagerouters_to_exclude: List
:return: None
"""
if vpool_guid is not None and vdisk_guid is not None:
raise ValueError('vpool and vdisk are mutually exclusive')
if storagerouters_to_exclude is None:
storagerouters_to_exclude = []
from ovs.lib.vpool import VPoolController
logger.info('DTL checkup started')
required_params = {'dtl_mode': (str, StorageDriverClient.VPOOL_DTL_MODE_MAP.keys()),
'dtl_enabled': (bool, None)}
vdisk = VDisk(vdisk_guid) if vdisk_guid else None
vpool = VPool(vpool_guid) if vpool_guid else None
errors_found = False
root_client_map = {}
vpool_dtl_config_cache = {}
vdisks = VDiskList.get_vdisks() if vdisk is None and vpool is None else vpool.vdisks if vpool is not None else [vdisk]
for vdisk in vdisks:
logger.info(' Verifying vDisk {0} with guid {1}'.format(vdisk.name, vdisk.guid))
vdisk.invalidate_dynamics(['storagedriver_client', 'storagerouter_guid'])
if vdisk.storagedriver_client is None:
continue
vpool = vdisk.vpool
if vpool.guid not in vpool_dtl_config_cache:
vpool_config = VPoolController.get_configuration(vpool.guid) # Config on vPool is permanent for DTL settings
vpool_dtl_config_cache[vpool.guid] = vpool_config
Toolbox.verify_required_params(required_params, vpool_config)
volume_id = str(vdisk.volume_id)
vpool_config = vpool_dtl_config_cache[vpool.guid]
dtl_vpool_enabled = vpool_config['dtl_enabled']
try:
current_dtl_config = vdisk.storagedriver_client.get_dtl_config(volume_id)
current_dtl_config_mode = vdisk.storagedriver_client.get_dtl_config_mode(volume_id)
except RuntimeError as rte:
# Can occur when a volume has not been stolen yet from a dead node
logger.error('Retrieving DTL configuration from storage driver failed with error: {0}'.format(rte))
errors_found = True
continue
if dtl_vpool_enabled is False and (current_dtl_config is None or current_dtl_config.host == 'null'):
logger.info(' DTL is globally disabled for vPool {0} with guid {1}'.format(vpool.name, vpool.guid))
vdisk.storagedriver_client.set_manual_dtl_config(volume_id, None)
continue
elif current_dtl_config_mode == DTLConfigMode.MANUAL and (current_dtl_config is None or current_dtl_config.host == 'null'):
logger.info(' DTL is disabled for virtual disk {0} with guid {1}'.format(vdisk.name, vdisk.guid))
continue
storage_router = StorageRouter(vdisk.storagerouter_guid)
available_storagerouters = []
# 1. Check available storage routers in the backup failure domain
if storage_router.secondary_failure_domain is not None:
for storagerouter in storage_router.secondary_failure_domain.primary_storagerouters:
if vpool.guid not in storagerouter.vpools_guids:
continue
if storagerouter not in root_client_map:
try:
root_client = SSHClient(storagerouter, username='root')
except UnableToConnectException:
logger.warning(' Storage Router with IP {0} of vDisk {1} is not reachable'.format(storagerouter.ip, vdisk.name))
continue
root_client_map[storagerouter] = root_client
else:
root_client = root_client_map[storagerouter]
if ServiceManager.get_service_status('dtl_{0}'.format(vpool.name), client=root_client) is True:
available_storagerouters.append(storagerouter)
# 2. Check available storage routers in the same failure domain as current storage router
if len(available_storagerouters) == 0:
for storagerouter in storage_router.primary_failure_domain.primary_storagerouters:
if vpool.guid not in storagerouter.vpools_guids or storagerouter == storage_router:
continue
if storagerouter not in root_client_map:
try:
root_client = SSHClient(storagerouter, username='root')
except UnableToConnectException:
logger.warning(' Storage Router with IP {0} of vDisk {1} is not reachable'.format(storagerouter.ip, vdisk.name))
continue
root_client_map[storagerouter] = root_client
else:
root_client = root_client_map[storagerouter]
if ServiceManager.get_service_status('dtl_{0}'.format(vpool.name), client=root_client) is True:
available_storagerouters.append(storagerouter)
# Remove storage routers to exclude
for sr_guid in storagerouters_to_exclude:
sr_to_exclude = StorageRouter(sr_guid)
#.........这里部分代码省略.........