PYTHON

YAML Basics

Example of a YAML file : List : — – 10.10.10.1 – 10.10.10.2 – 10.10.10.3 Dictionary : — Key:value device1: 10.10.10.1 device2: this is a string device3: “this can nclude special characters” device4: True or true or yes or no…
Read more

Jinja2 Basics

The Basic : Example of a configuration in one script : import jinja2 dict_variables = {‘key’:  ‘value’, etc…} template_cfg = ”’ config…{{ .key }} config…{{ .key }} config….{{ .key }} “”” template = jinja2.Template(template_cfg) print(template.render(dict_variables) To access : a key…
Read more

Classes

Function gives you one level of usability and Classes with methods give you a second level of usability. When you passing the same information more then once for the same thing you can then use Classes instead of repetitive same function. In…
Read more

Functions

Creating a function : def function_name(): ….action function_name()  <— calling the function function_name  <— referencing the function def function_ip(ip): ….print(“My ip is:{}”.format(ip)) or print(f’My ip is :{ip}’) ….return function_ip(‘10.1.1.1′) def function_ip(ip, mask, gtw): ….print(“My ip is:{} mask is : {}…
Read more

Regular Expressions

Summary : http://www.patrickdenis.biz/blog/regular-expressions-special-characters-and-patterns/ . Matches any single character, including white space. * Matches 0 or more sequences of the pattern. + Matches 1 or more sequences of the pattern. ? Matches 0 or 1 occurrences of the pattern. ^ Matches the beginning of…
Read more

Set

Set are like Dictionary but without key value pair, there are just element, if you convert a list to a a set it will remove all duplicate. ipv4 = [‘10.10.10.1’, ‘10.10.10.1’, ‘10.10.10.4, ‘10.10.10.3, ‘10.10.10.3, ‘10.10.10.2, ‘10.10.10.2] set(ipv4) {‘10.10.10.1’, ‘10.10.10.4, ‘10.10.10.3…
Read more

Dictionary Methods

device = {} device[‘ip_addr’] = ‘10.10.10.1’ print(device) {‘ip_addr’: ‘10.10.10.1’} dir(device) will list all method available To loop over a dictionary you can do it by key or key value or both : for key in device: ….print(key) for value in…
Read more