How to use create_virtual_disk method in lisa

Best Python code snippet using lisa_python

test_raid.py

Source:test_raid.py Github

copy

Full Screen

...239 'Disk1:Enclosure-1:RAID-1'],240 raid_enable=True)241 @mock.patch.object(dracclient.client.WSManClient, 'invoke',242 spec_set=True, autospec=True)243 def test_create_virtual_disk(self, mock_requests, mock_invoke):244 expected_selectors = {'SystemCreationClassName': 'DCIM_ComputerSystem',245 'CreationClassName': 'DCIM_RAIDService',246 'SystemName': 'DCIM:ComputerSystem',247 'Name': 'DCIM:RAIDService'}248 expected_properties = {'Target': 'controller',249 'PDArray': ['disk1', 'disk2'],250 'VDPropNameArray': ['Size', 'RAIDLevel'],251 'VDPropValueArray': ['42', '4']}252 mock_invoke.return_value = lxml.etree.fromstring(253 test_utils.RAIDInvocations[uris.DCIM_RAIDService][254 'CreateVirtualDisk']['ok'])255 result = self.drac_client.create_virtual_disk(256 raid_controller='controller', physical_disks=['disk1', 'disk2'],257 raid_level='1', size_mb=42)258 self.assertEqual({'commit_required': True}, result)259 mock_invoke.assert_called_once_with(260 mock.ANY, uris.DCIM_RAIDService, 'CreateVirtualDisk',261 expected_selectors, expected_properties,262 expected_return_value=utils.RET_SUCCESS)263 @mock.patch.object(dracclient.client.WSManClient, 'invoke',264 spec_set=True, autospec=True)265 def test_create_virtual_disk_with_extra_params(self, mock_requests,266 mock_invoke):267 expected_selectors = {'SystemCreationClassName': 'DCIM_ComputerSystem',268 'CreationClassName': 'DCIM_RAIDService',269 'SystemName': 'DCIM:ComputerSystem',270 'Name': 'DCIM:RAIDService'}271 expected_properties = {'Target': 'controller',272 'PDArray': ['disk1', 'disk2'],273 'VDPropNameArray': ['Size', 'RAIDLevel',274 'VirtualDiskName',275 'SpanDepth', 'SpanLength'],276 'VDPropValueArray': ['42', '4', 'name', '3',277 '2']}278 mock_invoke.return_value = lxml.etree.fromstring(279 test_utils.RAIDInvocations[uris.DCIM_RAIDService][280 'CreateVirtualDisk']['ok'])281 result = self.drac_client.create_virtual_disk(282 raid_controller='controller', physical_disks=['disk1', 'disk2'],283 raid_level='1', size_mb=42, disk_name='name', span_length=2,284 span_depth=3)285 self.assertEqual({'commit_required': True}, result)286 mock_invoke.assert_called_once_with(287 mock.ANY, uris.DCIM_RAIDService, 'CreateVirtualDisk',288 expected_selectors, expected_properties,289 expected_return_value=utils.RET_SUCCESS)290 def test_create_virtual_disk_fail(self, mock_requests):291 mock_requests.post(292 'https://1.2.3.4:443/wsman',293 text=test_utils.RAIDInvocations[294 uris.DCIM_RAIDService]['CreateVirtualDisk']['error'])295 self.assertRaises(...

Full Screen

Full Screen

nestedESXi.py

Source:nestedESXi.py Github

copy

Full Screen

...52 virtual_scsi_spec = vim.vm.device.VirtualDeviceSpec()53 virtual_scsi_spec.device = device54 virtual_scsi_spec.operation = "add"55 return virtual_scsi_spec56def create_virtual_disk(capacity, controller_key, unit_number, in_bytes=False):57 virtual_disk = vim.vm.device.VirtualDisk()58 if in_bytes:59 virtual_disk.capacityInBytes = capacity60 else:61 virtual_disk.capacityInKB = capacity62 virtual_disk.unitNumber = unit_number63 virtual_disk.controllerKey = controller_key64 virtual_disk_backing_info = vim.vm.device.VirtualDisk.FlatVer2BackingInfo()65 virtual_disk_backing_info.diskMode = "persistent"66 virtual_disk_backing_info.thinProvisioned = True67 virtual_disk.backing = virtual_disk_backing_info68 virtual_disk_spec = vim.vm.device.VirtualDeviceSpec()69 virtual_disk_spec.device = virtual_disk70 virtual_disk_spec.fileOperation = "create"71 virtual_disk_spec.operation = "add"72 return virtual_disk_spec73def createNIC(content, portGroup, isVDS):74 nic_spec = vim.vm.device.VirtualDeviceSpec()75 nic_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add76 nic_spec.device = vim.vm.device.VirtualE1000e()77 nic_spec.device.wakeOnLanEnabled = True78 nic_spec.device.deviceInfo = vim.Description()79 if not isVDS:80 nic_spec.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()81 nic_spec.device.backing.network = get_obj(content, [vim.Network], portGroup)82 nic_spec.device.backing.deviceName = portGroup83 else:84 network = get_obj(content, [vim.dvs.DistributedVirtualPortgroup], portGroup)85 dvs_port_connection = vim.dvs.PortConnection()86 dvs_port_connection.portgroupKey = network.key87 dvs_port_connection.switchUuid = network.config.distributedVirtualSwitch.uuid88 nic_spec.device.backing = vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo()89 nic_spec.device.backing.port = dvs_port_connection90 nic_spec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()91 nic_spec.device.connectable.startConnected = True92 nic_spec.device.connectable.allowGuestControl = True93 nic_spec.device.connectable.connected = True94 return nic_spec95def invoke_and_track(func, *args, **kw):96 try :97 task = func(*args, **kw)98 except:99 raise100def get_obj(content, vimtype, name):101 obj = None102 container = content.viewManager.CreateContainerView( content.rootFolder, vimtype, True)103 for c in container.view:104 if name:105 if c.name == name:106 obj = c107 break108 else:109 obj = c110 break111 return obj112def createCdrom(content, datastore, dataStorePath):113 cdspec = vim.vm.device.VirtualDeviceSpec()114 cdspec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add115 cdspec.device = vim.vm.device.VirtualCdrom()116 cdspec.device.key = 3000117 cdspec.device.controllerKey = 200118 cdspec.device.unitNumber = 0119 cdspec.device.deviceInfo = vim.Description()120 cdspec.device.deviceInfo.label = 'CD/DVD drive 1'121 cdspec.device.deviceInfo.summary = 'ISO'122 cdspec.device.backing = vim.vm.device.VirtualCdrom.IsoBackingInfo()123 cdspec.device.backing.fileName = "[" + datastore + "] "+ dataStorePath124 datastore = get_obj(content=content, vimtype=[vim.Datastore], name=datastore)125 cdspec.device.backing.datastore = datastore126 cdspec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()127 cdspec.device.connectable.startConnected = True128 cdspec.device.connectable.allowGuestControl = True129 cdspec.device.connectable.connected = False130 return cdspec131def wait_for_tasks(tasks):132 property_collector = service_instance.content.propertyCollector133 task_list = [str(task) for task in tasks]134 obj_specs = [vmodl.query.PropertyCollector.ObjectSpec(obj=task)135 for task in tasks]136 property_spec = vmodl.query.PropertyCollector.PropertySpec(type=vim.Task,137 pathSet=[],138 all=True)139 filter_spec = vmodl.query.PropertyCollector.FilterSpec()140 filter_spec.objectSet = obj_specs141 filter_spec.propSet = [property_spec]142 pcfilter = property_collector.CreateFilter(filter_spec, True)143 try:144 version, state = None, None145 while len(task_list):146 update = property_collector.WaitForUpdates(version)147 for filter_set in update.filterSet:148 for obj_set in filter_set.objectSet:149 task = obj_set.obj150 for change in obj_set.changeSet:151 if change.name == 'info':152 state = change.val.state153 elif change.name == 'info.state':154 state = change.val155 else:156 continue157 if not str(task) in task_list:158 continue159 if state == vim.TaskInfo.State.success:160 task_list.remove(str(task))161 elif state == vim.TaskInfo.State.error:162 raise task.info.error163 version = update.version164 finally:165 if pcfilter:166 pcfilter.Destroy()167def create_vm(vmName, content, clusterName, datastore, portGroup, CPUs, memory, dataStorePath, hdd_size):168 datacenter = content.rootFolder.childEntity[0]169 vmfolder = datacenter.vmFolder170 hosts = datacenter.hostFolder.childEntity171 cluster = get_obj(content, [vim.ClusterComputeResource], clusterName)172 resource_pool = cluster.resourcePool173 datastore_path = "[" + datastore + "]" + vmName174 vmx_file = vim.vm.FileInfo(logDirectory=None, snapshotDirectory=None, suspendDirectory=None, vmPathName=datastore_path)175 dev_changes = []176 disk_size = 1177 new_disk_kb = int(disk_size) * 1024 * 1024 * hdd_size178 disk_spec = create_virtual_disk(16777216, 0, 0, False)179 disk_spec2 = create_virtual_disk(new_disk_kb/2, 0, 1, False)180 disk_spec3 = create_virtual_disk(new_disk_kb, 0, 2, False)181 scsi_spec = add_scsi_controller()182 nic0_spec = createNIC(content, portGroup, False)183 nic1_spec = createNIC(content, portGroup, False)184 nic2_spec = createNIC(content, portGroup, False)185 nic3_spec = createNIC(content, portGroup, False)186 nic4_spec = createNIC(content, portGroup, False)187 cdrom = createCdrom(content, datastore, dataStorePath)188 dev_changes.append(cdrom)189 dev_changes.append(scsi_spec)190 dev_changes.append(disk_spec)191 dev_changes.append(disk_spec2)192 dev_changes.append(disk_spec3)193 dev_changes.append(nic0_spec)194 dev_changes.append(nic1_spec)...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1from fs import create_virtual_disk, read_virtual_disk2def main():3 # create_virtual_disk()4 superblock, inodes, blocks = read_virtual_disk()5 print(superblock)6 print(inodes)7 print(blocks)8 print(1)9if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful