Repository navigation
Expand file tree
/
Copy pathstartAPIContainer
More file actions
executable file
·210 lines (186 loc) · 6.8 KB
/
Copy pathstartAPIContainer
File metadata and controls
executable file
·210 lines (186 loc) · 6.8 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/python3
# -----------------------------------------------------------------------------
# Licensed Materials - Property of IBM
#
# (C) Copyright IBM Corp. 2024 All Rights Reserved
#
# US Government Users Restricted Rights - Use, duplication or disclosure
# restricted by GSA ADP Schedule Contract with IBM Corp.
#
# -----------------------------------------------------------------------------
#
# File name: startAPIContainer
# Description: It creates a sanitized apimgr.yml based on input and system
# -----------------------------------------------------------------------------
#
# Changelog:
# YYYY/MM/DD
# 2024/04/03 0.1 Initial Creation
# -----------------------------------------------------------------------------
import sys
import argparse
from classes.apimgr_yml import apimgr_yml
import os
import shutil
ownFile = __file__
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument(
'-d',
'--delete',
action='store_true',
dest='delete',
help='Delete the SSS API container and its systemd service unit.',
default=False)
parser.add_argument(
'-v',
'--verbose',
action='store_true',
dest='verbose',
help='Display verbose messages in the console.',
default=False)
# Install source: mutually exclusive — local tar file vs repo version
install_source = parser.add_mutually_exclusive_group()
install_source.add_argument(
'-f',
'--file-name',
action='store',
dest='filename',
metavar='FILE',
help='Restore from local container tar ball. (default: SSSAPI.tar)',
default=None)
install_source.add_argument(
'-vn',
'--image-version',
action='store',
dest='image_version',
metavar='VERSION',
help='API server version to deploy. (default: 7.0.1.2)',
default=None)
parser.add_argument(
'-p',
'--port',
action='store',
dest='port',
help='Port on which the API server listens. (default: 46443)',
default=None)
parser.add_argument(
'-i',
'--campus-interface',
action='store',
dest='campus_interface',
help='Name of the interface connected to the campus network. (default: campus)',
default=None)
parser.add_argument(
'-up',
'--utilitybaremetal-password',
action='store',
dest='utilitybaremetal_password',
help='Password for the root user on the utilityBareMetal host. (default: cluster)',
default=None)
parser.add_argument(
'-e',
'--is-emsvm23e-exist',
action='store',
dest='is_emsvm23e_exist',
help='Specify whether EMSVM-23E exists. (default: no)',
default=None)
parser.add_argument(
'-ep',
'--emsvm23e-password',
action='store',
dest='emsvm23e_password',
help='Password for the root user on EMSVM-23E. (default: cluster)',
default="")
args = parser.parse_args()
if args.delete:
start_only_args = [
('-f/--file-name', args.filename),
('-vn/--image-version', args.image_version),
('-p/--port', args.port),
('-i/--campus-interface', args.campus_interface),
('-up/--utilitybaremetal-password', args.utilitybaremetal_password),
('-e/--is-emsvm23e-exist', args.is_emsvm23e_exist),
('-ep/--emsvm23e-password', args.emsvm23e_password if args.emsvm23e_password != "" else None),
]
invalid_passed = [opt for opt, val in start_only_args if val is not None]
if invalid_passed:
parser.error(f"The following argument(s) cannot be used with -d/--delete: {', '.join(invalid_passed)}")
return args.verbose, args.filename, \
args.port, args.campus_interface, args.image_version, \
args.utilitybaremetal_password, args.is_emsvm23e_exist, args.emsvm23e_password, \
args.delete
def copyLogs():
if not os.path.isdir("/var/log/sssapi"):
return
dst_dir = "/var/log/sssapi/startAPIContainer"
if not os.path.isdir(dst_dir):
os.mkdir(dst_dir)
if not os.path.isdir("logs"):
os.mkdir("logs")
for logFile in os.listdir("logs"):
src = os.path.join("logs", logFile)
if os.path.isfile(src):
shutil.copy(src, os.path.join(dst_dir, logFile))
def main():
verbose, filename, port, campus_interface, image_version, utilitybaremetal_password, is_emsvm23e_exist, emsvm23e_password, delete = parse_arguments()
our_yml = apimgr_yml(
verbose,
filename,
port,
campus_interface,
image_version,
utilitybaremetal_password,
is_emsvm23e_exist,
emsvm23e_password,
delete
)
if delete:
our_yml.run_log.info("Going to delete the SSS API container.")
our_yml.delete_container()
sys.exit(0)
if is_emsvm23e_exist is not None and (is_emsvm23e_exist.lower() != 'yes' and is_emsvm23e_exist.lower() != 'no'):
our_yml.run_log.error(
"The parameter for is-emsvm23e-exist should be either 'yes' or 'no'. Fix and try again."
)
sys.exit(3)
# We need to ensure exit before this if clean up
our_yml.run_log.debug(
"Going to invoke input data method from main program"
)
entries_NOK = our_yml.startAPIContainer()
if entries_NOK:
our_yml.run_log.error(
"The file has been written but does not pass the checks. "
"You CANNOT continue with the next steps. "
"Check the ERROR messages above to understand which tests failed and fix them. "
"You can run this tool again, the data you entered will be shown as default entries."
)
sys.exit(1)
else:
our_yml.run_log.debug("Could generate the needed information into YML, going to start the SSS API container")
our_yml.run_log.debug("Going to prepare the container")
canPrep = our_yml.prep_container()
our_yml.run_log.debug("Back from prepare the container")
if canPrep:
could_start = our_yml.start_container()
if could_start:
our_yml.run_log.info(f"To start a new container, run the {ownFile} command.")
sys.exit(0)
else:
our_yml.run_log.error(
"There have been some issues on the run. "
"Check the above messages and follow up with './startAPIContainer'."
)
sys.exit(5)
else:
our_yml.run_log.error("Could not prepare the container")
sys.exit(6)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print("\nInterrupted by user.")
sys.exit(1)
finally:
copyLogs()