from django.utils.text import slugify
from netmiko import ConnectHandler
import netbox.settings
from extras.scripts import *
class RunCommand(Script):
class Meta:
name = "Run command on Cisco Devices via SSH"
description = "Run command on Cisco Devices via SSH"
field_order = ['input_ip', 'input_command']
input_ip = StringVar(
description="Enter the IP Address:"
)
CHOICES = (
('show ip dhcp pool | i .', 'Show DHCP Pools'),
('show ip dhcp binding', 'Show DHCP Bindings')
)
input_command = ChoiceVar(
choices=CHOICES
)
def run(self, data, commit):
cisco1 = {
"device_type": "cisco_ios",
"host": data['input_ip'],
"username": netbox.settings.NAPALM_USERNAME,
"password": netbox.settings.NAPALM_PASSWORD,
}
command = data['input_command']
with ConnectHandler(**cisco1) as net_connect:
output = net_connect.send_command(command)
self.log_success("View the information the in Output tab")
return ''.join(output)
************************
I would like to replace:
input_ip = StringVar(
description="Enter the IP Address:"
)
with an ObjectVar so I can select a device and use its primary IP.
What modules do I need to import and how should I define this ObjectVar.
I did try different ways based on examples found, but I do struggle with this.
Many thanks