
Untitled
By: a guest on
May 25th, 2012 | syntax:
Python | size: 1.47 KB | hits: 24 | expires: Never
from thinbox.lib.routeros import routeros_ssh_handler as ssh_handler
from thinbox.app.core import models as cmodels
from thinbox.app.core import constants as cconstants
class RouterOSHandler:
gateway = None
result = None
handler = None
def __init__(self,gateway,*args,**kwargs):
self.gateway = gateway
try:
if self.gateway.access_method == cconstants.ACCESS_METHOD_SSH:
self.result = self.ssh_exec()
self.handler = ssh_handler.SSHHandler()
if self.gateway.access_method == cconstants.ACCESS_METHOD_TELNET:
self.result = self.telnet_exec()
if self.gateway.access_method == cconstants.ACCESS_METHOD_API:
self.result = self.api_exec()
except AttributeError:
self.result = None
class InterfaceList(RouterOSHandler):
def ssh_exec(self):
#executa comando ssh e retorna
self.result = self.gateway.access_port
self.handler
return self.result
#Exemplo na View
class InterfaceListView(DetailView):
template_name = 'mobile/gateway/interface_list.html'
model = cmodels.Gateway
context_object_name = 'gateway'
slug_field = 'id'
def get(self,*args,**kwargs):
result = InterfaceList(gateway=self.get_object()).result
return HttpResponse(result)