def scriptrunner(scripttype, os, arch, logfile):
    """
    Chooses and runs an installation script, and which logfile 
    that script will write its output to.
    
    Though not all scripts are OS-dependent, the "os" and "arch" 
    variables are used to determine if the system is supported.
    
    Parameters:
        1. scripttype: A string describing the installation script
           that is being run.
           Supported values: "dependencies", "pip", "initialize_instance," "update_instance"
        2. os: A string describing the operating system.
           Supported values: "ubuntu"
        3. arch: Architecture. Ubuntu is supported for "x86" and "x64" architectures.)
        4. logfile: The log file to pass to the installation script.
    """
    if os == "ubuntu" and (arch != "x86" and arch != "x64"):
        logfile.write("Unsupported architecture for %s: %s\n" % (os, arch))
        logfile.write("Script could not be completed.\n")
        print "Unsupported architecture for %s: %s\n" % (os, arch)
        print "Script could not be completed.\n"
        
    elif os == "redhat":
        logfile.write("This is not the script for Red Hat Enterprise Linux. Use redhat_installer.py instead.\n")
        logfile.write("Script could not be completed.\n")
        print "This is not the script for Red Hat Enterprise Linux. Use redhat_installer.py instead.\n"
        print "Script could not be completed.\n"

    elif os != "ubuntu" and os != "redhat":
        logfile.write("Unsupported operating system: %s\n" % os)
        logfile.write("Script could not be completed\n.")
        print "Unsupported operating system: %s\n" % os
        print "Script could not be completed.\n"
    
    else: 
        if scripttype == "dependencies":
            if os == "ubuntu":
                logfile = dependency.dependency_ubuntu.run(arch, logfile)
            elif os == "redhat":
                logfile.write("This is not the script for Red Hat Enterprise Linux. Use redhat_installer.py instead.\n")
                logfile.write("Script could not be completed.")
                print "This is not the script for Red Hat Enterprise Linux. Use redhat_installer.py instead.\n"
                print "Script could not be completed.\n"
        elif scripttype == "pip":
            logfile = pip.pip_install.run(logfile)
        elif scripttype == "initialize_instance":
            logfile = run_initialize_instance.run(logfile)
        elif scripttype == "update_instance":
            logfile = run_update_instance.run(logfile)
        else:
            logfile.write("Error: install.py invoked with invalid command: %s\n" % scripttype)
            print "Error: install.py invoked with invalid command: %s\n" % scripttype
        
    # After the function is done, return the logfile.
    return logfile
Example #2
0
def scriptrunner(scripttype, logfile, arch="no_arch"):
    """
    Chooses and runs an installation script, and supplies the
    logfile that the script will write its output to.
    
    Though not all scripts are OS-dependent, the "arch" 
    parameter is used to determine if the system is supported.
    
    Parameters:
        1. scripttype: The installation script that is being run. 
           Supported values: 
           "dependencies", "cleanup", "pip", "initialize_instance", "update_instance"
        2. logfile: The log file to pass to the installation script.
        3. arch: Architecture. RHEL / CentOS are supported for x86 and x64 architectures.
           The "dependencies" option requires x86 or x64 to be specified.
           The default value is "no_arch".
    """
    if (arch == "x86" or arch == "x64" or arch == "no_arch"):
        if scripttype == "dependencies" and (arch == "x86" or arch == "x64"):
            logfile = redhat.dependency_redhat.run(arch, logfile)
        elif scripttype == "dependencies" and arch == "no_arch":
            logfile.write("No architecture specified for dependencies.")
            logfile.write("Script could not be completed.\n")
            print "No architecture specified for dependencies."
            print "Script could not be completed.\n"
        elif (scripttype
              in ["cleanup", "pip", "initialize_instance", "update_instance"]):
            if (arch == "x86" or arch == "x64"):
                print("%s script is x86 and x64-compatible." % scripttype)
            # Run one of the architecture-independent scripts
            if scripttype == "cleanup":
                logfile = cleanup.run(logfile)
            elif scripttype == "pip":
                logfile = pip_install.run(logfile)
            elif scripttype == "initialize_instance":
                logfile = run_initialize_instance.run(logfile)
            elif scripttype == "update_instance":
                logfile = run_update_instance.run(logfile)
        else:
            logfile.write(
                "Error: redhat_installer.py invoked with invalid command: %s\n"
                % scripttype)
            print "Error: redhat_installer.py invoked with invalid command: %s" % scripttype
    else:
        logfile.write("Unsupported architecture for RHEL / CentOS: %s\n" %
                      arch)
        logfile.write("Script could not be completed.\n")
        print "Unsupported architecture for RHEL / CentOS: %s" % arch
        print "Script could not be completed."
    # After the function is done, return the logfile.
    return logfile
def scriptrunner(scripttype, logfile, arch="no_arch"):
    """
    Chooses and runs an installation script, and supplies the 
    logfile that the script will write its output to.
    
    Though not all scripts are OS-dependent, the "arch" 
    parameter is used to determine if the system is supported.
    
    Parameters:
        1. scripttype: The installation script that is being run. 
           Supported values: 
           "dependencies", "cleanup", "pip", "initialize_instance", "update_instance"
        2. logfile: The log file to pass to the installation script.
        3. arch: Architecture. Ubuntu is supported for x86 and x64 architectures.
           The "dependencies" option requires x86 or x64 to be specified.
           The default value is "no_arch".
    """
    if (arch == "x86" or arch == "x64" or arch == "no_arch"):
        if scripttype == "dependencies" and (arch == "x86" or arch == "x64"):
            logfile = ubuntu.dependency_ubuntu.run(arch, logfile)
        elif scripttype == "dependencies" and arch == "no_arch":
            logfile.write("No architecture specified for dependencies.")
            logfile.write("Script could not be completed.\n")
            print "No architecture specified for dependencies."
            print "Script could not be completed.\n"
        elif (scripttype in ["cleanup","pip","initialize_instance","update_instance"]):
            if (arch == "x86" or arch == "x64"):
                print ("%s script is x86 and x64-compatible." % scripttype)
            # Run one of the architecture-independent scripts
            if scripttype == "cleanup":
                logfile = cleanup.run(logfile)
            elif scripttype == "pip":
                logfile = pip_install.run(logfile)
            elif scripttype == "initialize_instance":
                logfile = run_initialize_instance.run(logfile)
            elif scripttype == "update_instance":
                logfile = run_update_instance.run(logfile)
        else:
            logfile.write("Error: ubuntu_installer.py invoked with invalid command: %s\n" % scripttype)
            print "Error: ubuntu_installer.py invoked with invalid command: %s\n" % scripttype
    else:
        logfile.write("Unsupported architecture for Ubuntu: %s\n" % arch)
        logfile.write("Script could not be completed.\n")
        print "Unsupported architecture for Ubuntu: %s\n" % arch
        print "Script could not be completed.\n"
    # After the function is done, return the logfile.
    return logfile