@@ -72,6 +72,7 @@ class DBDeployer(object):
7272 magicString = 'This_is_a_magic_string_i_think_no_one_will_duplicate'
7373 tmpMysqlFile = os .path .join (os .path .expanduser ('~/' ), 'cloudstackmysql.tmp.sql' )
7474 mysqlBinPath = None
75+ skipUsersAutoCreation = False
7576
7677 def preRun (self ):
7778 def backUpDbDotProperties ():
@@ -219,6 +220,19 @@ for full help
219220 "" ),
220221 )
221222
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+
222236 scriptsToRun = ["create-database" ,"create-schema" , "create-database-premium" ,"create-schema-premium" ]
223237 if self .options .schemaonly :
224238 scriptsToRun = ["create-schema" , "create-schema-premium" ]
@@ -227,6 +241,8 @@ for full help
227241 p = os .path .join (self .dbFilesPath ,"%s.sql" % f )
228242 if not os .path .exists (p ): continue
229243 text = open (p ).read ()
244+ if self .options .skipUsersAutoCreation :
245+ for t , r in queriesToSkip : text = text .replace (t ,r )
230246 for t , r in replacements : text = text .replace (t ,r )
231247 self .info ("Applying %s" % p )
232248 self .runMysql (text , p , self .rootuser != None )
@@ -472,6 +488,8 @@ for example:
472488 self .encryptionJarPath = self .options .encryptionJarPath
473489 if self .options .mysqlbinpath :
474490 self .mysqlBinPath = self .options .mysqlbinpath
491+ if self .options .skipUsersAutoCreation :
492+ self .skipUsersAutoCreation = self .options .skipUsersAutoCreation
475493
476494 if self .options .encryptorVersion :
477495 self .encryptorVersion = "--encryptorversion %s" % self .options .encryptorVersion
@@ -612,6 +630,9 @@ for example:
612630 self .parser .add_option ("-g" , "--encryptor-version" , action = "store" , dest = "encryptorVersion" , default = "V2" ,
613631 help = "The encryptor version to be used to encrypt the values in db.properties" )
614632 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." )
615636 (self .options , self .args ) = self .parser .parse_args ()
616637 parseCasualCredit ()
617638 parseOtherOptions ()
0 commit comments