|
|
|
|
@ -26,6 +26,24 @@ chromalog.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
|
|
|
|
|
log = logging.getLogger("shepherd.agent")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def echo_heading(title, on_nl=True):
|
|
|
|
|
if on_nl:
|
|
|
|
|
click.echo("")
|
|
|
|
|
click.echo(click.style(".: ", fg='blue', bold=True) +
|
|
|
|
|
click.style(title, fg='white', bold=True) +
|
|
|
|
|
click.style(" :.", fg='blue', bold=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def echo_section(title, input_text=None, on_nl=True):
|
|
|
|
|
if on_nl:
|
|
|
|
|
click.echo("")
|
|
|
|
|
click.secho(":: ", bold=True, fg='blue', nl=False)
|
|
|
|
|
click.secho(title, bold=True, nl=False)
|
|
|
|
|
if input_text:
|
|
|
|
|
click.secho(F" {input_text}", fg='green', bold=True, nl=False)
|
|
|
|
|
click.echo("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.group(invoke_without_command=True)
|
|
|
|
|
@click.option('-c', '--config', 'default_config_path', type=click.Path(),
|
|
|
|
|
help="Shepherd config TOML file to be used as default config layer."
|
|
|
|
|
@ -110,34 +128,66 @@ def cli(ctx, default_config_path, local_operation, only_default_layer):
|
|
|
|
|
@click.argument('interface_function', required=False)
|
|
|
|
|
@click.pass_context
|
|
|
|
|
def test(ctx, plugin_name, interface_function):
|
|
|
|
|
echo_heading("Shepherd Test")
|
|
|
|
|
|
|
|
|
|
if not plugin_name:
|
|
|
|
|
click.echo("")
|
|
|
|
|
click.echo(click.style("===", fg='white', bold=True) +
|
|
|
|
|
click.style('Shepherd Test', fg='blue', bold=True) +
|
|
|
|
|
click.style("===", fg='white', bold=True))
|
|
|
|
|
click.secho(" Plugins loaded:", fg='green')
|
|
|
|
|
|
|
|
|
|
echo_section("Plugins loaded:")
|
|
|
|
|
if len(ctx.obj.plugin_configs) == 0:
|
|
|
|
|
click.echo("---none---")
|
|
|
|
|
for plugin_name, config in ctx.obj.plugin_configs.items():
|
|
|
|
|
click.secho(plugin_name, bold=True)
|
|
|
|
|
click.secho(F" {plugin_name}", fg='green')
|
|
|
|
|
|
|
|
|
|
click.secho("\n Loaded core config:", fg='green')
|
|
|
|
|
echo_section("Core config:")
|
|
|
|
|
pprint(ctx.obj.core_config)
|
|
|
|
|
|
|
|
|
|
click.secho("\n Loaded plugin configs:", fg='green')
|
|
|
|
|
echo_section("Plugin configs:")
|
|
|
|
|
if len(ctx.obj.plugin_configs) == 0:
|
|
|
|
|
click.echo("---none---")
|
|
|
|
|
for plugin_name, config in ctx.obj.plugin_configs.items():
|
|
|
|
|
click.secho(plugin_name, bold=True)
|
|
|
|
|
for name, config in ctx.obj.plugin_configs.items():
|
|
|
|
|
click.secho(F" {plugin_name}", fg='green')
|
|
|
|
|
pprint(config)
|
|
|
|
|
|
|
|
|
|
click.echo("")
|
|
|
|
|
|
|
|
|
|
log.info("Initialising plugins...")
|
|
|
|
|
plugin.init_plugins(ctx.obj.plugin_configs, ctx.obj.core_config)
|
|
|
|
|
log.info("Plugin initialisation done")
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
echo_section("Target plugin:", input_text=plugin_name, on_nl=False)
|
|
|
|
|
# TODO find plugin dependancies
|
|
|
|
|
|
|
|
|
|
if plugin_name not in ctx.obj.plugin_configs:
|
|
|
|
|
log.error(F"Supplied plugin name '{plugin_name}' is not loaded"
|
|
|
|
|
" (not present in config)")
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
echo_section(F"Config [{plugin_name}]:")
|
|
|
|
|
pprint(ctx.obj.plugin_configs[plugin_name])
|
|
|
|
|
|
|
|
|
|
interface = plugin.load_plugin(plugin_name)
|
|
|
|
|
|
|
|
|
|
if not interface_function:
|
|
|
|
|
echo_section(F"Interface functions [{plugin_name}]:")
|
|
|
|
|
|
|
|
|
|
for name, func in interface._functions.items():
|
|
|
|
|
click.echo(F" {name}")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
echo_section("Target interface function:", input_text=interface_function)
|
|
|
|
|
if interface_function not in interface._functions:
|
|
|
|
|
log.error(F"Supplied interface function name '{interface_function}' is not present in"
|
|
|
|
|
F" plugin {plugin_name}")
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
log.info("Initialising plugins...")
|
|
|
|
|
plugin.init_plugins({plugin_name: ctx.obj.plugin_configs[plugin_name]}, ctx.obj.core_config)
|
|
|
|
|
log.info("Plugin initialisation done")
|
|
|
|
|
|
|
|
|
|
interface._functions[interface_function]()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
|
@click.argument('plugin_name', required=False)
|
|
|
|
|
|