question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

change default_enter behavior for Aruba driver

See original GitHub issue

In reference to “how to hit enter after a send_command #330” you offered a solution to respond to a router prompt. I am having an issue in changing a password, when manually performing this it prompts for a Password: and for you to re-enter the password as seen below. The solution that you offered did not work for me and after looking at the logs it looks to be sending the first password successfully but it it not reading the prompt for the second password.

Any code examples or solutions that you can provide would be amazing.

Manual Example:

(exampledevice1) (config) #mgmt-user admin root              
Password:********
Re-Type password:********

My Python Code:

net_connect.config_mode()

command = 'mgmt-user admin root'
aruba_pass = 'examplepassword'

configure4 = net_connect.send_command_timing(command)
        if 'Password:' in configure4:
            configure4 += net_connect.send_command_timing(aruba_pass)
        if 'password:' in configure4:
            configure4 += net_connect.send_command_timing(aruba_pass)

net_connect.exit_config_mode()

output2 = net_connect.save_config()

I have tried several different ways and it still wont work, any help would be greatly appreciated.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
MikeJureckicommented, Jul 26, 2018

I literally just tried that and it worked. That was the solution, it took the command. Thank you so much for all of the help. For the sake of people like me here is the complete working code below:

# INFO :  ArubaOS WLC Password Change Script
# INFO :  Created On: 7/26/2018
# INFO :  Description: Changes local admin password on ArubaOS Wireless Controllers

import netmiko
from datetime import datetime
from shutil import copy
import os
from os import listdir
from os.path import isfile, join
import logging
import time
import threading

run_date = datetime.today().date()
run_date = str(run_date)
run_time = datetime.now().time()
run_time = str(run_time)
run_time = run_time[:-7]
run_time = run_time.replace(':', '.')

logging.basicConfig(filename='Aruba_password_' + run_time + '.log', filemode='w', level=logging.DEBUG)

print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
print('ArubaOS Passoword Change SCRIPT')
print('Created on 7/26/2018')
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
print('')

creds = []
with open('./creds/cred.txt', 'r') as file:
    creds = [line.strip() for line in file]

ios_ver = 'arubaos'
username = creds[0]
password = creds[1]

orig_path = './'
backup_path = './backups/'
postcap_path = './postcap/'
changes_path = './changes/'
logs_path = './logs/'

HOSTS = open('./hostlist/hostlist.txt', 'r')

HOST_FILE = []
for host1 in HOSTS:
    host1 = host1.rstrip('\n')
    if host1 == '':
        print('')  
    else:
        HOST_FILE.append(host1)

HOSTS.close()

failed_list = []

# INFO: This performed threading to hit multiple devices at a time

def thread_login(u, p):
    threads = []
    for ipaddress in HOST_FILE:
        t = threading.Thread(target=main_thread, args=(ipaddress, u, p,), )
        t.start()
        threads.append(t)
        print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
        print('STARTING NEW THREAD - IP ADDRESS:', ipaddress)
        print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
        time.sleep(4)

    for thread in threads:
        thread.join()


def main_thread(ipaddress, u, p): 


    current_time = datetime.now().time()
    current_time = str(current_time)
    print('Starting Change', ipaddress, current_time)

    SSH_Device = {
        'device_type': 'aruba_os',
        'ip': ipaddress,
        'username': u,
        'password': p,
        'secret': p,
        'default_enter': '\r'  # IMPORTANT: \r WAS THE KEY TO ALLOWING IT TO CHANGE THE PASSWORD
    }

    try:
        net_connect = netmiko.ConnectHandler(**SSH_Device)

    except Exception as e:
        e = str(e)
        failed = 'Connect Fail: ' + ipaddress + ':  ' + e
        failed_list.append(failed)
        print(e)


    try:
        # INFO: Creating Backup File
        print(ipaddress, str(datetime.now().time()), 'Gathering Backup Data')
        newconfigfilename = ipaddress + '_' + str(run_time) + '.cfg'
        newconfigfile = open(newconfigfilename, 'w')

        result1 = net_connect.send_command_expect('show run', delay_factor=2)
        newconfigfile.write(result1)

        newconfigfile.close()

    except Exception as e:
        e = str(e)
        failed = 'Connect Fail: ' + ipaddress + ':  ' + e
        failed_list.append(failed)
        print(ipaddress, str(datetime.now().time()), e)


    try:

        outputfilename = ipaddress + '_Change_' + run_date + run_time + '.txt'
        outputfile = open(outputfilename, 'w')

        outputfile.write('#### ' + ipaddress + ' ---- ' + run_time + '####\n')

        outputfile.write('###\n')
        outputfile.write('###\n')

        net_connect.config_mode()

        command = 'mgmt-user admin root'
        aruba_pass = 'exmpPass'

        configure4 = net_connect.send_command_timing(command)

        if 'Password:' in configure4:
            configure4 += net_connect.send_command_timing(aruba_pass)

        if 'Re-Type' in configure4:
            configure4 += net_connect.send_command_timing(aruba_pass)

        print('Password Configuration Applied', ipaddress)

        outputfile.write(configure4 + '\n')

        outputfile.write('###\n')
        outputfile.write('###\n')
        print('----')

        # INFO: Saving configuration
        outputfile.write('###\n')
        outputfile.write('###Saving Configuration\n')
        print(ipaddress, str(datetime.now().time()), 'Saving Configuration')

        net_connect.exit_config_mode()

        output2 = net_connect.save_config()
        outputfile.write(output2 + '\n')
        print(ipaddress, str(datetime.now().time()), output2)
        print('----')

        outputfile.close()

    except Exception as e:
        e = str(e)
        failed = 'Connect Fail: ' + ipaddress + ':  ' + e
        failed_list.append(failed)
        print(e)

# INFO: Threading Begins
thread_login(u=username, p=password)  

# INFO: This is moving all files to correct directory
filelist = [f for f in listdir(orig_path) if isfile(join(orig_path, f))]

# Moving Backup Files
for item in filelist:
    try:
        filename = orig_path + item

        if item.startswith("postcap"):
            copy(filename, postcap_path)
            os.remove(os.path.join(orig_path, item))

        if item.endswith(".cfg"):
            copy(filename, backup_path)
            os.remove(os.path.join(orig_path, item))

        if item.endswith(".txt"):
            copy(filename, changes_path)
            os.remove(os.path.join(orig_path, item))

        if item.endswith(".log"):
            copy(filename, logs_path)
            os.remove(os.path.join(orig_path, item))

    except:
        continue


# INFO: Creates failed file for all exceptions, with the IP Address
failedfile = 'FailedFile.txt'
failedfile2 = open(failedfile, 'w')
c = 1
for item in failed_list:
    failedfile2.write(str(c) + '. ' + item + '\n')
    c += 1

failedfile2.close()

# INFO: End of Script
end_time = datetime.now().time()
end_time = str(end_time)
end_time = end_time[:-7]
end_time = end_time.replace(':', '.')

print('Start Time:', run_time)
print('End time:', end_time)

@ktbyers Thanks again for all of the help!!! You are a great person!

1reaction
ktbyerscommented, Jul 26, 2018

You could try this:

    SSH_Device = {
        'device_type': 'aruba_os',
        'ip': ipaddress,
        'username': u,
        'password': p,
        'secret': p,
        'default_enter': '\r\n'
    }

And see if that makes any difference.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Aruba 2930 M/F Management and Configuration Guide for ...
Change in server behavior ... Among the keys that have been configured, one key or a set of keys must be ... Too...
Read more >
HP StorageWorks EVA 5000 - Procedures for Getting Started
Obtain a license key. Contact a Compaq Authorized Service Provider for hardware configuration. Enter the storage system World Wide Name (WWN) into the...
Read more >
Getting Started with Aruba CX 6100 Series Switches using CLI
In this video, we'll show you step-by-step how to get started with the Aruba CX 6100 switch series using the Command Line Interface...
Read more >
Changing Fleet Driver Behavior | CEI Network
Driver Awareness. The first step to engage drivers is to make them aware of their unsafe fleet driving behaviors. This is especially important...
Read more >
Driving in Aruba: What You Need To Know - TripSavvy
Additionally, there is a predominance of roundabouts instead of traffic lights at major intersections, which is a change that has been ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found