-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
72 lines (53 loc) · 2.07 KB
/
functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from ast import IfExp
from distutils.errors import DistutilsClassError
def vlan_exist(vlan): #"vlan" is a temp variable
vlans_on_switch = [10, 20, 30, 40, 50, 60]
return vlan in vlans_on_switch
print(vlan_exist(10)) #put the value inside the ()
# Result = "True"
def vlan_info(id, name):
print(f"The VLAN ID is {id} and the VLAN name is {name}")
print(vlan_info("10","MGMT"))
# The VLAN ID is 10 and the VLAN name is MGMT
# We need to obtain dynamic values and call the function, that doesn't change
def intf(interface, speed = "1000", duplex = "full"):
print(f"The interface of the router is {interface}")
print(f"The speed of the interface is {speed}")
print(f"The duplex of the interface is {duplex}")
print(intf("Gi0/1", "2000", "half"))
# Output
# The interface of the router is Gi0/1
# The speed of the interface is 2000
# The duplex of the interface is half
# Se non specifico niente per i valori già messi staticamente dentro la funzione
print(intf("Gi0/1"))
# Output is:
# The interface of the router is Gi0/1
# The speed of the interface is 1000
# The duplex of the interface is full
def get_ip(temp):
dict1 = {"hostname" : "R1", "os" : "IOS-XR", "mgmt_ip" : "10.1.1.1"}
if temp in dict1["os"]:
print(dict1["mgmt_ip"])
else:
print(f"The device is not running {temp}")
print(get_ip("IOS-XR"))
# result:
# 10.1.1.1
print(get_ip("IOS-XE"))
# result:
# The device is not running IOS-XE
# LAB
print("START LAB")
def device_ip(temp):
dict1 = {"hostname" : "R1", "OS" : "IOS-XE", "mgmt_ip" : "10.1.1.1"}
dict2 = {"hostname" : "R2", "OS" : "IOS-XR", "mgmt_ip" : "10.1.1.2"}
if temp in dict1["OS"] == "IOS-XE":
print("The management IP of ", dict1["hostname"], "is ", dict1["mgmt_ip"])
elif temp in dict2["OS"] == "IOS-XR":
print("The management IP of ", dict2["hostname"], "is ", dict2["mgmt_ip"])
else:
print("The device has an unknown image")
print(device_ip("IOS-XR"))
print(device_ip("IOS-XE"))
print(device_ip("PIPPO"))