|
|
|
|
@ -62,8 +62,18 @@ class Agent():
|
|
|
|
|
Holds the main state required to run Shepherd Agent
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
|
|
def __init__(self, default_config_path, use_custom_config=True, control_enabled=False,
|
|
|
|
|
new_device_mode=False):
|
|
|
|
|
"""
|
|
|
|
|
Load in the Shepherd Agent config and associated plugins.
|
|
|
|
|
Args:
|
|
|
|
|
default_config_path: The path to the default config file
|
|
|
|
|
use_custom_config: Set False to disable the local custom config layer
|
|
|
|
|
control_enabled: Set False to disable Shepherd Control remote management
|
|
|
|
|
(including any cached Control config layer)
|
|
|
|
|
new_device_mode: Set True to clear out any cached state and trigger new generation
|
|
|
|
|
of ID, as if it were being run on a fresh system.
|
|
|
|
|
"""
|
|
|
|
|
# Make sure the plugin system uses this instance rather making its own
|
|
|
|
|
core_interface._plugin_obj = self
|
|
|
|
|
|
|
|
|
|
@ -75,43 +85,17 @@ class Agent():
|
|
|
|
|
self.core_config = None
|
|
|
|
|
|
|
|
|
|
self.interface_functions = None
|
|
|
|
|
self.control_enabled = None
|
|
|
|
|
self.plugin_interfaces = None
|
|
|
|
|
|
|
|
|
|
self.restart_args = None
|
|
|
|
|
|
|
|
|
|
@ plugin.plugin_function
|
|
|
|
|
def root_dir(self):
|
|
|
|
|
return self.core_config["root_dir"]
|
|
|
|
|
|
|
|
|
|
@ plugin.plugin_function
|
|
|
|
|
def device_name(self):
|
|
|
|
|
return self.core_config["name"]
|
|
|
|
|
|
|
|
|
|
def load(self, default_config_path, use_custom_config=True, control_enabled=False,
|
|
|
|
|
new_device_mode=False):
|
|
|
|
|
"""
|
|
|
|
|
Load in the Shepherd Agent config and associated plugins.
|
|
|
|
|
Args:
|
|
|
|
|
default_config_path: The path to the default config file
|
|
|
|
|
use_custom_config: Set False to disable the local custom config layer
|
|
|
|
|
control_enabled: Set False to disable Shepherd Control remote management
|
|
|
|
|
(including any cached Control config layer)
|
|
|
|
|
new_device_mode: Set True to clear out any cached state and trigger new generation
|
|
|
|
|
of ID, as if it were being run on a fresh system.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
self.restart_args = [default_config_path,
|
|
|
|
|
use_custom_config, control_enabled, new_device_mode]
|
|
|
|
|
|
|
|
|
|
self.control_enabled = control_enabled
|
|
|
|
|
|
|
|
|
|
# Compile the config layers
|
|
|
|
|
|
|
|
|
|
confman = ConfigManager()
|
|
|
|
|
# Pre-seed confman with core confspec to bootstrap 'plugin_dir'. This is required even
|
|
|
|
|
# though 'load_config_layer_and_plugins()' will get the core confspec from the cached
|
|
|
|
|
# interface, as it needs 'plugin_dir' to list the plugins to load first.
|
|
|
|
|
# Pre-seed confman with core confspec to bootstrap 'plugin_dir'.
|
|
|
|
|
# The plugin load system will get it from the 'shepherd' plugin interface later, but we
|
|
|
|
|
# need the 'plugin_dir' before that.
|
|
|
|
|
confman.add_confspec("shepherd", core_interface.confspec)
|
|
|
|
|
|
|
|
|
|
compile_local_config(confman, default_config_path, use_custom_config)
|
|
|
|
|
@ -150,6 +134,14 @@ class Agent():
|
|
|
|
|
confman.dump_to_file(self.core_config["compiled_config_path"], message=message)
|
|
|
|
|
log.info(F"Saved compiled config to {self.core_config['compiled_config_path']}")
|
|
|
|
|
|
|
|
|
|
@ plugin.plugin_function
|
|
|
|
|
def root_dir(self):
|
|
|
|
|
return self.core_config["root_dir"]
|
|
|
|
|
|
|
|
|
|
@ plugin.plugin_function
|
|
|
|
|
def device_name(self):
|
|
|
|
|
return self.core_config["name"]
|
|
|
|
|
|
|
|
|
|
def restart(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@ -366,7 +358,6 @@ if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
agent = Agent()
|
|
|
|
|
agent.load(args.default_config_path, args.use_custom_config,
|
|
|
|
|
agent = Agent(args.default_config_path, args.use_custom_config,
|
|
|
|
|
args.control_enabled, args.new_device_mode)
|
|
|
|
|
agent.start()
|
|
|
|
|
|