Best Python code snippet using lisa_python
features.py
Source:features.py  
...1117    ) -> schema.NodeSpace:1118        platform: AzurePlatform = self._platform  # type: ignore1119        compute_client = get_compute_client(platform)1120        node_context = get_node_context(self._node)1121        new_vm_size_info = self._select_vm_size(resize_action)1122        # Creating parameter for VM Operations API call1123        hardware_profile = HardwareProfile(vm_size=new_vm_size_info.vm_size)1124        vm_update = VirtualMachineUpdate(hardware_profile=hardware_profile)1125        # Resizing with new Vm Size1126        lro_poller = compute_client.virtual_machines.begin_update(1127            resource_group_name=node_context.resource_group_name,1128            vm_name=node_context.vm_name,1129            parameters=vm_update,1130        )1131        # Waiting for the Long Running Operation to finish1132        wait_operation(lro_poller, time_out=1200)1133        self._node.close()1134        new_capability = copy.deepcopy(new_vm_size_info.capability)1135        self._node.capability = cast(schema.Capability, new_capability)1136        return new_capability1137    def _select_vm_size(1138        self, resize_action: ResizeAction = ResizeAction.IncreaseCoreCount1139    ) -> "AzureCapability":1140        platform: AzurePlatform = self._platform  # type: ignore1141        compute_client = get_compute_client(platform)1142        node_context = get_node_context(self._node)1143        node_runbook = self._node.capability.get_extended_runbook(AzureNodeSchema)1144        # Get list of vm sizes that the current sku can resize to1145        available_sizes = compute_client.virtual_machines.list_available_sizes(1146            node_context.resource_group_name, node_context.vm_name1147        )1148        # Get list of vm sizes available in the current location1149        location_info = platform.get_location_info(node_runbook.location, self._log)1150        capabilities = [value for _, value in location_info.capabilities.items()]1151        sorted_sizes = platform.get_sorted_vm_sizes(capabilities, self._log)...setup_azure.py
Source:setup_azure.py  
...815        return self._run_az([816            'vm', 'list-sizes',817            '--location', self._selected_resource_group['location']818        ])819    def _select_vm_size(self) -> dict:820        """821        Selects the vm size.822        :return: the selected vm size823        """824        if self._az_compute_node:825            for vm_size in self._az_vm_sizes:826                if vm_size['name'] == \827                        self._az_compute_node['compute']['vmSize']:828                    print(self.format('Selected vm size: {}',829                                      vm_size['name']))830                    return vm_size831        return self._select_object('vm_size', 'name', create=False)832    def _select_image(self) -> dict:833        """834        Selects the image to use as the basis for compute nodes.835        :return: the image data836        """837        #838        # If not interactive, then use the same URN as the installer839        # node840        #841        if not self.interactive and self._az_compute_node:842            if self.same_image and \843                    self._az_compute_node['compute']['publisher'] and \844                    self._az_compute_node['compute']['offer'] and \845                    self._az_compute_node['compute']['sku'] and \846                    self._az_compute_node['compute']['version']:847                urn = '{}:{}:{}:{}'.format(848                    self._az_compute_node['compute']['publisher'],849                    self._az_compute_node['compute']['offer'],850                    self._az_compute_node['compute']['sku'],851                    self._az_compute_node['compute']['version']852                )853            else:854                urn = self.DEFAULT_URN855            image: dict = self._get_image(urn)856            if not image:857                print(858                    self.format_error('The default URN is not valid: {}', urn)859                )860                urn = ''861        else:862            print('----------')863            urn = ''864            image: dict = None865        while not urn:866            urn = input(self.format('Enter the VM image URN: ')).strip()867            #868            # Attempt to get the image869            #870            try:871                image = self._get_image(urn)872            except Exception:873                pass874            #875            # If there is no image, then the URN is invalid876            #877            if not image:878                print(self.format_error('The URN is not valid: {}', urn))879                urn = ''880        #881        # Store the URN on the image data for future reference882        #883        image['urn'] = urn884        return image885    def _get_image(self, urn) -> dict:886        print('Getting the image details for {}...'.format(urn))887        return self._run_az([888            'vm', 'image', 'show',889            '--urn', urn890        ])891    def _run(self):892        """893        Runs the wizard.894        """895        select_first = not self.interactive896        #897        # Get the account information898        #899        self._az_account: dict = self._get_account()900        #901        # Gets the current compute node902        #903        self._az_compute_node: dict = self._get_current_compute_node()904        #905        # Select the application906        #907        self._az_applications = self._get_applications()908        if self.interactive:909            self._selected_application = self._select_object(910                'application', 'displayName')911        else:912            self._selected_application = self._create_application()913            print(self.format('Selected application: {}',914                              self._selected_application['displayName']))915        password = self._selected_application.get('password', None)916        if not password:917            while not password:918                password = input(919                    self.format('Enter the application API password: ')920                )921            self._selected_application['password'] = password922        #923        # Select the resource group924        #925        self._az_resource_groups = self._get_resource_groups()926        if self.interactive:927            self._selected_resource_group = self._select_object(928                'resource group', 'name')929        else:930            self._selected_resource_group = self._select_resource_group()931        #932        # Check resource group permissions933        #934        self._az_custom_roles = self._get_custom_roles()935        self._check_custom_roles()936        self._az_sub_role_assignments = self._get_sub_role_assignments()937        self._check_sub_role_assignments()938        self._az_rg_role_assignments = self._get_rg_role_assignments()939        self._check_rg_role_assignments()940        #941        # Select the virtual network942        #943        self._az_virtual_networks = self._get_virtual_networks()944        self._selected_virtual_network = self._select_object(945            'virtual network', 'name', select_first=select_first)946        #947        # Select the network security group948        #949        self._az_network_security_groups = self._get_network_security_groups()950        self._selected_network_security_group = self._select_object(951            'network security group', 'name', select_first=select_first)952        #953        # Select the subnet954        #955        self._az_subnets = self._get_subnets()956        self._selected_subnet = self._select_object(957            'subnet', 'name', select_first=select_first)958        #959        # Select the storage account960        #961        self._az_storage_accounts = self._get_storage_accounts()962        self._selected_storage_account = self._select_object(963            'storage account', 'name', select_first=select_first)964        #965        # Select VM size966        #967        self._az_vm_sizes = self._get_vm_sizes()968        if not self.interactive:969            self._selected_vm_size = self._select_vm_size()970        else:971            self._selected_vm_size = self._select_object(972                'vm_size', 'name', create=False)973        #974        # Select image975        #976        self._selected_image = self._select_image()977        self._run_completed = True978        config: Dict[str, str] = self.get_config()979        self._write_config_to_file(config, DEFAULT_CONFIGURATION_PROFILE_NAME)980        self._write_config_to_db(config, DEFAULT_CONFIGURATION_PROFILE_NAME)981    def _select_object(self, name: str, name_attr: str,982                       create: bool = True,983                       select_first: bool = False) -> dict:...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!!
