Skip to content

Commit bf24760

Browse files
committed
Add nested mark for update tools
Signed-off-by: Olivier Hoareau <olivier.hoareau@vates.tech>
1 parent d21f31b commit bf24760

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ For each pool target :
584584
2. Get attached secondary hosts of the pool
585585
* Repeat step `1.` for each secondary
586586

587+
It is possible to mark target as *"nested"* (XCP-ng inside VM). *See inventory example below*
588+
587589
**Inventory file**
588590

589591
`update` command can read an inventory file in [TOML v1.0.0](https://toml.io/en/v1.0.0) format:
@@ -604,6 +606,7 @@ Take a look at an example inventory file:
604606
parent = "ip_or_hostname" # master host
605607

606608
[all]
609+
nested = true
607610
enablerepos = ["xcp-ng-base"]
608611

609612
[servers]

lib/tools/cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def _command_update(args: argparse.Namespace) -> None:
1717
if args.inventory:
1818
inventory = load_inventory(args.inventory)
1919
else:
20-
inventory = into_inventory(args.hosts, args.repos, args.parent_host)
20+
inventory = into_inventory(args.hosts, args.repos, args.parent_host, args.nested)
2121

2222
update_pools(inventory)
2323

@@ -59,6 +59,9 @@ def cli() -> None:
5959
type=HostAddress,
6060
help="Address (hostname|ip) of the parent master host (works with '--nested')",
6161
)
62+
subparser_cmd_update.add_argument(
63+
"--nested", action="store_true", default=False, help="Indicate whether hosts are nested or not"
64+
)
6265
subparser_cmd_update.set_defaults(func=_command_update)
6366

6467
args = parser.parse_args()

lib/tools/inventory.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
from lib.common import HostAddress
99

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

1414
with open(inventory_path, "rb") as f:
1515
data = tomllib.load(f)
@@ -19,8 +19,13 @@ def load_inventory(inventory_path: Path) -> dict[str, dict[str, list[str]]]:
1919

2020
inventory_hosts = {}
2121
for server, config in servers.items():
22+
nested = config.get("nested", None)
23+
# We can't use 'False' as fallback value here, because 'False' is falsy...
24+
if nested is None:
25+
nested = all.get("nested", False)
2226
repos = config.get("enablerepos", [])
2327
host = {
28+
"nested": nested,
2429
"enablerepos": repos or all.get("enablerepos", [])
2530
}
2631
inventory_hosts[server] = host
@@ -31,17 +36,18 @@ def load_inventory(inventory_path: Path) -> dict[str, dict[str, list[str]]]:
3136
return inventory
3237

3338
def into_inventory(
34-
hosts: list[HostAddress], enablerepos: list[str], parent: HostAddress
35-
) -> dict[HostAddress, dict[str, list[str]]]:
39+
hosts: list[HostAddress], enablerepos: list[str], parent: HostAddress, nested: bool
40+
) -> dict[HostAddress, dict[str, list[str] | bool]]:
3641
"""Create an inventory object from arguments.
3742
3843
Basically, it is used as compatibility when we don't want inventory from file.
3944
"""
40-
inventory: dict[HostAddress, dict[str, list[str]]] = {}
45+
inventory: dict[HostAddress, dict[str, list[str] | bool]] = {}
4146

4247
inventory_hosts = {}
4348
for h in hosts:
44-
host: dict[str, list[str]] = {
49+
host: dict[str, list[str] | bool] = {
50+
"nested": nested or False,
4551
"enablerepos": enablerepos or [],
4652
}
4753
inventory_hosts[h] = host

0 commit comments

Comments
 (0)