Best Python code snippet using lisa_python
delete_disk_from_vm.py
Source: delete_disk_from_vm.py
...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__":...
Check out the latest blogs from LambdaTest on this topic:
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.
It’s strange to hear someone declare, “This can’t be tested.” In reply, I contend that everything can be tested. However, one must be pleased with the outcome of testing, which might include failure, financial loss, or personal injury. Could anything be tested when a claim is made with this understanding?
When it comes to UI components, there are two versatile methods that we can use to build it for your website: either we can use prebuilt components from a well-known library or framework, or we can develop our UI components from scratch.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!