blob: 3b2fa1a81858f43a235d07ed86d10b994d425e40 [file] [log] [blame]
#!/usr/bin/env python
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# $Id$
#
import os
import sys
import time
import string
import traceback
import optparse
import shutil
import urllib
import tarfile
a = os.path.join("../")
sys.path.append(a)
a = os.path.join("../../")
sys.path.append(a)
a = os.path.join("../../..")
sys.path.append(a)
from zoni.extra.util import *
from zoni.version import *
from zoni.bootstrap.pxe import Pxe
def main():
''' This file sets up the web files for Zoni '''
ver = version.split(" ")[0]
rev = revision
parser = optparse.OptionParser(usage="%prog ", version="%prog " + ver + " " + rev)
(options, args) = parser.parse_args()
(configs, configFiles) = getConfig()
ZoniWebSetup(configs)
ZoniCreateWebConfigFile(configs)
def ZoniCreateWebConfigFile(config):
zoniBaseDir = config['installBaseDir']
docRoot = config['wwwDocumentRoot']
baseDir = config['registrationBaseDir']
dbHost = config['dbHost']
dbPort = str(config['dbPort'])
dbInst = config['dbInst']
dbUser = config['dbUser']
dbPassword = config['dbPassword']
zoniHomeDomain = config['zoniHomeDomain']
zoniHomeNetwork = config['zoniHomeNetwork']
zoniIpmiNetwork = config['zoniIpmiNetwork']
zoniRoot = os.path.join(docRoot, baseDir)
includeDir = os.path.join(docRoot, baseDir, "include")
includeFile = os.path.join(includeDir, "zoni_www_registration.conf")
a = "<?php\n"
a += "/* Generated by Zoni on " + time.asctime() + " */\n\n\n"
a += "function init_globals() {\n"
a += " $G = array();\n"
a += "\n"
a += " // Zoni Install Base\n";
a += " $G['ZONI_BASE_DIR'] = \"" + zoniBaseDir + "\";\n"
a += "\n"
a += " // webserver directories\n";
a += " $G['ABSROOT'] = \"" + zoniRoot + "\";\n"
a += " $G['WEBROOT'] = \"" + baseDir + "\";\n"
a += "\n"
a += " // DB info\n";
a += " $G['DB_HOST'] = \"" + dbHost + "\";\n"
a += " $G['DB_USER'] = \"" + dbUser + "\";\n"
a += " $G['DB_PASS'] = \"" + dbPassword + "\";\n"
a += " $G['DB_INST'] = \"" + dbInst + "\";\n"
a += " $G['DB_PORT'] = \"" + dbPort + "\";\n"
a += "\n"
a += " // Zoni Home Domain \n";
a += " $G['ZONI_HOME_DOMAIN'] = \"" + zoniHomeDomain + "\";\n"
a += " $G['ZONI_HOME_NETWORK'] = \"" + zoniHomeNetwork + "\";\n"
a += " $G['ZONI_IPMI_NETWORK'] = \"" + zoniIpmiNetwork + "\";\n"
a += "\n"
a += " ini_set('display_errors', 1);\n"
a += " ini_set('error_reporting', E_ALL);\n"
a += "\n"
a += " return $G;\n"
a += "}\n"
a += "?>\n"
# Rename any existing
if os.path.exists(includeFile):
includeFileBak = os.path.join(includeFile + "." + str(int(time.time())))
shutil.move(includeFile, includeFileBak)
f = open(includeFile, "w")
f.write(a)
f.close()
@checkSuper
def ZoniWebSetup(config):
docRoot = config['wwwDocumentRoot']
baseDir = config['registrationBaseDir']
zoniInstallDir = config['installBaseDir']
zoniWebRoot = os.path.join(docRoot, baseDir )
if not (createDir(zoniWebRoot, 1)): print "Please use sudo"; exit()
zoniIncludeDir = os.path.join(zoniWebRoot, "include")
createDir(zoniIncludeDir)
zoniRegisterDir = os.path.join(zoniWebRoot, "register")
createDir(zoniRegisterDir)
sys.stdout.write(" Copying zoni_function.php\n")
zoniIncludeSrcFile = os.path.join(zoniInstallDir, "src", "zoni", "system", "registration", "www", "include", "zoni_functions.php")
shutil.copy(zoniIncludeSrcFile, zoniIncludeDir)
sys.stdout.write(" Copying register_node\n")
zoniRegisterSrcFile = os.path.join(zoniInstallDir, "src", "zoni", "system", "registration", "register", "register_node")
shutil.copy(zoniRegisterSrcFile, zoniRegisterDir)
sys.stdout.write(" Copying register_automate\n")
zoniRegisterAutoSrcFile = os.path.join(zoniInstallDir, "src", "zoni", "system", "registration", "register", "register_automate")
shutil.copy(zoniRegisterAutoSrcFile, zoniRegisterDir)
sys.stdout.write(" Copying zoni-register.php\n")
zoniRegisterSrcFile = os.path.join(zoniInstallDir, "src", "zoni", "system", "registration", "www", "zoni-register.php")
shutil.copy(zoniRegisterSrcFile, zoniWebRoot)
if __name__ in "__main__":
main()