Ejemplo n.º 1
0
class BaseXMLRPCTest(BaseTest):
    def __init__(self, config):
        BaseTest.__init__(self, config)
        self.haizea = None
        self.haizea_thread = None

    def start(self):
        Manager.reset_singleton()
        self.haizea = Manager(HaizeaConfig(self.config))
        self.haizea_thread = threading.Thread(target=self.haizea.start)
        self.haizea_thread.start()
        
    def stop(self):
        self.haizea.stop()
        self.haizea_thread.join()
Ejemplo n.º 2
0
def create_haizea_thread(config):
    Manager.reset_singleton()
    haizea = Manager(HaizeaConfig(self.config))
    return haizea, threading.Thread(target=self.haizea.start)
Ejemplo n.º 3
0
def load_tracefile(config, tracefile):
    config.set("tracefile", "tracefile", tracefile)
    Manager.reset_singleton()
    reset_lease_id_counter()
    return Manager(HaizeaConfig(config))
Ejemplo n.º 4
0
def get_persistence():
    from haizea.core.manager import Manager
    return Manager().persistence
Ejemplo n.º 5
0
def get_policy():
    from haizea.core.manager import Manager
    return Manager().policy
Ejemplo n.º 6
0
def get_clock():
    from haizea.core.manager import Manager
    return Manager().clock
Ejemplo n.º 7
0
def get_config():
    from haizea.core.manager import Manager
    return Manager().config
Ejemplo n.º 8
0
class haizea(Command):
    """
    This is the main Haizea command. By default, it will start Haizea as a daemon, which
    can receive requests via RPC or interact with other components such as OpenNebula. It can
    also start as a foreground process, and write all log messages to the console. All
    Haizea options are specified through the configuration file."""

    name = "haizea"

    def __init__(self, argv):
        Command.__init__(self, argv)

        self.optparser.add_option(
            Option("-c",
                   "--conf",
                   action="store",
                   type="string",
                   dest="conf",
                   help="""
                                         The location of the Haizea configuration file. If not
                                         specified, Haizea will first look for it in
                                         /etc/haizea/haizea.conf and then in ~/.haizea/haizea.conf.
                                         """))
        self.optparser.add_option(
            Option("-f",
                   "--fg",
                   action="store_true",
                   dest="foreground",
                   help="""
                                         Runs Haizea in the foreground.
                                         """))
        self.optparser.add_option(
            Option("--stop",
                   action="store_true",
                   dest="stop",
                   help="""
                                         Stops the Haizea daemon.
                                         """))

    def run(self):
        self.parse_options()

        pidfile = defaults.DAEMON_PIDFILE  # TODO: Make configurable

        if self.opt.stop == None:
            # Start Haizea

            # Check if a daemon is already running
            if os.path.exists(pidfile):
                pf = file(pidfile, 'r')
                pid = int(pf.read().strip())
                pf.close()

                try:
                    os.kill(pid, signal.SIG_DFL)
                except OSError, (err, msg):
                    if err == errno.ESRCH:
                        # Pidfile is stale. Remove it.
                        os.remove(pidfile)
                    else:
                        msg = "Unexpected error when checking pid file '%s'.\n%s\n" % (
                            pidfile, msg)
                        sys.stderr.write(msg)
                        sys.exit(1)
                else:
                    msg = "Haizea seems to be already running (pid %i)\n" % pid
                    sys.stderr.write(msg)
                    sys.exit(1)

            try:
                configfile = self.opt.conf
                if configfile == None:
                    # Look for config file in default locations
                    for loc in defaults.CONFIG_LOCATIONS:
                        if os.path.exists(loc):
                            config = HaizeaConfig.from_file(loc)
                            break
                    else:
                        print >> sys.stdout, "No configuration file specified, and none found at default locations."
                        print >> sys.stdout, "Make sure a config file exists at:\n  -> %s" % "\n  -> ".join(
                            defaults.CONFIG_LOCATIONS)
                        print >> sys.stdout, "Or specify a configuration file with the --conf option."
                        exit(1)
                else:
                    config = HaizeaConfig.from_file(configfile)
            except ConfigException, msg:
                print >> sys.stderr, "Error in configuration file:"
                print >> sys.stderr, msg
                exit(1)

            daemon = not self.opt.foreground

            manager = Manager(config, daemon, pidfile)

            manager.start()
Ejemplo n.º 9
0
 def start(self):
     Manager.reset_singleton()
     self.haizea = Manager(HaizeaConfig(self.config))
     self.haizea_thread = threading.Thread(target=self.haizea.start)
     self.haizea_thread.start()
Ejemplo n.º 10
0
 def test_wait(self):
     self.set_tracefile("wait.lwf")
     Manager.reset_singleton()
     haizea = Manager(HaizeaConfig(self.config))
     haizea.start()
Ejemplo n.º 11
0
 def test_migrate(self):
     self.set_tracefile("migrate.lwf")
     Manager.reset_singleton()
     haizea = Manager(HaizeaConfig(self.config))
     haizea.start()
Ejemplo n.º 12
0
 def test_reservation_prematureend(self):
     self.set_tracefile("reservation_prematureend.lwf")
     Manager.reset_singleton()
     haizea = Manager(HaizeaConfig(self.config))
     haizea.start()
Ejemplo n.º 13
0
 def test_preemption(self):
     self.set_tracefile("preemption.lwf")
     Manager.reset_singleton()
     haizea = Manager(HaizeaConfig(self.config))
     haizea.start()