pvl/verkko/hosts.py
changeset 186 0bfb34281141
parent 183 8fbaaf0564dc
child 199 ccc34415d6a9
equal deleted inserted replaced
185:2e5e1a130070 186:0bfb34281141
    25     TIME_FMT = '%H:%M:%S'
    25     TIME_FMT = '%H:%M:%S'
    26     
    26     
    27     MAC_HEX = r'([A-Za-z0-9]{2})'
    27     MAC_HEX = r'([A-Za-z0-9]{2})'
    28     MAC_SEP = r'[-:.]?'
    28     MAC_SEP = r'[-:.]?'
    29     MAC_RE = re.compile(MAC_SEP.join([MAC_HEX] * 6))
    29     MAC_RE = re.compile(MAC_SEP.join([MAC_HEX] * 6))
    30 
       
    31     @classmethod
       
    32     def query (cls, session, seen=None) :
       
    33         """
       
    34             seen        - select hosts seen during given timedelta period
       
    35         """
       
    36         
       
    37         query = session.query(cls)
       
    38 
       
    39         return query
       
    40 
    30 
    41     @classmethod
    31     @classmethod
    42     def normalize_mac (cls, mac) :
    32     def normalize_mac (cls, mac) :
    43         match = cls.MAC_RE.search(mac)
    33         match = cls.MAC_RE.search(mac)
    44 
    34 
   142 ))
   132 ))
   143 
   133 
   144 ## Controller 
   134 ## Controller 
   145 class HostsTable (table.Table) :
   135 class HostsTable (table.Table) :
   146     """
   136     """
   147         Table of hosts.
   137         <table> of hosts.
   148     """
   138     """
   149 
   139 
   150     ITEMS   = "Hosts"
   140     ITEMS   = "Hosts"
   151     COLUMNS = (
   141     COLUMNS = (
   152         table.Column('ip',    "IP",       Host.ip,        
   142         table.Column('ip',    "IP",       Host.ip,        
   178 
   168 
   179     CSS = web.DatabaseHandler.CSS + table.TableHandler.CSS + (
   169     CSS = web.DatabaseHandler.CSS + table.TableHandler.CSS + (
   180         "/static/dhcp/hosts.css", 
   170         "/static/dhcp/hosts.css", 
   181     )
   171     )
   182     
   172     
   183     # model
   173     # view
   184     TABLE = HostsTable
   174     TABLE = HostsTable
   185 
   175 
   186     def query (self) :
   176     def query (self) :
   187         """
   177         """
   188             Database SELECT query.
   178             Database SELECT query.