Skip to content

Commit 1aa52a9

Browse files
committed
tools/cli: add new arg for parent host
Signed-off-by: Olivier Hoareau <olivier.hoareau@vates.tech>
1 parent 7f6243a commit 1aa52a9

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ Take a look at an example inventory file:
603603

604604
```toml
605605
# my_inventory.toml
606+
parent = "ip_or_hostname" # master host
606607

607608
[all]
608609
nested = true
@@ -621,6 +622,6 @@ enablerepos = ["xcp-ng-updates"]
621622
> Config values under `servers` override values under `all`. For instance, the above inventory would produce
622623
> the following python dict:
623624
>
624-
> `{'hosts': {'ip_or_hostname-1': {'enablerepos': ['xcp-ng-base']}, 'ip_or_hostname-2': {'enablerepos': ['xcp-ng-updates']}}}`
625+
> `{'parent': 'ip_or_hostname', 'hosts': {'ip_or_hostname-1': {'enablerepos': ['xcp-ng-base']}, 'ip_or_hostname-2': {'enablerepos': ['xcp-ng-updates']}}}`
625626
>
626627
> Using *enablerepo flag* `-e` with inventory is still possible, it won't be used though.

lib/tools/cli.py

Lines changed: 7 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.nested)
20+
inventory = into_inventory(args.hosts, args.repos, args.nested, args.parent_host)
2121

2222
update_pools(inventory)
2323

@@ -56,6 +56,12 @@ def cli() -> None:
5656
subparser_cmd_update.add_argument(
5757
"--nested", action="store_true", default=False, help="Indicate whether hosts are nested or not"
5858
)
59+
subparser_cmd_update.add_argument(
60+
"-P",
61+
"--parent-host",
62+
type=HostAddress,
63+
help="Address (hostname|ip) of the parent master host (works with '--nested')",
64+
)
5965
subparser_cmd_update.set_defaults(func=_command_update)
6066

6167
args = parser.parse_args()

lib/tools/inventory.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ def load_inventory(inventory_path: Path) -> dict[str, dict[str, list[str]]]:
3131
inventory_hosts[server] = host
3232

3333
inventory["hosts"] = inventory_hosts
34+
inventory["parent"] = data.get("parent", None)
3435

3536
return inventory
3637

37-
def into_inventory(hosts: list[HostAddress], enablerepos: list[str], nested: bool) -> dict[HostAddress, dict[str, list[str]]]:
38+
def into_inventory(
39+
hosts: list[HostAddress], enablerepos: list[str], nested: bool, parent: HostAddress
40+
) -> dict[HostAddress, dict[str, list[str]]]:
3841
"""Create an inventory object from arguments.
3942
4043
Basically, it is used as compatibility when we don't want inventory from file.
@@ -50,5 +53,6 @@ def into_inventory(hosts: list[HostAddress], enablerepos: list[str], nested: boo
5053
inventory_hosts[h] = host
5154

5255
inventory["hosts"] = inventory_hosts
56+
inventory["parent"] = parent
5357

5458
return inventory

0 commit comments

Comments
 (0)