Hello Colleagues,
I want to do something very similar to what Mats asked.
In my case, to download a .txt file with a configuration snippet for device interfaces. All information will be gathered by existing models.
The web UI looks like
this.
When clicking in Run, it will gather the variables in some dictionary and render a config template.
The result .txt would look like this:
#--------------------------------------------------
echo "Router (Network Side) Configuration"
#--------------------------------------------------
router Base
interface "to-DC01"
port 1/1/1
no shutdown
exit
interface "to-DC02"
port 1/1/2
no shutdown
exit
interface "system"
no shutdown
exit
#--------------------------------------------------
Finally, I would like the end-user to download this file.
My questions:
- Is it possible to do what I'm trying to do?
- I'm lost in the part of how to download a file. Could you share an example?
- About how to render my config template: Within the python script, I could have something like:
var_config_file = (
"#--------------------------------------------------\n"
"echo "Router (Network Side) Configuration"' "\n"
"#--------------------------------------------------\n"
+ var_basic_config + var_config_interfaces +
"#--------------------------------------------------\n"
)
But it would be nicer to use some Jinja2 templates[1] to feed get the configs. I'm thinking this will grow to more large configurations.
i.e Jinja2 folders:
├── jinja_templates
│ ├── common
│ │ ├── cpu.j2
│ │ ├── log_events.j2
│ │ ├── interfaces.j2
│ │ ├── sys_config.j2
│ │ ├── services.j2
│ │ └── user_security.j2
I went through this tutorial[2] and is the basic concept but did anybody make something similar?
I welcome any advice or guidance :-)
Best Regards,
Felix