def start(instance="default", ipaddr="", port=10022, username="******", password="******", data_src="auto"): # Init environment env.logger_r = infrasim_log.get_logger(LoggerType.racadm.value, instance) env.auth_map[username] = password env.node_name = instance atexit.register(atexit_cb) signal.signal(signal.SIGTERM, atexit_cb) cmd_rev = 'racadmsim ' for word in sys.argv[1:]: cmd_rev += word+' ' env.logger_r.info('racadmsim command rev: {}'.format(cmd_rev)) if os.path.exists(data_src): env.racadm_data = data_src env.local_env.server = sshim.Server(iDRACServer, logger=env.logger_r, address=ipaddr, port=int(port), handler=iDRACHandler) env.logger_r.info("{}-racadm start on ip: {}, port: {}". format(env.node_name, ipaddr, port)) env.local_env.server.run()
def start(instance="default"): """ Attach ipmi-console to target instance specified by its name :param instance: infrasim instance name """ # initialize logging global logger_ic logger_ic = infrasim_log.get_logger(LoggerType.ipmi_console.value, instance) common.init_logger(instance) # initialize environment env.local_env.quit_flag = False common.init_env(instance) pid_file = "{}/{}/.ipmi_console.pid".format(config.infrasim_home, instance) daemon.daemonize(pid_file) with open(pid_file, "r") as fp: logger_ic.info("ipmi-console of {} start with pid {}". format(instance, fp.read().strip())) # parse the sdrs and build all sensors sdr.parse_sdrs() # running thread for each threshold based sensor _start_monitor(instance) _spawn_sensor_thread() _start_console(instance)
def start(instance="default"): """ Attach ipmi-console to target instance specified by its name :param instance: infrasim instance name """ # initialize logging global logger_ic logger_ic = infrasim_log.get_logger(LoggerType.ipmi_console.value, instance) common.init_logger(instance) # initialize environment env.local_env.quit_flag = False common.init_env(instance) daemon.daemonize("{}/{}/.ipmi_console.pid".format(config.infrasim_home, instance)) # parse the sdrs and build all sensors sdr.parse_sdrs() # running thread for each threshold based sensor _start_monitor(instance) _spawn_sensor_thread() _start_console(instance)
def __init__(self, node_info=None): self.__tasks_list = [] self.__node = node_info self.__node_name = "" self.workspace = None self.__sol_enabled = None self.__netns = None self.__logger = infrasim_log.get_logger(LoggerType.model.value)
def __init__(self, node_info=None): self.__tasks_list = [] self.__node = node_info self.__node_name = "" self.workspace = None self.__sol_enabled = None self.__netns = None self.__logger = infrasim_log.get_logger(LoggerType.model.value)
def _start_monitor(instance="default"): """ Create a monitor thread to watch vbmc status. :param instance: infrasim node name """ global logger_ic logger_ic = infrasim_log.get_logger(LoggerType.ipmi_console.value, instance) logger_ic.info("ipmi-console monitor thread starts to run.") monitor_thread = threading.Thread(target=monitor, args=(instance,)) monitor_thread.setDaemon(True) monitor_thread.start()
def _start_monitor(instance="default"): """ Create a monitor thread to watch vbmc status. :param instance: infrasim node name """ global logger_ic logger_ic = infrasim_log.get_logger(LoggerType.ipmi_console.value, instance) logger_ic.info("ipmi-console monitor thread starts to run.") monitor_thread = threading.Thread(target=monitor, args=(instance, )) monitor_thread.setDaemon(True) monitor_thread.start()
def _start_console(instance="default"): global logger_ic logger_ic = infrasim_log.get_logger(LoggerType.ipmi_console.value, instance) global server server = sshim.Server(IPMI_CONSOLE, logger_ic, port=env.PORT_SSH_FOR_CLIENT) try: logger_ic.info("command res: ipmi-console start {} " "is finished".format(instance)) server.run() except KeyboardInterrupt as e: logger_ic.error("{} \nstart to stop ipmi-console".format(str(e))) server.stop()
def __init__(self): # priroty should be range from 0 to 5 # +-----+-----+-----+----+-----+ # | 0 | 1 | 2 | 3 | 4 | # +-----+-----+-----+----+-----+ # |High | | Low | # +-----+-----+-----+----+-----+ self.__task_priority = None self.__workspace = None self.__task_name = None self.__log_path = "" self.__logger = infrasim_log.get_logger(LoggerType.model.value) # If any task set the __asyncronous to True, # this task shall only be maintained with information # no actual run shall be taken self.__asyncronous = False self.__netns = None
def __init__(self): # priroty should be range from 0 to 5 # +-----+-----+-----+----+-----+ # | 0 | 1 | 2 | 3 | 4 | # +-----+-----+-----+----+-----+ # |High | | Low | # +-----+-----+-----+----+-----+ self.__task_priority = None self.__workspace = None self.__task_name = None self.__log_path = "" self.__logger = infrasim_log.get_logger(LoggerType.model.value) # If any task set the __asyncronous to True, # this task shall only be maintained with information # no actual run shall be taken self.__asyncronous = False self.__netns = None
def stop(instance="default"): """ Stop ipmi-console of target instance specified by its name :param instance: infrasim instance name """ global logger_ic logger_ic = infrasim_log.get_logger(LoggerType.ipmi_console.value, instance) try: file_ipmi_console_pid = "{}/{}/.ipmi_console.pid".\ format(config.infrasim_home, instance) with open(file_ipmi_console_pid, "r") as f: pid = f.readline().strip() os.kill(int(pid), signal.SIGTERM) logger_ic.info("SIGTERM is sent to pid: {}".format(pid)) os.remove(file_ipmi_console_pid) except IOError: # When pid file is missing, by e.g., node destroy, # find process id by instance name if instance == "default": process_name = "ipmi-console start$" else: process_name = "ipmi-console start {}".format(instance) ps_cmd = r"ps ax | grep '{}' | grep Sl | awk '{{print $1}}' | head -n1".format( process_name) logger_ic.warning("Fail to find ipmi console pid file, check by:") logger_ic.warning("> {}".format(ps_cmd)) _, pid = run_command(cmd=ps_cmd) logger_ic.warning("ipmi console pid got: {}".format(pid)) if not pid: logger_ic.warning( "ipmi console for instance {} is not running".format(instance)) return os.kill(int(pid), signal.SIGTERM) logger_ic.info("SIGTERM is sent to pid: {}".format(pid)) except Exception: logger_ic.warning(traceback.format_exc()) pass
def stop(instance="default"): """ Stop ipmi-console of target instance specified by its name :param instance: infrasim instance name """ global logger_ic logger_ic = infrasim_log.get_logger(LoggerType.ipmi_console.value, instance) try: file_ipmi_console_pid = "{}/{}/.ipmi_console.pid".\ format(config.infrasim_home, instance) with open(file_ipmi_console_pid, "r") as f: pid = f.readline().strip() os.remove(file_ipmi_console_pid) os.kill(int(pid), signal.SIGTERM) except: pass
def stop(instance="default"): """ Stop ipmi-console of target instance specified by its name :param instance: infrasim instance name """ global logger_ic logger_ic = infrasim_log.get_logger(LoggerType.ipmi_console.value, instance) try: file_ipmi_console_pid = "{}/{}/.ipmi_console.pid".\ format(config.infrasim_home, instance) with open(file_ipmi_console_pid, "r") as f: pid = f.readline().strip() os.kill(int(pid), signal.SIGTERM) logger_ic.info("SIGTERM is sent to pid: {}".format(pid)) os.remove(file_ipmi_console_pid) except IOError: # When pid file is missing, by e.g., node destroy, # find process id by instance name if instance == "default": process_name = "ipmi-console start$" else: process_name = "ipmi-console start {}".format(instance) ps_cmd = r"ps ax | grep '{}' | grep Sl | awk '{{print $1}}' | head -n1".format(process_name) logger_ic.warning("Fail to find ipmi console pid file, check by:") logger_ic.warning("> {}".format(ps_cmd)) _, pid = run_command(cmd=ps_cmd) logger_ic.warning("ipmi console pid got: {}".format(pid)) if not pid: logger_ic.warning("ipmi console for instance {} is not running".format(instance)) return os.kill(int(pid), signal.SIGTERM) logger_ic.info("SIGTERM is sent to pid: {}".format(pid)) except Exception: logger_ic.warning(traceback.format_exc()) pass
def console_main(instance="default"): """ Usage: ipmi-console [start | stop ] [ node_name ] node_name is optional. """ global logger_ic cmdline = 'ipmi-console ' for word in sys.argv[1:]: cmdline += word + " " try: #register the atexit call back function atexit.register(atexit_cb) signal.signal(signal.SIGTERM, atexit_cb) arg_num = len(sys.argv) if arg_num < 2 or arg_num > 3: logger_ic.info('command rev: {}'.format(cmdline)) logger_ic.error(console_main.__doc__) raise IpmiError("{}".format(console_main.__doc__)) if arg_num == 3: if sys.argv[2] == "-h": logger_ic.info('command rev: {}'.format(cmdline)) print console_main.__doc__ logger_ic.info('command res: have shown the help') sys.exit() instance = sys.argv[2] logger_ic = infrasim_log.get_logger(LoggerType.ipmi_console.value, instance) logger_ic.info('command res: {}'.format(cmdline)) if sys.argv[1] == "start": start(instance) elif sys.argv[1] == "stop": stop(instance) logger_ic.info("command res: stop ipmi-console is finished.") else: logger_ic.error(console_main.__doc__) raise IpmiError("{}".format(console_main.__doc__)) except Exception as e: sys.exit(e)
def console_main(instance="default"): """ Usage: ipmi-console [start | stop ] [ node_name ] node_name is optional. """ global logger_ic cmdline = 'ipmi-console ' for word in sys.argv[1:]: cmdline += word+" " try: #register the atexit call back function atexit.register(atexit_cb) signal.signal(signal.SIGTERM, atexit_cb) arg_num = len(sys.argv) if arg_num < 2 or arg_num > 3: logger_ic.info('command rev: {}'.format(cmdline)) logger_ic.error(console_main.__doc__) raise IpmiError("{}".format(console_main.__doc__)) if arg_num == 3: if sys.argv[2] == "-h": logger_ic.info('command rev: {}'.format(cmdline)) print console_main.__doc__ logger_ic.info('command res: have shown the help') sys.exit() instance = sys.argv[2] logger_ic = infrasim_log.get_logger( LoggerType.ipmi_console.value, instance) logger_ic.info('command res: {}'.format(cmdline)) if sys.argv[1] == "start": start(instance) elif sys.argv[1] == "stop": stop(instance) logger_ic.info("command res: stop ipmi-console is finished.") else: logger_ic.error(console_main.__doc__) raise IpmiError("{}".format(console_main.__doc__)) except Exception as e: sys.exit(e)
def __init__(self): self.__option_list = [] self.__owner = None self.__logger = infrasim_log.get_logger(LoggerType.model.value)
from infrasim.log import infrasim_log, LoggerType mlog = infrasim_log.get_logger(logger_name=LoggerType.monitor.value, node_name=None) def init_logger(node_name): mlog = infrasim_log.get_logger(logger_name=LoggerType.monitor.value, node_name=node_name) return mlog def get_logger(): return mlog
def init_logger(node_name): mlog = infrasim_log.get_logger(logger_name=LoggerType.monitor.value, node_name=node_name) return mlog
import signal import time import atexit import traceback from infrasim import daemon from infrasim import sshim from infrasim import config from infrasim import run_command from .command import Command_Handler from .common import msg_queue from .common import IpmiError import env, sdr, common from infrasim.log import infrasim_log, LoggerType logger_ic = infrasim_log.get_logger(LoggerType.ipmi_console.value) sensor_thread_list = [] def atexit_cb(sig=signal.SIGTERM, stack=None): env.local_env.quit_flag = True _free_resource() _stop_console() class IPMI_CONSOLE(threading.Thread): WELCOME = 'You have connected to the test server.' PROMPT = "IPMI_SIM> " def __init__(self, script): threading.Thread.__init__(self)
def init(self): """ 1. Prepare CNode attributes: - self.__node 2. Then use this information to init workspace 3. Use this information to init sub module """ if 'name' in self.__node: self.set_node_name(self.__node['name']) else: raise ArgsNotCorrect( "[Node] No node name is given in node information.") self.__logger = infrasim_log.get_logger(LoggerType.model.value, self.__node_name) if self.__node['compute'] is None: raise ArgsNotCorrect("[Node] No compute information") if 'sol_enable' not in self.__node: self.__node['sol_enable'] = True self.__sol_enabled = self.__node['sol_enable'] self.__netns = self.__node.get("namespace") # If user specify "network_mode" as "bridge" but without MAC # address, generate one for this network. for network in self.__node['compute']['networks']: if 'mac' not in network: uuid_val = uuid.uuid4() str1 = str(uuid_val)[-2:] str2 = str(uuid_val)[-4:-2] str3 = str(uuid_val)[-6:-4] network['mac'] = ":".join(["52:54:BE", str1, str2, str3]) # If user specify "nmve" controller(drive) in "storage_backend" # with NO serial, generate one for it, since QEMU now (2.10.1) # treat "serail" as a mandatory attribute for "nvme" for storage in self.__node['compute']['storage_backend']: if storage.get('type') == 'nvme': if not storage.get('serial', ''): storage['serial'] = helper.random_serial() if self.__sol_enabled: socat_obj = CSocat() socat_obj.logger = self.__logger socat_obj.set_priority(0) socat_obj.set_task_name("{}-socat".format(self.__node_name)) self.__tasks_list.append(socat_obj) bmc_info = self.__node.get('bmc', {}) bmc_obj = CBMC(bmc_info) bmc_obj.logger = self.__logger bmc_obj.set_priority(1) bmc_obj.set_task_name("{}-bmc".format(self.__node_name)) bmc_obj.enable_sol(self.__sol_enabled) bmc_obj.set_log_path("/var/log/infrasim/{}/openipmi.log".format( self.__node_name)) bmc_obj.set_node_name(self.__node['name']) self.__tasks_list.append(bmc_obj) compute_obj = CCompute(self.__node['compute']) compute_obj.logger = self.__logger asyncr = bmc_info.get("startnow", True) compute_obj.set_asyncronous(asyncr) compute_obj.enable_sol(self.__sol_enabled) compute_obj.set_priority(2) compute_obj.set_task_name("{}-node".format(self.__node_name)) compute_obj.set_log_path("/var/log/infrasim/{}/qemu.log".format( self.__node_name)) self.__tasks_list.append(compute_obj) if "type" in self.__node and "dell" in self.__node["type"]: racadm_info = self.__node.get("racadm", {}) racadm_obj = CRacadm(racadm_info) racadm_obj.logger = self.__logger racadm_obj.set_priority(3) racadm_obj.set_node_name(self.__node_name) racadm_obj.set_task_name("{}-racadm".format(self.__node_name)) racadm_obj.set_log_path("/var/log/infrasim/{}/racadm.log".format( self.__node_name)) self.__tasks_list.append(racadm_obj) # Set interface if "type" not in self.__node: raise ArgsNotCorrect("[Node] Can't get infrasim type") else: bmc_obj.set_type(self.__node['type']) compute_obj.set_type(self.__node['type']) if self.__sol_enabled: if "sol_device" in self.__node: socat_obj.set_sol_device(self.__node["sol_device"]) bmc_obj.set_sol_device(self.__node["sol_device"]) if "serial_socket" not in self.__node: self.__node["serial_socket"] = os.path.join( config.infrasim_home, self.__node["name"], ".serial") socat_obj.set_socket_serial(self.__node["serial_socket"]) compute_obj.set_socket_serial(self.__node["serial_socket"]) if "ipmi_console_port" in self.__node: bmc_obj.set_port_ipmi_console(self.__node["ipmi_console_port"]) # ipmi-console shall connect to same port with the same conf file if "bmc_connection_port" in self.__node: bmc_obj.set_port_qemu_ipmi(self.__node["bmc_connection_port"]) compute_obj.set_port_qemu_ipmi(self.__node["bmc_connection_port"]) self.workspace = Workspace(self.__node) for task in self.__tasks_list: task.set_workspace(self.workspace.get_workspace()) if not self.__is_running(): self.workspace.init() if self.__netns: for task in self.__tasks_list: task.netns = self.__netns for task in self.__tasks_list: task.init()
def init(self): """ 1. Prepare CNode attributes: - self.__node 2. Then use this information to init workspace 3. Use this information to init sub module """ if 'name' in self.__node: self.set_node_name(self.__node['name']) else: raise ArgsNotCorrect( "[Node] No node name is given in node information.") self.__logger = infrasim_log.get_logger(LoggerType.model.value, self.__node_name) if self.__node['compute'] is None: raise ArgsNotCorrect("[Node] No compute information") if 'sol_enable' not in self.__node: self.__node['sol_enable'] = True self.__sol_enabled = self.__node['sol_enable'] self.__netns = self.__node.get("namespace") if 'uuid' in self.__node["compute"]: uuid_num = self.__node["compute"].get("uuid") else: uuid_num = str(uuid.uuid4()) self.__node["compute"]["uuid"] = uuid_num if 'serial_number' in self.__node["compute"]: serial_number = self.__node["compute"].get("serial_number") else: serial_number = pre_serial_number + ''.join( random.SystemRandom().choice(string.digits) for _ in range(3)) self.__node["compute"]["serial_number"] = serial_number # If user specify "network_mode" as "bridge" but without MAC # address, generate one for this network. for network in self.__node['compute']['networks']: if 'mac' not in network: uuid_val = uuid.uuid4() str1 = str(uuid_val)[-2:] str2 = str(uuid_val)[-4:-2] str3 = str(uuid_val)[-6:-4] network['mac'] = ":".join(["52:54:BE", str1, str2, str3]) # If user specify "nmve" controller(drive) in "storage_backend" # with NO serial, generate one for it, since QEMU now (2.10.1) # treat "serail" as a mandatory attribute for "nvme" for storage in self.__node['compute']['storage_backend']: if storage.get('type') == 'nvme': if not storage.get('serial', ''): storage['serial'] = helper.random_serial() if self.__sol_enabled: socat_obj = CSocat() socat_obj.logger = self.__logger socat_obj.set_priority(0) socat_obj.set_task_name("{}-socat".format(self.__node_name)) socat_obj.set_node_name(self.__node['name']) self.__tasks_list.append(socat_obj) bmc_info = self.__node.get('bmc', {}) bmc_obj = CBMC(bmc_info) bmc_obj.logger = self.__logger bmc_obj.set_priority(1) bmc_obj.set_task_name("{}-bmc".format(self.__node_name)) bmc_obj.enable_sol(self.__sol_enabled) bmc_obj.set_log_path( os.path.join(config.infrasim_log_dir, self.__node_name, "openipmi.log")) bmc_obj.set_node_name(self.__node['name']) self.__tasks_list.append(bmc_obj) compute_obj = CCompute(self.__node['compute']) compute_obj.logger = self.__logger asyncr = bmc_info.get("startnow", True) compute_obj.set_asyncronous(asyncr) compute_obj.enable_sol(self.__sol_enabled) compute_obj.set_priority(2) compute_obj.set_uuid(uuid_num) compute_obj.set_serial_number(self.__node["compute"]["serial_number"]) compute_obj.set_task_name("{}-node".format(self.__node_name)) compute_obj.set_log_path( os.path.join(config.infrasim_log_dir, self.__node_name, "qemu.log")) self.__tasks_list.append(compute_obj) if "type" in self.__node and "dell" in self.__node["type"]: racadm_info = self.__node.get("racadm", {}) racadm_obj = CRacadm(racadm_info) racadm_obj.logger = self.__logger racadm_obj.set_priority(3) racadm_obj.set_node_name(self.__node_name) racadm_obj.set_task_name("{}-racadm".format(self.__node_name)) racadm_obj.set_log_path( os.path.join(config.infrasim_log_dir, self.__node_name, "racadm.log")) self.__tasks_list.append(racadm_obj) # Set interface if "type" not in self.__node: raise ArgsNotCorrect("[Node] Can't get infrasim type") else: bmc_obj.set_type(self.__node['type']) compute_obj.set_type(self.__node['type']) if self.__sol_enabled: if "sol_device" in self.__node: socat_obj.set_sol_device(self.__node["sol_device"]) bmc_obj.set_sol_device(self.__node["sol_device"]) if "serial_socket" not in self.__node: self.__node["serial_socket"] = os.path.join( config.infrasim_home, self.__node["name"], ".serial") socat_obj.set_socket_serial(self.__node["serial_socket"]) compute_obj.set_socket_serial(self.__node["serial_socket"]) if "ipmi_console_port" in self.__node: bmc_obj.set_port_ipmi_console(self.__node["ipmi_console_port"]) # ipmi-console shall connect to same port with the same conf file if "bmc_connection_port" in self.__node: bmc_obj.set_port_qemu_ipmi(self.__node["bmc_connection_port"]) compute_obj.set_port_qemu_ipmi(self.__node["bmc_connection_port"]) # Init monitor task monitor_info = {} if "monitor" not in self.__node: monitor_info = { "enable": True, # Interface and port is for north bound REST service of # infrasim-monitor, not the socket of QEMU monitor "inferface": None, "port": 9005 } else: monitor_info = { "enable": self.__node["monitor"].get("enable", True), "interface": self.__node["monitor"].get("interface", None), "port": self.__node["monitor"].get("port", 9005) } if not isinstance(monitor_info["enable"], bool): raise ArgsNotCorrect("[Monitor] Invalid setting") if monitor_info["enable"]: compute_obj.enable_qemu_monitor() monitor_obj = CMonitor(monitor_info) monitor_obj.logger = self.__logger monitor_obj.set_priority(4) monitor_obj.set_node_name(self.__node_name) monitor_obj.set_task_name("{}-monitor".format(self.__node_name)) monitor_obj.set_log_path( os.path.join(config.infrasim_log_dir, self.__node_name, "monitor.log")) self.__tasks_list.append(monitor_obj) self.workspace = Workspace(self.__node) for task in self.__tasks_list: task.set_workspace(self.workspace.get_workspace()) if not self.__is_running(): self.workspace.init() if self.__netns: for task in self.__tasks_list: task.netns = self.__netns for task in self.__tasks_list: task.init()
import re import paramiko import os import logging import atexit import signal from os import linesep from infrasim import sshim from . import env from .api import iDRACConsole from infrasim.log import LoggerType, infrasim_log import sys from infrasim.helper import literal_string env.logger_r = infrasim_log.get_logger(LoggerType.racadm.value) def atexit_cb(sig=signal.SIGTERM, stack=None): if "server" in env.local_env.__dict__: env.local_env.server.stop() def auth(username, password): if username in env.auth_map and env.auth_map[username] == password: return paramiko.AUTH_SUCCESSFUL else: return paramiko.AUTH_FAILED class iDRACHandler(sshim.Handler):
def init(self): """ 1. Prepare CNode attributes: - self.__node 2. Then use this information to init workspace 3. Use this information to init sub module """ if 'name' in self.__node: self.set_node_name(self.__node['name']) else: raise ArgsNotCorrect("[Node] No node name is given in node information.") self.__logger = infrasim_log.get_logger(LoggerType.model.value, self.__node_name) if self.__node['compute'] is None: raise ArgsNotCorrect("[Node] No compute information") if 'sol_enable' not in self.__node: self.__node['sol_enable'] = True self.__sol_enabled = self.__node['sol_enable'] self.__netns = self.__node.get("namespace") # If user specify "network_mode" as "bridge" but without MAC # address, generate one for this network. for network in self.__node['compute']['networks']: if 'mac' not in network: uuid_val = uuid.uuid4() str1 = str(uuid_val)[-2:] str2 = str(uuid_val)[-4:-2] str3 = str(uuid_val)[-6:-4] network['mac'] = ":".join(["52:54:BE", str1, str2, str3]) # If user specify "nmve" controller(drive) in "storage_backend" # with NO serial, generate one for it, since QEMU now (2.10.1) # treat "serail" as a mandatory attribute for "nvme" for storage in self.__node['compute']['storage_backend']: if storage.get('type') == 'nvme': if not storage.get('serial', ''): storage['serial'] = helper.random_serial() if self.__sol_enabled: socat_obj = CSocat() socat_obj.logger = self.__logger socat_obj.set_priority(0) socat_obj.set_task_name("{}-socat".format(self.__node_name)) self.__tasks_list.append(socat_obj) bmc_info = self.__node.get('bmc', {}) bmc_obj = CBMC(bmc_info) bmc_obj.logger = self.__logger bmc_obj.set_priority(1) bmc_obj.set_task_name("{}-bmc".format(self.__node_name)) bmc_obj.enable_sol(self.__sol_enabled) bmc_obj.set_log_path("/var/log/infrasim/{}/openipmi.log". format(self.__node_name)) bmc_obj.set_node_name(self.__node['name']) self.__tasks_list.append(bmc_obj) compute_obj = CCompute(self.__node['compute']) compute_obj.logger = self.__logger asyncr = bmc_info.get("startnow", True) compute_obj.set_asyncronous(asyncr) compute_obj.enable_sol(self.__sol_enabled) compute_obj.set_priority(2) compute_obj.set_task_name("{}-node".format(self.__node_name)) compute_obj.set_log_path("/var/log/infrasim/{}/qemu.log". format(self.__node_name)) self.__tasks_list.append(compute_obj) if "type" in self.__node and "dell" in self.__node["type"]: racadm_info = self.__node.get("racadm", {}) racadm_obj = CRacadm(racadm_info) racadm_obj.logger = self.__logger racadm_obj.set_priority(3) racadm_obj.set_node_name(self.__node_name) racadm_obj.set_task_name("{}-racadm".format(self.__node_name)) racadm_obj.set_log_path("/var/log/infrasim/{}/racadm.log". format(self.__node_name)) self.__tasks_list.append(racadm_obj) # Set interface if "type" not in self.__node: raise ArgsNotCorrect("[Node] Can't get infrasim type") else: bmc_obj.set_type(self.__node['type']) compute_obj.set_type(self.__node['type']) if self.__sol_enabled: if "sol_device" in self.__node: socat_obj.set_sol_device(self.__node["sol_device"]) bmc_obj.set_sol_device(self.__node["sol_device"]) if "serial_socket" not in self.__node: self.__node["serial_socket"] = os.path.join(config.infrasim_home, self.__node["name"], ".serial") socat_obj.set_socket_serial(self.__node["serial_socket"]) compute_obj.set_socket_serial(self.__node["serial_socket"]) if "ipmi_console_port" in self.__node: bmc_obj.set_port_ipmi_console(self.__node["ipmi_console_port"]) # ipmi-console shall connect to same port with the same conf file if "bmc_connection_port" in self.__node: bmc_obj.set_port_qemu_ipmi(self.__node["bmc_connection_port"]) compute_obj.set_port_qemu_ipmi(self.__node["bmc_connection_port"]) # Init monitor task monitor_info = {} if "monitor" not in self.__node: monitor_info = { "enable": True, # Interface and port is for north bound REST service of # infrasim-monitor, not the socket of QEMU monitor "inferface": None, "port": 9005 } else: monitor_info = { "enable": self.__node["monitor"].get("enable", True), "interface": self.__node["monitor"].get("interface", None), "port": self.__node["monitor"].get("port", 9005) } if not isinstance(monitor_info["enable"], bool): raise ArgsNotCorrect("[Monitor] Invalid setting") if monitor_info["enable"]: compute_obj.enable_qemu_monitor() monitor_obj = CMonitor(monitor_info) monitor_obj.logger = self.__logger monitor_obj.set_priority(4) monitor_obj.set_node_name(self.__node_name) monitor_obj.set_task_name("{}-monitor".format(self.__node_name)) monitor_obj.set_log_path("/var/log/infrasim/{}/monitor.log". format(self.__node_name)) self.__tasks_list.append(monitor_obj) self.workspace = Workspace(self.__node) for task in self.__tasks_list: task.set_workspace(self.workspace.get_workspace()) if not self.__is_running(): self.workspace.init() if self.__netns: for task in self.__tasks_list: task.netns = self.__netns for task in self.__tasks_list: task.init()
def __init__(self): self.__option_list = [] self.__owner = None self.__logger = infrasim_log.get_logger(LoggerType.model.value)
from infrasim.log import infrasim_log, LoggerType mlog = infrasim_log.get_logger(logger_name=LoggerType.monitor.value, node_name=None) def init_logger(node_name): mlog = infrasim_log.get_logger(logger_name=LoggerType.monitor.value, node_name=node_name) return mlog def get_logger(): return mlog
def init_logger(node_name): mlog = infrasim_log.get_logger(logger_name=LoggerType.monitor.value, node_name=node_name) return mlog
import time import atexit import traceback from infrasim import daemon from infrasim import sshim from infrasim import config from infrasim import run_command from .command import Command_Handler from .common import msg_queue from .common import IpmiError import env, sdr, common from infrasim.log import infrasim_log, LoggerType logger_ic = infrasim_log.get_logger(LoggerType.ipmi_console.value) sensor_thread_list = [] def atexit_cb(sig=signal.SIGTERM, stack=None): env.local_env.quit_flag = True _free_resource() _stop_console() class IPMI_CONSOLE(threading.Thread): WELCOME = 'You have connected to the test server.' PROMPT = "IPMI_SIM> " def __init__(self, script): threading.Thread.__init__(self)