Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfontini committed Mar 31, 2024
1 parent 932988e commit a19645a
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 0 deletions.
44 changes: 44 additions & 0 deletions netmiko/actions/send_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from netmiko import ConnectHandler
import sys
from st2common.runners.base_action import Action


def connect(hostname, username, password, device_type, port):
try:
device = {
'device_type': device_type,
'ip': hostname,
'username': username,
'password': password,
'port': port,

}
connection = ConnectHandler(**device)
return connection
except Exception as e:
print(e)
return None


class main(Action):

def run(self, hostname, device_type, port, command):
credentials = self.config
USER = credentials['user']
PASSWORD = credentials['password']

if credentials:
connection = connect(hostname, USER, PASSWORD,
device_type=device_type, port=port)
if connection != None:
output = connection.send_command(command)
connection.disconnect()
print(output)
return output
else:
print("Connection failed")
return sys.exit(1)
else:
print(
"No credentials found, please check your config file /opt/stackstorm/configs/pack_name")
return sys.exit(1)
156 changes: 156 additions & 0 deletions netmiko/actions/send_command.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
name: "netmiko_send_command"
pack: netmiko_automation
runner_type: "python-script"
description: "This action make a connection to the device and return the data"
enabled: true
entry_point: "send_command.py"
parameters:
hostname:
type: "string"
description: "hostname or ip "
required: true
device_type:
type: "string"
description: "choose device type "
required: true
enum:
[
"a10",
"accedian",
"adtran_os",
"adva_fsp150f2",
"adva_fsp150f3",
"alcatel_aos",
"alcatel_sros",
"allied_telesis_awplus",
"apresia_aeos",
"arista_eos",
"arris_cer",
"aruba_os",
"aruba_osswitch",
"aruba_procurve",
"audiocode_66",
"audiocode_72",
"audiocode_shell",
"avaya_ers",
"avaya_vsp",
"broadcom_icos",
"brocade_fastiron",
"brocade_fos",
"brocade_netiron",
"brocade_nos",
"brocade_vdx",
"brocade_vyos",
"calix_b6",
"casa_cmts",
"cdot_cros",
"centec_os",
"checkpoint_gaia",
"ciena_saos",
"cisco_asa",
"cisco_ftd",
"cisco_ios",
"cisco_nxos",
"cisco_s200",
"cisco_s300",
"cisco_tp",
"cisco_viptela",
"cisco_wlc",
"cisco_xe",
"cisco_xr",
"cloudgenix_ion",
"coriant",
"dell_dnos9",
"dell_force10",
"dell_isilon",
"dell_os10",
"dell_os6",
"dell_os9",
"dell_powerconnect",
"dell_sonic",
"dlink_ds",
"digi_transport",
"eltex",
"eltex_esr",
"endace",
"enterasys",
"ericsson_ipos",
"ericsson_mltn63",
"ericsson_mltn66",
"extreme",
"extreme_ers",
"extreme_exos",
"extreme_netiron",
"extreme_nos",
"extreme_slx",
"extreme_tierra",
"extreme_vdx",
"extreme_vsp",
"extreme_wing",
"f5_linux",
"f5_ltm",
"f5_tmsh",
"flexvnf",
"fortinet",
"generic",
"generic_termserver",
"hillstone_stoneos",
"hp_comware",
"hp_procurve",
"huawei",
"huawei_olt",
"huawei_smartax",
"huawei_vrp",
"huawei_vrpv8",
"ipinfusion_ocnos",
"juniper",
"juniper_junos",
"juniper_screenos",
"keymile",
"keymile_nos",
"linux",
"mellanox",
"mellanox_mlnxos",
"mikrotik_routeros",
"mikrotik_switchos",
"mrv_lx",
"mrv_optiswitch",
"netapp_cdot",
"netgear_prosafe",
"netscaler",
"nokia_srl",
"nokia_sros",
"oneaccess_oneos",
"ovs_linux",
"paloalto_panos",
"pluribus",
"quanta_mesh",
"rad_etx",
"raisecom_roap",
"ruckus_fastiron",
"ruijie_os",
"sixwind_os",
"sophos_sfos",
"supermicro_smis",
"teldat_cit",
"tplink_jetstream",
"ubiquiti_edge",
"ubiquiti_edgerouter",
"ubiquiti_edgeswitch",
"ubiquiti_unifiswitch",
"vyatta_vyos",
"vyos",
"watchguard_fireware",
"yamaha",
"zte_zxros",
"zyxel_os",
]
port:
type: "string"
description: "port ex 22,23"
required: true
command:
type: "string"
description: "ex show ip interface brief"
required: true
11 changes: 11 additions & 0 deletions netmiko/config.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
user:
description: "Username"
type: "string"
required: true
secret: false
password:
description: "Username"
type: "string"
required: true
secret: true
Binary file added netmiko/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions netmiko/pack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
ref: netmiko_automation
name: netmiko_automation
description: netmiko_automation
keywords:
- automation
- config python
- netmiko
version: 1.0.0
python_versions:
- "3"
author: Lucas Fontini
email: [email protected]
1 change: 1 addition & 0 deletions netmiko/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
netmiko

0 comments on commit a19645a

Please sign in to comment.