Skip to content

Commit

Permalink
handle error if group has no peers
Browse files Browse the repository at this point in the history
  • Loading branch information
marcom4rtinez committed Jun 11, 2024
1 parent 050c278 commit 27c514b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions nornir_infrahub/plugins/inventory/infrahub.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any, Callable, Dict, List, Optional, Set, Type, Union

import ruamel.yaml
from infrahub_sdk import Config, InfrahubClientSync, InfrahubNodeSync, NodeSchema
from infrahub_sdk import Config, InfrahubClientSync, InfrahubNodeSync, NodeNotFoundError, NodeSchema
from nornir.core.inventory import (
ConnectionOptions,
Defaults,
Expand Down Expand Up @@ -111,6 +111,7 @@ def validate_include(cls, data: Any) -> Any:
data["include"] = ["member_of_groups"]
return data


def get_related_nodes(node_schema: NodeSchema, attrs: Set[str]) -> Set[str]:
nodes = {"CoreStandardGroup"}
relationship_schemas = {schema.name: schema.peer for schema in node_schema.relationships}
Expand Down Expand Up @@ -219,7 +220,12 @@ def load(self) -> Inventory: # noqa: PLR0912
host["data"] = {"InfrahubNode": host_node}
hosts[name] = _get_inventory_element(Host, host, name, defaults)

extracted_groups = [related_node.peer.name.value for related_node in host_node.member_of_groups.peers]
extracted_groups = []
for related_node in host_node.member_of_groups.peers:
try:
extracted_groups.append(related_node.peer.name.value)
except NodeNotFoundError:
continue

for group_mapping in self.group_mappings:
attrs = group_mapping.split(".")
Expand Down

0 comments on commit 27c514b

Please sign in to comment.