attemp at connection plugin

This commit is contained in:
Valentin Gurmeza 2018-01-08 11:16:55 -08:00
parent b8a95fa401
commit f89e689418
2 changed files with 26 additions and 18 deletions

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python
from ansible.module_utils import mt_api
from ansible.module_utils import MikrotikConnection
import re
import sys
@ -59,9 +59,6 @@ class MikrotikIdempotent():
self, hostname, username, password, desired_params, api_path,
state, idempotent_param, check_mode=False):
self.hostname = hostname
self.username = username
self.password = password
self.state = state
self.desired_params = desired_params
self.idempotent_param = idempotent_param
@ -75,20 +72,7 @@ class MikrotikIdempotent():
self.failed = False
self.failed_msg = []
self.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.",
self.mk = MikrotikConnection.login()
def get_current_params(self):
clean_params(self.desired_params)

View 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.",