mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
[DB] Add force recreate parameter to cloudstack-setup-databases script (#11239)
This commit is contained in:
parent
cca8b2fef9
commit
21dde2b9a2
@ -129,6 +129,12 @@ class DBDeployer(object):
|
|||||||
(value, index) = self.dbDotProperties[key]
|
(value, index) = self.dbDotProperties[key]
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def areCloudDatabasesCreated(self):
|
||||||
|
cmd = "SELECT CASE WHEN COUNT(DISTINCT SCHEMA_NAME) >= 1 THEN 1 ELSE 0 END AS schema_exists \
|
||||||
|
FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME IN ('cloud', 'cloud_usage');"
|
||||||
|
databases = self.runMysql(cmd, "databases", self.rootuser != None)
|
||||||
|
return databases.replace("schema_exists", "").strip() == "1"
|
||||||
|
|
||||||
def runMysql(self, text, table, isRoot=False):
|
def runMysql(self, text, table, isRoot=False):
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if not isRoot:
|
if not isRoot:
|
||||||
@ -151,7 +157,7 @@ class DBDeployer(object):
|
|||||||
open(self.tmpMysqlFile, 'w').write(text)
|
open(self.tmpMysqlFile, 'w').write(text)
|
||||||
mysqlCmds.append('<')
|
mysqlCmds.append('<')
|
||||||
mysqlCmds.append(self.tmpMysqlFile)
|
mysqlCmds.append(self.tmpMysqlFile)
|
||||||
runCmd(mysqlCmds)
|
return runCmd(mysqlCmds)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
err = '''Encountering an error when executing mysql script
|
err = '''Encountering an error when executing mysql script
|
||||||
@ -233,6 +239,10 @@ for full help
|
|||||||
("DROP USER 'cloud'@'%' ;", "DO NULL;")
|
("DROP USER 'cloud'@'%' ;", "DO NULL;")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.areCloudDatabasesCreated() and not self.options.forcerecreate:
|
||||||
|
self.errorAndExit("Aborting script as the databases (cloud, cloud_usage) already exist.\n" \
|
||||||
|
"Please use the --force-recreate parameter if you want to recreate the schemas.")
|
||||||
|
|
||||||
scriptsToRun = ["create-database","create-schema", "create-database-premium","create-schema-premium"]
|
scriptsToRun = ["create-database","create-schema", "create-database-premium","create-schema-premium"]
|
||||||
if self.options.schemaonly:
|
if self.options.schemaonly:
|
||||||
scriptsToRun = ["create-schema", "create-schema-premium"]
|
scriptsToRun = ["create-schema", "create-schema-premium"]
|
||||||
@ -610,6 +620,9 @@ for example:
|
|||||||
help="Creates the db schema without having to pass root credentials - " \
|
help="Creates the db schema without having to pass root credentials - " \
|
||||||
"Please note: The databases (cloud, cloud_usage) and user (cloud) has to be configured " \
|
"Please note: The databases (cloud, cloud_usage) and user (cloud) has to be configured " \
|
||||||
"manually prior to running this script when using this flag.")
|
"manually prior to running this script when using this flag.")
|
||||||
|
self.parser.add_option("--force-recreate", action="store_true", dest="forcerecreate", default=False,
|
||||||
|
help="Force recreation of the existing DB schemas. This option is disabled by default." \
|
||||||
|
"Please note: The databases (cloud, cloud_usage) and its tables data will be lost and recreated.")
|
||||||
|
|
||||||
self.parser.add_option("-a", "--auto", action="store", type="string", dest="serversetup", default="",
|
self.parser.add_option("-a", "--auto", action="store", type="string", dest="serversetup", default="",
|
||||||
help="Path to an XML file describing an automated unattended cloud setup")
|
help="Path to an XML file describing an automated unattended cloud setup")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user