Same as search, but will throw an error if there are multiple or no results. If there are multiple results and only one is an exact match on api_version, that resource will be returned.
(self, **kwargs)
| 195 | return resources |
| 196 | |
| 197 | def get(self, **kwargs): |
| 198 | """ Same as search, but will throw an error if there are multiple or no |
| 199 | results. If there are multiple results and only one is an exact match |
| 200 | on api_version, that resource will be returned. |
| 201 | """ |
| 202 | results = self.search(**kwargs) |
| 203 | # If there are multiple matches, prefer exact matches on api_version |
| 204 | if len(results) > 1 and kwargs.get('api_version'): |
| 205 | results = [ |
| 206 | result for result in results if result.group_version == kwargs['api_version'] |
| 207 | ] |
| 208 | # If there are multiple matches, prefer non-List kinds |
| 209 | if len(results) > 1 and not all([isinstance(x, ResourceList) for x in results]): |
| 210 | results = [result for result in results if not isinstance(result, ResourceList)] |
| 211 | if len(results) == 1: |
| 212 | return results[0] |
| 213 | elif not results: |
| 214 | raise ResourceNotFoundError('No matches found for {}'.format(kwargs)) |
| 215 | else: |
| 216 | raise ResourceNotUniqueError('Multiple matches found for {}: {}'.format(kwargs, results)) |
| 217 | |
| 218 | |
| 219 | class LazyDiscoverer(Discoverer): |
no test coverage detected