How to use delete_virtual_disk method in lisa

Best Python code snippet using lisa_python

delete_disk_from_vm.py

Source:delete_disk_from_vm.py Github

copy

Full Screen

...25 'English': 'Hard disk ',26 'Chinese': u'硬盘 '27 }28 return language_prefix_label_mapper.get(language)29def delete_virtual_disk(si, vm_obj, disk_number, language):30 """ Deletes virtual Disk based on disk number31 :param si: Service Instance32 :param vm_obj: Virtual Machine Object33 :param disk_number: Hard Disk Unit Number34 :param language: Vcenter API language35 :return: True if success36 """37 hdd_prefix_label = get_hdd_prefix_label(language)38 if not hdd_prefix_label:39 raise RuntimeError('Hdd prefix label could not be found')40 hdd_label = hdd_prefix_label + str(disk_number)41 virtual_hdd_device = None42 for dev in vm_obj.config.hardware.device:43 if isinstance(dev, vim.vm.device.VirtualDisk) \44 and dev.deviceInfo.label == hdd_label:45 virtual_hdd_device = dev46 if not virtual_hdd_device:47 raise RuntimeError('Virtual {} could not '48 'be found.'.format(virtual_hdd_device))49 virtual_hdd_spec = vim.vm.device.VirtualDeviceSpec()50 virtual_hdd_spec.operation = \51 vim.vm.device.VirtualDeviceSpec.Operation.remove52 virtual_hdd_spec.device = virtual_hdd_device53 spec = vim.vm.ConfigSpec()54 spec.deviceChange = [virtual_hdd_spec]55 task = vm_obj.ReconfigVM_Task(spec=spec)56 tasks.wait_for_tasks(si, [task])57 return True58def get_args():59 parser = cli.build_arg_parser()60 parser.add_argument('-n', '--vmname', required=True,61 help="Name of the VirtualMachine you want to change.")62 parser.add_argument('-m', '--unitnumber', required=True,63 help='HDD number to delete.', type=int)64 parser.add_argument('-y', '--yes',65 help='Confirm disk deletion.', action='store_true')66 parser.add_argument('-l', '--language', default='English',67 help='Language your vcenter used.')68 my_args = parser.parse_args()69 return cli.prompt_for_password(my_args)70def get_obj(content, vim_type, name):71 obj = None72 container = content.viewManager.CreateContainerView(73 content.rootFolder, vim_type, True)74 for c in container.view:75 if c.name == name:76 obj = c77 break78 return obj79def main():80 args = get_args()81 # connect to vc82 si = SmartConnect(83 host=args.host,84 user=args.user,85 pwd=args.password,86 port=args.port)87 # disconnect vc88 atexit.register(Disconnect, si)89 content = si.RetrieveContent()90 print('Searching for VM {}'.format(args.vmname))91 vm_obj = get_obj(content, [vim.VirtualMachine], args.vmname)92 if vm_obj:93 if not args.yes:94 cli.prompt_y_n_question("Are you sure you want "95 "to delete HDD "96 "{}?".format(args.unitnumber),97 default='no')98 delete_virtual_disk(si, vm_obj, args.unitnumber, args.language)99 print('VM HDD "{}" successfully deleted.'.format(args.unitnumber))100 else:101 print('VM not found')102# start103if __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