Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 25th, 2012  |  syntax: Python  |  size: 1.47 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from thinbox.lib.routeros import routeros_ssh_handler as ssh_handler
  2. from thinbox.app.core import models as cmodels
  3. from thinbox.app.core import constants as cconstants
  4.  
  5. class RouterOSHandler:
  6.     gateway = None
  7.     result = None
  8.     handler = None
  9.    
  10.     def __init__(self,gateway,*args,**kwargs):
  11.         self.gateway = gateway
  12.        
  13.         try:
  14.             if self.gateway.access_method == cconstants.ACCESS_METHOD_SSH:
  15.                 self.result = self.ssh_exec()
  16.                 self.handler = ssh_handler.SSHHandler()
  17.        
  18.             if self.gateway.access_method == cconstants.ACCESS_METHOD_TELNET:
  19.                 self.result = self.telnet_exec()
  20.            
  21.             if self.gateway.access_method == cconstants.ACCESS_METHOD_API:
  22.                 self.result = self.api_exec()
  23.                
  24.         except AttributeError:
  25.             self.result = None
  26.        
  27.        
  28. class InterfaceList(RouterOSHandler):
  29.     def ssh_exec(self):
  30.         #executa comando ssh e retorna
  31.         self.result = self.gateway.access_port
  32.        
  33.         self.handler
  34.        
  35.         return self.result
  36.  
  37.  
  38.  
  39. #Exemplo na View
  40. class InterfaceListView(DetailView):
  41.     template_name = 'mobile/gateway/interface_list.html'
  42.     model = cmodels.Gateway
  43.     context_object_name = 'gateway'
  44.     slug_field = 'id'
  45.    
  46.     def get(self,*args,**kwargs):
  47.         result = InterfaceList(gateway=self.get_object()).result
  48.        
  49.         return HttpResponse(result)