@@ -72,6 +72,7 @@ class DBDeployer(object):
72
72
magicString = 'This_is_a_magic_string_i_think_no_one_will_duplicate'
73
73
tmpMysqlFile = os .path .join (os .path .expanduser ('~/' ), 'cloudstackmysql.tmp.sql' )
74
74
mysqlBinPath = None
75
+ skipUsersAutoCreation = False
75
76
76
77
def preRun (self ):
77
78
def backUpDbDotProperties ():
@@ -219,6 +220,19 @@ for full help
219
220
"" ),
220
221
)
221
222
223
+ queriesToSkip = (
224
+ ("CREATE USER cloud@`localhost` identified by 'cloud';" , "" ),
225
+ ("CREATE USER cloud@`%` identified by 'cloud';" , "" ),
226
+ ("GRANT ALL ON cloud.* to cloud@`localhost`;" , "" ),
227
+ ("GRANT ALL ON cloud.* to cloud@`%`;" , "" ),
228
+ ("GRANT ALL ON cloud_usage.* to cloud@`localhost`;" , "" ),
229
+ ("GRANT ALL ON cloud_usage.* to cloud@`%`;" , "" ),
230
+ ("GRANT process ON *.* TO cloud@`localhost`;" , "" ),
231
+ ("GRANT process ON *.* TO cloud@`%`;" , "" ),
232
+ ("DROP USER 'cloud'@'localhost' ;" , "DO NULL;" ),
233
+ ("DROP USER 'cloud'@'%' ;" , "DO NULL;" )
234
+ )
235
+
222
236
scriptsToRun = ["create-database" ,"create-schema" , "create-database-premium" ,"create-schema-premium" ]
223
237
if self .options .schemaonly :
224
238
scriptsToRun = ["create-schema" , "create-schema-premium" ]
@@ -227,6 +241,8 @@ for full help
227
241
p = os .path .join (self .dbFilesPath ,"%s.sql" % f )
228
242
if not os .path .exists (p ): continue
229
243
text = open (p ).read ()
244
+ if self .options .skipUsersAutoCreation :
245
+ for t , r in queriesToSkip : text = text .replace (t ,r )
230
246
for t , r in replacements : text = text .replace (t ,r )
231
247
self .info ("Applying %s" % p )
232
248
self .runMysql (text , p , self .rootuser != None )
@@ -472,6 +488,8 @@ for example:
472
488
self .encryptionJarPath = self .options .encryptionJarPath
473
489
if self .options .mysqlbinpath :
474
490
self .mysqlBinPath = self .options .mysqlbinpath
491
+ if self .options .skipUsersAutoCreation :
492
+ self .skipUsersAutoCreation = self .options .skipUsersAutoCreation
475
493
476
494
if self .options .encryptorVersion :
477
495
self .encryptorVersion = "--encryptorversion %s" % self .options .encryptorVersion
@@ -612,6 +630,9 @@ for example:
612
630
self .parser .add_option ("-g" , "--encryptor-version" , action = "store" , dest = "encryptorVersion" , default = "V2" ,
613
631
help = "The encryptor version to be used to encrypt the values in db.properties" )
614
632
self .parser .add_option ("-b" , "--mysql-bin-path" , action = "store" , dest = "mysqlbinpath" , help = "The mysql installed bin path" )
633
+ self .parser .add_option ("-u" , "--skip-users-auto-creation" , action = "store_true" , dest = "skipUsersAutoCreation" ,
634
+ help = "Indicates whether to skip the auto-creation of users in the database. Use this flag when your database users " \
635
+ "are already configured and you only want to populate the db.properties file." )
615
636
(self .options , self .args ) = self .parser .parse_args ()
616
637
parseCasualCredit ()
617
638
parseOtherOptions ()
0 commit comments