Skip to content
Snippets Groups Projects
Select Git revision
  • 66c22d7d55e77b34d1b98abddf46613780a554fe
  • master default
  • issue-752
  • develop
  • issue-677
  • issue-677-original-with-migrate
  • issue-716
  • issue-654
  • issue-732
  • issue-737
  • issue-735
  • issue-707
  • issue-706
  • issue-705
  • issue-703
  • issue-696
  • issue-690
  • issue-675
  • issue-670
  • issue-635
  • issue-404
  • 7.19
  • 2012-04-18
  • 2012-04-03
  • 2012-04-02
  • 2012-03-01
  • 2012-02-07
  • 20120207
  • 2012-01-13
  • 2012-01-12
  • 2011-12-16
  • 2011-12-05
  • 2011-11-17
  • 2011-11-14
  • 2011-11-08.2
  • 2011-11-08
  • 2011-11-01
  • 2011-10-27
  • 2011-10-06
  • 2011-10-03
  • 2011-09-19
41 results

timezone.js

Blame
  • Forked from UNL Information Services / UNL-CMS
    Source project has a limited visibility.
    PortFlipper.py 4.71 KiB
    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)