From c7f325015100abd3aed2307f95943590758bdf42 Mon Sep 17 00:00:00 2001 From: Damodar Reddy Date: Thu, 17 Apr 2014 14:54:07 +0530 Subject: [PATCH] CLOUDSTACK-6435: Add new Command line options to setup/bindir/cloud-setup-databases.in and remove OS specific commands --- setup/bindir/cloud-setup-databases.in | 28 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/setup/bindir/cloud-setup-databases.in b/setup/bindir/cloud-setup-databases.in index 2ba7d5142d1..dd22e56c427 100755 --- a/setup/bindir/cloud-setup-databases.in +++ b/setup/bindir/cloud-setup-databases.in @@ -25,8 +25,8 @@ from random import choice import string from optparse import OptionParser import commands -import MySQLdb import shutil +import socket # squelch mysqldb spurious warnings import warnings @@ -336,14 +336,8 @@ for example: def grabSystemInfo(self): def getIpAddr(): try: - stuff = runCmd(['ifconfig', '|', 'grep "inet addr"']) - for l in stuff.split("\n"): - l = l.strip() - secondSpace = l.find(' ', len('inet addr')) - ipStr = l[:secondSpace] - (x, ip) = ipStr.split(':') - if ip != '127.0.0.1': return ip - return '127.0.0.1' + ip = socket.gethostbyname(socket.gethostname()) + return ip except Exception, e: return "127.0.0.1" @@ -380,7 +374,7 @@ for example: def checkHostName(): self.info("Checking local machine hostname ...", None) try: - output= runCmd(['hostname', '--fqdn']) + output= socket.getfqdn() except Exception, e: err = "The host name of this computer does not resolve to an IP address.\nPlease use your operating system's network setup tools to fix this ('hostname --fqdn' %s).\n"%e.__str__() self.errorAndExit(err) @@ -404,7 +398,7 @@ for example: def processEncryptionStuff(self): def encrypt(input): cmd = ['java','-classpath',self.encryptionJarPath,'org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI', 'encrypt.sh', 'input=%s'%input, 'password=%s'%self.mgmtsecretkey,'verbose=false'] - return runCmd(cmd).strip('\n') + return runCmd(cmd).strip('\r\n') def saveMgmtServerSecretKey(): if self.encryptiontype == 'file': @@ -460,6 +454,14 @@ for example: self.mgmtsecretkey = self.options.mgmtsecretkey self.dbsecretkey = self.options.dbsecretkey self.isDebug = self.options.debug + if self.options.dbConfPath: + self.dbConfPath = self.options.dbConfPath + if self.options.dbFilesPath: + self.dbFilesPath = self.options.dbFilesPath + if self.options.encryptionKeyFile: + self.encryptionKeyFile = self.options.encryptionKeyFile + if self.options.encryptionJarPath: + self.encryptionJarPath = self.options.encryptionJarPath def parseUserAndPassword(cred): stuff = cred.split(':') @@ -576,6 +578,10 @@ for example: help="Cluster management server host IP. A string, by default it will try to detect a local IP") self.parser.add_option("-r", "--regionid", action="store", type="string", dest="regionid", default="1", help="Region Id for the management server cluster") + self.parser.add_option("-c", "--db-conf-path", action="store", dest="dbConfPath", help="The path to find db.properties which hold db properties") + self.parser.add_option("-f", "--db-files-path", action="store", dest="dbFilesPath", help="The path to find sql files to create initial database(s)") + 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") + 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") (self.options, self.args) = self.parser.parse_args() parseCasualCredit()