fesenkokd / python2024_fesenko

Fesenko Kirill
GNU General Public License v3.0
0 stars 0 forks source link

019.conditionals #4

Open alsigna opened 2 months ago

alsigna commented 2 months ago

@fesenkokd

Task1:

Task2:

Task4:

access = """
   interface {if_name}
      switchport mode access
      switchport access vlan {vlan}
   !
   """.strip()
trunk = """
    interface {if_name}
       switchport mode trunk
       switchport trunk allowed vlan {vlan}
    !
    """.strip()
templates = {
    "access": access,
    "trunk": trunk,
}

intf1 = {
    "if_name": "gi0/1",
    "vlan": 102,
    "mode": "access",
}
intf2 = {
    "if_name": "gi0/2",
    "vlan": 103,
    "mode": "trunk",
}

template = templates.get(intf1.get("mode"))
print(template.format(**intf1))

template = templates.get(intf2.get("mode"))
print(template.format(**intf2))