Ejemplo n.º 1
0
 def install(vcl_db, vcl_host, vcl_username, vcl_password,
                 webserver_ip_address):    
     call(["yum", "install", "httpd", "mod_ssl", "php", "php-gd",
             "php-mysql", "php-xml", "php-xmlrpc", "php-ldap", "-y"])
     call(["/sbin/chkconfig", "--level", "345", "httpd", "on"])
     call(["/sbin/service", "httpd", "start"])
 
     # Install the front end
     saved_path = os.getcwd()
     shutil.copytree("apache-VCL-2.3.1/web/", "/var/www/html/vcl")
     os.chdir("/var/www/html/vcl/.ht-inc")
     shutil.copy("secrets-default.php", "secrets.php")
 
     # Update the default values
     file_handler, abs_path = mkstemp()    
     
     old_file = open("secrets.php")
     temp_file = open(abs_path, 'w')
 
     parameters = dict()
     parameters["$vclhost"] = "'%s'" % vcl_host
     parameters["$vcldb"] = "'%s'" % vcl_db
     parameters["$vclusername"] = "******" % vcl_username
     parameters["$vclpassword"] = "******" % vcl_password
     parameters["$cryptkey"] = "'%s'" % Utilities.generate_random_text()
     parameters["$pemkey"] = "'%s'" % Utilities.generate_random_text()
 
     for line in old_file:
         if "=" in line:
             key, value = line.split('=')
             newline = "%s = %s;%s" % (key.strip(),
                                         parameters[key.strip()],
                                         value.split(';')[1])
             temp_file.write(newline)
         else:
             temp_file.write(line)
     
     old_file.close()
     temp_file.close()
     close(file_handler)
 
     # Copy from the temp file to secrets.php (so as not to loose the 
     # file permissions on secrets.php
     secrets_file = open("secrets.php", 'w')
     temp_file = open(abs_path)
 
     for line in temp_file:
         secrets_file.write(line)
 
     secrets_file.close()
 
     call("./genkeys.sh")
     shutil.copy("conf-default.php", "conf.php")
     # Update the IP address in conf.php
     file_handler, abs_path = mkstemp()
 
     old_file = open("conf.php")
     temp_file = open(abs_path, 'w')
 
     for line in old_file:
         if "vcl.example.org" in line:            
             newline = line.replace("vcl.example.org", webserver_ip_address)
             temp_file.write(newline)
         elif "\".example.org\"" in line:
             newline = line.replace(".example.org", "")
             temp_file.write(newline)
         else:
             temp_file.write(line)
     
     old_file.close()
     temp_file.close()
     close(file_handler)
 
     # Copy from the temp file to secrets.php (so as not to loose the 
     # file permissions on secrets.php
     conf_file = open("conf.php", 'w')
     temp_file = open(abs_path)
 
     for line in temp_file:
         conf_file.write(line)
 
     conf_file.close()
     
     # TODO: Update the help and error email ids in conf.php
     call(["chown", "apache", "maintenance"])
    
     # TODO: Do not hard coded the user and module name
     WebserverInstaller.add_management_node(
                                 database_ip_address=webserver_ip_address,
                                 hostname=vcl_host,
                                 username="******",
                                 pred_module_name="predictive_level_0")
 
     os.chdir(saved_path)