Giter Club home page Giter Club logo

python-for-beginners's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-for-beginners's Issues

How to connect netmiko and django application

as netmiko specifies there should be a device type, IP Address, username and a password so i made a model named devices and what i am trying to do is when i click on each device created in a table it should execute netmiko with the four credentials such as Device type, IP Address, Username and password for the specific device selected or clicked and it should allow me to type a command which can be executed by a press of button

can you please help me with the code

Model.py
class Device(models.Model):
    CISCO1 = 1
    CISCO2 = 2
    CISCO3 = 3
    CISCO4 = 4
    DEVICE_TYPES = (
        (CISCO1, 'cisco_ios'),
        (CISCO2, 'cisco_nxos_ssh'),
        (CISCO3, 'cisco_s300'),
        (CISCO4, 'cisco_tp_tcce'),
    )
    device_name = models.CharField(max_length=50)
    publication_date = models.DateField(null=True)
    IP_address = models.CharField(max_length=50)
    username = models.CharField(max_length=30)
    password = models.CharField(max_length=30)
    device_type = models.PositiveSmallIntegerField(choices=DEVICE_TYPES)
    timestamp = models.DateField(auto_now_add=True, auto_now=False)

    def __str__(self):
        return self.device_name
View.py

This is the connection code
i want to get what is written in the fields and post it in the connection method so it runs
but i dont know know to get data from the Model (Device) and pass it here or when i select a device from the view it should get the credential to this method


def connection_manage(request):
    if request.method == "POST":
        form = CommandForm(request.POST)
        if form.is_valid():
            from netmiko import ConnectHandler
            device = {}
            device['device_type'] = 'cisco_ios'
            device['ip'] = 'DESKTOP-CT4RSIT'
            device['username'] = ''
            device['password'] = ''
            cmd = request.POST.get('command', '')
            conn = ConnectHandler(**device)
            output = conn.send_command(cmd)
            return render(request, 'connect.html', {'form': form, 'output': output})
    else:
        form = CommandForm()
        return render(request, 'connect.html', {'form': form})
form.py

class CommandForm(BSModalForm):
    command = forms.CharField(label='Command to execute')
    class Meta:
        model = Device
        exclude = ['timestamp', 'publication_date', 'device_type']
connect.html

{% load static %}
<!doctype html>

<head>
    <title>Mannai Co.</title>
    <link href="{% static 'assets/css/bootstrap.min.css' %}" rel="stylesheet">
    <link rel="stylesheet" href="{% static 'assets/css/login.css' %}">
</head>

<body>
    <div class="wrapper fadeInDown">

        <div id="formContent">

            <div class="fadeIn first">
                <br>
                <img src="{% static 'assets/img/manni-png.png' %}" id="icon" alt="User Icon">
            </div>
            <h3 class="fadeIn second">Netminko APP</h3>
            <p>Run command:</p>
            <form method="POST">
                {% csrf_token %}
                {{form}}
                <br>
                <input type="submit" value="Run command!" class="fadeIn fourth" />
            </form>
            {% if request.POST %}
            <p>Command output:</p>
            <pre>{{ output }}</pre>
            {% endif %}

        </div>
    </div>
    <script src="{% static 'assets/js/bootstrap.min.js' %}"></script>
    <script src="{% static 'assets/js/jquery.min.js' %}"></script>

</body>

</html>

urs.py
path('execute/',connection_manage, name='execute_device'),

First Setup needed
when i click on this one it should make me able to enter all details manually and press execute
b

enter all fields manually and execute
this is the view from the website but whatever i type it still going to connect to cisco_ios
xxx

output
zzz

Second Setup needed
when i click on the each filed button it should pop a modal which is currently working with all fields populated and when i type and command and execute it should run for the specified device

table

running

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.