forked from freeipa/ipa-vagrant-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipa-vagrant-ci-topology-create
executable file
·146 lines (128 loc) · 5.05 KB
/
ipa-vagrant-ci-topology-create
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/python3
# Author: Martin Basti
# See LICENSE file for license
import argparse
import os
import sys
import logging
import traceback
from ipavagrant import constants
from ipavagrant.config import IPAVagrantConfig
from ipavagrant.ipaci import IPACITopology
def main():
parser = argparse.ArgumentParser(description="")
parser.add_argument("topology_name", type=str,
help="Name for topology (directory with this name "
"will be created)",
nargs="?")
parser.add_argument("--replicas", dest="replicas", type=int, default=0,
metavar="INT",
help="Number of IPA replicas to be prepared "
"(default: 0)")
parser.add_argument('--clients', dest="clients", type=int, default=0,
metavar="INT",
help="Number of IPA clients to be prepared "
"(default: 0)")
test_config = parser.add_argument_group("Test configuration options")
test_config.add_argument(
'--add-package', dest="packages", action="append",
help="Allows to specify packages that will be installed from "
"repository",
default=[], metavar="NAME")
test_config.add_argument(
'--add-copr', dest="copr_repos", action="append",
help="Allows to specify copr repositories that will be enabled",
default=[], metavar="NAME")
test_config.add_argument(
'--memory-controller', dest="memory_controller",
help="Allows to specify memory for controller [MB]",
metavar="MBytes", default=None)
test_config.add_argument(
'--memory-server', dest="memory_server",
help="Allows to specify memory for server [MB]",
metavar="MBytes", default=None)
test_config.add_argument(
'--memory-client', dest="memory_client",
help="Allows to specify memory for client [MB]",
metavar="MBytes", default=None)
# selinux
test_config.add_argument(
'--selinux-enforce', dest="selinux_enforcing",
action='store_true',
help="Set SELinux to enforce mode")
test_config.add_argument(
'--no-selinux-enforce', dest="selinux_enforcing",
action='store_false',
help="Set SELinux to permissive mode")
test_config.set_defaults(selinux_enforcing=None)
test_config.add_argument(
'--box', dest="box", default=None,
help="Set box that will be used")
test_config.add_argument(
'--domain', dest="domain", type=str,
default=None, help="Domain for provisioned VM")
file_config = parser.add_argument_group("Configuration file options")
file_config.add_argument(
'--config-file', dest="config_file", default=None,
help="Path to configuration file (default: %s)" %
constants.DEFAULT_CONFIG_FILENAME)
file_config.add_argument(
'--export-config', dest="export_config", default=False,
action="store_true", help="export current configuration to config "
"file (destination: --config-file)")
file_config.add_argument(
'--show-config', dest="show_config", default=False,
action="store_true", help="show current configuration")
parser.add_argument("--debug", action="store_true", default=False,
dest='debug',
help="Enables DEBUG level logging")
args = parser.parse_args()
if args.debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
if not args.topology_name:
if args.show_config or args.export_config:
topology_path = "_unused_"
else:
raise RuntimeError("Topology name is required")
else:
topology_path = os.path.abspath(args.topology_name)
config = IPAVagrantConfig(
filename=args.config_file,
# options
domain=args.domain,
memory_controller=args.memory_controller,
memory_server=args.memory_server,
memory_client=args.memory_client,
selinux_enforcing=args.selinux_enforcing,
box=args.box,
packages=args.packages,
copr_repos=args.copr_repos
)
ci_topo = IPACITopology(
topology_path,
config=config,
replicas=args.replicas,
clients=args.clients,
)
if args.show_config:
print("Current configuration:")
keys = sorted(ci_topo.config.config.keys())
for key in keys:
print(" %s: %r" % (key, ci_topo.config.config[key]))
print("Path to used config file: ", ci_topo.config.get_filename())
if not args.export_config:
return
if args.export_config:
where = ci_topo.config.export_config()
print("Configuration saved to %s" % where, file=sys.stderr)
return
ci_topo.create()
if __name__ == '__main__':
try:
main()
except RuntimeError as e:
logging.debug(traceback.format_exc())
print(e, file=sys.stderr)
sys.exit(2)