本文整理汇总了Python中ovs.lib.vdisk.VDiskController.set_as_template方法的典型用法代码示例。如果您正苦于以下问题:Python VDiskController.set_as_template方法的具体用法?Python VDiskController.set_as_template怎么用?Python VDiskController.set_as_template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ovs.lib.vdisk.VDiskController
的用法示例。
在下文中一共展示了VDiskController.set_as_template方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_as_template
# 需要导入模块: from ovs.lib.vdisk import VDiskController [as 别名]
# 或者: from ovs.lib.vdisk.VDiskController import set_as_template [as 别名]
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')
示例2: set_as_template
# 需要导入模块: from ovs.lib.vdisk import VDiskController [as 别名]
# 或者: from ovs.lib.vdisk.VDiskController import set_as_template [as 别名]
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()
示例3: test_create_from_template
# 需要导入模块: from ovs.lib.vdisk import VDiskController [as 别名]
# 或者: from ovs.lib.vdisk.VDiskController import set_as_template [as 别名]
def test_create_from_template(self):
"""
Test the create from template functionality
- Create a vDisk and convert to vTemplate
- Attempt to create from template from a vDisk which is not a vTemplate
- Create from template basic scenario
- Attempt to create from template using same name
- Attempt to create from template using same devicename
- Attempt to create from template using Storage Router on which vPool is not extended
- Attempt to create from template using non-existing Storage Driver
- Attempt to create from template using Storage Driver which does not have an MDS service
- Create from template on another Storage Router
- Create from template without specifying a Storage Router
"""
structure = Helper.build_service_structure(
{'vpools': [1],
'storagerouters': [1, 2, 3],
'storagedrivers': [(1, 1, 1), (2, 1, 2)], # (<id>, <vpool_id>, <storagerouter_id>)
'mds_services': [(1, 1), (2, 2)]} # (<id>, <storagedriver_id>)
)
vpool = structure['vpools'][1]
mds_services = structure['mds_services']
storagedrivers = structure['storagedrivers']
storagerouters = structure['storagerouters']
self._roll_out_dtl_services(vpool=vpool, storagerouters=storagerouters)
template = VDisk(VDiskController.create_new(volume_name='vdisk_1', volume_size=1024 ** 3, storagedriver_guid=storagedrivers[1].guid))
vdisk_name = 'from_template_1'
VDiskController.set_as_template(vdisk_guid=template.guid)
self.assertTrue(expr=template.is_vtemplate, msg='Dynamic property "is_vtemplate" should be True')
# Create from vDisk which is not a vTemplate
template.storagedriver_client._set_object_type(template.volume_id, 'BASE')
template.invalidate_dynamics(['info', 'is_vtemplate'])
with self.assertRaises(RuntimeError):
VDiskController.create_from_template(vdisk_guid=template.guid, name=vdisk_name, storagerouter_guid=storagerouters[1].guid)
# Create from template
template.storagedriver_client._set_object_type(template.volume_id, 'TEMPLATE')
template.invalidate_dynamics(['info', 'is_vtemplate'])
info = VDiskController.create_from_template(vdisk_guid=template.guid, name=vdisk_name, storagerouter_guid=storagerouters[1].guid)
expected_keys = ['vdisk_guid', 'name', 'backingdevice']
self.assertEqual(first=set(info.keys()),
second=set(expected_keys),
msg='Create from template returned not the expected keys')
vdisks = VDiskList.get_vdisks()
self.assertTrue(expr=len(vdisks) == 2, msg='Expected 2 vDisks')
vdisk = [vdisk for vdisk in vdisks if vdisk.is_vtemplate is False][0]
self.assertTrue(expr=vdisk.name == vdisk_name, msg='vDisk name is incorrect. Expected: {0} - Actual: {1}'.format(vdisk_name, vdisk.name))
self.assertTrue(expr=vdisk.parent_vdisk == template, msg='The parent of the vDisk is incorrect')
# Attempt to create from template using same name
with self.assertRaises(RuntimeError):
VDiskController.create_from_template(vdisk_guid=template.guid, name=vdisk_name, storagerouter_guid=storagerouters[1].guid)
vdisks = VDiskList.get_vdisks()
self.assertTrue(expr=len(vdisks) == 2, msg='Expected 2 vDisks after failed attempt 1')
# Attempt to create from template using same devicename
with self.assertRaises(RuntimeError):
VDiskController.create_from_template(vdisk_guid=template.guid, name='^{0}$*'.format(vdisk_name), storagerouter_guid=storagerouters[1].guid)
vdisks = VDiskList.get_vdisks()
self.assertTrue(expr=len(vdisks) == 2, msg='Expected 2 vDisks after failed attempt 2')
# Attempt to create from template on Storage Router on which vPool is not extended
with self.assertRaises(RuntimeError):
VDiskController.create_from_template(vdisk_guid=template.guid, name='from_template_2', storagerouter_guid=storagerouters[3].guid)
vdisks = VDiskList.get_vdisks()
self.assertTrue(expr=len(vdisks) == 2, msg='Expected 2 vDisks after failed attempt 3')
# Attempt to create on non-existing Storage Driver
storagedrivers[1].storagedriver_id = 'non-existing'
storagedrivers[1].save()
with self.assertRaises(RuntimeError):
VDiskController.create_from_template(vdisk_guid=template.guid, name='from_template_2')
vdisks = VDiskList.get_vdisks()
self.assertTrue(expr=len(vdisks) == 2, msg='Expected 2 vDisks after failed attempt 4')
storagedrivers[1].storagedriver_id = '1'
storagedrivers[1].save()
# Attempt to create on Storage Driver without MDS service
mds_services[1].service.storagerouter = storagerouters[3]
mds_services[1].service.save()
with self.assertRaises(RuntimeError):
VDiskController.create_from_template(vdisk_guid=template.guid, name='from_template_2', storagerouter_guid=storagerouters[1].guid)
vdisks = VDiskList.get_vdisks()
self.assertTrue(expr=len(vdisks) == 2, msg='Expected 2 vDisks after failed attempt 5')
mds_services[1].service.storagerouter = storagerouters[1]
mds_services[1].service.save()
# Create from template on another Storage Router
vdisk2 = VDisk(VDiskController.create_from_template(vdisk_guid=template.guid, name='from_template_2', storagerouter_guid=storagerouters[2].guid)['vdisk_guid'])
self.assertTrue(expr=vdisk2.storagerouter_guid == storagerouters[2].guid, msg='Expected vdisk2 to be hosted by Storage Router 2')
# Create from template without specifying Storage Router
vdisk3 = VDisk(VDiskController.create_from_template(vdisk_guid=template.guid, name='from_template_3')['vdisk_guid'])
self.assertTrue(expr=vdisk3.storagerouter_guid == template.storagerouter_guid, msg='Expected vdisk3 to be hosted by Storage Router 1')