Skip to content

Commit 1a9c4ba

Browse files
authored
Merge pull request #417 from xcp-ng/ohu/xcpng-539/002
Tools - Add CLI for using update scripts
2 parents 7b98058 + be477e4 commit 1a9c4ba

3 files changed

Lines changed: 83 additions & 0 deletions

File tree

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,26 @@ INFO:root:Setting bridge to xenbr0
555555
```
556556
557557
For more details, see `xva_bridge.py --help`.
558+
559+
## Tools
560+
561+
Helper tools are available through the entrypoint `scripts/tools.py`:
562+
563+
```bash
564+
uv run scripts/tools.py -h
565+
```
566+
567+
### Update
568+
569+
This command performs an update operation on remote targets.
570+
571+
```bash
572+
uv run scripts/tools.py update primary1 primary2
573+
```
574+
575+
For each primary target :
576+
577+
1. Clean cached metadata
578+
2. Update with repository manager (yum): Optionally enables repositories
579+
3. Reboot
580+
4. Get attached secondary hosts and repeats three previous steps for each secondary

lib/tools/cli.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""CLI Entrypoint
2+
3+
The main entrypoint for running tools script.
4+
"""
5+
import argparse
6+
import logging
7+
8+
from lib.common import HostAddress
9+
from lib.tools import logger
10+
from lib.tools.tasks.update import update_all
11+
12+
def _command_update(args):
13+
update_all(args.hosts, args.repos)
14+
15+
16+
def cli():
17+
parser = argparse.ArgumentParser(
18+
description="Tools that help developers for running recurrent tasks on their XCP-ng sandbox."
19+
)
20+
parser.add_argument("-d", "--debug", action="store_true", default=False, help="Enable debug level")
21+
22+
subparsers = parser.add_subparsers(required=True, metavar="COMMAND")
23+
24+
# subparser - command: update
25+
subparser_cmd_update = subparsers.add_parser(
26+
name="update",
27+
description="Run update tasks on target(s)",
28+
help="Run update tasks on target(s)",
29+
)
30+
subparser_cmd_update.add_argument(
31+
"hosts", type=HostAddress, metavar="HOST", nargs="+", help="Hostname(s) or ip address(es) of target(s)"
32+
)
33+
subparser_cmd_update.add_argument(
34+
"--enablerepo",
35+
metavar="REPO",
36+
action="append",
37+
dest="repos",
38+
help="repositories to enable when updating",
39+
)
40+
subparser_cmd_update.set_defaults(func=_command_update)
41+
42+
args = parser.parse_args()
43+
44+
if args.debug:
45+
logger.setLevel(logging.DEBUG)
46+
47+
args.func(args)

scripts/tools.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Just a wrapper to run cli tools package.
2+
"""
3+
import sys
4+
from pathlib import Path
5+
6+
# Add root project directory into PYTHONPATH
7+
sys.path.append(str(Path(__file__).absolute().parent.parent))
8+
9+
# flake8: noqa: E402 module level import not at top of file
10+
from lib.tools.cli import cli
11+
12+
if __name__ == "__main__":
13+
cli()

0 commit comments

Comments
 (0)