mirror of
https://github.com/zahodi/ansible-mikrotik.git
synced 2025-07-15 12:44:22 +02:00
attemp at connection plugin
This commit is contained in:
parent
b8a95fa401
commit
f89e689418
2 changed files with 26 additions and 18 deletions
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from ansible.module_utils import mt_api
|
from ansible.module_utils import MikrotikConnection
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -59,9 +59,6 @@ class MikrotikIdempotent():
|
||||||
self, hostname, username, password, desired_params, api_path,
|
self, hostname, username, password, desired_params, api_path,
|
||||||
state, idempotent_param, check_mode=False):
|
state, idempotent_param, check_mode=False):
|
||||||
|
|
||||||
self.hostname = hostname
|
|
||||||
self.username = username
|
|
||||||
self.password = password
|
|
||||||
self.state = state
|
self.state = state
|
||||||
self.desired_params = desired_params
|
self.desired_params = desired_params
|
||||||
self.idempotent_param = idempotent_param
|
self.idempotent_param = idempotent_param
|
||||||
|
@ -75,20 +72,7 @@ class MikrotikIdempotent():
|
||||||
self.failed = False
|
self.failed = False
|
||||||
self.failed_msg = []
|
self.failed_msg = []
|
||||||
|
|
||||||
self.login()
|
self.mk = MikrotikConnection.login()
|
||||||
|
|
||||||
def login(self):
|
|
||||||
self.mk = mt_api.Mikrotik(
|
|
||||||
self.hostname,
|
|
||||||
self.username,
|
|
||||||
self.password,
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.mk.login()
|
|
||||||
self.login_success = True
|
|
||||||
except:
|
|
||||||
self.failed_msg = "Could not log into Mikrotik device." + " Check the username and password.",
|
|
||||||
|
|
||||||
def get_current_params(self):
|
def get_current_params(self):
|
||||||
clean_params(self.desired_params)
|
clean_params(self.desired_params)
|
||||||
|
|
24
pythonlibs/mt_connection.py
Normal file
24
pythonlibs/mt_connection.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
from ansible.module_utils import mt_api
|
||||||
|
|
||||||
|
class MikrotikConnection():
|
||||||
|
'''This will be a connection class
|
||||||
|
|
||||||
|
'''
|
||||||
|
def __init__():
|
||||||
|
self.hostname = "localhost"
|
||||||
|
self.username = "admin"
|
||||||
|
self.password = ""
|
||||||
|
|
||||||
|
def login(self):
|
||||||
|
self.mk = mt_api.Mikrotik(
|
||||||
|
self.hostname,
|
||||||
|
self.username,
|
||||||
|
self.password,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.mk.login()
|
||||||
|
self.login_success = True
|
||||||
|
except:
|
||||||
|
self.failed_msg = "Could not log into Mikrotik device." + " Check the username and password.",
|
Loading…
Add table
Add a link
Reference in a new issue