Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ For each pool target :
2. Get attached secondary hosts of the pool
* Repeat step `1.` for each secondary

It is possible to mark target as *"nested"* (XCP-ng inside VM). *See inventory example below*

**Inventory file**

`update` command can read an inventory file in [TOML v1.0.0](https://toml.io/en/v1.0.0) format:
Expand All @@ -603,6 +605,7 @@ Take a look at an example inventory file:
# my_inventory.toml

[all]
nested = true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

enablerepos = ["xcp-ng-base"]

[servers]
Expand Down
5 changes: 4 additions & 1 deletion lib/tools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _command_update(args: argparse.Namespace) -> None:
if args.inventory:
inventory = load_inventory(args.inventory)
else:
inventory = into_inventory(args.hosts, args.repos)
inventory = into_inventory(args.hosts, args.repos, args.nested)

update_pools(inventory)

Expand Down Expand Up @@ -53,6 +53,9 @@ def cli() -> None:
dest="repos",
help="repositories to enable when updating",
)
subparser_cmd_update.add_argument(
"--nested", action="store_true", default=False, help="Indicate whether hosts are nested or not"
)
subparser_cmd_update.set_defaults(func=_command_update)

args = parser.parse_args()
Expand Down
18 changes: 13 additions & 5 deletions lib/tools/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

from lib.common import HostAddress

def load_inventory(inventory_path: Path) -> dict[str, dict[str, list[str]]]:
def load_inventory(inventory_path: Path) -> dict[str, dict[str, list[str] | bool]]:
"""Create an inventory object from loaded inventory file."""
inventory: dict[str, dict[str, list[str]]] = {}
inventory: dict[str, dict[str, list[str] | bool]] = {}

with open(inventory_path, "rb") as f:
data = tomllib.load(f)
Expand All @@ -18,23 +18,31 @@ def load_inventory(inventory_path: Path) -> dict[str, dict[str, list[str]]]:
servers = data.get("servers", [])

for server, config in servers.items():
nested = config.get("nested", None)
# We can't use 'False' as fallback value here, because 'False' is falsy...
if nested is None:
nested = all.get("nested", False)
repos = config.get("enablerepos", [])
host = {
"nested": nested,
"enablerepos": repos or all.get("enablerepos", [])
}
inventory[server] = host

return inventory

def into_inventory(hosts: list[HostAddress], enablerepos: list[str]) -> dict[HostAddress, dict[str, list[str]]]:
def into_inventory(
hosts: list[HostAddress], enablerepos: list[str], nested: bool
) -> dict[HostAddress, dict[str, list[str] | bool]]:
"""Create an inventory object from arguments.

Basically, it is used as compatibility when we don't want inventory from file.
"""
inventory: dict[HostAddress, dict[str, list[str]]] = {}
inventory: dict[HostAddress, dict[str, list[str] | bool]] = {}

for h in hosts:
host = {
host: dict[str, list[str] | bool] = {
"nested": nested or False,
"enablerepos": enablerepos or [],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would sort alphabatically (e before n)

}
inventory[h] = host
Expand Down
Loading