Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added add_host and add_group functions to nornir.core.inventory.Inventory class #372

Merged
merged 4 commits into from
Apr 8, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions nornir/core/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,18 +439,24 @@ def children_of_group(self, group: Union[str, Group]) -> Set[Host]:
hosts.add(host)
return hosts

def add_host(self, name: str, defaults: Optional[Defaults] = None,
dbarrosop marked this conversation as resolved.
Show resolved Hide resolved
**kwargs) -> None:
def add_host(self, name: str, **kwargs) -> None:
"""
Add a host to the inventory after initialization
"""
host = {name: Host(name, defaults=self.defaults, **kwargs)}
host = {
brandomando marked this conversation as resolved.
Show resolved Hide resolved
name: deserializer.inventory.InventoryElement.deserialize_host(
name=name, defaults=self.defaults, **kwargs
)
}
self.hosts.update(host)

def add_group(self, name: str, defaults: Optional[Defaults] = None,
dbarrosop marked this conversation as resolved.
Show resolved Hide resolved
**kwargs) -> None:
def add_group(self, name: str, **kwargs) -> None:
"""
Add a group to the inventory after initialization
"""
group = {name: Group(name, defaults=self.defaults, **kwargs)}
group = {
brandomando marked this conversation as resolved.
Show resolved Hide resolved
name: deserializer.inventory.InventoryElement.deserialize_group(
name=name, defaults=self.defaults, **kwargs
)
}
self.groups.update(group)