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

Source Code for Package backend.server.rhnServer

 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  # Module for handling the rhnServer objects. 
16  # 
17   
18   
19  # these are pretty much the only entry points 
20  from spacewalk.common.usix import StringType, UnicodeType 
21  from spacewalk.common.rhnException import rhnFault 
22  from spacewalk.common.rhnLog import log_debug, log_error 
23  from spacewalk.server import rhnUser 
24   
25  # Local imports 
26  from server_class import Server 
27  from server_certificate import Certificate 
28  from server_token import fetch_token, fetch_org_token 
29   
30   
31 -def get(system_id, load_user=1):
32 """ retrieve the server with matching certificate from the database """ 33 log_debug(3, "load_user = %s" % load_user) 34 # This has to be a string 35 if not isinstance(system_id, (StringType, UnicodeType)): 36 return None 37 # Try to initialize the certificate object 38 cert = Certificate() 39 if not cert.reload(system_id) == 0: 40 return None 41 # if invalid, stop here 42 if not cert.valid(): 43 return None 44 45 # this looks like a real server 46 server = Server(None) 47 # and load it up 48 if not server.loadcert(cert, load_user) == 0: 49 return None 50 # okay, it is a valid certificate 51 return server
52 53
54 -def search(server_id, username=None):
55 """ search for a server in the database and return the Server object """ 56 log_debug(3, server_id, username) 57 s = Server(None) 58 if not s.reload(server_id) == 0: 59 log_error("Reloading server id %d failed" % server_id) 60 # we can't say that the server is not really found 61 raise rhnFault(20) 62 # now that it is reloaded, fix up the s.user field 63 if username: 64 s.user = rhnUser.search(username) 65 return s
66 67
68 -def search_token(token):
69 log_debug(3, token) 70 return fetch_token(token)
71 72
73 -def search_org_token(org_id):
74 log_debug(3, org_id) 75 return fetch_org_token(org_id)
76