mirror of https://github.com/apache/cloudstack.git
Connect cloud-setup-databases with deploydb. Use MySQLdb instead of using the command-line MySQL client. Detect the existence of the MySQLdb python module on Windows. Works on windows.
This commit is contained in:
parent
4289dd79ec
commit
10d62a5fe6
|
|
@ -182,12 +182,11 @@ Summary: Cloud.com setup tools
|
|||
Obsoletes: vmops-setup < %{version}-%{release}
|
||||
Requires: java >= 1.6.0
|
||||
Requires: python
|
||||
Requires: mysql
|
||||
Requires: MySQL-python
|
||||
Requires: %{name}-utils = %{version}-%{release}
|
||||
Requires: %{name}-server = %{version}-%{release}
|
||||
Requires: %{name}-deps = %{version}-%{release}
|
||||
Requires: %{name}-python = %{version}-%{release}
|
||||
Requires: MySQL-python
|
||||
Group: System Environment/Libraries
|
||||
%description setup
|
||||
The Cloud.com setup tools let you set up your Management Server and Usage Server.
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ Provides: vmops-setup
|
|||
Conflicts: vmops-setup
|
||||
Replaces: vmops-setup
|
||||
Architecture: any
|
||||
Depends: openjdk-6-jre, python, cloud-utils (= ${source:Version}), mysql-client, cloud-deps (= ${source:Version}), cloud-server (= ${source:Version}), cloud-python (= ${source:Version}), python-mysqldb
|
||||
Depends: openjdk-6-jre, python, cloud-utils (= ${source:Version}), cloud-deps (= ${source:Version}), cloud-server (= ${source:Version}), cloud-python (= ${source:Version}), python-mysqldb
|
||||
Description: Cloud.com client
|
||||
The Cloud.com setup tools let you set up your Management Server and Usage Server.
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,3 +1,2 @@
|
|||
if bld.env.DISTRO not in ['Windows','Mac']:
|
||||
obj = bld(features = 'py',name='pythonmodules')
|
||||
obj.find_sources_in_dirs('lib', exts=['.py'])
|
||||
obj = bld(features = 'py',name='pythonmodules')
|
||||
obj.find_sources_in_dirs('lib', exts=['.py'])
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from random import choice
|
|||
import string
|
||||
from optparse import OptionParser
|
||||
import commands
|
||||
import MySQLdb
|
||||
|
||||
# ---- This snippet of code adds the sources path and the waf configured PYTHONDIR to the Python path ----
|
||||
# ---- We do this so cloud_utils can be looked up in the following order:
|
||||
|
|
@ -128,22 +129,34 @@ def get_creds(parser,options,args):
|
|||
host,port = parse_hostport(hostinfo)
|
||||
return (user,password,host,port)
|
||||
|
||||
def run_mysql(text,user,password,host,port,extraargs=None):
|
||||
cmd = ["mysql",
|
||||
"--user=%s"%user,
|
||||
"--host=%s"%host,
|
||||
]
|
||||
if password:
|
||||
cmd.append("--password=%s"%password)
|
||||
if password:
|
||||
cmd.append("--port=%s"%port)
|
||||
if extraargs:
|
||||
cmd.extend(extraargs)
|
||||
|
||||
p = subprocess.Popen(cmd,stdin=subprocess.PIPE)
|
||||
p.communicate(text)
|
||||
ret = p.wait()
|
||||
if ret != 0: raise CalledProcessError(ret,cmd)
|
||||
def run_mysql(text,user,password,host,port,debug=False):
|
||||
kwargs = {}
|
||||
kwargs['host'] = host
|
||||
kwargs['user'] = user
|
||||
if password: kwargs['passwd'] = password
|
||||
if port: kwargs['port'] = port
|
||||
|
||||
conn = MySQLdb.connect(**kwargs)
|
||||
cur = conn.cursor()
|
||||
import re
|
||||
exp = re.compile("DELIMITER (.*)$",re.M)
|
||||
pairs = [";"]+[x.strip() for x in exp.split(text)]
|
||||
delims = []
|
||||
chunks = []
|
||||
while pairs:
|
||||
delims.append( pairs[0] )
|
||||
chunks.append( pairs[1] )
|
||||
pairs = pairs[2:]
|
||||
|
||||
for delim,chunk in zip(delims,chunks):
|
||||
for stmt in chunk.split(delim):
|
||||
stmt = stmt.strip()
|
||||
if not stmt: continue
|
||||
if debug: print stmt
|
||||
cur.execute(stmt)
|
||||
cur.close()
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def ifaces():
|
||||
status,lines = commands.getstatusoutput('LANG=C /sbin/ip address show')
|
||||
|
|
@ -239,8 +252,8 @@ if options.serversetup and not os.path.isfile(options.serversetup):
|
|||
e("%s is not a valid file"%options.serversetup)
|
||||
|
||||
|
||||
dbfilepath = "@SETUPDATADIR@"
|
||||
dbppaths = [ os.path.join("@MSCONF@","db.properties") ] # , os.path.join("@USAGESYSCONFDIR@","db.properties") ]
|
||||
dbfilepath = r"@SETUPDATADIR@"
|
||||
dbppaths = [ os.path.join(r"@MSCONF@","db.properties") ] # , os.path.join("@USAGESYSCONFDIR@","db.properties") ]
|
||||
dbppaths = [ x for x in dbppaths if os.path.exists(x) ]
|
||||
if not dbppaths:
|
||||
print "No services to set up installed on this system. Refusing to continue."
|
||||
|
|
@ -249,28 +262,29 @@ if not dbppaths:
|
|||
#run sanity checks
|
||||
# checkutc()
|
||||
checkdbserverhostname(host)
|
||||
checkhostname()
|
||||
if sys.platform != "win32": checkhostname()
|
||||
try: checkselinux()
|
||||
except OSError,e:
|
||||
if e.errno == 2: pass
|
||||
else: raise
|
||||
checknetwork()
|
||||
if sys.platform != 'win32': checknetwork()
|
||||
|
||||
|
||||
#initialize variables
|
||||
ipaddr = firstip(ifaces())
|
||||
if sys.platform != 'win32': ipaddr = firstip(ifaces())
|
||||
else: ipaddr = None
|
||||
if not ipaddr: ipaddr='127.0.0.1'
|
||||
|
||||
|
||||
if rootuser:
|
||||
print "Testing specified deployment credentials on server %s:%s"%(host,port)
|
||||
try: run_mysql("SELECT * from mysql.user limit 0",rootuser,rootpassword,host,port)
|
||||
try: run_mysql("SELECT * from mysql.user limit 0",rootuser,rootpassword,host,port,debug=options.debug)
|
||||
except CalledProcessError:
|
||||
print "The deployment credentials you specified are not valid. Refusing to continue."
|
||||
sys.exit(19)
|
||||
else:
|
||||
print "Testing specified connection credentials on server %s:%s"%(host,port)
|
||||
try: run_mysql("SELECT * from cloud.user limit 0",user,password,host,port)
|
||||
try: run_mysql("SELECT * from cloud.user limit 0",user,password,host,port,debug=options.debug)
|
||||
except CalledProcessError:
|
||||
print "The connection credentials you specified are not valid. Refusing to continue."
|
||||
sys.exit(19)
|
||||
|
|
@ -315,22 +329,27 @@ if rootuser:
|
|||
if not os.path.exists(p): continue
|
||||
text = file(p).read()
|
||||
for t,r in replacements: text = text.replace(t,r)
|
||||
print "Applying file %s to the database on server %s:%s"%(p,host,port)
|
||||
try: run_mysql(text,rootuser,rootpassword,host,port)
|
||||
print "Applying file %s to the database on server %s:%s"%(p,host,port)
|
||||
try: run_mysql(text,rootuser,rootpassword,host,port,debug=options.debug)
|
||||
except CalledProcessError: sys.exit(20)
|
||||
|
||||
if options.serversetup:
|
||||
systemjars = "@SYSTEMJARS@".split()
|
||||
pipe = subprocess.Popen(["build-classpath"]+systemjars,stdout=subprocess.PIPE)
|
||||
systemcp,throwaway = pipe.communicate()
|
||||
systemcp = systemcp.strip()
|
||||
if pipe.wait(): # this means that build-classpath failed miserably
|
||||
systemcp = "@SYSTEMCLASSPATH@"
|
||||
pcp = os.path.pathsep.join( glob.glob( os.path.join ( "@PREMIUMJAVADIR@" , "*" ) ) )
|
||||
mscp = "@MSCLASSPATH@"
|
||||
depscp = "@DEPSCLASSPATH@"
|
||||
conf = os.path.dirname(dbppaths[0])
|
||||
classpath = os.path.pathsep.join([pcp,systemcp,depscp,mscp,conf])
|
||||
pcp = os.path.pathsep.join( glob.glob( os.path.join ( r"@PREMIUMJAVADIR@" , "*" ) ) )
|
||||
if sys.platform == 'win32':
|
||||
mscp = r"@MSCLASSPATH@"
|
||||
depscp = r"@DEPSCLASSPATH@"
|
||||
classpath = os.path.pathsep.join([pcp,depscp,mscp,conf])
|
||||
else:
|
||||
systemjars = r"@SYSTEMJARS@".split()
|
||||
pipe = subprocess.Popen(["build-classpath"]+systemjars,stdout=subprocess.PIPE)
|
||||
systemcp,throwaway = pipe.communicate()
|
||||
systemcp = systemcp.strip()
|
||||
if pipe.wait(): # this means that build-classpath failed miserably
|
||||
systemcp = r"@SYSTEMCLASSPATH@"
|
||||
mscp = r"@MSCLASSPATH@"
|
||||
depscp = r"@DEPSCLASSPATH@"
|
||||
classpath = os.path.pathsep.join([pcp,systemcp,depscp,mscp,conf])
|
||||
print "Performing unattended automated setup using file %s"%options.serversetup
|
||||
cmd = ["java","-cp",classpath,"com.cloud.test.DatabaseConfig",options.serversetup]
|
||||
if options.debug: print "Running command: %s"%" ".join(cmd)
|
||||
|
|
@ -343,19 +362,19 @@ if rootuser:
|
|||
p = os.path.join(dbfilepath,"%s.sql"%f)
|
||||
text = file(p).read()
|
||||
print "Applying file %s to the database on server %s:%s"%(p,host,port)
|
||||
try: run_mysql(text,rootuser,rootpassword,host,port)
|
||||
try: run_mysql(text,rootuser,rootpassword,host,port,debug=options.debug)
|
||||
except CalledProcessError: sys.exit(22)
|
||||
|
||||
for f in ["templates.%s"%virttech,"create-index-fk"]:
|
||||
p = os.path.join(dbfilepath,"%s.sql"%f)
|
||||
text = file(p).read()
|
||||
print "Applying file %s to the database on server %s:%s"%(p,host,port)
|
||||
try: run_mysql(text,rootuser,rootpassword,host,port)
|
||||
try: run_mysql(text,rootuser,rootpassword,host,port,debug=options.debug)
|
||||
except CalledProcessError: sys.exit(22)
|
||||
|
||||
p = os.path.join(dbfilepath,"schema-level.sql")
|
||||
if os.path.isfile(p):
|
||||
text = file(p).read()
|
||||
print "Applying file %s to the database on server %s:%s"%(p,host,port)
|
||||
try: run_mysql(text,rootuser,rootpassword,host,port)
|
||||
try: run_mysql(text,rootuser,rootpassword,host,port,debug=options.debug)
|
||||
except CalledProcessError: sys.exit(22)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ BEGIN
|
|||
IF foo > 0 THEN
|
||||
DROP USER 'cloud'@'%' ;
|
||||
END IF;
|
||||
END ;$$
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `mysql`.`cloud_drop_user_if_exists`() ;
|
||||
|
|
|
|||
68
wscript
68
wscript
|
|
@ -731,64 +731,26 @@ def installdebdeps(context):
|
|||
|
||||
@throws_command_errors
|
||||
def deploydb(ctx,virttech=None):
|
||||
if not virttech: raise Utils.WafError('use deploydb_xenserver or deploydb_kvm rather than deploydb')
|
||||
if not virttech: raise Utils.WafError('use deploydb_xenserver, deploydb_vmware or deploydb_kvm rather than deploydb')
|
||||
|
||||
ctx = _getbuildcontext()
|
||||
srcdir = ctx.path.abspath()
|
||||
builddir = ctx.path.abspath(ctx.env)
|
||||
setupdatabases = _join(ctx.env.BINDIR,"cloud-setup-databases")
|
||||
serversetup = _join(ctx.env.SETUPDATADIR,"server-setup.xml")
|
||||
|
||||
dbhost = ctx.env.DBHOST
|
||||
dbuser = ctx.env.DBUSER
|
||||
dbpw = ctx.env.DBPW
|
||||
dbdir = ctx.env.DBDIR
|
||||
if not _exists(setupdatabases): # Needs install!
|
||||
Scripting.install(ctx)
|
||||
|
||||
cmd = [
|
||||
ctx.env.PYTHON,
|
||||
setupdatabases,
|
||||
"cloud@%s"%ctx.env.DBHOST,
|
||||
virttech,
|
||||
"--auto=%s"%serversetup,
|
||||
"--deploy-as=%s:%s"%(ctx.env.DBUSER,ctx.env.DBPW),
|
||||
]
|
||||
|
||||
if not _exists(_join(builddir,"client","tomcatconf","db.properties")): raise Utils.WafError("Please build at least once to generate the db.properties configuration file")
|
||||
|
||||
cp = []
|
||||
cp += [ _join(builddir,"client","tomcatconf") ]
|
||||
cp += [ _join("test","conf") ]
|
||||
cp += _glob(_join(builddir,"target", "jar", "*.jar"))
|
||||
cp += [ctx.env.CLASSPATH]
|
||||
cp = pathsep.join(cp)
|
||||
|
||||
before = ""
|
||||
for f in ["create-database","create-schema"]:
|
||||
p = _join("setup","db",f+".sql")
|
||||
p = dev_override(p)
|
||||
before = before + file(p).read()
|
||||
Utils.pprint("GREEN","Reading database code from %s"%p)
|
||||
|
||||
cmd = [ctx.env.MYSQL,"--user=%s"%dbuser,"-h",dbhost,"--password=%s"%dbpw]
|
||||
Utils.pprint("GREEN","Deploying database scripts to %s (user %s)"%(dbhost,dbuser))
|
||||
Utils.pprint("BLUE"," ".join(cmd))
|
||||
p = _Popen(cmd,stdin=PIPE,stdout=None,stderr=None)
|
||||
p.communicate(before)
|
||||
retcode = p.wait()
|
||||
if retcode: raise CalledProcessError(retcode,cmd)
|
||||
|
||||
serversetup = dev_override(_join("setup","db","server-setup.xml"))
|
||||
Utils.pprint("GREEN","Configuring database with com.cloud.test.DatabaseConfig")
|
||||
run_java("com.cloud.test.DatabaseConfig",cp,['-Dlog4j.configuration=log4j-stdout.properties'],[serversetup])
|
||||
|
||||
after = ""
|
||||
for f in ["templates.%s"%virttech,"create-index-fk"]:
|
||||
p = _join("setup","db",f+".sql")
|
||||
p = dev_override(p)
|
||||
after = after + file(p).read()
|
||||
Utils.pprint("GREEN","Reading database code from %s"%p)
|
||||
|
||||
p = _join("setup","db","schema-level.sql")
|
||||
if _exists(p):
|
||||
p = dev_override(p)
|
||||
after = after + file(p).read()
|
||||
Utils.pprint("GREEN","Reading database code from %s"%p)
|
||||
|
||||
cmd = [ctx.env.MYSQL,"--user=%s"%dbuser,"-h",dbhost,"--password=%s"%dbpw]
|
||||
Utils.pprint("GREEN","Deploying post-configuration database scripts to %s (user %s)"%(dbhost,dbuser))
|
||||
Utils.pprint("BLUE"," ".join(cmd))
|
||||
p = _Popen(cmd,stdin=PIPE,stdout=None,stderr=None)
|
||||
p.communicate(after)
|
||||
retcode = p.wait()
|
||||
retcode = Utils.exec_command(cmd,shell=False,stdout=None,stderr=None,log=True)
|
||||
if retcode: raise CalledProcessError(retcode,cmd)
|
||||
|
||||
def deploydb_xenserver(ctx):
|
||||
|
|
|
|||
|
|
@ -115,12 +115,14 @@ conf.check_tool('tar')
|
|||
try: conf.check_tool('mkisofs')
|
||||
except Configure.ConfigurationError,e:
|
||||
raise Configure.ConfigurationError, "The program genisoimage (or mkisofs) could not be found.\nOn Linux: ./waf installrpmdeps or ./waf installdebdeps according to your distro's package format.\nOn Windows: Use cygwin to install the mkisofs package, then ensure that the program is in your PATH."
|
||||
try: conf.find_program('mysql',mandatory=True)
|
||||
except Configure.ConfigurationError,e:
|
||||
raise Configure.ConfigurationError, "The program mysql (or mysql.exe) could not be found.\nOn Linux: ./waf installrpmdeps or ./waf installdebdeps according to your distro's package format.\nOn Windows: Install the MySQL client package and ensure that the mysql.exe program is in your PATH."
|
||||
conf.check_tool('java')
|
||||
conf.check_tool("python")
|
||||
conf.check_python_version((2,4,0))
|
||||
conf.check_message_1('Detecting Python MySQL module')
|
||||
try: import MySQLdb
|
||||
except ImportError,e:
|
||||
raise Configure.ConfigurationError, "The Python MySQLdb module could not be found.\nOn Linux: ./waf installrpmdeps or ./waf installdebdeps according to your distro's package format.\nOn Windows: Install MySQL on your machine, then install the Python MySQLdb module for Python %s.\nThe module for Python 2.6 / win32 is available here: http://soemin.googlecode.com/files/MySQL-python-1.2.3c1.win32-py2.6.exe"%conf.env.PYTHON_VERSION
|
||||
conf.check_message_2('MySQLdb','GREEN')
|
||||
|
||||
if conf.env.DISTRO not in ["Windows","Mac"]:
|
||||
conf.check_tool('compiler_cc')
|
||||
|
|
|
|||
Loading…
Reference in New Issue