Skip to content

Commit 563cb30

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

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

README.md

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

584+
It is possible to mark target as *"nested"* (XCP-ng inside VM). *See inventory example below*
585+
584586
**Inventory file**
585587

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

602604
[all]
605+
nested = true
603606
enablerepos = ["xcp-ng-base"]
604607

605608
[servers]

lib/tools/cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def _command_update(args):
1515
if args.inventory:
1616
inventory = load_inventory(args.inventory)
1717
else:
18-
inventory = into_inventory(args.hosts, args.repos)
18+
inventory = into_inventory(args.hosts, args.repos, args.nested)
1919

2020
update_pools(inventory)
2121

@@ -51,6 +51,9 @@ def cli():
5151
dest="repos",
5252
help="repositories to enable when updating",
5353
)
54+
subparser_cmd_update.add_argument(
55+
"--nested", action="store_true", default=False, help="Indicate whether hosts are nested or not"
56+
)
5457
subparser_cmd_update.set_defaults(func=_command_update)
5558

5659
args = parser.parse_args()

lib/tools/inventory.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ def load_inventory(inventory_path: Path) -> dict:
1616
servers = data.get("servers", [])
1717

1818
for server, config in servers.items():
19+
nested = config.get("nested", None)
20+
# We can't use 'False' as fallback value here, because 'False' is falsy...
21+
if nested is None:
22+
nested = all.get("nested", False)
1923
repos = config.get("enablerepos", [])
2024
host = {
25+
"nested": nested,
2126
"enablerepos": repos or all.get("enablerepos", [])
2227
}
2328
inventory[server] = host
2429

2530
return inventory
2631

27-
def into_inventory(hosts: list[HostAddress], enablerepos: list[str]) -> dict:
32+
def into_inventory(hosts: list[HostAddress], enablerepos: list[str], nested: bool) -> dict:
2833
"""Create an inventory object from arguments.
2934
3035
Basically, it is used as compatibility when we don't want inventory from file.
@@ -33,6 +38,7 @@ def into_inventory(hosts: list[HostAddress], enablerepos: list[str]) -> dict:
3338

3439
for h in hosts:
3540
host = {
41+
"nested": nested or False,
3642
"enablerepos": enablerepos or [],
3743
}
3844
inventory[h] = host

0 commit comments

Comments
 (0)