forked from ibmcb/cbtool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·294 lines (228 loc) · 10.7 KB
/
configure
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#!/usr/bin/env python
#/*******************************************************************************
# Copyright (c) 2012 IBM Corp.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/*******************************************************************************
'''
Created on Nov 1, 2012
CREAT (CBTOOL) Configuration Tool
@author: Marcio Silva, Michael R. Hines
'''
import os
import re
import socket
from pwd import getpwuid
from shutil import copyfile
from logging import getLogger, StreamHandler, Formatter, Filter, DEBUG, ERROR, \
INFO, WARN, CRITICAL
from logging.handlers import logging, SysLogHandler, RotatingFileHandler
from sys import stdout,path, argv
from optparse import OptionParser
from lib.auxiliary.code_instrumentation import VerbosityFilter, MsgFilter, cbdebug, cberr, cbwarn, cbinfo, cbcrit
def main() :
'''
TBD
'''
_path = re.compile(".*\/").search(os.path.realpath(__file__)).group(0)
usage = '''usage: %prog [options] [command]
'''
_parser = OptionParser(usage)
_parser.add_option("--tpdir", \
dest="tpdir", \
default= _path + "/3rd_party", \
help="Name of the third-party directory")
_parser.add_option("--dfdir", \
dest="dfdir", \
default= _path + "/docker", \
help="Name of the Dockerfile directory")
_parser.add_option("--creddir", \
dest="creddir", \
default=_path + "/credentials/", \
help="Credentials configuration file defaults dir")
_parser.add_option("--defdir", \
dest="defdir", \
default=_path + "/configs/templates/", \
help="Dependencies configuration file defaults dir")
_parser.add_option("--cusdir", \
dest="cusdir", \
default=_path + "/configs/", \
help="Dependencies configuration file customizations dir")
_parser.add_option("--utildir", \
dest="utildir", \
default=_path + "/util/", \
help="Utility scripts dir")
_parser.add_option("-r", "--role", \
dest = "role", \
default = None, \
help = "The role assigned to this node (\"orchestrator\" or \"workload\")")
_parser.add_option("--wksdir", \
dest = "wksdir", \
default = _path + "/scripts/", \
help = "Workload dependencies configuration file dir")
_parser.add_option("-w","--wks", \
dest = "wks", \
default = None, \
help = "Comma-separated workload list")
_parser.add_option("-c","--custom", \
dest = "custom", \
default = "", \
help = "Dependencies customization file name")
_parser.add_option("-a","--addr", \
dest = "addr", \
default = None, \
help = "Package (and pip) repository address")
_parser.add_option("-f","--filestore", \
dest = "filestore", \
default = "127.0.0.1-10000-root", \
help = "The filestore URL in the form IP-PORT-DIR")
_parser.add_option("--clouds", \
dest = "clouds", \
default = "all", \
help = "Cloud adapters to install (comma-separated values)")
_parser.add_option("--venv",\
action="store_true", \
dest="venv", \
default=False, \
help="Install on a python virtual environment (python dependencies ONLY !!!)")
_parser.add_option("--cleanupimageid",\
action="store_true", \
dest="cleanupimageid", \
default=False, \
help="Remove /etc/image-id from the instance's disk. Useful when preparing images for cloning")
_parser.add_option("--logdest", dest = "logdest", metavar = "LOGDEST", \
default = "console", help ="Alter default logging behavior")
_parser.add_option("--syslogp", dest = "syslogp", metavar = "SYSLOGP", \
default = None, \
help ="Set syslog port")
_parser.add_option("--syslogh", dest = "syslogh", metavar = "SYSLOGH", \
default = None, \
help ="Set syslog hostname")
_parser.add_option("--syslogf", dest = "syslogf", metavar = "SYSLOGF", \
default = None, \
help ="Set syslog facility")
_parser.add_option("--syslogr", dest = "syslogr", metavar = "SYSLOGR", \
default = 'UDP', \
help ="Set syslog protocol")
_parser.add_option("-v", "--verbosity", dest = "verbosity", metavar = "LV", \
default = -1, help = "Set verbosity level.")
_parser.add_option("-q", dest = "quiet", action = "store_true", \
help = "Set quiet output.")
_parser.set_defaults()
(options, _args) = _parser.parse_args()
# HACK ALERT - A very crude "syslog facility selector"
_syslog_selector = {}
_syslog_selector["16"] = SysLogHandler.LOG_LOCAL0
_syslog_selector["17"] = SysLogHandler.LOG_LOCAL1
_syslog_selector["18"] = SysLogHandler.LOG_LOCAL2
_syslog_selector["19"] = SysLogHandler.LOG_LOCAL3
_syslog_selector["20"] = SysLogHandler.LOG_LOCAL4
_syslog_selector["21"] = SysLogHandler.LOG_LOCAL5
_syslog_selector["22"] = SysLogHandler.LOG_LOCAL6
_syslog_selector["23"] = SysLogHandler.LOG_LOCAL7
_verbosity = int(options.verbosity)
logger = getLogger()
# Reset the logging handlers
while len(logger.handlers) != 0 :
logger.removeHandler(logger.handlers[0])
if options.logdest == "console" or (not options.syslogh or not options.syslogp) :
hdlr = StreamHandler(stdout)
else :
_facility = int(options.syslogf)
if _facility > 23 or _facility < 16 :
_facility = 23
_socktype = socket.SOCK_DGRAM
if options.syslogr == "TCP" :
_socktype = socket.SOCK_STREAM
hdlr = SysLogHandler(address = (options.syslogh, int(options.syslogp)), \
facility=_syslog_selector[str(_facility)], \
socktype = _socktype)
formatter = Formatter("[%(asctime)s] [%(levelname)s] %(message)s")
# formatter = Formatter('%(asctime)s %(levelname)s %(module)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
if _verbosity :
if int(_verbosity) > 1 :
logger.setLevel(DEBUG)
else :
hdlr.addFilter(VerbosityFilter("ProcessManagement"))
logger.setLevel(DEBUG)
else :
logger.setLevel(INFO)
if options.quiet :
logger.setLevel(ERROR)
_3rd_party = options.tpdir
_util = options.utildir
options.basedir = _path.strip().split('/')[-2]
if not os.path.exists(_3rd_party) :
os.mkdir(_3rd_party)
for _ue in [ "cb_is_hadoop_installed.sh", "cb_is_java_installed.sh"] :
copyfile(_util + '/' + _ue, "/tmp/" + _ue)
os.chmod("/tmp/" + _ue, 0755)
from lib.auxiliary.dependencies import dependency_checker_installer,instance_preparation
_tool = "Cloud Rapid Experimentation Analysis and Toolkit (cbtool)"
_bname = os.path.basename(argv[0])
if not options.role :
_msg = "You need to select a role for this node (option \"-r\" or \"--role\""
_msg += "). Possible roles are \"orchestrator\" (needs at least 10 GB of "
_msg += "free space) or \"workload\"."
cberr(_msg)
exit(1)
if options.role.count("orchestrator") :
options.wks = ''
elif options.role.count("workload") :
if not options.wks :
_msg = "You need to select one of the workloads (option \"-w\" or \"--wks\")"
cberr(_msg)
exit(2)
else :
if not options.wks.count("nullworkload") :
options.wks = "nullworkload," + options.wks
else :
_msg = "Unknown node role: \"" + options.role + "\"."
cberr(_msg)
exit(3)
if _bname == "configure" :
_msg = "Checking for " + _tool + " dependencies on this node........."
cbinfo(_msg)
else :
_msg = "Installing dependencies for " + _tool + " on this node........."
cbinfo(_msg)
_depsdict = {}
_status, _msg = dependency_checker_installer("127.0.0.1", _depsdict, getpwuid(os.getuid())[0], _bname, options)
if _status :
cberr(_msg)
exit(_status)
if not len(options.wks) :
_username = getpwuid(os.getuid())[0]
_msg = "Checking for a \"private\" configuration file for user \"" + _username
_msg += "\" in " + _path + "/configs/" + _username + "_cloud_definitions.txt)"
cbinfo(_msg)
if not os.path.exists(_path + "/configs/" + _username + "_cloud_definitions.txt") :
_msg = "Copying " + _path + "/configs/cloud_definitions.txt to "
_msg += _path + "/configs/" + _username + "_cloud_definitions.txt..."
cbinfo(_msg)
copyfile(_path + "/configs/cloud_definitions.txt", _path + "/configs/" + _username + "_cloud_definitions.txt")
cbinfo("Please re-run configure again")
else :
cbinfo("File already exists, tool is ready to be used.")
else :
cbinfo(_msg)
print '\n'
_status, _msg = instance_preparation("127.0.0.1", _depsdict, options)
if not _status :
print '\n------------------------------------------------------------\n'
if str(options.addr).lower() != "bypass" :
_msg = "SUCCESS! Please go back to CBTOOL's CLI and capture the image"
else :
_msg = "SUCCESS! Proceeding with Application Instance deployment"
cbinfo(_msg)
exit(_status)
main()