コード例 #1
0
def send_command():
    form = SendCommandForm()
    if form.validate_on_submit():
        result = redis_connect.redis_send(form.ipaddress.data,
                                          form.command.data)
        return redirect('/result_job/{}'.format(result.id))
    return render_template('send_command.html', form=form)
コード例 #2
0
def send_command():
    form = SendCommandForm()
    if form.validate_on_submit():
        if subprocess.run(['ping',form.ipaddress.data,'-c','1'],stdout=subprocess.DEVNULL).returncode==0:
           result = 'is ok'
           try:
            device={'device_type':'cisco_ios_telnet','username':'******','password':'******','ip':form.ipaddress.data}
            print (device,'\n',form.command.data)
            with netmiko.ConnectHandler(**device,verbose=True) as ssh:
              print ('>>>try connect to host',device['ip'])
              result_command=ssh.send_command(form.command.data)
              if 'Incomplete' in result:
                  print ('Error in command')
              print ('result_connection_to_dev',result_command)
#              flash ('')
              return render_template('send_command.html',result_command=result_command,form=form)
           except:
              print ('>>>netmiko_return_error',device['ip'])


#           return  render_template('send_command.html',host=form.ipaddress.data,result=result,form=form)
        else:
           result = "no ping"
           flash ("no ping")
#           return  render_template('send_command.html',host=form.ipaddress.data,result=result,form=form)
    return render_template('send_command.html',form=form)
コード例 #3
0
def send_command():
    form = SendCommandForm()
    if form.validate_on_submit():
        if subprocess.run(['ping', form.ipaddress.data, '-c', '1'],
                          stdout=subprocess.DEVNULL).returncode == 0:
            result = 'is ok'
            try:
                device = {
                    'device_type': 'cisco_ios_telnet',
                    'username': '******',
                    'password': '******',
                    'ip': form.ipaddress.data
                }
                print(device, '\n', form.command.data)
                with netmiko.ConnectHandler(**device, verbose=True) as ssh:
                    result_command = ssh.send_command(form.command.data)
                    print(result_command)
                    return render_template('send_command.html',
                                           result_command=result_command,
                                           form=form)
            except:
                print(result_command)
                return render_template('send_command.html',
                                       result_command='error from device',
                                       form=form)
        else:
            flash("device not response")
    return render_template('send_command.html', form=form)
コード例 #4
0
def redis_send_command():
    form = SendCommandForm()
    job_id = False
    if not job_id:
        if form.validate_on_submit():
            job = redis_ssh.redis_send(form.ipaddress.data, form.command.data)
            job_id = job.get_id()
    else:
        return render_template('redis_result.html', form=form, job=job)

    return render_template('redis_send_command.html', form=form)
コード例 #5
0
def redis_send_command():
    form = SendCommandForm()
    if form.validate_on_submit():
        job = redis_ssh.redis_send(form.ipaddress.data, form.command.data)
        response_object = {
            'status': 'success',
            'data': {
                'task_id': job.get_id()
            }
        }
        return jsonify(response_object), 202


#        return render_template('redis_result.html',form=form,job=job)
    return render_template('redis_send_command.html', form=form)
コード例 #6
0
def ping_host():
    form = SendCommandForm()
    if form.validate_on_submit():
        if subprocess.run(['ping', form.ipaddress.data, '-c', '1'],
                          stdout=subprocess.DEVNULL).returncode == 0:
            result = 'is ok'
            flash("ping ok")
#           return  render_template('send_command.html',host=form.ipaddress.data,result=result,form=form)
        else:
            result = "no ping"
            flash("no ping")


#           return  render_template('send_command.html',host=form.ipaddress.data,result=result,form=form)
    return render_template('send_command.html', form=form)
コード例 #7
0
def ping_host(host):
    form = SendCommandForm()
    if form.validate_on_submit():
        #    print('try ping to host:',host)
        if subprocess.run(['ping', host, '-c', '1'],
                          stdout=subprocess.DEVNULL).returncode == 0:
            result = 'is ok'
            #          return ('is ok')
            return render_template('send_command.html',
                                   host=host,
                                   result=result,
                                   form=form)
        else:
            result = "no ping"
            return "no ping"