Skip to content
Snippets Groups Projects
Commit d4b78bcf authored by Thomas Schneider's avatar Thomas Schneider
Browse files

Implement get-config command

parent efccff70
No related branches found
No related tags found
No related merge requests found
......@@ -107,3 +107,35 @@ def get_models(ctx: click.Context, device, host, port, username, destination):
with open(os.path.join(destination, filename), "w") as fp:
fp.write(r.data)
@main.command()
@click.option("-D", "--device", help="Device defined in config")
@click.option("-o", "--output", type=click.File("w"), default="-")
@click.option(
"--source",
type=click.Choice(["running", "startup", "candidate"]),
default="running",
help="Config store",
)
@click.argument("xpath")
def get_config(device, output, source, xpath):
"""Get config from device"""
dev = cfg["devices"][device]
try:
password = getpass(prompt="Password (C-d for none/agent only): ")
except EOFError:
password = None
with manager.connect(
host=dev.get("hostname"),
port=dev.get("port", 830), # TODO
username=dev.get("user"),
password=password,
timeout=90,
device_params=dev.get("params"),
) as m:
res = m.get_config(source, filter=("xpath", (dev.get("namespaces", {}), xpath)))
output.write(res.data_xml)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment