-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpost_install.py
executable file
·1128 lines (980 loc) · 37.8 KB
/
post_install.py
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Post install steps file for Goldstone Server."""
# Copyright 2015 Solinea, Inc.
#
# 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.
from __future__ import print_function
import os
import django
from django.core.exceptions import ObjectDoesNotExist
from fabric.colors import green, cyan, red
from fabric.contrib.files import upload_template, exists
from fabric.decorators import task
from fabric.utils import fastprint
from fabric.operations import prompt, run, settings as fab_settings
import operator
INSTALL_DIR = os.environ.get('APPDIR') # set in the Dockerfile
SETTINGS = os.environ.get('DJANGO_SETTTINGS_MODULE') # set in compose env
PROD_CONFIG = INSTALL_DIR + "/config"
def cloud_init(gs_tenant,
stack_tenant,
stack_user,
stack_password,
stack_auth_url,
settings=SETTINGS,
install_dir=INSTALL_DIR):
"""Create a single OpenStack cloud under the tenant.
:keyword gs_tenant: The name of the tenant to be created. If not specified,
a default is used.
:type gs_tenant: str
:keyword stack_tenant: The openstack tenant to associate with this tenant
:type stack_tenant: str
:keyword stack_admin: The openstack username to authenticate with
:type stack_admin: str
:keyword stack_password: The openstack password to authenticate with
:type stack_password: str
:keyword stack_auth_url: The openstack auth url (without version)
:type stack_auth_url: str
:keyword settings: The path of the Django settings file to use.
:type settings: str
:keyword install_dir: The path to the Goldstone installation directory.
:type install_dir: str
"""
import re
from goldstone.tenants.models import Cloud
# production deployments will generally have the user configure settings
# upon first login.
if stack_tenant is None or stack_user is None or stack_auth_url is None \
or stack_password is None:
fastprint("\nSkipping cloud setup.")
return None
# developers may want to put the connection settings in the docker env
# since they will redeploy often.
try:
# Note: There's a db unique constraint on (tenant, tenant_name, and
# username).
Cloud.objects.get(tenant=gs_tenant,
tenant_name=stack_tenant,
username=stack_user)
except ObjectDoesNotExist:
# Create the row!
Cloud.objects.create(tenant=gs_tenant,
tenant_name=stack_tenant,
username=stack_user,
password=stack_password,
auth_url=stack_auth_url)
else:
fastprint("\nCloud entry already exists.")
def django_admin_init(username='admin',
password=None,
email='root@localhost',
settings=SETTINGS,
install_dir=INSTALL_DIR):
"""Create the Django admin user.
:keyword username: the django admin user name
:type username: str
:keyword password: the django admin password
:type password: str
:keyword email: the django admin email
:type email: str
:keyword settings: The path of the Django settings file to use.
:type settings: str
:keyword install_dir: The path to the Goldstone installation directory.
:type install_dir: str
"""
from django.contrib.auth import get_user_model
try:
get_user_model().objects.get(username=username)
except ObjectDoesNotExist:
fastprint(green("Creating Django admin account.\n"))
if password is None:
password = prompt(cyan("Enter Django admin password: "))
get_user_model().objects.create_superuser(username, email, password)
fastprint("done.\n")
else:
# The tenant_admin already exists. Print a message.
fastprint("Account %s already exists. We will use it.\n" % username)
def tenant_init(gs_tenant='default',
gs_tenant_owner='None',
gs_tenant_admin='gsadmin',
gs_tenant_admin_password=None,
settings=SETTINGS,
install_dir=INSTALL_DIR):
"""Create a tenant and default_tenant_admin, or use existing ones.
If the tenant doesn't exist, we create it. If the admin doesn't exist, we
create it as the default_tenant_admin, and the tenant's tenant_admin.
If the tenant already exists, we print an informational message and leave
it alone.
If the admin already exists, we print an informational message. If he/she
is not a tenant admin of the new tenant, we make him/her it. He/she gets
made the (a) default_tenant_admin.
:keyword gs_tenant: The name of the tenant to be created. If not specified,
a default is used.
:type gs_tenant: str
:keyword gs_tenant_owner: The tenant owner. If unspecified, a default is
used
:type gs_tenant_owner: str
:keyword gs_tenant_admin: The name of the tenant_admin to be created. If
unspecified, a default is used
:type gs_tenant_admin: str
:keyword gs_tenant_admin_password: The admin account's password, *if* we
create it
:type gs_tenant_admin_password: str
:keyword settings: The path of the Django settings file to use.
:type settings: str
:keyword install_dir: The path to the Goldstone installation directory.
:type install_dir: str
"""
from django.contrib.auth import get_user_model
from goldstone.tenants.models import Tenant
print(green(
"\nInitializing the Goldstone tenant and OpenStack connection."))
# Process the tenant.
try:
tenant = Tenant.objects.get(name=gs_tenant)
fastprint("\nTenant %s already exists.\n" % tenant)
except ObjectDoesNotExist:
# The tenant does not already exist. Create it.
tenant = Tenant.objects.create(name=gs_tenant,
owner=gs_tenant_owner)
# Process the tenant admin.
try:
user = get_user_model().objects.get(username=gs_tenant_admin)
# The tenant_admin already exists. Print a message.
fastprint("\nAdmin account %s already exists.\n\n" %
gs_tenant_admin)
except ObjectDoesNotExist:
fastprint("Creating Goldstone tenant admin account.")
if gs_tenant_admin_password is None:
gs_tenant_admin_password = prompt(
cyan("\nEnter Goldstone admin password: "))
user = get_user_model().objects.create_user(
username=gs_tenant_admin, password=gs_tenant_admin_password)
# Link the tenant_admin account to this tenant.
user.tenant = tenant
user.tenant_admin = True
user.default_tenant_admin = True
user.save()
return tenant
def docker_install():
"""Create Goldstone default tenant and initialize cloud, deriving values
from environment variables provided in the Dockerfile.
If env vars are not provided by the container, then the install will be
made in a way that is configured for the goldstone developer environment.
Supported env vars are:
DJANGO_SETTINGS_MODULE (default: goldstone.settings.docker)
DJANGO_ADMIN_USER (default: admin)
DJANGO_ADMIN_PASSWORD (default: goldstone)
DJANGO_ADMIN_EMAIL (default: root@localhost)
GOLDSTONE_TENANT_ADMIN_PASSWORD (default: goldstone)
OS_TENANT_NAME (default: admin)
OS_USERNAME (default: admin)
OS_PASSWORD (default: solinea)
OS_AUTH_URL (default: http://172.24.4.100:5000/v2.0/)
"""
# pull params out of the environment
django_admin_user = os.environ.get('DJANGO_ADMIN_USER', 'admin')
django_admin_password = os.environ.get(
'DJANGO_ADMIN_PASSWORD', 'goldstone')
django_admin_email = os.environ.get('DJANGO_ADMIN_EMAIL', 'root@localhost')
gs_tenant = 'default'
gs_tenant_owner = 'None'
gs_tenant_admin = 'gsadmin'
gs_tenant_admin_password = os.environ.get(
'GOLDSTONE_TENANT_ADMIN_PASSWORD', 'goldstone')
stack_tenant = os.environ.get('OS_TENANT_NAME')
stack_user = os.environ.get('OS_USERNAME')
stack_password = os.environ.get('OS_PASSWORD')
stack_auth_url = os.environ.get('OS_AUTH_URL', None)
print(green("Setting up Django admin account."))
django_admin_init(
username=django_admin_user,
password=django_admin_password,
email=django_admin_email
)
print(green("Setting up default Goldstone tenant admin account."))
tenant = tenant_init(
gs_tenant,
gs_tenant_owner,
gs_tenant_admin,
gs_tenant_admin_password
)
django_settings = os.environ.get('DJANGO_SETTINGS_MODULE', None)
print(green("DJANGO_SETTINGS_MODULE = %s" % django_settings))
print(green("OS_TENANT_NAME = %s" % stack_tenant))
print(green("OS_USERNAME = %s" % stack_user))
print(green("OS_AUTH_URL = %s" % stack_auth_url))
print(green("Initializing connection to OpenStack cloud."))
cloud_init(
tenant,
stack_tenant,
stack_user,
stack_password,
stack_auth_url
)
#################################################
# openstack node configuration support below here
#################################################
def _set_single_value_configs(file_name, edits_list):
"""
Edits StrOpt entries in a config file.
:param file_name: the config file name
:param edits_list: the list of edits to make
:return: None
"""
if exists(file_name, use_sudo=True, verbose=True):
print(green("\tEditing %s" % file_name))
for config_entry in edits_list:
cmd = "crudini --existing=file --set %s %s %s '%s'" % \
(file_name, config_entry['section'],
config_entry['parameter'], config_entry['value'])
run(cmd)
print(green("\tSet %s:%s to %s" %
(config_entry['section'], config_entry['parameter'],
config_entry['value'])))
else:
raise IOError("File not found: %s" % file_name)
def _set_multi_value_configs(file_name, edits_list):
"""
Edits MultiStrOpt entries in a config file. Currently only supports adding
a new parameter.
:param file_name: the config file name
:param edits_list: the list of edits to make
:return: None
"""
import re
from fabric.contrib.files import sed, contains
if exists(file_name, use_sudo=True, verbose=True):
print(green("\tEditing %s" % file_name))
for config_entry in edits_list:
# hopefully match all forms of key = [other_val] val [other_val]
# while avoiding key = [other_val] xvalx [other_val]
# pylint: disable=W1401
empty_setting_regex = '^\<%s\>[:space:]*=[:space]*$' % \
(config_entry['parameter'])
setting_regex = '^\<%s\>[ \t]*=.*\<%s\>.*$' % \
(config_entry['parameter'], config_entry['value'])
empty_setting_exists = contains(
file_name, empty_setting_regex, escape=False)
setting_exists = contains(
file_name, setting_regex, escape=False)
if not setting_exists and empty_setting_exists:
print(green("\tReplacing empty %s entry" %
(config_entry['parameter'])))
sed(file_name,
'^%s[\s]*=[\s]*$' % (config_entry['parameter']),
'%s = %s' % (config_entry['parameter'],
config_entry['value']),
backup='.gsbak')
# we have our own backup, so delete the one that sed made
run("rm %s.gsbak" % file_name)
elif not setting_exists:
# add a new line to the appropriate section
print(green("\tAdding new %s entry" %
(config_entry['parameter'])))
sed(file_name,
'^\[%s\][\s]*$' % (config_entry['section']),
'\[%s\]\\n%s = %s' % (config_entry['section'],
config_entry['parameter'],
config_entry['value']),
backup='.gsbak')
# we have our own backup, so delete the one that sed made
run("rm %s.gsbak" % file_name)
else:
print(green("\tNo changes required for %s" %
(config_entry['parameter'])))
else:
raise IOError("File not found: %s" % file_name)
def _backup_config_file(file_name, backup_postfix, previously_backed_up):
"""Back up a configuration file if it hasn't been backed up already.
:param file_name: name of file
:param backup_postfix: postfix to append
:param previously_backed_up: list of already backed up files
:return: updated previously backed up files
"""
if file_name not in previously_backed_up and \
exists(file_name, use_sudo=True, verbose=True):
backup_file = file_name + "." + str(backup_postfix)
run("cp " + file_name + " " + backup_file)
previously_backed_up.append(file_name)
return previously_backed_up
def _configure_service(service_name, backup_postfix, single_value_edits,
multi_value_edits, template_dir, template_files):
"""
Configure a service as defined in the supplied params.
:param service_name: eg: Nova
:param single_value_edits: dict of configuration instructions
:param multi_value_edits: dict of configuration instructions
:param template_dir: directory on calling host where templates are found
:param template_files: dict of configuration instructions
:return:
"""
backed_up_files = []
with fab_settings(warn_only=True, user="root"):
print(green("\nConfiguring %s" % service_name))
# process config changes for single value entries
for entry in single_value_edits.items():
file_name = entry[0]
backed_up_files = _backup_config_file(
file_name, backup_postfix, backed_up_files)
# set StrOpt values
try:
_set_single_value_configs(file_name, entry[1])
except IOError:
pass
# process config changes for multi value entries
for entry in multi_value_edits.items():
file_name = entry[0]
backed_up_files = _backup_config_file(
file_name, backup_postfix, backed_up_files)
# set MultiStrOpt values
try:
_set_multi_value_configs(file_name, entry[1])
except IOError:
pass
# upload template files
for entry in template_files:
file_name = entry['file']
template_name = entry['template']
template_context = entry['context'] if 'context' in entry else {}
backed_up_files = _backup_config_file(
file_name, backup_postfix, backed_up_files)
upload_template(
template_name,
file_name,
context=template_context,
template_dir=template_dir,
backup=False)
@task
def _configure_nova(backup_postfix, restart='yes', config_loc=PROD_CONFIG):
"""Configures nova on OpenStack hosts.
:param backup_postfix: A string to append to any config files that are
backed up (a timestamp would be nice).
:type backup_postfix: str
:param restart: restart the service? (yes/no)
:type restart: str
"""
single_value_edits = {
"/etc/nova/nova.conf": [
{
"section": "DEFAULT",
"parameter": "syslog_log_facility",
"value": "LOG_LOCAL0"},
{
"section": "DEFAULT",
"parameter": "use_syslog",
"value": str(True)
},
{
"section": "DEFAULT",
"parameter": "verbose",
"value": str(True)
},
{
"section": "DEFAULT",
"parameter": "instance_usage_audit",
"value": str(True)
},
{
"section": "DEFAULT",
"parameter": "instance_usage_audit_period",
"value": "hour"
},
{
"section": "DEFAULT",
"parameter": "notify_on_state_change",
"value": "vm_and_task_state"
},
],
"/etc/nova/api-paste.ini": [
{
"section": "composite:openstack_compute_api_v2",
"parameter": "keystone",
"value": "compute_req_id faultwrap sizelimit authtoken "
"keystonecontext ratelimit audit osapi_compute_app_v2"
},
{
"section": "composite:openstack_compute_api_v2",
"parameter": "keystone_nolimit",
"value": "compute_req_id faultwrap sizelimit authtoken "
"keystonecontext audit osapi_compute_app_v2"
},
{
"section": "composite:openstack_compute_api_v21",
"parameter": "keystone",
"value": "compute_req_id faultwrap sizelimit authtoken "
"keystonecontext audit osapi_compute_app_v21"
},
{
"section": "composite:openstack_compute_api_v3",
"parameter": "keystone",
"value": "request_id faultwrap sizelimit authtoken "
"keystonecontext audit osapi_compute_app_v3"
},
{
"section": "filter:audit",
"parameter": "paste.filter_factory",
"value": "keystonemiddleware.audit:filter_factory"
},
{
"section": "filter:audit",
"parameter": "audit_map_file",
"value": "/etc/nova/nova_api_audit_map.conf"
}
]
}
# config lines that accept multiple values per line
multi_value_edits = {
"/etc/nova/nova.conf": [
{
"section": "DEFAULT",
"parameter": "notification_driver",
"value": "messagingv2"
}
]
}
template_dir = os.path.join(config_loc, "nova")
template_files = [
{
"file": "/etc/nova/nova_api_audit_map.conf",
"template": "nova_api_audit_map.conf.template"
}
]
_configure_service('Nova', backup_postfix, single_value_edits,
multi_value_edits, template_dir, template_files)
if restart == 'yes':
print(green("\nRestarting Nova service."))
run("openstack-service restart nova")
else:
print(green("\nRestart Nova to apply changes."))
@task
def _configure_cinder(backup_postfix, restart='yes', config_loc=PROD_CONFIG):
"""Configures cinder on OpenStack hosts.
:param backup_postfix: A string to append to any config files that are
backed up (a timestamp would be nice).
:type backup_postfix: str
:param restart: restart the service? (yes/no)
:type restart: str
"""
single_value_edits = {
"/etc/cinder/cinder.conf": [
{
"section": "DEFAULT",
"parameter": "syslog_log_facility",
"value": "LOG_LOCAL5"},
{
"section": "DEFAULT",
"parameter": "use_syslog",
"value": str(True)
},
{
"section": "DEFAULT",
"parameter": "verbose",
"value": str(True)
},
{
"section": "DEFAULT",
"parameter": "control_exchange",
"value": "cinder"
}
],
"/etc/cinder/api-paste.ini": [
{
"section": "composite:openstack_volume_api_v1",
"parameter": "keystone",
"value": "request_id faultwrap sizelimit osprofiler authtoken "
"keystonecontext audit apiv1"
},
{
"section": "composite:openstack_volume_api_v1",
"parameter": "keystone_nolimit",
"value": "request_id faultwrap sizelimit osprofiler authtoken "
"keystonecontext audit apiv1"
},
{
"section": "composite:openstack_volume_api_v2",
"parameter": "keystone",
"value": "request_id faultwrap sizelimit osprofiler authtoken "
"keystonecontext audit apiv2"
},
{
"section": "composite:openstack_volume_api_v2",
"parameter": "keystone_nolimit",
"value": "request_id faultwrap sizelimit osprofiler authtoken "
"keystonecontext audit apiv2"
},
{
"section": "filter:audit",
"parameter": "paste.filter_factory",
"value": "keystonemiddleware.audit:filter_factory"
},
{
"section": "filter:audit",
"parameter": "audit_map_file",
"value": "/etc/cinder/cinder_api_audit_map.conf"
}
]
}
# config lines that accept multiple values per line
multi_value_edits = {
"/etc/cinder/cinder.conf": [
{
"section": "DEFAULT",
"parameter": "notification_driver",
"value": "messagingv2"
}
]
}
template_dir = os.path.join(config_loc, "cinder")
template_files = [
{
"file": "/etc/cinder/cinder_api_audit_map.conf",
"template": "cinder_api_audit_map.conf.template"
}
]
_configure_service('Cinder', backup_postfix, single_value_edits,
multi_value_edits, template_dir, template_files)
if restart == 'yes':
print(green("\nRestarting Cinder service."))
run("openstack-service restart cinder")
else:
print(green("\nRestart Cinder to apply changes."))
@task
def _configure_keystone(backup_postfix, restart='yes', config_loc=PROD_CONFIG):
"""Configures keystone on OpenStack hosts.
:param backup_postfix: A string to append to any config files that are
backed up (a timestamp would be nice).
:type backup_postfix: str
:param restart: restart the service? (yes/no)
:type restart: str
"""
single_value_edits = {
"/etc/keystone/keystone.conf": [
{
"section": "DEFAULT",
"parameter": "syslog_log_facility",
"value": "LOG_LOCAL6"},
{
"section": "DEFAULT",
"parameter": "use_syslog",
"value": str(True)
},
{
"section": "DEFAULT",
"parameter": "verbose",
"value": str(True)
},
{
"section": "DEFAULT",
"parameter": "notification_format",
"value": "cadf"
},
]
}
# config lines that accept multiple values per line
multi_value_edits = {
"/etc/keystone/keystone.conf": [
{
"section": "DEFAULT",
"parameter": "notification_driver",
"value": "messaging"
}
]
}
template_dir = os.path.join(config_loc, "keystone")
template_files = []
_configure_service('Keystone', backup_postfix, single_value_edits,
multi_value_edits, template_dir, template_files)
if restart == 'yes':
print(green("\nRestarting Keystone service."))
run("systemctl restart httpd")
else:
print(green("\nRestart Keystone to apply changes."))
@task
def _configure_neutron(backup_postfix, restart='yes', config_loc=PROD_CONFIG):
"""Configures neutron on OpenStack hosts.
:param backup_postfix: A string to append to any config files that are
backed up (a timestamp would be nice).
:type backup_postfix: str
:param restart: restart the service? (yes/no)
:type restart: str
"""
single_value_edits = {
"/etc/neutron/neutron.conf": [
{
"section": "DEFAULT",
"parameter": "syslog_log_facility",
"value": "LOG_LOCAL2"},
{
"section": "DEFAULT",
"parameter": "use_syslog",
"value": str(True)
},
{
"section": "DEFAULT",
"parameter": "verbose",
"value": str(True)
}
],
"/etc/neutron/api-paste.ini": [
{
"section": "composite:neutronapi_v2_0",
"parameter": "use",
"value": "call:neutron.auth:pipeline_factory"
},
{
"section": "composite:neutronapi_v2_0",
"parameter": "noauth",
"value": "request_id catch_errors extensions "
"neutronapiapp_v2_0"
},
{
"section": "composite:neutronapi_v2_0",
"parameter": "keystone",
"value": "request_id catch_errors authtoken keystonecontext "
"audit extensions neutronapiapp_v2_0"
},
{
"section": "filter:audit",
"parameter": "paste.filter_factory",
"value": "keystonemiddleware.audit:filter_factory"
},
{
"section": "filter:audit",
"parameter": "audit_map_file",
"value": "/etc/neutron/neutron_api_audit_map.conf"
},
]
}
# config lines that accept multiple values per line
multi_value_edits = {
"/etc/neutron/neutron.conf": [
{
"section": "DEFAULT",
"parameter": "notification_driver",
"value": "neutron.openstack.common.notifier.rpc_notifier"
}
]
}
template_dir = os.path.join(config_loc, "neutron")
template_files = [
{
"file": "/etc/neutron/neutron_api_audit_map.conf",
"template": "neutron_api_audit_map.conf.template"
}
]
_configure_service('Neutron', backup_postfix, single_value_edits,
multi_value_edits, template_dir, template_files)
if restart == 'yes':
print(green("\nRestarting Neutron service."))
run("openstack-service restart neutron")
else:
print(green("\nRestart Neutron to apply changes."))
@task
def _configure_glance(backup_postfix, restart='yes', config_loc=PROD_CONFIG):
"""Configures glance on OpenStack hosts.
:param backup_postfix: A string to append to any config files that are
backed up (a timestamp would be nice).
:type backup_postfix: str
:param restart: restart the service? (yes/no)
:type restart: str
"""
single_value_edits = {
"/etc/glance/glance-cache.conf": [
{
"section": "DEFAULT",
"parameter": "syslog_log_facility",
"value": "LOG_LOCAL1"},
{
"section": "DEFAULT",
"parameter": "use_syslog",
"value": str(True)
},
{
"section": "DEFAULT",
"parameter": "verbose",
"value": str(True)
}
],
"/etc/glance/glance-api.conf": [
{
"section": "DEFAULT",
"parameter": "syslog_log_facility",
"value": "LOG_LOCAL1"},
{
"section": "DEFAULT",
"parameter": "use_syslog",
"value": str(True)
},
{
"section": "DEFAULT",
"parameter": "verbose",
"value": str(True)
},
{
"section": "paste_deploy",
"parameter": "config_file",
"value": "/etc/glance/glance-api-paste.ini"
}
],
"/etc/glance/glance-registry.conf": [
{
"section": "DEFAULT",
"parameter": "syslog_log_facility",
"value": "LOG_LOCAL1"},
{
"section": "DEFAULT",
"parameter": "use_syslog",
"value": str(True)
},
{
"section": "DEFAULT",
"parameter": "verbose",
"value": str(True)
}
],
"/etc/glance/glance-scrubber.conf": [
{
"section": "DEFAULT",
"parameter": "syslog_log_facility",
"value": "LOG_LOCAL1"},
{
"section": "DEFAULT",
"parameter": "use_syslog",
"value": str(True)
},
{
"section": "DEFAULT",
"parameter": "verbose",
"value": str(True)
}
],
}
# config lines that accept multiple values per line
multi_value_edits = {
"/etc/glance/glance-api.conf": [
{
"section": "DEFAULT",
"parameter": "notification_driver",
"value": "messagingv2"
}
],
"/etc/glance/glance-registry.conf": [
{
"section": "DEFAULT",
"parameter": "notification_driver",
"value": "messagingv2"
}
]
}
template_dir = os.path.join(config_loc, "glance")
template_files = [
{
"file": "/etc/glance/glance-api-paste.ini",
"template": "glance-api-paste.ini.template"
},
{
"file": "/etc/glance/glance_api_audit_map.conf",
"template": "glance_api_audit_map.conf.template"
}
]
_configure_service('Glance', backup_postfix, single_value_edits,
multi_value_edits, template_dir, template_files)
if restart == 'yes':
print(green("\nRestarting Glance service."))
run("openstack-service restart glance")
else:
print(green("\nRestart Glance to apply changes."))
@task
def _configure_ceilometer(backup_postfix, goldstone_addr, restart='yes',
config_loc=PROD_CONFIG):
"""Configures ceilometer on OpenStack hosts.
:param backup_postfix: A string to append to any config files that are
backed up (a timestamp would be nice).
:type backup_postfix: str
:param goldstone_addr: IP address of the goldstone server
:type goldstone_addr: str
:param restart: restart the service? (yes/no)
:type restart: str
"""
single_value_edits = {
"/etc/ceilometer/ceilometer.conf": [
{
"section": "event",
"parameter": "definitions_cfg_file",
"value": "event_definitions.yaml"
},
{
"section": "event",
"parameter": "drop_unmatched_notifications",
"value": str(False)
},
{
"section": "notification",
"parameter": "store_events",
"value": str(True)
},
{
"section": "notification",
"parameter": "disable_non_metric_meters",
"value": str(True)
},
{
"section": "database",
"parameter": "event_connection",
"value": "es://%s:9200" % goldstone_addr
},
{
"section": "database",
"parameter": "time_to_live",
"value": "604800" # one week
},
],
"/etc/ceilometer/api_paste.ini": [
{
"section": "pipeline:main",
"parameter": "pipeline",
"value": "request_id authtoken audit api-server"
},
{
"section": "filter:audit",
"parameter": "paste.filter_factory",
"value": "keystonemiddleware.audit:filter_factory"
},
{
"section": "filter:audit",
"parameter": "audit_map_file",
"value": "/etc/ceilometer/ceilometer_api_audit_map.conf"
},
]
}
# config lines that accept multiple values per line
multi_value_edits = {}
template_dir = os.path.join(config_loc, "ceilometer")
template_files = [
{
"file": "/etc/ceilometer/event_pipeline.yaml",
"template": "event_pipeline.yaml.template"
},
{
"file": "/etc/ceilometer/event_definitions.yaml",
"template": "event_definitions.yaml.template"
},
]
_configure_service('Ceilometer', backup_postfix, single_value_edits,
multi_value_edits, template_dir, template_files)
if restart == 'yes':
print(green("\nRestarting Ceilometer service."))
run("openstack-service restart ceilometer")
else:
print(green("\nRestart Ceilometer to apply changes."))