forked from redhat-openstack/packstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprescript_000.py
More file actions
409 lines (381 loc) · 20.7 KB
/
Copy pathprescript_000.py
File metadata and controls
409 lines (381 loc) · 20.7 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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
"""
Plugin responsible for setting OpenStack global options
"""
import glob
import logging
import os
import re
import uuid
from packstack.installer import (basedefs, exceptions, processors, utils,
validators)
from packstack.modules.common import filtered_hosts
from packstack.modules.ospluginutils import (getManifestTemplate,
appendManifestFile)
# Controller object will be initialized from main flow
controller = None
# Plugin name
PLUGIN_NAME = "OS-PRESCRIPT"
logging.debug("plugin %s loaded", __name__)
def initConfig(controllerObject):
global controller
controller = controllerObject
paramsList = [{"CMD_OPTION" : "ssh-public-key",
"USAGE" : "Path to a Public key to install on servers. If a usable key has not been installed on the remote servers the user will be prompted for a password and this key will be installed so the password will not be required again",
"PROMPT" : "Enter the path to your ssh Public key to install on servers",
"OPTION_LIST" : [],
"VALIDATORS" : [validators.validate_file,
validators.validate_sshkey],
"PROCESSORS" : [processors.process_ssh_key],
"DEFAULT_VALUE" : (glob.glob(os.path.join(os.environ["HOME"], ".ssh/*.pub"))+[""])[0],
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_SSH_KEY",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "os-mysql-install",
"USAGE" : "Set to 'y' if you would like Packstack to install MySQL",
"PROMPT" : "Should Packstack install MySQL DB",
"OPTION_LIST" : ["y", "n"],
"VALIDATORS" : [validators.validate_options],
"DEFAULT_VALUE" : "y",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_MYSQL_INSTALL",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "os-glance-install",
"USAGE" : "Set to 'y' if you would like Packstack to install OpenStack Image Service (Glance)",
"PROMPT" : "Should Packstack install OpenStack Image Service (Glance)",
"OPTION_LIST" : ["y", "n"],
"VALIDATORS" : [validators.validate_options],
"DEFAULT_VALUE" : "y",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_GLANCE_INSTALL",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "os-cinder-install",
"USAGE" : "Set to 'y' if you would like Packstack to install OpenStack Block Storage (Cinder)",
"PROMPT" : "Should Packstack install OpenStack Block Storage (Cinder) service",
"OPTION_LIST" : ["y", "n"],
"VALIDATORS" : [validators.validate_options],
"DEFAULT_VALUE" : "y",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_CINDER_INSTALL",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "os-nova-install",
"USAGE" : "Set to 'y' if you would like Packstack to install OpenStack Compute (Nova)",
"PROMPT" : "Should Packstack install OpenStack Compute (Nova) service",
"OPTION_LIST" : ["y", "n"],
"VALIDATORS" : [validators.validate_options],
"DEFAULT_VALUE" : "y",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_NOVA_INSTALL",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "os-neutron-install",
"USAGE" : "Set to 'y' if you would like Packstack to install OpenStack Networking (Neutron)",
"PROMPT" : "Should Packstack install OpenStack Networking (Neutron) service",
"OPTION_LIST" : ["y", "n"],
"VALIDATORS" : [validators.validate_options],
"DEFAULT_VALUE" : "y",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_NEUTRON_INSTALL",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "os-horizon-install",
"USAGE" : "Set to 'y' if you would like Packstack to install OpenStack Dashboard (Horizon)",
"PROMPT" : "Should Packstack install OpenStack Dashboard (Horizon)",
"OPTION_LIST" : ["y", "n"],
"VALIDATORS" : [validators.validate_options],
"DEFAULT_VALUE" : "y",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_HORIZON_INSTALL",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "os-swift-install",
"USAGE" : "Set to 'y' if you would like Packstack to install OpenStack Object Storage (Swift)",
"PROMPT" : "Should Packstack install OpenStack Object Storage (Swift)",
"OPTION_LIST" : ["y", "n"],
"VALIDATORS" : [validators.validate_options],
"DEFAULT_VALUE" : "y",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_SWIFT_INSTALL",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "os-ceilometer-install",
"USAGE" : "Set to 'y' if you would like Packstack to install OpenStack Metering (Ceilometer)",
"PROMPT" : "Should Packstack install OpenStack Metering (Ceilometer)",
"OPTION_LIST" : ["y", "n"],
"VALIDATORS" : [validators.validate_options],
"DEFAULT_VALUE" : "y",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_CEILOMETER_INSTALL",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "os-heat-install",
"USAGE" : "Set to 'y' if you would like Packstack to install OpenStack Orchestration (Heat)",
"PROMPT" : "Should Packstack install OpenStack Orchestration (Heat)",
"OPTION_LIST" : ["y", "n"],
"VALIDATORS" : [validators.validate_options],
"DEFAULT_VALUE" : "n",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_HEAT_INSTALL",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "os-client-install",
"USAGE" : "Set to 'y' if you would like Packstack to install the OpenStack Client packages. An admin \"rc\" file will also be installed",
"PROMPT" : "Should Packstack install OpenStack client tools",
"OPTION_LIST" : ["y", "n"],
"VALIDATORS" : [validators.validate_options],
"DEFAULT_VALUE" : "y",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_CLIENT_INSTALL",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "ntp-servers",
"USAGE" : "Comma separated list of NTP servers. Leave plain if Packstack should not install ntpd on instances.",
"PROMPT" : "Enter a comma separated list of NTP server(s). Leave plain if Packstack should not install ntpd on instances.",
"OPTION_LIST" : [],
"DEFAULT_VALUE" : '',
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_NTP_SERVERS",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "nagios-install",
"USAGE" : "Set to 'y' if you would like Packstack to install Nagios to monitor OpenStack hosts",
"PROMPT" : "Should Packstack install Nagios to monitor OpenStack hosts",
"OPTION_LIST" : ["y", "n"],
"VALIDATORS" : [validators.validate_options],
"DEFAULT_VALUE" : 'y',
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_NAGIOS_INSTALL",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "exclude-servers",
"USAGE" : "Comma separated list of servers to be excluded from installation in case you are running Packstack the second time with the same answer file and don't want Packstack to touch these servers. Leave plain if you don't need to exclude any server.",
"PROMPT" : "Enter a comma separated list of server(s) to be excluded. Leave plain if you don't need to exclude any server.",
"OPTION_LIST" : [],
"DEFAULT_VALUE" : '',
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "EXCLUDE_SERVERS",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "os-debug-mode",
"USAGE" : ("Set to 'y' if you want to run "
"OpenStack services in debug mode. "
"Otherwise set to 'n'."),
"PROMPT" : ("Do you want to run OpenStack services"
" in debug mode"),
"OPTION_LIST" : ["y", "n"],
"DEFAULT_VALUE" : "n",
"VALIDATORS" : [validators.validate_options],
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_DEBUG_MODE",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "os-vmware",
"USAGE" : ("Set to 'y' if you want to use "
"VMware vCenter as hypervisor and storage"
"Otherwise set to 'n'."),
"PROMPT" : ("Do you want to use VMware vCenter as"
" hypervisor and datastore"),
"OPTION_LIST" : ["y","n"],
"DEFAULT_VALUE" : "n",
"VALIDATORS" : [validators.validate_options],
"MASK_INPUT" : False,
"LOOSE_VALIDATION": False,
"CONF_NAME" : "CONFIG_VMWARE_BACKEND",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
]
groupDict = { "GROUP_NAME" : "GLOBAL",
"DESCRIPTION" : "Global Options",
"PRE_CONDITION" : lambda x: 'yes',
"PRE_CONDITION_MATCH" : "yes",
"POST_CONDITION" : False,
"POST_CONDITION_MATCH" : True}
controller.addGroup(groupDict, paramsList)
def use_vcenter(config):
return (config['CONFIG_NOVA_INSTALL'] == 'y' and
config['CONFIG_VMWARE_BACKEND'] == 'y')
paramsList = [
{"CMD_OPTION" : "vcenter-host",
"USAGE" : ("The IP address of the VMware vCenter server"),
"PROMPT" : ("Enter the IP address of the VMware vCenter server to use with Nova"),
"OPTION_LIST" : [],
"VALIDATORS" : [validators.validate_ip],
"DEFAULT_VALUE" : "",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": True,
"CONF_NAME" : "CONFIG_VCENTER_HOST",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False },
{"CMD_OPTION" : "vcenter-username",
"USAGE" : ("The username to authenticate to VMware vCenter server"),
"PROMPT" : ("Enter the username to authenticate on VMware vCenter server"),
"DEFAULT_VALUE" : "",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": True,
"CONF_NAME" : "CONFIG_VCENTER_USER",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False,},
{"CMD_OPTION" : "vcenter-password",
"USAGE" : ("The password to authenticate to VMware vCenter server"),
"PROMPT" : ("Enter the password to authenticate on VMware vCenter server"),
"DEFAULT_VALUE" : "",
"MASK_INPUT" : True,
"LOOSE_VALIDATION": True,
"CONF_NAME" : "CONFIG_VCENTER_PASSWORD",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False,},
{"CMD_OPTION" : "vcenter-cluster",
"USAGE" : ("The name of the vCenter cluster"),
"PROMPT" : ("Enter the name of the vCenter datastore"),
"DEFAULT_VALUE" : "",
"MASK_INPUT" : False,
"LOOSE_VALIDATION": True,
"CONF_NAME" : "CONFIG_VCENTER_CLUSTER_NAME",
"USE_DEFAULT" : False,
"NEED_CONFIRM" : False,
"CONDITION" : False,},
]
groupDict = {"GROUP_NAME" : "VMWARE",
"DESCRIPTION" : "vCenter Config Parameters",
"PRE_CONDITION" : use_vcenter,
"PRE_CONDITION_MATCH" : True,
"POST_CONDITION" : False,
"POST_CONDITION_MATCH" : True}
controller.addGroup(groupDict, paramsList)
def initSequences(controller):
prescript_steps = [
{'title': 'Setting up ssh keys',
'functions':[install_keys]},
{'title': 'Discovering hosts\' details',
'functions': [discover]},
{'title': 'Adding pre install manifest entries',
'functions':[create_manifest]},
]
if controller.CONF['CONFIG_NTP_SERVERS']:
prescript_steps.append({
'title': 'Installing time synchronization via NTP',
'functions': [create_ntp_manifest],
})
else:
controller.MESSAGES.append('Time synchronization installation '
'was skipped. Please note that '
'unsynchronized time on server '
'instances might be problem for '
'some OpenStack components.')
controller.addSequence("Running pre install scripts", [], [],
prescript_steps)
def install_keys(config):
with open(config["CONFIG_SSH_KEY"]) as fp:
sshkeydata = fp.read().strip()
for hostname in filtered_hosts(config):
if '/' in hostname:
hostname = hostname.split('/')[0]
server = utils.ScriptRunner(hostname)
# TODO replace all that with ssh-copy-id
server.append("mkdir -p ~/.ssh")
server.append("chmod 500 ~/.ssh")
server.append("grep '%s' ~/.ssh/authorized_keys > /dev/null 2>&1 || "
"echo %s >> ~/.ssh/authorized_keys"
% (sshkeydata, sshkeydata))
server.append("chmod 400 ~/.ssh/authorized_keys")
server.append("restorecon -r ~/.ssh")
server.execute()
def discover(config):
"""
Discovers details about hosts.
"""
# TODO: Once Controller is refactored, move this function to it (facter can
# be used for that too).
details = {}
release_regexp = re.compile(r'^(?P<OS>.*) release (?P<release>[\d\.]*)')
for host in filtered_hosts(config):
details.setdefault(host, {})
server = utils.ScriptRunner(host)
# discover OS and release
server.append('cat /etc/redhat-release')
try:
rc, out = server.execute()
match = release_regexp.search(out)
if not match:
raise exceptions.ScriptRuntimeError()
except exceptions.ScriptRuntimeError:
details[host]['os'] = 'Unknown'
details[host]['release'] = 'Unknown'
else:
opsys = match.group('OS')
for pattern, surr in [('^Red Hat Enterprise Linux.*', 'RHEL'),
('^Fedora.*', 'Fedora'),
('^CentOS.*', 'CentOS'),
('^Scientific Linux.*', 'SL')]:
opsys = re.sub(pattern, surr, opsys)
details[host]['os'] = opsys
details[host]['release'] = match.group('release')
# Create the packstack tmp directory
server.clear()
server.append("mkdir -p %s" % basedefs.PACKSTACK_VAR_DIR)
# Separately create the tmp directory for this packstack run, this will
# fail if the directory already exists
host_dir = os.path.join(basedefs.PACKSTACK_VAR_DIR, uuid.uuid4().hex)
server.append("mkdir --mode 0700 %s" % host_dir)
for i in ('modules', 'resources'):
server.append("mkdir --mode 0700 %s" % os.path.join(host_dir, i))
server.execute()
details[host]['tmpdir'] = host_dir
config['HOST_DETAILS'] = details
def create_manifest(config):
key = 'CONFIG_DEBUG_MODE'
config[key] = config[key] == 'y' and 'true' or 'false'
for hostname in filtered_hosts(config):
manifestfile = "%s_prescript.pp" % hostname
manifestdata = getManifestTemplate("prescript.pp")
appendManifestFile(manifestfile, manifestdata)
def create_ntp_manifest(config):
srvlist = [i.strip()
for i in config['CONFIG_NTP_SERVERS'].split(',')
if i.strip()]
config['CONFIG_NTP_SERVERS'] = ' '.join(srvlist)
definiton = '\n'.join(['server %s' % i for i in srvlist])
config['CONFIG_NTP_SERVER_DEF'] = '%s\n' % definiton
marker = uuid.uuid4().hex[:16]
for hostname in filtered_hosts(config):
manifestdata = getManifestTemplate('ntpd.pp')
appendManifestFile('%s_ntpd.pp' % hostname,
manifestdata,
marker=marker)