@@ -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 process ON *.* TO cloud@`localhost`;" ,
229+ "GRANT process ON *.* TO cloud@`%`;" ,
230+ "GRANT ALL ON cloud_usage.* to cloud@`localhost`;" ,
231+ "GRANT ALL ON cloud_usage.* to cloud@`%`;" ,
232+ "GRANT process ON *.* TO cloud@`localhost`;" ,
233+ "GRANT process ON *.* TO cloud@`%`;" ,
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 in queriesToSkip : text = text .replace (t ,"" )
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 )
@@ -470,6 +486,8 @@ for example:
470486 self .encryptionJarPath = self .options .encryptionJarPath
471487 if self .options .mysqlbinpath :
472488 self .mysqlBinPath = self .options .mysqlbinpath
489+ if self .options .skipUsersAutoCreation :
490+ self .skipUsersAutoCreation = self .options .skipUsersAutoCreation
473491
474492 if self .options .encryptorVersion :
475493 self .encryptorVersion = "--encryptorversion %s" % self .options .encryptorVersion
@@ -610,6 +628,9 @@ for example:
610628 self .parser .add_option ("-g" , "--encryptor-version" , action = "store" , dest = "encryptorVersion" , default = "V2" ,
611629 help = "The encryptor version to be used to encrypt the values in db.properties" )
612630 self .parser .add_option ("-b" , "--mysql-bin-path" , action = "store" , dest = "mysqlbinpath" , help = "The mysql installed bin path" )
631+ self .parser .add_option ("-u" , "--skip-users-auto-creation" , action = "store_true" , dest = "skipUsersAutoCreation" ,
632+ help = "Indicates whether to skip the auto-creation of users in the database. Use this flag when your database users " \
633+ "are already configured and you only want to populate the db.properties file." )
613634 (self .options , self .args ) = self .parser .parse_args ()
614635 parseCasualCredit ()
615636 parseOtherOptions ()
0 commit comments