Package backend :: Package server :: Package rhnServer :: Module server_route
[hide private]
[frames] | no frames]

Source Code for Module backend.server.rhnServer.server_route

  1  # 
  2  # Copyright (c) 2008--2016 Red Hat, Inc. 
  3  # 
  4  # This software is licensed to you under the GNU General Public License, 
  5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
  6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
  8  # along with this software; if not, see 
  9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
 10  # 
 11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
 12  # granted to use or replicate Red Hat trademarks that are incorporated 
 13  # in this software or its documentation. 
 14  # 
 15  # 
 16  # Module for storing client route through proxies 
 17  # 
 18   
 19  import string 
 20   
 21  from spacewalk.common import rhnFlags 
 22  from spacewalk.common.rhnLog import log_debug 
 23  from spacewalk.server import rhnSQL, apacheAuth 
 24   
 25   
26 -def store_client_route(server_id):
27 """ Stores the route the client took to get to hosted or the Satellite """ 28 29 log_debug(5, server_id) 30 31 # get the old routing information for this server_id 32 # oldRoute in this format: [(id0, hostname0), (id1, hostname1), ...] 33 # closest to client, ..., closest to server 34 h = rhnSQL.prepare(""" 35 select position, 36 proxy_server_id, 37 hostname 38 from rhnServerPath 39 where server_id = :server_id 40 order by position 41 """) 42 h.execute(server_id=server_id) 43 oldRoute = h.fetchall_dict() or [] 44 newRoute = [] 45 46 # construct oldRoute_ from oldRoute, to have the actual format described above 47 oldRouteTuples = [] 48 for oldRouteDict in oldRoute: 49 oldRouteTuples.append((str(oldRouteDict['proxy_server_id']), oldRouteDict['hostname'])) 50 51 # code block if there *is* routing info in the headers 52 # NOTE: X-RHN-Proxy-Auth described in proxy/broker/rhnProxyAuth.py 53 if rhnFlags.test('X-RHN-Proxy-Auth'): 54 tokens = string.split(rhnFlags.get('X-RHN-Proxy-Auth'), ',') 55 tokens = [token for token in tokens if token] 56 57 log_debug(4, "route tokens", tokens) 58 # newRoute in this format: [(id0, hostname0), (id1, hostname1), ...] 59 # closest to client, ..., closest to server 60 for token in tokens: 61 token, hostname = apacheAuth.splitProxyAuthToken(token) 62 if hostname is None: 63 log_debug(3, "NOTE: Spacewalk Proxy v1.1 detected - route tracking is unsupported") 64 newRoute = [] 65 break 66 newRoute.append((token[0], hostname)) 67 68 log_debug(4, "newRoute", newRoute) 69 70 if oldRouteTuples == newRoute: 71 # Nothing to do here 72 # This also catches the case of no routes at all 73 return 74 75 if oldRouteTuples: 76 # blow away table rhnServerPath entries for server_id 77 log_debug(8, 'blow away route-info for %s' % server_id) 78 h = rhnSQL.prepare(""" 79 delete from rhnServerPath where server_id = :server_id 80 """) 81 h.execute(server_id=server_id) 82 83 if not newRoute: 84 log_debug(3, "No new route to add") 85 rhnSQL.commit() 86 return 87 88 log_debug(8, 'adding route-info entries: %s - %s' % (server_id, newRoute)) 89 90 h = rhnSQL.prepare(""" 91 insert into rhnServerPath 92 (server_id, proxy_server_id, position, hostname) 93 values (:server_id, :proxy_server_id, :position, :hostname) 94 """) 95 server_ids = [] 96 proxy_ids = [] 97 proxy_hostnames = [] 98 positions = [] 99 counter = 0 100 for p in newRoute: 101 proxy_id, proxy_hostname = p[:2] 102 proxy_ids.append(proxy_id) 103 proxy_hostnames.append(proxy_hostname) 104 server_ids.append(server_id) 105 positions.append(counter) 106 counter = counter + 1 107 108 log_debug(5, server_ids, proxy_ids, positions, 109 proxy_hostnames) 110 h.executemany(server_id=server_ids, proxy_server_id=proxy_ids, 111 position=positions, hostname=proxy_hostnames) 112 113 rhnSQL.commit()
114