def rebootPrimary(switch_ip):
    device = {
        "host": switch_ip,
        "auth_username": switch_username,
        "auth_password": switch_password,
        "auth_strict_key": False,
        "platform": "juniper_junos"
    }
    logging.info("Logging in to switch {}".format(switch_ip))
    try:
        conn = Scrapli(**device)
        conn.open()
        response = conn.send_command("request system configuration rescue save")
        response = conn.send_interactive(
            [
                ("request system reboot slice alternate media internal at 22",
                "Reboot the system ", False),
                ("yes", "", False)
            ]
        )
        logging.info(response.elapsed_time)
        logging.info(response.result)
        if 'Shutdown at' in response.result:
            return True
        else:
            return False
        conn.close()
    except:
        logging.warning("Couldn't reboot switch {}".format(switch_ip))
        print("Couldn't reboot switch {}".format(switch_ip))
        return False
Example #2
0
def bouncePOE(switch_interface):
    device = {
        "host": switch_interface['SwitchIP'],
        "auth_username": switch_username,
        "auth_password": switch_password,
        "auth_strict_key": False,
        "platform": "juniper_junos"
    }
    logging.info("Logging in to switch {} with IP {}".format(
        switch_interface['SwitchName'], switch_interface['SwitchIP']))
    conn = Scrapli(**device)
    conn.open()
    response = conn.send_config("set poe interface {} disable".format(
        switch_interface['PortName']))
    response = conn.send_config("commit confirmed 2 comment netscripts01")
    logging.info(response.elapsed_time)
    logging.info(response.result)
    conn.close()
Example #3
0
def addVlansToSwitch(switch):
    device = {
        "host": switch['IPAddress'],
        "auth_username": switch_username,
        "auth_password": switch_password,
        "auth_strict_key": False,
        "platform": "juniper_junos"
    }
    logging.info("Logging in to switch {} with IP {}".format(
        switch['Caption'], switch['IPAddress']))
    conn = Scrapli(**device)
    conn.open()
    response = conn.send_command("show chassis hardware | display xml")
    response_dict = xmltodict.parse(response.result)
    response_json = json.dumps(response_dict)
    switch_hardware = json.loads(response_json)[
        'rpc-reply']['chassis-inventory']['chassis']
    switch_model = switch_hardware['description']
    print(switch_model)
    if "EX2300" in switch_model:
        response = conn.send_command(
            "show configuration interfaces interface-range uplink")
        if "unit 0" in response.result:
            response = conn.send_config(
                "set interfaces interface-range uplink unit 0 family ethernet-switching vlan members byod")
            response = conn.send_config(
                "set interfaces interface-range uplink unit 0 family ethernet-switching vlan members guest")
        response = conn.send_config(
            "set interfaces interface-range downlink unit 0 family ethernet-switching vlan members byod")
        response = conn.send_config(
            "set interfaces interface-range downlink unit 0 family ethernet-switching vlan members guest")
        response = conn.send_config(
            "set interfaces interface-range ap unit 0 family ethernet-switching vlan members byod")
        response = conn.send_config(
            "set interfaces interface-range ap unit 0 family ethernet-switching vlan members guest")
        response = conn.send_config(
            "set vlans byod vlan-id 39")
        response = conn.send_config(
            "set vlans guest vlan-id 38")
        response = conn.send_config(
            'commit confirmed 5 comment "MIST preparation"')
        response = conn.send_config(
            'commit')
    elif "EX2200" in switch_model:
        response = conn.send_command(
            "show configuration interfaces interface-range uplink")
        if "unit 0" in response.result:
            response = conn.send_config(
                "set vlans byod interface uplink")
            response = conn.send_config(
                "set vlans guest interface uplink")
        response = conn.send_config(
            "set vlans byod interface downlink")
        response = conn.send_config(
            "set vlans guest interface downlink")
        response = conn.send_config(
            "set vlans byod interface ap")
        response = conn.send_config(
            "set vlans guest interface ap")
        response = conn.send_config(
            "set vlans byod vlan-id 39")
        response = conn.send_config(
            "set vlans guest vlan-id 38")
        response = conn.send_config(
            'commit confirmed 5 comment "MIST preparation"')
        response = conn.send_config(
            'commit')

    #poe_interface_power = interface_poe['rpc-reply']['poe']['interface-information-detail']['interface-power-detail']
    #response = conn.send_config("commit confirmed 2")
    logging.info(response.elapsed_time)
    logging.info(response.result)
    print(response.result)
    conn.close()