Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemorency committed Nov 19, 2024
1 parent 42d6e02 commit 378c167
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions plugins/plugin_utils/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,30 @@ async def add_intermediate_path_part_to_filter_spec(self, intermediate_object_na

# Resource pools can only be in the vm filter spec
if self.object_type == "vm":
if self.__add_object_to_filter_spec_if_exists(intermediate_object_name, "resource_pool", "resource_pools"):
if self.__add_object_to_filter_spec_if_exists(
intermediate_object_name, "resource_pool", "resource_pools"
):
return

Check warning on line 193 in plugins/plugin_utils/lookup.py

View check run for this annotation

Codecov / codecov/patch

plugins/plugin_utils/lookup.py#L193

Added line #L193 was not covered by tests

# Clusters can be used in the vm, host, or resource pool filter specs
if self.object_type in ("vm", "host", "resource_pool"):
if self.__add_object_to_filter_spec_if_exists(intermediate_object_name, "cluster", "clusters"):
if self.__add_object_to_filter_spec_if_exists(
intermediate_object_name, "cluster", "clusters"
):
return

Check warning on line 200 in plugins/plugin_utils/lookup.py

View check run for this annotation

Codecov / codecov/patch

plugins/plugin_utils/lookup.py#L200

Added line #L200 was not covered by tests

# Hosts can be in the filter spec for vms, networks, datastores, or resource pools
if self.object_type in ("vm", "network", "datastore", "resource_pool"):
if self.__add_object_to_filter_spec_if_exists(intermediate_object_name, "host", "hosts"):
if self.__add_object_to_filter_spec_if_exists(
intermediate_object_name, "host", "hosts"
):
return

Check warning on line 207 in plugins/plugin_utils/lookup.py

View check run for this annotation

Codecov / codecov/patch

plugins/plugin_utils/lookup.py#L207

Added line #L207 was not covered by tests

# Folders can be used in the filter spec for everything except resource pools
if self.object_type != "resource_pool":
if self.__add_object_to_filter_spec_if_exists(intermediate_object_name, "folder", "parent_folders"):
if self.__add_object_to_filter_spec_if_exists(
intermediate_object_name, "folder", "parent_folders"
):
return

Check warning on line 214 in plugins/plugin_utils/lookup.py

View check run for this annotation

Codecov / codecov/patch

plugins/plugin_utils/lookup.py#L214

Added line #L214 was not covered by tests

raise InvalidVspherePathError(

Check warning on line 216 in plugins/plugin_utils/lookup.py

View check run for this annotation

Codecov / codecov/patch

plugins/plugin_utils/lookup.py#L216

Added line #L216 was not covered by tests
Expand All @@ -219,14 +227,14 @@ async def __add_datacenter_to_filter_spec_if_exists(self, object_name):
Datacenter MOID or None
"""
self._searched_for_datacenter = True
result = await self.get_object_moid_by_name_and_type(
object_name, "datacenter"
)
result = await self.get_object_moid_by_name_and_type(object_name, "datacenter")

Check warning on line 230 in plugins/plugin_utils/lookup.py

View check run for this annotation

Codecov / codecov/patch

plugins/plugin_utils/lookup.py#L229-L230

Added lines #L229 - L230 were not covered by tests
if result:
self.active_filters["datacenters"] = result
return result

Check warning on line 233 in plugins/plugin_utils/lookup.py

View check run for this annotation

Codecov / codecov/patch

plugins/plugin_utils/lookup.py#L232-L233

Added lines #L232 - L233 were not covered by tests

async def __add_object_to_filter_spec_if_exists(self, object_name, object_type, filter_key):
async def __add_object_to_filter_spec_if_exists(
self, object_name, object_type, filter_key
):
"""
Search for an object name as a specific object type. If found, add the object ID to the
active filter spec.
Expand All @@ -237,9 +245,7 @@ async def __add_object_to_filter_spec_if_exists(self, object_name, object_type,
Returns:
Object MOID or None
"""
result = await self.get_object_moid_by_name_and_type(
object_name, object_type
)
result = await self.get_object_moid_by_name_and_type(object_name, object_type)

Check warning on line 248 in plugins/plugin_utils/lookup.py

View check run for this annotation

Codecov / codecov/patch

plugins/plugin_utils/lookup.py#L248

Added line #L248 was not covered by tests
if result:
self.set_new_filters_with_datacenter({filter_key: result})
return result

Check warning on line 251 in plugins/plugin_utils/lookup.py

View check run for this annotation

Codecov / codecov/patch

plugins/plugin_utils/lookup.py#L250-L251

Added lines #L250 - L251 were not covered by tests
Expand Down

0 comments on commit 378c167

Please sign in to comment.