本文整理汇总了Python中ovs.lib.vdisk.VDiskController类的典型用法代码示例。如果您正苦于以下问题:Python VDiskController类的具体用法?Python VDiskController怎么用?Python VDiskController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VDiskController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run_and_validate_dtl_checkup
def _run_and_validate_dtl_checkup(self, vdisk, validations):
"""
Execute the DTL checkup for a vDisk and validate the settings afterwards
"""
single_node = len(StorageRouterList.get_storagerouters()) == 1
VDiskController.dtl_checkup(vdisk_guid=vdisk.guid)
config = vdisk.storagedriver_client.get_dtl_config(vdisk.volume_id)
config_mode = vdisk.storagedriver_client.get_dtl_config_mode(vdisk.volume_id)
msg = '{0} node - {{0}} - Actual: {{1}} - Expected: {{2}}'.format('Single' if single_node is True else 'Multi')
validations.append({'key': 'config_mode', 'value': DTLConfigMode.MANUAL})
for validation in validations:
key = validation['key']
value = validation['value']
if key == 'config':
actual_value = config
elif key == 'host':
actual_value = config.host
elif key == 'port':
actual_value = config.port
elif key == 'mode':
actual_value = config.mode
else:
actual_value = config_mode
if isinstance(value, list):
self.assertTrue(expr=actual_value in value,
msg=msg.format(key.capitalize(), actual_value, ', '.join(value)))
else:
self.assertEqual(first=actual_value,
second=value,
msg=msg.format(key.capitalize(), actual_value, value))
return config
示例2: devicename_exists
def devicename_exists(self, vpool, name=None, names=None):
"""
Checks whether a given name can be created on the vpool
:param vpool: vPool object
:type vpool: VPool
:param name: Candidate name
:type name: str
:param names: Candidate names
:type names: list
:return: Whether the devicename exists
:rtype: bool
"""
error_message = None
if not (name is None) ^ (names is None):
error_message = 'Either the name (string) or the names (list of strings) parameter must be passed'
if name is not None and not isinstance(name, basestring):
error_message = 'The name parameter must be a string'
if names is not None and not isinstance(names, list):
error_message = 'The names parameter must be a list of strings'
if error_message is not None:
raise HttpNotAcceptableException(error_description=error_message,
error='impossible_request')
if name is not None:
devicename = VDiskController.clean_devicename(name)
return VDiskList.get_by_devicename_and_vpool(devicename, vpool) is not None
for name in names:
devicename = VDiskController.clean_devicename(name)
if VDiskList.get_by_devicename_and_vpool(devicename, vpool) is not None:
return True
return False
示例3: snapshot_vdisk
def snapshot_vdisk(vdisk):
metadata = {'label': 'snap-' + vdisk.name,
'is_consistent': True,
'timestamp': time.time(),
'is_automatic': False,
'is_sticky': False}
VDiskController.create_snapshot(vdisk.guid, metadata)
示例4: set_as_template
def set_as_template(machineguid):
"""
Set a vmachine as template
@param machineguid: guid of the machine
@return: vmachine template conversion successful: True|False
"""
# Do some magic on the storage layer?
# This is most likely required as extra security measure
# Suppose the template is set back to a real machine
# it can be deleted within vmware which should be blocked.
# This might also require a storagerouter internal check
# to be implemented to discourage volumes from being deleted
# when clones were made from it.
vmachine = VMachine(machineguid)
if vmachine.hypervisor_status == 'RUNNING':
raise RuntimeError('vMachine {0} may not be running to set it as vTemplate'.format(vmachine.name))
for disk in vmachine.vdisks:
VDiskController.set_as_template(diskguid=disk.guid)
vmachine.is_vtemplate = True
vmachine.invalidate_dynamics(['snapshots'])
vmachine.save()
示例5: download_to_vpool
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()
示例6: copy_image_to_volume
def copy_image_to_volume(self, context, volume, image_service, image_id):
"""Copy image to volume
Called on "nova volume-create --image-id ..."
or "cinder create --image-id"
Downloads image from glance server into local .raw
:param volume: volume reference (sqlalchemy Model)
"""
_debug_vol_info("CP_IMG_TO_VOL", volume)
LOG.info("CP_IMG_TO_VOL %s %s" % (image_service, image_id))
name = volume.display_name
if not name:
name = volume.name
volume.display_name = volume.name
# downloading from an existing image
destination_path = volume.provider_location
if destination_path:
try:
LOG.info("CP_IMG_TO_VOL Deleting existing empty raw file %s " % destination_path)
VDiskController.delete_volume(location=destination_path)
LOG.info("CP_IMG_TO_VOL Downloading image to %s" % destination_path)
image_utils.fetch_to_raw(context, image_service, image_id, destination_path, "1M", size=volume["size"])
LOG.info("CP_IMG_TO_VOL Resizing volume to size %s" % volume["size"])
self.extend_volume(volume=volume, size_gb=volume["size"])
except Exception as ex:
LOG.error("CP_IMG_TO_VOL Internal error %s " % unicode(ex))
self.delete_volume(volume)
raise
ovs_disk = self._find_ovs_model_disk_by_location(volume.provider_location, str(volume.host))
ovs_disk.name = name
ovs_disk.save()
示例7: create_volume
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']}
示例8: extend_volume
def extend_volume(self, volume, size_gb):
"""Extend volume to new size size_gb
"""
_debug_vol_info("EXTEND_VOL", volume)
LOG.info("EXTEND_VOL Size %s" % size_gb)
location = volume.provider_location
if location is not None:
LOG.info("DO_EXTEND_VOLUME %s" % (location))
VDiskController.extend_volume(location=location, size=size_gb)
示例9: test_event_resize_from_volumedriver
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')
示例10: delete_volume
def delete_volume(self, volume):
"""Deletes a logical volume.
Called on "cinder delete ... "
:param volume: volume reference (sqlalchemy Model)
"""
_debug_vol_info("DELETE", volume)
location = volume.provider_location
if location is not None:
LOG.info('DO_DELETE_VOLUME %s' % (location))
VDiskController.delete_volume(location = location)
示例11: snapshot
def snapshot(machineguid, label=None, is_consistent=False, timestamp=None, is_automatic=False, is_sticky=False):
"""
Snapshot VMachine disks
:param machineguid: guid of the machine
:param label: label to give the snapshots
:param is_consistent: flag indicating the snapshot was consistent or not
:param timestamp: override timestamp, if required. Should be a unix timestamp
:param is_automatic: Flag to determine automated snapshots
:param is_sticky: Flag indicating the snapshot is not to be deleted automatically
"""
timestamp = timestamp if timestamp is not None else time.time()
timestamp = str(int(float(timestamp)))
if is_automatic is True and is_sticky is True:
raise ValueError('Snapshot {0} cannot be both automatic and sticky'.format(label))
metadata = {'label': label,
'is_consistent': is_consistent,
'timestamp': timestamp,
'machineguid': machineguid,
'is_automatic': is_automatic,
'is_sticky': is_sticky}
machine = VMachine(machineguid)
# @todo: we now skip creating a snapshot when a vmachine's disks
# is missing a mandatory property: volume_id
# sub-task will now raise an exception earlier in the workflow
for disk in machine.vdisks:
if not disk.volume_id:
message = 'Missing volume_id on disk {0} - unable to create snapshot for vm {1}'.format(
disk.guid, machine.guid
)
VMachineController._logger.info('Error: {0}'.format(message))
raise RuntimeError(message)
snapshots = {}
success = True
for disk in machine.vdisks:
try:
snapshots[disk.guid] = VDiskController.create_snapshot(diskguid=disk.guid,
metadata=metadata)
except Exception as ex:
VMachineController._logger.info('Error taking snapshot of disk {0}: {1}'.format(disk.name, str(ex)))
success = False
for diskguid, snapshotid in snapshots.iteritems():
VDiskController.delete_snapshot(diskguid=diskguid,
snapshotid=snapshotid)
VMachineController._logger.info('Create snapshot for vMachine {0}: {1}'.format(
machine.name, 'Success' if success else 'Failure'
))
machine.invalidate_dynamics(['snapshots'])
if not success:
raise RuntimeError('Failed to snapshot vMachine {0}'.format(machine.name))
示例12: test_clone_from_template_happypath
def test_clone_from_template_happypath(self):
"""
Test clone from template - happy path
"""
StorageDriverModule.use_good_client()
vdisk_1_1, pmachine = self._prepare()
VDiskController.create_from_template(vdisk_1_1.guid, 'vmachine_2', 'vdisk_1_1-clone', pmachine.guid)
vdisks = VDiskList.get_vdisk_by_name('vdisk_1_1')
self.assertEqual(len(vdisks), 1, 'Vdisk not modeled')
clones = VDiskList.get_vdisk_by_name('vdisk_1_1-clone')
self.assertEqual(len(clones), 1, 'Clone not modeled')
示例13: delete_snapshot
def delete_snapshot(self, snapshot):
"""Deletes a snapshot.
:param snapshot: snapshot reference (sqlalchemy Model)
"""
_debug_vol_info("DELETE_SNAP", snapshot)
volume = snapshot.volume
hostname = volume.host
location = volume.provider_location
ovs_disk = self._find_ovs_model_disk_by_location(location, hostname)
LOG.debug("DELETE_SNAP %s" % snapshot.id)
VDiskController.delete_snapshot(diskguid=ovs_disk.guid, snapshotid=str(snapshot.id))
LOG.debug("DELETE_SNAP OK")
示例14: delete_snapshot
def delete_snapshot(vmachineguid, timestamp):
"""
Remove a snapshot from the vmachine
@param vmachineguid: Guid of the virtual machine
@param timestamp: timestamp of the snapshot
"""
vmachine = VMachine(vmachineguid)
vmachine_snapshots = [snap for snap in vmachine.snapshots if snap['timestamp'] == str(timestamp)]
if len(vmachine_snapshots) != 1:
raise RuntimeError('Snapshot {0} does not belong to vmachine {1}'.format(timestamp, vmachine.name))
vmachine_snapshot = vmachine_snapshots[0]
VMachineController._logger.info('Deleting snapshot {0} from vmachine {1}'.format(timestamp, vmachine.name))
for diskguid, snapshotid in vmachine_snapshot['snapshots'].items():
VDiskController.delete_snapshot(diskguid, snapshotid)
VMachineController._logger.info('Deleted snapshot {0}'.format(timestamp))
vmachine.invalidate_dynamics(['snapshots'])
示例15: test_create_snapshot
def test_create_snapshot(self):
"""
Test the create snapshot functionality
- Create a vDisk
- Attempt to create a snapshot providing incorrect parameters
- Create a snapshot 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']
vdisk1 = VDisk(VDiskController.create_new(volume_name='vdisk_1', volume_size=1024 ** 3, storagedriver_guid=storagedrivers[1].guid))
with self.assertRaises(ValueError):
# noinspection PyTypeChecker
VDiskController.create_snapshot(vdisk_guid=vdisk1.guid,
metadata='')
now = int(time.time())
snapshot_id = VDiskController.create_snapshot(vdisk_guid=vdisk1.guid, metadata={'timestamp': now,
'label': 'label1',
'is_consistent': True,
'is_automatic': True,
'is_sticky': False})
self.assertTrue(expr=len(vdisk1.snapshots) == 1,
msg='Expected to find 1 snapshot')
snapshot = vdisk1.snapshots[0]
expected_keys = {'guid', 'timestamp', 'label', 'is_consistent', 'is_automatic', 'is_sticky', 'in_backend', 'stored'}
self.assertEqual(first=expected_keys,
second=set(snapshot.keys()),
msg='Set of expected keys differs from reality. Expected: {0} - Reality: {1}'.format(expected_keys, set(snapshot.keys())))
for key, value in {'guid': snapshot_id,
'label': 'label1',
'stored': 0,
'is_sticky': False,
'timestamp': now,
'in_backend': True,
'is_automatic': True,
'is_consistent': True}.iteritems():
self.assertEqual(first=value,
second=snapshot[key],
msg='Value for key "{0}" does not match reality. Expected: {1} - Reality: {2}'.format(key, value, snapshot[key]))