fork download
  1. import jinja2
  2. from jinja2 import Environment, meta
  3.  
  4. # Define the template string
  5. template_string = "Found the BGP established with PEER IP {{peer_ip}} {{hostname}}"
  6.  
  7. # Create a Jinja2 Environment
  8. env = Environment()
  9.  
  10. # Parse the template string to extract variable names
  11. parsed_content = env.parse(template_string)
  12. variable_names = meta.find_undeclared_variables(parsed_content)
  13.  
  14. # Print the extracted variable names
  15. rca_format_values={'peer_ip':'10.0.0.4','hostname':'everest'}
  16. probable_cause = Environment().from_string(template_string).render(**rca_format_values)
  17. print("probable cause - ",probable_cause)
Success #stdin #stdout 0.04s 15416KB
stdin
Standard input is empty
stdout
('probable cause - ', u'Found the BGP established with PEER IP 10.0.0.4 everest')