original_docstring: Store the given RIB data into the database.
  
          Updating the database involves two steps. First is to make sure
          that old entries are deleted and then to add each RIB entry into
          its own row indexed by the router id.
  
          Args:
              rib: A dict containing parsed RIB information
              ts: Timestamp associated with the polled data
  
          Returns:
              None
          
docstring: Store the given RIB data into the database.
  Updating the database involves two steps. First is to make sure
  that old entries are deleted and then to add each RIB entry into
  its own row indexed by the router id.
docstring_tokens: Store the given RIB data into the database . Updating the database involves two steps . First is to make sure that old entries are deleted and then to add each RIB entry into its own row indexed by the router id .
code: def store_in_db(self, rib, ts):
          """Store the given RIB data into the database.
  
          Updating the database involves two steps. First is to make sure
          that old entries are deleted and then to add each RIB entry into
          its own row indexed by the router id.
  
          Args:
              rib: A dict containing parsed RIB information
              ts: Timestamp associated with the polled data
  
          Returns:
              None
          """
          if not rib:
              print "Could not refresh database with new data for %s." % self.device
          else:
              print "Updating Database with new data for %s." % self.device
              #pprint(rib)
              cur = self.sql.cursor()
              cur.execute("SELECT rtr_id, device FROM rtr_cache WHERE device = ?", (self.device, ))
              try:
                  rtr_id, device = cur.fetchone()
                  cur.execute("PRAGMA foreign_keys = on")
                  cur.execute("DELETE FROM rtr_cache WHERE device = ?", (self.device, ))
                  raise TypeError # Simulate lookup failure case
              except TypeError:
                  cur.execute("INSERT INTO rtr_cache (device, rtrupdt) VALUES (?, ?)", (self.device, ts))
                  rtr_id = cur.lastrowid
              # Update RIB info
              idx = 0
              saved_pfx = None
              saved_pfxlen = None
              for r in rib:
                  # Split path into pathbutone and orig_asn
                  pathbutone = r.path
                  orig_asn = pathbutone.pop()
                  pathbutonestr = ' '.join(pathbutone)
                  # The IP address may be omitted when they are identical
                  # in two consecutive lines. So save the current one for
                  # next use
                  if r.pfx and r.pfxlen:
                      saved_pfx = r.pfx
                      saved_pfxlen = r.pfxlen
                  elif saved_pfx:
                      r.pfx = saved_pfx
                      r.pfxlen = saved_pfxlen
                  else:
                      continue
                  ipstr = unicode(str(r.pfx) + "/" + str(r.pfxlen), "utf-8")
                  prefixint_min = netaddr.IPNetwork(ipstr).first
                  prefixint_max = netaddr.IPNetwork(ipstr).last
                  values = (rtr_id, 
                            idx,
                            r.status, 
                            r.pfx, 
                            int(r.pfxlen), 
                            EOMGenericPoller.get_ip_str(prefixint_min),
                            EOMGenericPoller.get_ip_str(prefixint_max),
                            r.nexthop, 
                            int(r.metric) if r.metric else -1, 
                            int(r.locpref) if r.locpref else -1, 
                            int(r.weight) if r.weight else -1, 
                            pathbutonestr, 
                            int(orig_asn), 
                            r.route_orig)
                  cur.execute("INSERT INTO rtr_rib (rtr_id, idx, status, "
                              "pfx, pfxlen, pfxstr_min, pfxstr_max, nexthop, "
                              "metric, locpref, weight, pathbutone, orig_asn, route_orig) "
                              "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                              values)
                  idx += 1
              self.sql.commit()
code_tokens: def store_in_db ( self , rib , ts ) : if not rib : print "Could not refresh database with new data for %s." % self . device else : print "Updating Database with new data for %s." % self . device cur = self . sql . cursor ( ) cur . execute ( "SELECT rtr_id, device FROM rtr_cache WHERE device = ?" , ( self . device , ) ) try : rtr_id , device = cur . fetchone ( ) cur . execute ( "PRAGMA foreign_keys = on" ) cur . execute ( "DELETE FROM rtr_cache WHERE device = ?" , ( self . device , ) ) raise TypeError except TypeError : cur . execute ( "INSERT INTO rtr_cache (device, rtrupdt) VALUES (?, ?)" , ( self . device , ts ) ) rtr_id = cur . lastrowid idx = 0 saved_pfx = None saved_pfxlen = None for r in rib : pathbutone = r . path orig_asn = pathbutone . pop ( ) pathbutonestr = ' ' . join ( pathbutone ) if r . pfx and r . pfxlen : saved_pfx = r . pfx saved_pfxlen = r . pfxlen elif saved_pfx : r . pfx = saved_pfx r . pfxlen = saved_pfxlen else : continue ipstr = unicode ( str ( r . pfx ) + "/" + str ( r . pfxlen ) , "utf-8" ) prefixint_min = netaddr . IPNetwork ( ipstr ) . first prefixint_max = netaddr . IPNetwork ( ipstr ) . last values = ( rtr_id , idx , r . status , r . pfx , int ( r . pfxlen ) , EOMGenericPoller . get_ip_str ( prefixint_min ) , EOMGenericPoller . get_ip_str ( prefixint_max ) , r . nexthop , int ( r . metric ) if r . metric else - 1 , int ( r . locpref ) if r . locpref else - 1 , int ( r . weight ) if r . weight else - 1 , pathbutonestr , int ( orig_asn ) , r . route_orig ) cur . execute ( "INSERT INTO rtr_rib (rtr_id, idx, status, " "pfx, pfxlen, pfxstr_min, pfxstr_max, nexthop, " "metric, locpref, weight, pathbutone, orig_asn, route_orig) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" , values ) idx += 1 self . sql . commit ( )
short_docstring: Store the given RIB data into the database.
short_docstring_tokens: Store the given RIB data into the database .
comment: """Store the given RIB data into the database.
  
          Updating the database involves two steps. First is to make sure
          that old entries are deleted and then to add each RIB entry into
          its own row indexed by the router id.
  
          Args:
              rib: A dict containing parsed RIB information
              ts: Timestamp associated with the polled data
  
          Returns:
              None
          """$SEP$#pprint(rib)$SEP$# Simulate lookup failure case$SEP$# Update RIB info$SEP$# Split path into pathbutone and orig_asn$SEP$# The IP address may be omitted when they are identical$SEP$# in two consecutive lines. So save the current one for$SEP$# next use