forked from StackOps/stackops-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.py
2309 lines (2004 loc) · 112 KB
/
configuration.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
# Copyright 2011 STACKOPS TECHNOLOGIES S.L.
#
# 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 Feb 21, 2011
@author: Diego Parrilla
"""
import getpass
import flags
import install
import utils
import os, os.path
import shutil
import re
import time
import base64
from twisted.python import log
class VanillaConfig(object):
'''
classdocs
'''
_DEBUG = True
_filename = "nofilename"
_flags = flags.Flags()
_filler = install.Filler()
_operatingsystem = install.OperatingSystem()
def __init__(self):
"""
Constructor
"""
def _readFile(self, filename):
return self._flags.readFile("/etc/nova", filename)
def _writeFile(self, filename, parameters):
self._flags.writeFile("/etc/nova", filename, parameters)
def readXML(self):
raise NotImplementedError("Should have implemented this")
def writeXML(self):
raise NotImplementedError("Should have implemented this")
def install(self, hostname):
raise NotImplementedError("Should have implemented this")
def uninstall(self, hostname):
raise NotImplementedError("Should have implemented this")
def write(self, xmldoc):
raise NotImplementedError("Should have implemented this")
def _installDeb(self, name, interactive=True):
if interactive:
utils.execute('apt-get -y install %s' % name)
else:
utils.execute('DEBIAN_FRONTEND=noninteractive apt-get -y install %s' % name)
def installPackages(self):
raise NotImplementedError("Should have implemented this")
def whatIsMyIp(self, management_interface):
iface_list = self._operatingsystem.getNetworkConfiguration()
myip = '127.0.0.1'
for iface in iface_list:
if iface['name'] == management_interface:
myip = iface['address']
return myip
class Config(VanillaConfig):
'''
classdocs
'''
def installPackagesCommon(self):
# self._installDeb('collectd-core')
# self._installDeb('snmp')
# self._installDeb('snmpd')
print
class MySQLMasterConfig(Config):
def __init__(self):
"""
Constructor
"""
# Write the parameters (if possible) from the xml file
def write(self, xmldoc):
# Basic Infrastructure Services
self.install_mysql = self._filler.getPropertyValue(xmldoc, 'infrastructure', 'install_mysql', 'true') == 'true'
self.mysql_root_password = self._filler.getPropertyValue(xmldoc, 'infrastructure', 'mysql_password', 'stackops')
# NOVA database configuration
self.nova_username = self._filler.getPropertyValue(xmldoc, 'database', 'username', 'nova')
self.nova_password = self._filler.getPropertyValue(xmldoc, 'database', 'password', 'nova')
self.nova_schema = self._filler.getPropertyValue(xmldoc, 'database', 'schema', 'nova')
self.nova_drop_schema = self._filler.getPropertyValue(xmldoc, 'database', 'dropschema', 'true') == 'true'
# GLANCE database configuration
self.glance_username = self._filler.getPropertyValue(xmldoc, 'glance_database', 'username', 'glance')
self.glance_password = self._filler.getPropertyValue(xmldoc, 'glance_database', 'password', 'nova')
self.glance_schema = self._filler.getPropertyValue(xmldoc, 'glance_database', 'schema', 'glance')
self.glance_drop_schema = self._filler.getPropertyValue(xmldoc, 'glance_database', 'dropschema',
'true') == 'true'
# KEYSTONE database configuration
self.keystone_username = self._filler.getPropertyValue(xmldoc, 'keystone_database', 'username', 'keystone')
self.keystone_password = self._filler.getPropertyValue(xmldoc, 'keystone_database', 'password', 'nova')
self.keystone_schema = self._filler.getPropertyValue(xmldoc, 'keystone_database', 'schema', 'keystone')
self.keystone_drop_schema = self._filler.getPropertyValue(xmldoc, 'keystone_database', 'dropschema',
'true') == 'true'
# PORTAL database configuration
self.portal_username = self._filler.getPropertyValue(xmldoc, 'portal_database', 'username', 'portal')
self.portal_password = self._filler.getPropertyValue(xmldoc, 'portal_database', 'password', 'portal')
self.portal_schema = self._filler.getPropertyValue(xmldoc, 'portal_database', 'schema', 'portal')
self.portal_drop_schema = self._filler.getPropertyValue(xmldoc, 'portal_database', 'dropschema',
'true') == 'true'
return
def _configureMySQL(self):
utils.execute("sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf")
utils.execute('service mysql restart')
if self.nova_drop_schema:
utils.execute('mysql -uroot -p%s -e "DROP DATABASE IF EXISTS nova;"' % self.mysql_root_password,
check_exit_code=False)
if self.glance_drop_schema:
utils.execute('mysql -uroot -p%s -e "DROP DATABASE IF EXISTS glance;"' % self.mysql_root_password,
check_exit_code=False)
if self.keystone_drop_schema:
utils.execute('mysql -uroot -p%s -e "DROP DATABASE IF EXISTS keystone;"' % self.mysql_root_password,
check_exit_code=False)
if self.portal_drop_schema:
utils.execute('mysql -uroot -p%s -e "DROP DATABASE IF EXISTS portal;"' % self.mysql_root_password,
check_exit_code=False)
utils.execute('mysql -uroot -p%s -e "CREATE DATABASE %s default character set utf8;"' % (self.mysql_root_password, self.nova_schema))
utils.execute('mysql -uroot -p%s -e "CREATE DATABASE %s default character set utf8;"' % (self.mysql_root_password, self.glance_schema))
utils.execute('mysql -uroot -p%s -e "CREATE DATABASE %s default character set utf8;"' % (self.mysql_root_password, self.keystone_schema))
utils.execute('mysql -uroot -p%s -e "CREATE DATABASE %s default character set utf8;"' % (self.mysql_root_password, self.portal_schema))
utils.execute(
'''mysql -uroot -p%s -e "GRANT ALL PRIVILEGES ON %s.* TO '%s'@'localhost' IDENTIFIED BY '%s';"''' % (
self.mysql_root_password, self.portal_schema, self.portal_username, self.portal_password))
utils.execute('''mysql -uroot -p%s -e "GRANT ALL PRIVILEGES ON %s.* TO '%s'@'%%' IDENTIFIED BY '%s';"''' % (
self.mysql_root_password, self.portal_schema, self.portal_username, self.portal_password))
if self.nova_username == 'root' and self.glance_username == 'root' and self.keystone_username == 'root':
utils.execute(
'''mysql -uroot -p%s -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%%' IDENTIFIED BY '%s';"''' % (
self.mysql_root_password, self.mysql_root_password))
else:
utils.execute(
'''mysql -uroot -p%s -e "GRANT ALL PRIVILEGES ON %s.* TO '%s'@'localhost' IDENTIFIED BY '%s';"''' % (
self.mysql_root_password, self.nova_schema, self.nova_username, self.nova_password))
utils.execute(
'''mysql -uroot -p%s -e "GRANT ALL PRIVILEGES ON %s.* TO '%s'@'localhost' IDENTIFIED BY '%s';"''' % (
self.mysql_root_password, self.glance_schema, self.glance_username, self.glance_password))
utils.execute(
'''mysql -uroot -p%s -e "GRANT ALL PRIVILEGES ON %s.* TO '%s'@'localhost' IDENTIFIED BY '%s';"''' % (
self.mysql_root_password, self.keystone_schema, self.keystone_username, self.keystone_password))
utils.execute('''mysql -uroot -p%s -e "GRANT ALL PRIVILEGES ON %s.* TO '%s'@'%%' IDENTIFIED BY '%s';"''' % (
self.mysql_root_password, self.nova_schema, self.nova_username, self.nova_password))
utils.execute('''mysql -uroot -p%s -e "GRANT ALL PRIVILEGES ON %s.* TO '%s'@'%%' IDENTIFIED BY '%s';"''' % (
self.mysql_root_password, self.glance_schema, self.glance_username, self.glance_password))
utils.execute('''mysql -uroot -p%s -e "GRANT ALL PRIVILEGES ON %s.* TO '%s'@'%%' IDENTIFIED BY '%s';"''' % (
self.mysql_root_password, self.keystone_schema, self.keystone_username, self.keystone_password))
def install(self, hostname):
"""
Install all stuff needed to run a mysql database for Nova
"""
result = ''
try:
if getpass.getuser() == 'root':
# Install packages for component
self.installPackages()
self._configureMySQL()
except Exception as inst:
result = 'ERROR: %s' % str(inst)
return result
def uninstall(self, hostname):
"""
MySQL database cannot be uninstalled.
"""
raise NotImplementedError("MySQL Database cannot be uninstalled.")
def installPackages(self):
self.installPackagesCommon()
utils.execute(
'echo mysql-server-5.5 mysql-server/root_password password ' + self.mysql_root_password + ' | debconf-set-selections')
utils.execute(
'echo mysql-server-5.5 mysql-server/root_password_again password ' + self.mysql_root_password + ' | debconf-set-selections')
utils.execute('echo mysql-server-5.5 mysql-server/start_on_boot boolean true')
self._installDeb('mysql-server python-mysqldb')
class RabbitMQMasterConfig(Config):
def __init__(self):
"""
Constructor
"""
# Write the parameters (if possible) from the xml file
def write(self, xmldoc):
# Basic Infrastructure Services
self.install_rabbitmq = self._filler.getPropertyValue(xmldoc, 'infrastructure', 'install_rabbitmq',
'true') == 'true'
return
def _configureRabbitMQ(self):
# Do nothing (security here????)
return
def install(self, hostname):
"""
Install all stuff needed to run RabbitMQ for Nova
"""
result = ''
try:
if getpass.getuser() == 'root':
# Install packages for component
self.installPackages()
self._configureRabbitMQ()
except Exception as inst:
result = 'ERROR: %s' % str(inst)
return result
def uninstall(self, hostname):
"""
RabbitMQ uninstall process
"""
utils.execute("apt-get -y --purge remove rabbitmq-server memcached python-memcache", check_exit_code=False)
utils.execute("apt-get -y clean", check_exit_code=False)
shutil.rmtree('/var/lib/rabbitmq', ignore_errors=True)
return
def installPackages(self):
self.installPackagesCommon()
self._installDeb('rabbitmq-server memcached python-memcache', interactive=False)
return
class KeystoneConfig(Config):
def __init__(self):
"""
Constructor
"""
# Write the parameters (if possible) from the xml file
def write(self, xmldoc):
# keystone is always used. Flag kept for backwards compatibility
self.use_keystone = self._filler.getPropertyValue(xmldoc, 'auth_users', 'keystone_enabled', 'true') == 'true'
self.keystone_username = self._filler.getPropertyValue(xmldoc, 'keystone_database', 'username', 'keystone')
self.keystone_password = self._filler.getPropertyValue(xmldoc, 'keystone_database', 'password', 'nova')
self.keystone_host = self._filler.getPropertyValue(xmldoc, 'keystone_database', 'host', '127.0.0.1')
self.keystone_port = self._filler.getPropertyValue(xmldoc, 'keystone_database', 'port', '3306')
self.keystone_schema = self._filler.getPropertyValue(xmldoc, 'keystone_database', 'schema', 'keystone')
self.keystone_sql_connection = 'mysql://%s:%s@%s:%s/%s' % (
self.keystone_username, self.keystone_password, self.keystone_host, self.keystone_port,
self.keystone_schema)
self.admin_password = self._filler.getPropertyValue(xmldoc, 'auth_users', 'admin_password', 'password')
self.default_password = self._filler.getPropertyValue(xmldoc, 'auth_users', 'default_password',
'password')
self.default_username = self._filler.getPropertyValue(xmldoc, 'auth_users', 'default_username', '')
self.default_tenant = self._filler.getPropertyValue(xmldoc, 'auth_users', 'default_tenant', '')
self.endpoint = 'http://localhost:35357/v2.0'
self.ec2_hostname = self._filler.getPropertyValue(xmldoc, 'ec2', 'hostname', '127.0.0.1')
return
def get_id(self, str):
(stdout, stderr) = utils.execute("echo '%s' | awk '/ id / { print $4 }'" % str)
return stdout.replace('\n', '')
def _configureKeystone(self):
utils.execute(
"sed -i 's/admin_token = ADMIN/admin_token = %s/g' /etc/keystone/keystone.conf" % self.admin_password)
utils.execute(
"sed -i 's#connection = sqlite:////var/lib/keystone/keystone.db#connection = %s#g' /etc/keystone/keystone.conf" % self.keystone_sql_connection)
utils.execute(
"sed -i 's#driver = keystone.catalog.backends.sql.Catalog#driver = keystone.catalog.backends.templated.TemplatedCatalog\\ntemplate_file = /etc/keystone/default_catalog.templates#g' /etc/keystone/keystone.conf")
utils.execute('sed -i /catalog.RegionOne.identity.publicURL/d /etc/keystone/default_catalog.templates')
utils.execute('sed -i /catalog.RegionOne.compute.publicURL/d /etc/keystone/default_catalog.templates')
utils.execute('sed -i /catalog.RegionOne.volume.publicURL/d /etc/keystone/default_catalog.templates')
utils.execute('sed -i /catalog.RegionOne.ec2.publicURL/d /etc/keystone/default_catalog.templates')
utils.execute('sed -i /catalog.RegionOne.image.publicURL/d /etc/keystone/default_catalog.templates')
public_ip = self.ec2_hostname
public_port = '80'
utils.execute(
'echo "catalog.RegionOne.identity.publicURL = http://%s:%s/keystone/v2.0" >> /etc/keystone/default_catalog.templates' % (
public_ip, public_port))
utils.execute(
'echo "catalog.RegionOne.compute.publicURL = http://%s:%s/compute/v1.1/\$(tenant_id)s" >> /etc/keystone/default_catalog.templates' % (
public_ip, public_port))
utils.execute(
'echo "catalog.RegionOne.volume.publicURL = http://%s:%s/volume/v1/\$(tenant_id)s" >> /etc/keystone/default_catalog.templates' % (
public_ip, public_port))
utils.execute(
'echo "catalog.RegionOne.ec2.publicURL = http://%s:%s/services/Cloud" >> /etc/keystone/default_catalog.templates' % (
public_ip, public_port))
utils.execute(
'echo "catalog.RegionOne.image.publicURL = http://%s:%s/glance/v1" >> /etc/keystone/default_catalog.templates' % (
public_ip, public_port))
utils.execute("service keystone restart")
utils.execute("keystone-manage db_sync")
# Configure service users/roles
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s tenant-create --name=admin' % (self.endpoint, self.admin_password))
admin_tenant = self.get_id(stdout)
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s tenant-create --name=service' % (self.endpoint, self.admin_password))
service_tenant = self.get_id(stdout)
# StackOps Portal default tenant
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s tenant-create --name=portal' % (self.endpoint, self.admin_password))
portal_tenant = self.get_id(stdout)
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s user-create --name=admin --pass=%s [email protected]' % (
self.endpoint, self.admin_password, self.admin_password))
admin_user = self.get_id(stdout)
# Stackops Portal default user
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s user-create --name=portal --pass=%s --tenant_id %s [email protected]' % (
self.endpoint, self.admin_password, self.admin_password, portal_tenant))
portal_user = self.get_id(stdout)
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s user-create --name=nova --pass=%s --tenant_id %s [email protected]' % (
self.endpoint, self.admin_password, self.admin_password, service_tenant))
nova_user = self.get_id(stdout)
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s user-create --name=glance --pass=%s --tenant_id %s [email protected]' % (
self.endpoint, self.admin_password, self.admin_password, service_tenant))
glance_user = self.get_id(stdout)
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s role-create --name=admin' % (self.endpoint, self.admin_password))
admin_role = self.get_id(stdout)
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s role-create --name=KeystoneAdmin' % (self.endpoint, self.admin_password))
keystone_admin_role = self.get_id(stdout)
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s role-create --name=KeystoneServiceAdmin' % (
self.endpoint, self.admin_password))
keystone_service_admin_role = self.get_id(stdout)
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s role-create --name=Member' % (self.endpoint, self.admin_password))
member_role = self.get_id(stdout)
# StackOps Portal role
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s role-create --name=ROLE_PORTAL_ADMIN' % (
self.endpoint, self.admin_password))
portal_admin_role = self.get_id(stdout)
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s role-create --name=ROLE_PORTAL_USER' % (
self.endpoint, self.admin_password))
portal_user_role = self.get_id(stdout)
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s user-role-add --user %s --role %s --tenant_id %s' % (
self.endpoint, self.admin_password, admin_user, admin_role, admin_tenant))
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s user-role-add --user %s --role %s --tenant_id %s' % (
self.endpoint, self.admin_password, admin_user, keystone_admin_role, admin_tenant))
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s user-role-add --user %s --role %s --tenant_id %s' % (
self.endpoint, self.admin_password, admin_user, keystone_service_admin_role, admin_tenant))
# StackOps Portal user-role-add
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s user-role-add --user %s --role %s --tenant_id %s' % (
self.endpoint, self.admin_password, portal_user, portal_admin_role, portal_tenant))
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s user-role-add --user %s --role %s --tenant_id %s' % (
self.endpoint, self.admin_password, portal_user, portal_user_role, portal_tenant))
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s user-role-add --user %s --role %s --tenant_id %s' % (
self.endpoint, self.admin_password, nova_user, admin_role, service_tenant))
(stdout, stderr) = utils.execute(
'keystone --endpoint %s --token %s user-role-add --user %s --role %s --tenant_id %s' % (
self.endpoint, self.admin_password, glance_user, admin_role, service_tenant))
return
def install(self, hostname):
"""
Install all stuff needed to run Keystone
"""
result = ''
try:
if getpass.getuser() == 'root':
# Install packages for component
self.installPackages()
self._configureKeystone()
except Exception as inst:
result = 'ERROR: %s' % str(inst)
return result
def uninstall(self, hostname):
"""
Keystone uninstall process
"""
utils.execute("apt-get -y --purge remove keystone python-keystone python-keystoneclient python-mysqldb",
check_exit_code=False)
utils.execute("apt-get -y clean", check_exit_code=False)
shutil.rmtree('/var/lib/keystone', ignore_errors=True)
return
def installPackages(self):
self.installPackagesCommon()
self._installDeb('keystone python-keystone python-keystoneclient python-mysqldb')
return
class GlanceConfig(Config):
def __init__(self):
"""
Constructor
"""
# Write the parameters (if possible) from the xml file
def write(self, xmldoc):
# Keystone admin password
self.admin_password = self._filler.getPropertyValue(xmldoc, 'auth_users', 'admin_password', 'password')
# GLANCE database configuration
self.glance_username = self._filler.getPropertyValue(xmldoc, 'glance_database', 'username', 'glance')
self.glance_password = self._filler.getPropertyValue(xmldoc, 'glance_database', 'password', 'nova')
self.glance_host = self._filler.getPropertyValue(xmldoc, 'glance_database', 'host', '127.0.0.1')
self.glance_port = self._filler.getPropertyValue(xmldoc, 'glance_database', 'port', '3306')
self.glance_schema = self._filler.getPropertyValue(xmldoc, 'glance_database', 'schema', 'glance')
self.glance_drop_schema = self._filler.getPropertyValue(xmldoc, 'glance_database', 'dropschema',
'true') == 'true'
self.glance_sql_connection = 'mysql://%s:%s@%s:%s/%s' % (
self.glance_username, self.glance_password, self.glance_host, self.glance_port, self.glance_schema)
# images store type
self.glance_mount_type = self._filler.getPropertyValue(xmldoc, 'glance', 'mount_type', 'local')
if self.glance_mount_type == 'local':
self.glance_mount_point = self._filler.getPropertyValue(xmldoc, 'glance', 'mount_point', None)
self.glance_mount_parameters = self._filler.getPropertyValue(xmldoc, 'glance', 'mount_parameters', None)
else:
self.glance_mount_point = self._filler.getPropertyValue(xmldoc, 'glance', 'mount_point',
'192.168.10.198:/volumes/vol1/openstack-nfs-images')
self.glance_mount_parameters = self._filler.getPropertyValue(xmldoc, 'glance', 'mount_parameters',
'rw,dev,noexec,nosuid,auto,nouser,noatime,async,rsize=8192,wsize=8192')
return
def _configureGlance(self):
utils.execute(
"sed -i 's/%%SERVICE_PASSWORD%%/%s/g' /etc/glance/glance-api-paste.ini" % self.admin_password)
utils.execute(
"sed -i 's/%%SERVICE_PASSWORD%%/%s/g' /etc/glance/glance-registry-paste.ini" % self.admin_password)
utils.execute(
"sed -i 's/%%SERVICE_TENANT_NAME%%/%s/g' /etc/glance/glance-api-paste.ini" % 'admin')
utils.execute(
"sed -i 's/%%SERVICE_TENANT_NAME%%/%s/g' /etc/glance/glance-registry-paste.ini" % 'admin')
utils.execute(
"sed -i 's/%%SERVICE_USER%%/%s/g' /etc/glance/glance-api-paste.ini" % 'admin')
utils.execute(
"sed -i 's/%%SERVICE_USER%%/%s/g' /etc/glance/glance-registry-paste.ini" % 'admin')
utils.execute(
"sed -i 's#sql_connection = sqlite:////var/lib/glance/glance.sqlite#sql_connection = %s#g' /etc/glance/glance-registry.conf" % self.glance_sql_connection)
utils.execute('sed -i "/paste_deploy/d" /etc/glance/glance-registry.conf')
utils.execute('echo "[paste_deploy]" >> /etc/glance/glance-registry.conf')
utils.execute('sed -i "/flavor = keystone/d" /etc/glance/glance-registry.conf')
utils.execute('echo "flavor = keystone" >> /etc/glance/glance-registry.conf')
utils.execute('sed -i "/paste_deploy/d" /etc/glance/glance-api.conf')
utils.execute('echo "[paste_deploy]" >> /etc/glance/glance-api.conf')
utils.execute('sed -i "/flavor = keystone/d" /etc/glance/glance-api.conf')
utils.execute('echo "flavor = keystone" >> /etc/glance/glance-api.conf')
utils.execute("service glance-api stop && service glance-registry stop")
utils.execute('rm -fr /var/lib/glance/images', check_exit_code=False)
utils.execute('mkdir -p /var/lib/glance/images', check_exit_code=False)
utils.execute('chown glance:glance -R /var/lib/glance/images')
if self.glance_mount_type == 'nfs':
# configure NFS mount
mpoint = '%s %s nfs %s 0 0' % (
self.glance_mount_point, '/var/lib/glance/images', self.glance_mount_parameters)
utils.execute("sed -i 's#%s##g' /etc/fstab" % mpoint)
utils.execute('echo "\n%s" >> /etc/fstab' % mpoint)
# mount NFS remote
utils.execute('mount -a')
utils.execute("service glance-api start && service glance-registry start")
utils.execute("glance-manage version_control 0")
utils.execute("glance-manage db_sync")
return
def install(self, hostname):
"""
Install all stuff needed to run Keystone
"""
result = ''
try:
if getpass.getuser() == 'root':
# Install packages for component
self.installPackages()
self._configureGlance()
except Exception as inst:
result = 'ERROR: %s' % str(inst)
return result
def uninstall(self, hostname):
"""
Keystone uninstall process
"""
utils.execute(
"apt-get -y --purge remove glance glance-api glance-client glance-common glance-registry python-mysqldb nfs-common"
,
check_exit_code=False)
utils.execute("apt-get -y clean", check_exit_code=False)
shutil.rmtree('/var/lib/glance', ignore_errors=True)
return
def installPackages(self):
self.installPackagesCommon()
if self.glance_mount_type == 'nfs':
self._installDeb('nfs-common')
self._installDeb('glance glance-api glance-client glance-common glance-registry python-mysqldb')
return
class NovaApiConfig(Config):
_filename = "nova-api-stackops.conf"
def __init__(self):
"""
Constructor
"""
self.TOKEN_SIZE = 8
# Write the parameters (if possible) from the xml file
def write(self, xmldoc):
# Basic common parameters
self.verbose = self._filler.getPropertyValue(xmldoc, 'generic', 'verbose', 'true')
self.nodaemon = self._filler.getPropertyValue(xmldoc, 'generic', 'nodaemon', 'true')
self.auth_driver = self._filler.getPropertyValue(xmldoc, 'authentication', 'driver',
'nova.auth.dbdriver.DbDriver')
self.use_project_ca = self._filler.getPropertyValue(xmldoc, 'authentication', 'use_project_ca', 'true')
self.logdir = self._filler.getPropertyValue(xmldoc, 'logs', 'dir', '/var/log/nova')
self.state_path = self._filler.getPropertyValue(xmldoc, 'state', 'path', '/var/lib/nova')
self.lock_path = self._filler.getPropertyValue(xmldoc, 'generic', 'lock_path', '/var/lock/nova')
# NOVA database configuration
self.nova_username = self._filler.getPropertyValue(xmldoc, 'database', 'username', 'root')
self.nova_password = self._filler.getPropertyValue(xmldoc, 'database', 'password', 'nova')
self.nova_host = self._filler.getPropertyValue(xmldoc, 'database', 'host', '127.0.0.1')
self.nova_port = self._filler.getPropertyValue(xmldoc, 'database', 'port', '3306')
self.nova_schema = self._filler.getPropertyValue(xmldoc, 'database', 'schema', 'nova')
self.nova_drop_schema = self._filler.getPropertyValue(xmldoc, 'database', 'dropschema', 'true') == 'true'
self.nova_charset = self._filler.getPropertyValue(xmldoc, 'database', 'charset', 'utf8')
self.nova_sql_connection = 'mysql://%s:%s@%s:%s/%s?charset=%s' % (
self.nova_username, self.nova_password, self.nova_host, self.nova_port, self.nova_schema, self.nova_charset)
# RabbitMQ configuration
self.rabbit_host = self._filler.getPropertyValue(xmldoc, 'rabbitmq', 'hostname', '127.0.0.1')
# EC2 API Configuration
self.ec2_hostname = self._filler.getPropertyValue(xmldoc, 'ec2', 'hostname', '127.0.0.1')
self.ec2_dmz = self._filler.getPropertyValue(xmldoc, 'ec2', 'dmz', '127.0.0.1')
self.ec2_port = self._filler.getPropertyValue(xmldoc, 'ec2', 'dmz_port', '8773')
# Openstack API Configuration
self.osapi_port = self._filler.getPropertyValue(xmldoc, 'osapi', 'dmz_port', '8774')
# S3 API configuration
self.s3_hostname = self._filler.getPropertyValue(xmldoc, 's3', 'hostname', self.ec2_hostname)
self.s3_dmz = self._filler.getPropertyValue(xmldoc, 's3', 'dmz', self.ec2_dmz)
self.s3_port = self._filler.getPropertyValue(xmldoc, 's3', 'port', '3333')
# GLANCE Service configuration
self.glance_hostname = self._filler.getPropertyValue(xmldoc, 'glance', 'hostname', self.ec2_hostname)
self.glance_port = self._filler.getPropertyValue(xmldoc, 'glance', 'port', '9292')
self.image_service = self._filler.getPropertyValue(xmldoc, 'glance', 'image_service',
'nova.image.glance.GlanceImageService')
# KEYSTONE Service configuration
self.keystone_host = self._filler.getPropertyValue(xmldoc, 'auth_users', 'keystone_host', self.ec2_hostname)
self.keystone_user_port = self._filler.getPropertyValue(xmldoc, 'auth_users', 'keystone_user_port', '5000')
self.keystone_admin_port = self._filler.getPropertyValue(xmldoc, 'auth_users', 'keystone_admin_port', '32357')
# Keystone admin password
self.admin_password = self._filler.getPropertyValue(xmldoc, 'auth_users', 'admin_password', 'password')
# My IP
self.management_interface = self._filler.getPropertyValue(xmldoc, 'interfaces', 'management_interface', 'eth0')
self.my_ip = self.whatIsMyIp(self.management_interface)
# api paste configuration
self.api_paste_config = '/etc/nova/api-paste.ini'
# Enable admin API extensions
self.allow_admin_api = self._filler.getPropertyValue(xmldoc, 'osapi', 'allow_admin_api', 'true')
# Quotas
self.quota_instances = self._filler.getPropertyValue(xmldoc, 'scheduler', 'quota_instances', '4096')
self.quota_cores = self._filler.getPropertyValue(xmldoc, 'scheduler', 'quota_cores', '8192')
self.quota_ram = self._filler.getPropertyValue(xmldoc, 'scheduler', 'quota_ram', str(1024 * 1024 * 20))
self.quota_volumes = self._filler.getPropertyValue(xmldoc, 'scheduler', 'quota_volumes', '8192')
self.quota_gigabytes = self._filler.getPropertyValue(xmldoc, 'scheduler', 'quota_gigabytes', str(1024 * 20))
self.quota_floating_ips = self._filler.getPropertyValue(xmldoc, 'scheduler', 'quota_floating_ips', '254')
self.quota_metadata_items = self._filler.getPropertyValue(xmldoc, 'scheduler', 'quota_metadata_items', '128')
self.quota_max_injected_files = self._filler.getPropertyValue(xmldoc, 'scheduler', 'quota_max_injected_files',
'5')
self.quota_max_injected_file_content_bytes = self._filler.getPropertyValue(xmldoc, 'scheduler',
'quota_max_injected_file_content_bytes', str(10 * 1024))
self.quota_max_injected_file_path_bytes = self._filler.getPropertyValue(xmldoc, 'scheduler',
'quota_max_injected_file_path_bytes', '255')
# Flavors configuration
self.set_flavors = self._filler.getPropertyValue(xmldoc, 'flavors', 'delete_default', 'false') == 'true'
if self.set_flavors:
self.flavors_list = self._filler.getPropertyValue(xmldoc, 'flavors', 'list', '[]')
else:
self.flavors_list = '[]'
return
def _configureNovaApi(self):
parameters = {'lock_path': self.lock_path,
'verbose': self.verbose,
'nodaemon': self.nodaemon,
'use_project_ca': self.use_project_ca,
'sql_connection': self.nova_sql_connection,
'auth_driver': self.auth_driver,
'logdir': self.logdir,
'state_path': self.state_path,
'root_helper': 'sudo nova-rootwrap',
'rabbit_host': self.rabbit_host,
'my_ip': self.my_ip,
# NOVA-API SPECIFIC
'auth_strategy': 'keystone',
'ec2_host': self.ec2_hostname,
'ec2_dmz_host': self.ec2_dmz,
'ec2_port': self.ec2_port,
's3_host': self.s3_hostname,
's3_dmz': self.s3_dmz,
's3_port': self.s3_port,
'osapi_compute_listen_port': self.osapi_port,
'keystone_ec2_url': '%s://%s:%s/v2.0/ec2tokens' % (
'http', self.keystone_host, self.keystone_user_port),
'api_paste_config': self.api_paste_config,
'allow_admin_api': self.allow_admin_api,
'use_deprecated_auth': 'false',
# GLANCE SPECIFIC
'image_service': self.image_service,
'glance_api_servers': '%s:%s' % (self.glance_hostname, self.glance_port),
'quota_instances': self.quota_instances,
'quota_cores': self.quota_cores,
'quota_ram': self.quota_ram,
'quota_volumes': self.quota_volumes,
'quota_gigabytes': self.quota_gigabytes,
'quota_floating_ips': self.quota_floating_ips,
'quota_metadata_items': self.quota_metadata_items,
'quota_max_injected_files': self.quota_max_injected_files,
'quota_max_injected_file_content_bytes': self.quota_max_injected_file_content_bytes,
'quota_max_injected_file_path_bytes': self.quota_max_injected_file_path_bytes}
self._writeFile(self._filename, parameters)
utils.execute("service nova-api stop", check_exit_code=False)
utils.execute(
"sed -i 's#--flagfile=/etc/nova/nova.conf#%s#g' /etc/init/nova-api.conf" % '--flagfile=/etc/nova/nova-api-stackops.conf')
utils.execute(
"sed -i 's/%%SERVICE_PASSWORD%%/%s/g' /etc/nova/api-paste.ini" % self.admin_password)
utils.execute(
"sed -i 's/%%SERVICE_TENANT_NAME%%/%s/g' /etc/nova/api-paste.ini" % 'service')
utils.execute(
"sed -i 's/%%SERVICE_USER%%/%s/g' /etc/nova/api-paste.ini" % 'nova')
utils.execute('rm -f /etc/nova/nova.conf', check_exit_code=False)
utils.execute('ln -s /etc/nova/nova-api-stackops.conf /etc/nova/nova.conf', check_exit_code=False)
if os.path.exists(self.state_path):
utils.execute('chown nova:nova -R %s' % self.state_path)
utils.execute("service nova-api start")
utils.execute("nova-manage db sync")
return
def _generateToken(self):
return os.urandom(self.TOKEN_SIZE).encode("hex")
def _deleteFlavors(self):
# Get flavors
(out, err) = utils.execute('nova-manage flavor list')
old_flavors = out.split('\n')
flavorids = []
for str in old_flavors:
if len(str) > 0:
(flavorid, err) = utils.execute("echo '%s' | sed 's/: Memory:\(.*\)//g'" % str)
flavorids.append(flavorid)
for flavor in flavorids:
utils.execute('nova-manage flavor delete %s' % flavor)
def _addFlavors(self):
# Add flavors
flavors = eval(self.flavors_list)
for str in flavors:
flavor = str.split(';')
name = flavor[0]
memory = flavor[1]
cpu = flavor[2]
root_gb = flavor[3]
flavorid = flavor[4]
ephemeral_gb = '0'
if len(flavor) > 5:
ephemeral_gb = flavor[5]
utils.execute(
'nova-manage flavor create --name=%s --memory=%s --cpu=%s --root_gb=%s --flavor=%s --ephemeral_gb=%s' % (
name, memory, cpu, root_gb, flavorid, ephemeral_gb))
def install(self, hostname):
"""
Install all stuff needed to run NovaApi for Nova
"""
result = ''
try:
if getpass.getuser() == 'root':
# Install packages for component
self.installPackages()
self._configureNovaApi()
if self.set_flavors:
self._deleteFlavors()
self._addFlavors()
except Exception as inst:
result = 'ERROR: %s' % str(inst)
return result
def uninstall(self, hostname):
"""
NovaApi uninstall process
"""
utils.execute("apt-get -y --purge remove nova-api", check_exit_code=False)
utils.execute("apt-get -y clean", check_exit_code=False)
shutil.rmtree('/var/lib/nova', ignore_errors=True)
return
def installPackages(self):
self.installPackagesCommon()
self._installDeb('nova-api', interactive=False)
return
class NovaSchedulerConfig(Config):
_filename = "nova-scheduler-stackops.conf"
def __init__(self):
"""
Constructor
"""
# Write the parameters (if possible) from the xml file
def write(self, xmldoc):
# Basic common parameters
self.verbose = self._filler.getPropertyValue(xmldoc, 'generic', 'verbose', 'true')
self.nodaemon = self._filler.getPropertyValue(xmldoc, 'generic', 'nodaemon', 'true')
self.auth_driver = self._filler.getPropertyValue(xmldoc, 'authentication', 'driver',
'nova.auth.dbdriver.DbDriver')
self.use_project_ca = self._filler.getPropertyValue(xmldoc, 'authentication', 'use_project_ca', 'true')
self.logdir = self._filler.getPropertyValue(xmldoc, 'logs', 'dir', '/var/log/nova')
self.state_path = self._filler.getPropertyValue(xmldoc, 'state', 'path', '/var/lib/nova')
self.lock_path = self._filler.getPropertyValue(xmldoc, 'generic', 'lock_path', '/var/lock/nova')
# NOVA database configuration
self.nova_username = self._filler.getPropertyValue(xmldoc, 'database', 'username', 'root')
self.nova_password = self._filler.getPropertyValue(xmldoc, 'database', 'password', 'nova')
self.nova_host = self._filler.getPropertyValue(xmldoc, 'database', 'host', '127.0.0.1')
self.nova_port = self._filler.getPropertyValue(xmldoc, 'database', 'port', '3306')
self.nova_schema = self._filler.getPropertyValue(xmldoc, 'database', 'schema', 'nova')
self.nova_drop_schema = self._filler.getPropertyValue(xmldoc, 'database', 'dropschema', 'true') == 'true'
self.nova_charset = self._filler.getPropertyValue(xmldoc, 'database', 'charset', 'utf8')
self.nova_sql_connection = 'mysql://%s:%s@%s:%s/%s?charset=%s' % (
self.nova_username, self.nova_password, self.nova_host, self.nova_port, self.nova_schema, self.nova_charset)
# RabbitMQ configuration
self.rabbit_host = self._filler.getPropertyValue(xmldoc, 'rabbitmq', 'hostname', '127.0.0.1')
# My IP
self.management_interface = self._filler.getPropertyValue(xmldoc, 'interfaces', 'management_interface', 'eth0')
self.my_ip = self.whatIsMyIp(self.management_interface)
# NOVA-SCHEDULER configruration
self.scheduler_max_cores = self._filler.getPropertyValue(xmldoc, 'scheduler', 'max_cores', '16')
self.scheduler_max_gigabytes = self._filler.getPropertyValue(xmldoc, 'scheduler', 'max_gigabytes', '2048') # 2TB
self.scheduler_max_networks = self._filler.getPropertyValue(xmldoc, 'scheduler', 'max_networks', '1000')
self.scheduler_driver = self._filler.getPropertyValue(xmldoc, 'scheduler', 'driver',
'nova.scheduler.simple.SimpleScheduler')
return
def _configureNovaScheduler(self):
parameters = {'lock_path': self.lock_path,
'verbose': self.verbose,
'nodaemon': self.nodaemon,
'use_project_ca': self.use_project_ca,
'sql_connection': self.nova_sql_connection,
'auth_driver': self.auth_driver,
'logdir': self.logdir,
'state_path': self.state_path,
'root_helper': 'sudo nova-rootwrap',
'rabbit_host': self.rabbit_host,
'my_ip': self.my_ip,
# NOVA-SCHEDULER SPECIFIC
'scheduler_driver': self.scheduler_driver,
'max_cores': self.scheduler_max_cores,
'max_gigabytes': self.scheduler_max_gigabytes,
'max_networks': self.scheduler_max_networks}
self._writeFile(self._filename, parameters)
utils.execute("service nova-scheduler stop", check_exit_code=False)
utils.execute(
"sed -i 's#--flagfile=/etc/nova/nova.conf#%s#g' /etc/init/nova-scheduler.conf" % '--flagfile=/etc/nova/nova-scheduler-stackops.conf')
if os.path.exists(self.state_path):
utils.execute('chown nova:nova -R %s' % self.state_path)
utils.execute("service nova-scheduler start")
return
def install(self, hostname):
"""
Install all stuff needed to run NovaScheduler for Nova
"""
result = ''
try:
if getpass.getuser() == 'root':
# Install packages for component
self.installPackages()
self._configureNovaScheduler()
except Exception as inst:
result = 'ERROR: %s' % str(inst)
return result
def uninstall(self, hostname):
"""
NovaScheduler uninstall process
"""
utils.execute("apt-get -y --purge remove nova-scheduler", check_exit_code=False)
utils.execute("apt-get -y clean", check_exit_code=False)
return
def installPackages(self):
self.installPackagesCommon()
self._installDeb('nova-scheduler', interactive=False)
return
class NovaNetworkConfig(Config):
_filename = "nova-network-stackops.conf"
def __init__(self):
"""
Constructor
"""
# Write the parameters (if possible) from the xml file
def write(self, xmldoc):
# Basic common parameters
self.verbose = self._filler.getPropertyValue(xmldoc, 'generic', 'verbose', 'true')
self.nodaemon = self._filler.getPropertyValue(xmldoc, 'generic', 'nodaemon', 'true')
self.auth_driver = self._filler.getPropertyValue(xmldoc, 'authentication', 'driver',
'nova.auth.dbdriver.DbDriver')
self.use_project_ca = self._filler.getPropertyValue(xmldoc, 'authentication', 'use_project_ca', 'true')
self.logdir = self._filler.getPropertyValue(xmldoc, 'logs', 'dir', '/var/log/nova')
self.state_path = self._filler.getPropertyValue(xmldoc, 'state', 'path', '/var/lib/nova')
self.lock_path = self._filler.getPropertyValue(xmldoc, 'generic', 'lock_path', '/var/lock/nova')
# NOVA database configuration
self.nova_username = self._filler.getPropertyValue(xmldoc, 'database', 'username', 'root')
self.nova_password = self._filler.getPropertyValue(xmldoc, 'database', 'password', 'nova')
self.nova_host = self._filler.getPropertyValue(xmldoc, 'database', 'host', '127.0.0.1')
self.nova_port = self._filler.getPropertyValue(xmldoc, 'database', 'port', '3306')
self.nova_schema = self._filler.getPropertyValue(xmldoc, 'database', 'schema', 'nova')
self.nova_drop_schema = self._filler.getPropertyValue(xmldoc, 'database', 'dropschema', 'true') == 'true'
self.nova_charset = self._filler.getPropertyValue(xmldoc, 'database', 'charset', 'utf8')
self.nova_sql_connection = 'mysql://%s:%s@%s:%s/%s?charset=%s' % (
self.nova_username, self.nova_password, self.nova_host, self.nova_port, self.nova_schema, self.nova_charset)
# RabbitMQ configuration
self.rabbit_host = self._filler.getPropertyValue(xmldoc, 'rabbitmq', 'hostname', '127.0.0.1')
# NOVA-NETWORK SPECIFIC
self.dhcpbridge = self._filler.getPropertyValue(xmldoc, 'dhcpbridge', 'process', '/usr/bin/nova-dhcpbridge')
self.dhcpbridge_flagfile = self._filler.getPropertyValue(xmldoc, 'dhcpbridge', 'file',
'/etc/nova/nova-network-stackops.conf')
if self.dhcpbridge_flagfile == '/etc/nova/nova-network.conf':
self.dhcpbridge_flagfile = '/etc/nova/nova-network-stackops.conf'
self.routing_source_ip = self._filler.getPropertyValue(xmldoc, 'interfaces', 'routing_source_ip', None)
self.floating_range = self._filler.getPropertyValue(xmldoc, 'interfaces', 'floating_range', None)
# Default Fixed range configuration
self.network_manager = self._filler.getPropertyValue(xmldoc, 'network', 'type',
'nova.network.manager.FlatDHCPManager')
self.fixed_range = self._filler.getPropertyValue(xmldoc, 'network', 'fixed_range', '10.0.0.0/8')
self.network_size = self._filler.getPropertyValue(xmldoc, 'network', 'network_size', '256')
self.network_number = self._filler.getPropertyValue(xmldoc, 'network', 'network_number', '1')
self.vlanstart = self._filler.getPropertyValue(xmldoc, 'network', 'vlanstart', '100')
self.bridge = self._filler.getPropertyValue(xmldoc, 'network', 'bridge', 'br100')
self.dns1 = self._filler.getPropertyValue(xmldoc, 'network', 'dns1', '8.8.8.8')
self.dns2 = self._filler.getPropertyValue(xmldoc, 'network', 'dns2', '8.8.4.4')
# Interfaces configuration
self.flat_interface = self._filler.getPropertyValue(xmldoc, 'interfaces', 'flat_interface')
self.public_interface = self._filler.getPropertyValue(xmldoc, 'interfaces', 'public_interface')
self.management_interface = self._filler.getPropertyValue(xmldoc, 'interfaces', 'management_interface', 'eth0')
self.bridged_interface = self._filler.getPropertyValue(xmldoc, 'interfaces', 'bridged_interface',
self.flat_interface)
iface_list = self._operatingsystem.getNetworkConfiguration()
for iface in iface_list:
if iface['name'] == self.management_interface:
self.my_ip = iface['address']
if self.routing_source_ip is None:
if iface['name'] == self.public_interface:
self.routing_source_ip = iface['address']
self.public_ip = self._filler.getPropertyValue(xmldoc, 'interfaces', 'public_ip', '')
self.public_ip_mask = self._filler.getPropertyValue(xmldoc, 'interfaces', 'public_ip_mask', '255.255.255.255')
self.public_ip_gateway = self._filler.getPropertyValue(xmldoc, 'interfaces', 'public_ip_gateway', '')
self.firewall_public_ip = self._filler.getPropertyValue(xmldoc, 'interfaces', 'firewall_public_ip',
'false') == 'true'
octets = self.fixed_range.split('/')[0].split('.')
self.flat_network_dhcp_start = '%s.%s.%s.%i' % (octets[0], octets[1], octets[2], int(octets[3]) + 2)
return
def _configureNovaNetwork(self):
if os.path.exists('/usr/bin/nova-dhcpbridge'):
self.dhcpbridge = '/usr/bin/nova-dhcpbridge'
if os.path.exists('/var/lib/nova/bin/nova-dhcpbridge'):
self.dhcpbridge = '/var/lib/nova/bin/nova-dhcpbridge'
parameters = {'lock_path': self.lock_path,
'verbose': self.verbose,
'nodaemon': self.nodaemon,
'use_project_ca': self.use_project_ca,
'sql_connection': self.nova_sql_connection,
'auth_driver': self.auth_driver,
'logdir': self.logdir,
'state_path': self.state_path,
'root_helper': 'sudo nova-rootwrap',
'rabbit_host': self.rabbit_host,
'my_ip': self.my_ip,
# NOVA-NETWORK SPECIFIC
'dhcpbridge': self.dhcpbridge,
'dhcpbridge_flagfile': self.dhcpbridge_flagfile,
'routing_source_ip': self.routing_source_ip,
'public_interface': self.public_interface,
'network_manager': self.network_manager,
'flat_network_dhcp_start': self.flat_network_dhcp_start,
'force_dhcp_release': 'true',
'fixed_range': self.fixed_range,
'override_bridge_interface': self.flat_interface}
self._writeFile(self._filename, parameters)
utils.execute("service nova-network stop", check_exit_code=False)
utils.execute(
"sed -i 's#--flagfile=/etc/nova/nova.conf#%s#g' /etc/init/nova-network.conf" % '--flagfile=/etc/nova/nova-network-stackops.conf')
if os.path.exists(self.state_path):
utils.execute('chown nova:nova -R %s' % self.state_path)
utils.execute("service nova-network start")
return
def _addFloatingIP(self, ip_list):
# Add floating ips
if ip_list.startswith('['):
ips = eval(ip_list)
for ip in ips:
utils.execute('/var/lib/stackops/addfloatingip.sh %s %s %s %s %s' % (
self.nova_host, self.nova_port, self.nova_username, self.nova_password, ip))
else:
utils.execute(