Skip to content
Snippets Groups Projects
Commit a758a00c authored by rick.mollard's avatar rick.mollard
Browse files

update

parent bfd5c670
No related branches found
No related tags found
No related merge requests found
from urllib3 import exceptions # Prevent SSL Self-Signed Certificate Error
import requests # Creation Of New Object
import urllib3
from netmiko import (ConnectHandler,NetmikoTimeoutException) # SSH Connection
import socket # DNS Lookup
import time # For Waiting
import CampusSelector
import SwitchCommands
def main(ArubaUsername, ArubaPassword):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # Disable Certificate Warning
# Get the Campus or Switch IP Address
campus = CampusSelector.Campus_Selector()
ip = campus[1]
campus_selection = campus[2]
campus = campus[0]
# Get the Role we want to bounce
role = CampusSelector.Role_Selector()
if campus_selection == "6":
hostname = socket.getfqdn(ip)
print('Current Switch:', hostname, ":", ip)
# Create Session Object
session = requests.session()
# Create SSH Connection
ssh = ConnectHandler(
device_type="aruba_procurve",
host=ip,
username=ArubaUsername,
password=ArubaPassword,
)
try:
cli = ssh.send_command(f"show port-access clients")
parse = cli.split("\n")
for line in parse:
line = line.lstrip()
if role in line:
interface = line.split(" ")[0]
if interface == 'd':
interface = line.split(" ")[1]
print("Non-Tunneled Device, Skip:", interface)
else:
interface = line.split(" ")[0]
# int_config = [f'interface {interface}', 'shut']
SwitchCommands.shutport(ssh, interface)
# config_send = ssh.send_config_set(int_config)
print("Sending Command: ", interface, "\n Port Shutdown - Waiting 2 Seconds")
# int_config = [f'interface {interface}', 'no shut']
SwitchCommands.noshutport(ssh, interface)
# config_send = ssh.send_config_set(int_config)
print("Sending Command: ", interface, "\n Flipped - Waiting 1 Second For Next Port")
finally:
print("Logging Out From Switch", hostname, ip)
ssh.disconnect()
time.sleep(1)
if campus_selection != "6":
with open(campus) as file:
while line := file.readline().rstrip():
ip = line
hostname = socket.getfqdn(ip)
print('Current Switch:', hostname, ":", ip)
# Create Session Object
session = requests.session()
# Create SSH Connection
try:
ssh = ConnectHandler(
device_type="aruba_procurve",
host=ip,
username=ArubaUsername,
password=ArubaPassword,
)
try:
cli = ssh.send_command(f"show port-access clients")
parse = cli.split("\n")
for line in parse:
line = line.lstrip()
if role in line:
interface = line.split(" ")[0]
if interface == 'd':
interface = line.split(" ")[1]
print("Non-Tunneled Device, Skip:", interface)
else:
interface = line.split(" ")[0]
# int_config = [f'interface {interface}', 'shut']
SwitchCommands.shutport(ssh, interface)
# config_send = ssh.send_config_set(int_config)
print("Sending Command: ", interface, "\n Port Shutdown - Waiting 2 Seconds")
# int_config = [f'interface {interface}', 'no shut']
SwitchCommands.noshutport(ssh, interface)
# config_send = ssh.send_config_set(int_config)
print("Sending Command: ", interface, "\n Flipped - Waiting 1 Second For Next Port")
finally:
print("Logging Out From Switch", hostname, ip)
ssh.disconnect()
except (NetmikoTimeoutException) as error:
print("Switch is not responding-----> " + ip)
print("Switch is not responding-----> " + ip)
print("Switch is not responding-----> " + ip)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment