-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathmodules_after.py
More file actions
94 lines (80 loc) · 3.13 KB
/
Copy pathmodules_after.py
File metadata and controls
94 lines (80 loc) · 3.13 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /usr/bin/env python
"""
"""
# Import and functions
from dnac_resources import dnac
from dnac_functions import (
dnac_login,
host_list,
verify_single_host,
print_host_details,
network_device_list,
interface_details,
print_network_device_details,
print_interface_details,
)
# Entry point for program
if __name__ == "__main__":
# Setup Arg Parse for Command Line parameters
import argparse
parser = argparse.ArgumentParser()
# Command Line Parameters for Source and Destination IP
parser.add_argument("source_ip", help="Source IP Address")
parser.add_argument("destination_ip", help="Destination IP Address")
args = parser.parse_args()
# Get Source and Destination IPs from Command Line
source_ip = args.source_ip
destination_ip = args.destination_ip
# Print Starting message
print("Running Troubleshooting Script for ")
print(" Source IP: {} ".format(source_ip))
print(" Destination IP: {}".format(destination_ip))
print("")
# Log into the dnac Controller to get Ticket
token = dnac_login(
dnac["host"], dnac["port"], dnac["username"], dnac["password"]
)
# Step 1: Identify involved hosts
# Retrieve Host Details from dnac
source_host = host_list(dnac["host"], token, ip=source_ip)
destination_host = host_list(dnac["host"], token, ip=destination_ip)
# Verify single host found for each IP
verify_single_host(source_host, source_ip)
verify_single_host(destination_host, destination_ip)
# Print Out Host details
print("Source Host Details:")
print("-" * 25)
print_host_details(source_host[0])
print("Destination Host Details:")
print("-" * 25)
print_host_details(destination_host[0])
# Step 2: Where are they in the network?
# Retrieve and Print Source Device Details from dnac
source_host_net_device = network_device_list(
dnac["host"], token, id=source_host[0]["connectedNetworkDeviceId"]
) # noqa: E501
print("Source Host Network Connection Details:")
print("-" * 45)
print_network_device_details(source_host_net_device[0])
# If Host is wired, collect interface details
if source_host[0]["hostType"] == "wired":
source_host_interface = interface_details(
dnac["host"], token, id=source_host[0]["connectedInterfaceId"]
) # noqa: E501
print("Attached Interface:")
print("-" * 20)
print_interface_details(source_host_interface)
destination_host_net_device = network_device_list(
dnac["host"], token, id=destination_host[0]["connectedNetworkDeviceId"]
) # noqa: E501
print("Destination Host Network Connection Details:")
print("-" * 45)
print_network_device_details(destination_host_net_device[0])
# If Host is wired, collect interface details
if destination_host[0]["hostType"] == "wired":
destination_host_interface = interface_details(
dnac["host"], token, id=destination_host[0]["connectedInterfaceId"]
) # noqa: E501
print("Attached Interface:")
print("-" * 20)
print_interface_details(destination_host_interface)