def run(self):
     # keep relative space
     # allow newline chars in title. This is useful for plugins
     alignedTitle = self.getTitle()
     if re.search('\n', alignedTitle):
         alignedTitle = self.getTitle().split('\n')[-1]
     for color in basedefs.COLORS:
         if color in alignedTitle:
             alignedTitle = string.replace(alignedTitle, color, '')
     spaceLen = basedefs.SPACE_LEN - len(alignedTitle)
     sys.stdout.write("%s..." % self.getTitle())
     sys.stdout.flush()
     for function in self.getFunctions():
         try:
             logging.debug("running %s" % (function.func_name))
             function()
         except:
             logging.debug(traceback.format_exc())
             print("[ " + utils.getColoredText(output_messages.INFO_ERROR,
                                               basedefs.RED) +
                   " ]").rjust(spaceLen)
             raise
     print("[ " +
           utils.getColoredText(output_messages.INFO_DONE, basedefs.GREEN) +
           " ]").rjust(spaceLen)
Esempio n. 2
0
def runFunc(funcList, dispString):
    print "%s..."%(dispString),
    sys.stdout.flush()
    spaceLen = basedefs.SPACE_LEN - len(dispString)
    try:
        for func in funcList:
            if type(func) is types.ListType:
                func[0](*func[1:])
            else:
                func()
        print ("[ " + utils.getColoredText(MSG_INFO_DONE, basedefs.GREEN) + " ]").rjust(spaceLen)
    except:
        print ("[ " + utils.getColoredText(MSG_INFO_ERROR, basedefs.RED) + " ]").rjust(spaceLen+3)
        raise
def runFunc(funcList, dispString):
    print "%s..." % (dispString),
    sys.stdout.flush()
    spaceLen = basedefs.SPACE_LEN - len(dispString)
    try:
        for func in funcList:
            if type(func) is types.ListType:
                func[0](*func[1:])
            else:
                func()
        print("[ " + utils.getColoredText(MSG_INFO_DONE, basedefs.GREEN) +
              " ]").rjust(spaceLen)
    except:
        print("[ " + utils.getColoredText(MSG_INFO_ERROR, basedefs.RED) +
              " ]").rjust(spaceLen + 3)
        raise
Esempio n. 4
0
def _main(configFile=None):
    try:
        logging.debug("Entered main(configFile='%s')"%(configFile))
        print output_messages.INFO_HEADER

        # Get parameters
        _handleParams(configFile)

        # Update masked_value_list with user input values
        _updateMaskedValueSet()

        # Print masked conf
        logging.debug(mask(controller.CONF))

        # Start configuration stage
        logging.debug("Entered Configuration stage")
        print "\n",output_messages.INFO_INSTALL

        # Initialize Sequences
        initPluginsSequences()

        # Run main setup logic
        runSequences()

        # Lock rhevm version
        #_lockRpmVersion()

        # Print info
        _addFinalInfoMsg()
        print output_messages.INFO_INSTALL_SUCCESS

    except Exception, e:
        controller.MESSAGES.append(utils.getColoredText("ERROR : "+str(e), basedefs.RED))
        controller.MESSAGES.append(output_messages.ERR_CHECK_LOG_FILE_FOR_MORE_INFO%(logFile))
        logging.exception(e)
Esempio n. 5
0
class Step(object):
    def __init__(self, title=None, functions=[]):
        self.__TITLE = None
        self.__FUNCTIONS = []
        if title:
            if not isinstance(title, str):
                raise TypeError(
                    "step's title should be of string type instead of %s" %
                    type(title))
        if not isinstance(functions, list):
            raise TypeError(
                "step's function should be of list type instead of %s" %
                type(functions))
        for function in functions:
            if not callable(function):
                raise TypeError(
                    "All parameters which pass as functions should be callable. %s is not callable"
                    % function)

        self.setTitle(title)
        for function in functions:
            self.addFunction(function)

    def setTitle(self, title):
        self.__TITLE = title

    def getTitle(self):
        return self.__TITLE

    def addFunction(self, function):
        self.__FUNCTIONS.append(function)

    def removeFunction(self, function):
        self.__FUNCTIONS.remove(function)

    def getFunctions(self):
        return self.__FUNCTIONS

    def run(self):
        #keep relative space
        spaceLen = basedefs.SPACE_LEN - len(self.getTitle())
        print "%s..." % (self.getTitle()),
        sys.stdout.flush()
        for function in self.getFunctions():
            try:
                logging.debug("running %s" % (function.func_name))
                function()
            except Exception, (instance):
                print(
                    "[ " + utils.getColoredText(output_messages.INFO_ERROR,
                                                basedefs.RED) +
                    " ]").rjust(spaceLen)
                raise Exception(instance)
        print("[ " +
              utils.getColoredText(output_messages.INFO_DONE, basedefs.GREEN) +
              " ]").rjust(spaceLen)
 def run(self):
     # keep relative space
     # allow newline chars in title. This is useful for plugins
     alignedTitle = self.getTitle()
     if re.search('\n', alignedTitle):
         alignedTitle = self.getTitle().split('\n')[-1]
     for color in basedefs.COLORS:
         if color in alignedTitle:
             alignedTitle = string.replace(alignedTitle, color, '')
     spaceLen = basedefs.SPACE_LEN - len(alignedTitle)
     sys.stdout.write("%s..." % self.getTitle())
     sys.stdout.flush()
     for function in self.getFunctions():
         try:
             logging.debug("running %s"%(function.func_name))
             function()
         except:
             logging.debug(traceback.format_exc())
             print ("[ " + utils.getColoredText(output_messages.INFO_ERROR, basedefs.RED) + " ]").rjust(spaceLen)
             raise
     print ("[ " + utils.getColoredText(output_messages.INFO_DONE, basedefs.GREEN) + " ]").rjust(spaceLen)
 def run(self):
     #keep relative space
     spaceLen = basedefs.SPACE_LEN - len(self.getTitle())
     print "%s..."%(self.getTitle()),
     sys.stdout.flush()
     for function in self.getFunctions():
         try:
             logging.debug("running %s"%(function.func_name))
             function()
         except Exception, (instance):
             print ("[ " + utils.getColoredText(output_messages.INFO_ERROR, basedefs.RED) + " ]").rjust(spaceLen)
             raise Exception(instance)
Esempio n. 8
0
 def run(self):
     #keep relative space
     spaceLen = basedefs.SPACE_LEN - len(self.getTitle())
     print "%s..." % (self.getTitle()),
     sys.stdout.flush()
     for function in self.getFunctions():
         try:
             logging.debug("running %s" % (function.func_name))
             function()
         except Exception, (instance):
             print(
                 "[ " + utils.getColoredText(output_messages.INFO_ERROR,
                                             basedefs.RED) +
                 " ]").rjust(spaceLen)
             raise Exception(instance)
Esempio n. 9
0
def remove_remote_var_dirs():
    """
    Removes the temp directories on remote hosts,
    doesn't remove data on localhost
    """
    for host in gethostlist(controller.CONF):
        try:
            host_dir = controller.temp_map[host]
        except KeyError:
            # Nothing was added to this host yet, so we have nothing to delete
            continue
        logging.info(output_messages.INFO_REMOVE_REMOTE_VAR % (host_dir, host))
        server = utils.ScriptRunner(host)
        server.append('rm -rf %s' % host_dir)
        try:
            server.execute()
        except Exception, e:
            msg = output_messages.ERR_REMOVE_REMOTE_VAR % (host_dir, host)
            logging.error(msg)
            logging.exception(e)
            controller.MESSAGES.append(utils.getColoredText(msg, basedefs.RED))
Esempio n. 10
0
def remove_remote_var_dirs():
    """
    Removes the temp directories on remote hosts,
    doesn't remove data on localhost
    """
    for host in gethostlist(controller.CONF):
        try:
            host_dir = controller.temp_map[host]
        except KeyError:
            # Nothing was added to this host yet, so we have nothing to delete
            continue
        logging.info(output_messages.INFO_REMOVE_REMOTE_VAR % (host_dir, host))
        server = utils.ScriptRunner(host)
        server.append('rm -rf %s' % host_dir)
        try:
            server.execute()
        except Exception, e:
            msg = output_messages.ERR_REMOVE_REMOTE_VAR % (host_dir, host)
            logging.error(msg)
            logging.exception(e)
            controller.MESSAGES.append(utils.getColoredText(msg, basedefs.RED))
Esempio n. 11
0
from ovirtsdk.api import API
from ovirtsdk.xml import params

# Override basedefs default so that status message are aligned
basedefs.SPACE_LEN = 80

# Product version
MAJOR = '3'
MINOR = '1'

# Controller object will be initialized from main flow
controller = None

# Plugin name
PLUGIN_NAME = "AIO"
PLUGIN_NAME_COLORED = utils.getColoredText(PLUGIN_NAME, basedefs.BLUE)

# INFO Messages
INFO_CONF_PARAMS_ALL_IN_ONE_USAGE = "Configure all in one"
INFO_CONF_PARAMS_ALL_IN_ONE_PROMPT = "Configure VDSM on this host?"
INFO_CONF_PARAMS_LOCAL_STORAGE = "Local storage domain path"
INFO_LIBVIRT_START = "libvirt service is started"
INFO_CREATE_HOST_WAITING_UP = "Waiting for the host to start"

# ERROR MESSAGES
SYSTEM_ERROR = "System Error"
ERROR_CREATE_API_OBJECT = "Error: could not create ovirtsdk API object"
ERROR_CREATE_LOCAL_DATACENTER = "Error: Could not create local datacenter"
ERROR_CREATE_LOCAL_CLUSTER = "Error: Could not create local cluster"
ERROR_CREATE_LOCAL_HOST = "Error: Could not install local host"
ERROR_CREATE_HOST_FAILED = "Error: Host was found in a 'Failed' state. Please check engine and bootstrap installation logs."
Esempio n. 12
0
            if options.answer_file:
                validateSingleFlag(options, "answer_file")
                confFile = os.path.expanduser(options.answer_file)
                if not os.path.exists(confFile):
                    raise Exception(output_messages.ERR_NO_ANSWER_FILE %
                                    confFile)
            else:
                _set_command_line_values(options)
            _main(confFile)

    except FlagValidationError, ex:
        optParser.print_help()
        print
    except Exception as e:
        logging.error(traceback.format_exc())
        print
        print utils.getColoredText("ERROR : " + str(e), basedefs.RED)
        print output_messages.ERR_CHECK_LOG_FILE_FOR_MORE_INFO % (logFile)
        sys.exit(1)

    finally:
        remove_remote_var_dirs()

        # Always print user params to log
        _printAdditionalMessages()
        _summaryParamsToLog()


if __name__ == "__main__":
    main()
Esempio n. 13
0
from ovirtsdk.api import API
from ovirtsdk.xml import params

# Override basedefs default so that status message are aligned
basedefs.SPACE_LEN = 80

# Product version
MAJOR = '3'
MINOR = '1'

# Controller object will be initialized from main flow
controller = None

# Plugin name
PLUGIN_NAME = "AIO"
PLUGIN_NAME_COLORED = utils.getColoredText(PLUGIN_NAME, basedefs.BLUE)

# INFO Messages
INFO_CONF_PARAMS_ALL_IN_ONE_USAGE = "Configure all in one"
INFO_CONF_PARAMS_ALL_IN_ONE_PROMPT = "Configure VDSM on this host?"
INFO_CONF_PARAMS_LOCAL_STORAGE = "Local storage domain path"
INFO_LIBVIRT_START = "libvirt service is started"
INFO_CREATE_HOST_WAITING_UP = "Waiting for the host to start"

# ERROR MESSAGES
SYSTEM_ERROR = "System Error"
ERROR_CREATE_API_OBJECT = "Error: could not create ovirtsdk API object"
ERROR_CREATE_LOCAL_DATACENTER = "Error: Could not create local datacenter"
ERROR_CREATE_LOCAL_CLUSTER = "Error: Could not create local cluster"
ERROR_CREATE_LOCAL_HOST = "Error: Could not install local host"
ERROR_CREATE_HOST_FAILED = "Error: Host was found in a 'Failed' state. Please check engine and bootstrap installation logs."
Esempio n. 14
0
            # Make sure only --answer-file was supplied
            if options.answer_file:
                validateSingleFlag(options, "answer_file")
                confFile = os.path.expanduser(options.answer_file)
                if not os.path.exists(confFile):
                    raise Exception(output_messages.ERR_NO_ANSWER_FILE % confFile)
            else:
                _set_command_line_values(options)
            _main(confFile)

    except FlagValidationError, ex:
        optParser.print_help()
        print
    except Exception as e:
        logging.error(traceback.format_exc())
        print
        print utils.getColoredText("ERROR : "+str(e), basedefs.RED)
        print output_messages.ERR_CHECK_LOG_FILE_FOR_MORE_INFO%(logFile)
        sys.exit(1)

    finally:
        remove_remote_var_dirs()

        # Always print user params to log
        _printAdditionalMessages()
        _summaryParamsToLog()


if __name__ == "__main__":
    main()