Best Python code snippet using lisa_python
platform_.py
Source:platform_.py
...1962 # wait able for released resource.1963 (1964 available_capabilities,1965 awaitable_capabilities,1966 ) = self._parse_cap_availabilities(candidate_caps)1967 # sort vm sizes to match1968 available_capabilities = self.get_sorted_vm_sizes(1969 available_capabilities, log1970 )1971 # match vm sizes by capability or use the predefined vm sizes.1972 candidate_cap = self._get_matched_capability(req, available_capabilities)1973 if candidate_cap:1974 caps[req_index] = candidate_cap1975 else:1976 # the error will be overwritten, if there is vm sizes without1977 # quota.1978 error = f"no available vm size found on '{location}'."1979 if not candidate_cap:1980 # check if there is awaitable VMs1981 candidate_cap = self._get_matched_capability(1982 req, awaitable_capabilities1983 )1984 if candidate_cap:1985 # True means awaitable.1986 caps[req_index] = True1987 error = f"no quota found on '{location}'"1988 return caps, error1989 def _get_allowed_capabilities(1990 self, req: schema.NodeSpace, location: str, log: Logger1991 ) -> Tuple[List[AzureCapability], str]:1992 node_runbook = req.get_extended_runbook(AzureNodeSchema, AZURE)1993 error: str = ""1994 if node_runbook.vm_size:1995 # find the vm_size1996 allowed_vm_sizes = self._get_normalized_vm_sizes(1997 name=node_runbook.vm_size, location=location, log=log1998 )1999 # Some preview vm size may not be queried from the list.2000 # Force to add.2001 if not allowed_vm_sizes:2002 log.debug(2003 f"no vm size matched '{node_runbook.vm_size}' on location "2004 f"'{location}', using the raw string as vm size name."2005 )2006 allowed_vm_sizes = [node_runbook.vm_size]2007 else:2008 location_info = self.get_location_info(location, log)2009 allowed_vm_sizes = [key for key, _ in location_info.capabilities.items()]2010 # build the capability of vm sizes. The information is useful to2011 # check quota.2012 allowed_capabilities = self._get_capabilities(2013 vm_sizes=allowed_vm_sizes,2014 location=location,2015 use_max_capability=node_runbook.maximize_capability,2016 log=log,2017 )2018 if not allowed_capabilities:2019 error = f"no vm size found in '{location}' for {allowed_vm_sizes}."2020 return allowed_capabilities, error2021 def _parse_cap_availabilities(2022 self, capabilities: List[AzureCapability]2023 ) -> Tuple[List[AzureCapability], List[AzureCapability]]:2024 available_capabilities: List[AzureCapability] = []2025 awaitable_capabilities: List[AzureCapability] = []2026 if not capabilities:2027 return ([], [])2028 # skip because it needs call azure API.2029 if is_unittest():2030 return (capabilities, [])2031 # assume all vm sizes are in the same location.2032 location = capabilities[0].location2033 quotas = self._get_quotas(location=location)2034 for capability in capabilities:2035 quota = quotas.get(capability.vm_size, None)...
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!!