def start_dummy_rack(host, port, start_immediately=True, args=None): logger = get_logger() rack = DeviceRack("DummyRack", host, port, logger) load_dev(rack, args, logger) if start_immediately: rack.start() return rack
if not splited: raise InvalidParameterException dummy = DummyDev( splited[2].encode("utf-8") if args else b"Dummy data 1") rack.load_device(splited[1], dummy) # This function is not necessary, it is put here just for testing purpose. def start_dummy_rack(host, port, start_immediately=True, args=None): logger = get_logger() rack = DeviceRack("DummyRack", host, port, logger) load_dev(rack, args, logger) if start_immediately: rack.start() return rack # If this module is not loaded by rack_starter, then it need to load itself. if __name__ == "__main__": logger = get_logger() parser = get_parser() args = parser.parse_args() rack = DeviceRack("DummyRack", args.host, args.port, logger) load_dev(rack, args, logger) rack.start()
def start_rack_with_config(start_immediately=True): logger = get_logger() parser = argparse.ArgumentParser( description="Rack starter of the DeviceRepo.") parser.add_argument("-c", "--config", dest="config", type=str, help="path to the config file") args = parser.parse_args() racks_dict = list_all_racks() with open(args.config, "r") as f: config = yaml.safe_load(f) try: host_addr = config['network']['host_address'] host_port = config['network']['host_port'] except KeyError: print("Error: No host address or port discovered in the config file.") exit(1) try: dev_init_list = config['devices'] assert isinstance(dev_init_list, list) assert len(dev_init_list) > 0 except (KeyError, AssertionError): print( "Error: No device initialization instruction discovered in the config file." ) exit(1) rack = DeviceRack("RackStarter", host_addr, host_port, logger) for dev_init_inst in dev_init_list: argv = list(filter(lambda x: x, dev_init_inst.split(" "))) dev = argv[0].lower() logger.info(f"=> Initializing device {argv[0]}") if dev in racks_dict: module = get_module(racks_dict[dev][0], racks_dict[dev][1]) parser = module.get_parser() try: argv.pop(0) args = parser.parse_args(argv) except (SystemExit, InvalidParameterException): print( f"Error: Invalid initialization instruction for {argv[0]}." ) parser.print_help() exit(1) module.load_dev(rack, args, logger) else: print(f"Error: Device {argv[0]} not found.") exit(1) logger.info("Initialization finished.") if start_immediately: rack.start() return rack