Skip to content

Commit 041b8f6

Browse files
authored
schema: Added ability to create schemas only when using cloudstack-setup-data… (#5187)
* Added ability to create schemas only when using cloudstack-setup-databases * Renamed var name * Added a check for passing --schema-only and --deploy-as together/. * Moved validation to appropriate method * Moved description * fixed whitespace
1 parent 6509f43 commit 041b8f6

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

setup/bindir/cloud-setup-databases.in

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ for full help
188188
sys.exit(1)
189189

190190
def setupDBSchema(self):
191-
if not self.rootuser:
191+
if not self.options.schemaonly and not self.rootuser:
192192
self.info("No mysql root user specified, will not create Cloud DB schema\n", None)
193193
return
194194

@@ -219,13 +219,17 @@ for full help
219219
""),
220220
)
221221

222-
for f in ["create-database","create-schema", "create-database-premium","create-schema-premium"]:
222+
scriptsToRun = ["create-database","create-schema", "create-database-premium","create-schema-premium"]
223+
if self.options.schemaonly:
224+
scriptsToRun = ["create-schema", "create-schema-premium"]
225+
226+
for f in scriptsToRun:
223227
p = os.path.join(self.dbFilesPath,"%s.sql"%f)
224228
if not os.path.exists(p): continue
225229
text = open(p).read()
226230
for t, r in replacements: text = text.replace(t,r)
227231
self.info("Applying %s"%p)
228-
self.runMysql(text, p, True)
232+
self.runMysql(text, p, self.rootuser != None)
229233
self.info(None, True)
230234

231235
if self.serversetup:
@@ -248,21 +252,21 @@ for full help
248252
p = os.path.join(self.dbFilesPath, 'server-setup.sql')
249253
text = open(p).read()
250254
self.info("Applying %s"%p)
251-
self.runMysql(text, p, True)
255+
self.runMysql(text, p, self.rootuser != None)
252256
self.info(None, True)
253257

254258
for f in ["templates"]:
255259
p = os.path.join(self.dbFilesPath,"%s.sql"%f)
256260
text = open(p).read()
257261
self.info("Applying %s"%p)
258-
self.runMysql(text, p, True)
262+
self.runMysql(text, p, self.rootuser != None)
259263
self.info(None, True)
260264

261265
p = os.path.join(self.dbFilesPath,"schema-level.sql")
262266
if os.path.isfile(p):
263267
text = open(p).read()
264268
self.info("Applying %s"%p)
265-
self.runMysql(text, p, True)
269+
self.runMysql(text, p, self.rootuser != None)
266270
self.info(None, True)
267271

268272
def prepareDBFiles(self):
@@ -514,6 +518,8 @@ for example:
514518
self.info("Mysql server port:%s"%self.port, True)
515519

516520
def validateParameters():
521+
if self.options.schemaonly and self.rootuser != None:
522+
self.errorAndExit("--schema-only and --deploy-as cannot be passed together\n")
517523
if self.encryptiontype != 'file' and self.encryptiontype != 'web':
518524
self.errorAndExit('Wrong encryption type %s, --encrypt-type can only be "file" or "web'%self.encryptiontype)
519525

@@ -559,6 +565,11 @@ for example:
559565
help="If enabled, print the commands it will run as they run")
560566
self.parser.add_option("-d", "--deploy-as", action="store", type="string", dest="rootcreds", default="",
561567
help="Colon-separated user name and password of a MySQL user with administrative privileges")
568+
self.parser.add_option("-s", "--schema-only", action="store_true", dest="schemaonly", default=False,
569+
help="Creates the db schema without having to pass root credentials - " \
570+
"Please note: The databases (cloud, cloud_usage) and user (cloud) has to be configured " \
571+
"manually prior to running this script when using this flag.")
572+
562573
self.parser.add_option("-a", "--auto", action="store", type="string", dest="serversetup", default="",
563574
help="Path to an XML file describing an automated unattended cloud setup")
564575
self.parser.add_option("-e", "--encrypt-type", action="store", type="string", dest="encryptiontype", default="file",
@@ -576,7 +587,6 @@ for example:
576587
self.parser.add_option("-j", "--encryption-jar-path", action="store", dest="encryptionJarPath", help="The path to the jasypt library to be used to encrypt the values in db.properties")
577588
self.parser.add_option("-n", "--encryption-key-file", action="store", dest="encryptionKeyFile", help="The name of the file in which encryption key to be generated")
578589
self.parser.add_option("-b", "--mysql-bin-path", action="store", dest="mysqlbinpath", help="The mysql installed bin path")
579-
580590
(self.options, self.args) = self.parser.parse_args()
581591
parseCasualCredit()
582592
parseOtherOptions()

0 commit comments

Comments
 (0)