-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.py
More file actions
73 lines (59 loc) · 2.11 KB
/
deploy.py
File metadata and controls
73 lines (59 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""
Deploy - A Multi-threaded Deployment and Control Framework
A lightweight deployment tool that executes scripts and commands across multiple
hosts concurrently. Supports Linux, Windows, and network devices with flexible
configuration options.
Author: /coz/
Version: 2.0.0
"""
import sys
import logging
from modules.logging import setup_logging
from modules.task_manager import TaskManager
from modules.arguments import parse_args, BANNER
from modules.configuration import load_config_file
from modules.exceptions import ConfigurationError, HostLoadError, ScriptLoadError
from modules.configuration import (
create_settings, load_hosts, load_scripts,
list_hosts_and_scripts, setup_tasks, execute_and_report,
)
sys.dont_write_bytecode = True
if __name__ == "__main__":
"""
Main entry point for the Deploy application.
Returns:
Exit code (0 for success, 1 for error)
"""
args = parse_args()
setup_logging(args.verbose)
logger = logging.getLogger("deploy")
if not args.quiet:
print(BANNER)
try:
config = load_config_file(args.config)
hosts = load_hosts(args, logger)
scripts = load_scripts(args, logger)
if args.list:
list_hosts_and_scripts(hosts, scripts, args, logger)
sys.exit(0)
logger.info(f"Loaded {len(hosts)} hosts and {len(scripts)} scripts")
settings = create_settings(args)
task_manager = TaskManager(settings)
task_manager.add_hosts(hosts)
task_manager.add_scripts(scripts)
setup_tasks(args, task_manager, hosts, scripts, logger)
execute_and_report(task_manager, logger, args)
except (ConfigurationError, HostLoadError, ScriptLoadError) as e:
logger.error(f"Configuration error: {e}")
sys.exit(1)
except KeyboardInterrupt:
logger.warning("Operation interrupted by user")
sys.exit(1)
except Exception as e:
logger.error(f"Unexpected error: {e}")
if args.verbose:
import traceback
logger.error(traceback.format_exc())
sys.exit(1)
sys.exit(0)