예제 #1
0
def start_qemu(conf_file=config.infrasim_default_config):
    try:
        with open(conf_file, 'r') as f_yml:
            conf = yaml.load(f_yml)
        compute = CCompute(conf["compute"])
        node_name = conf["name"] if "name" in conf else "node-0"

        logger_qemu = infrasim_log.get_logger(
            LoggerType.qemu.value, node_name)

        workspace = "{}/.infrasim/{}".format(os.environ["HOME"], node_name)
        if not os.path.isdir(workspace):
            os.mkdir(workspace)
        path_log = "/var/log/infrasim/{}".format(node_name)
        compute.logger = infrasim_log.get_logger(LoggerType.model.value, node_name)
        if not os.path.isdir(path_log):
            os.mkdir(path_log)

        sol_enabled = conf["sol_enable"] if "sol_enable" in conf else True

        compute.netns = conf.get("namespace")

        # Set attributes
        compute.enable_sol(sol_enabled)
        compute.set_task_name("{}-node".format(node_name))
        compute.set_log_path("/var/log/infrasim/{}/qemu.log".
                             format(node_name))
        compute.set_workspace("{}/.infrasim/{}".
                              format(os.environ["HOME"], node_name))
        compute.set_type(conf["type"])

        # Set interface
        if "type" not in conf:
            raise ArgsNotCorrect("Can't get infrasim type")
        else:
            compute.set_type(conf['type'])

        if "serial_socket" in conf:
            compute.set_socket_serial(conf["serial_socket"])

        if "bmc_connection_port" in conf:
            compute.set_port_qemu_ipmi(conf["bmc_connection_port"])

        compute.init()
        compute.precheck()
        compute.run()

        logger_qemu.info("qemu start")

        return
    except CommandRunFailed as e:
        logger_qemu.exception(e.value)
        raise e
    except ArgsNotCorrect as e:
        logger_qemu.exception(e.value)
        raise e
    except InfraSimError as e:
        logger_qemu.exception(e.value)
        raise e
예제 #2
0
def stop_qemu(conf_file=config.infrasim_default_config):
    try:
        with open(conf_file, 'r') as f_yml:
            conf = yaml.load(f_yml)
        compute = CCompute(conf["compute"])
        node_name = conf["name"] if "name" in conf else "node-0"

        logger_qemu = infrasim_log.get_logger(
            LoggerType.qemu.value, node_name)

        # Set attributes
        compute.logger = infrasim_log.get_logger(
            LoggerType.model.value, node_name)
        compute.set_task_name("{}-node".format(node_name))
        compute.set_log_path("/var/log/infrasim/{}/qemu.log".
                             format(node_name))
        compute.set_workspace("{}/.infrasim/{}".
                              format(os.environ["HOME"], node_name))
        compute.set_type(conf["type"])

        # Set interface
        if "type" not in conf:
            raise ArgsNotCorrect("Can't get infrasim type")
        else:
            compute.set_type(conf['type'])

        if "serial_socket" in conf:
            compute.set_socket_serial(conf["serial_socket"])

        if "bmc_connection_port" in conf:
            compute.set_port_qemu_ipmi(conf["bmc_connection_port"])

        compute.init()
        compute.terminate()

        logger_qemu.info("qemu stopped")
    except Exception, e:
        logger_qemu.exception(e.value)
        raise e