本文整理汇总了Python中spacewalk.common.rhnException.rhnException函数的典型用法代码示例。如果您正苦于以下问题:Python rhnException函数的具体用法?Python rhnException怎么用?Python rhnException使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rhnException函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, db, seq):
if not seq or not isinstance(seq, str):
raise rhnException("First argument needs to be a sequence name", seq)
self.__seq = seq
if not isinstance(db, sql_base.Database):
raise rhnException("Argument db is not a database instance", db)
self.__db = db
开发者ID:flavio,项目名称:spacewalk,代码行数:7,代码来源:sql_sequence.py
示例2: select
def select(self, row):
if not isinstance(row, dict) and not isinstance(row, UserDictCase):
raise rhnException("Expecting hash argument. %s is invalid" % type(row),
row)
if row == {}:
raise rhnException("The hash argument is empty", row)
keys = row.keys()
# Sort the list of keys, to always get the same list of arguments
keys.sort()
args = []
for col in keys:
if row[col] in (None, ''):
clause = "%s is null" % col
else:
clause = "%s = :%s" % (col, col)
args.append(clause)
sql = "select * from %s where " % self.__table
cursor = self.__db.prepare(sql + string.join(args, " and "))
cursor.execute(**row)
rows = cursor.fetchall_dict()
if rows is None:
return None
# fill up the cache
if self.__cache is not None:
for row in rows:
self.__cache[row[self.__hashid]] = row
return map(lambda a: UserDictCase(a), rows)
开发者ID:cliffy94,项目名称:spacewalk,代码行数:27,代码来源:sql_table.py
示例3: __init__
def __init__(self, db, table, hashid, cache=False):
if not table or not isinstance(table, str):
raise rhnException("First argument needs to be a table name",
table)
self.__table = table
if not hashid or not isinstance(hashid, str):
raise rhnException("Second argument needs to be the name of the unique index column",
hashid)
self.__hashid = hashid
if not isinstance(db, sql_base.Database):
raise rhnException("Argument db is not a database instance", db)
self.__db = db
self.__cache = None
if cache:
self.__cache = {}
开发者ID:cliffy94,项目名称:spacewalk,代码行数:15,代码来源:sql_table.py
示例4: check_password
def check_password(self, password):
""" simple check for a password that might become more complex sometime """
good_pwd = str(self.contact["password"])
old_pwd = str(self.contact["old_password"])
if CFG.pam_auth_service:
# a PAM service is defined
# We have to check the user's rhnUserInfo.use_pam_authentication
# XXX Should we create yet another __init_blah function?
# since it's the first time we had to lool at rhnUserInfo,
# I'll assume it's not something to happen very frequently,
# so I'll use a query for now
# - misa
#
h = rhnSQL.prepare("""
select ui.use_pam_authentication
from web_contact w, rhnUserInfo ui
where w.login_uc = UPPER(:login)
and w.id = ui.user_id""")
h.execute(login=self.contact["login"])
data = h.fetchone_dict()
if not data:
# This should not happen
raise rhnException("No entry found for user %s" %
self.contact["login"])
if data['use_pam_authentication'] == 'Y':
# use PAM
import rhnAuthPAM
return rhnAuthPAM.check_password(self.contact["login"],
password, CFG.pam_auth_service)
# If the entry in rhnUserInfo is 'N', perform regular
# authentication
return check_password(password, good_pwd, old_pwd)
开发者ID:adelton,项目名称:spacewalk,代码行数:32,代码来源:rhnUser.py
示例5: join_groups
def join_groups(self):
""" For a new server, join server groups """
# Sanity check - we should always have a user
if not self.user:
raise rhnException("User not specified")
server_id = self.getid()
user_id = self.user.getid()
h = rhnSQL.prepare(
"""
select system_group_id
from rhnUserDefaultSystemGroups
where user_id = :user_id
"""
)
h.execute(user_id=user_id)
while 1:
row = h.fetchone_dict()
if not row:
break
server_group_id = row["system_group_id"]
log_debug(5, "Subscribing server to group %s" % server_group_id)
server_lib.join_server_group(server_id, server_group_id)
开发者ID:Bearlock,项目名称:spacewalk,代码行数:26,代码来源:server_class.py
示例6: reload
def reload(self, server, reload_all=0):
log_debug(4, server, "reload_all = %d" % reload_all)
if not self.server.load(int(server)):
log_error("Could not find server record for reload", server)
raise rhnFault(29, "Could not find server record in the database")
self.cert = None
# it is lame that we have to do this
h = rhnSQL.prepare("""
select label from rhnServerArch where id = :archid
""")
h.execute(archid=self.server["server_arch_id"])
data = h.fetchone_dict()
if not data:
raise rhnException("Found server with invalid numeric "
"architecture reference",
self.server.data)
self.archname = data['label']
# we don't know this one anymore (well, we could look for, but
# why would we do that?)
self.user = None
# XXX: Fix me
if reload_all:
if not self.reload_packages_byid(self.server["id"]) == 0:
return -1
if not self.reload_hardware_byid(self.server["id"]) == 0:
return -1
return 0
开发者ID:dewayneHat,项目名称:spacewalk,代码行数:29,代码来源:server_class.py
示例7: _push_config_file
def _push_config_file(self, file):
config_info_query = self._query_lookup_non_symlink_config_info
if self._is_link(file) and file.get("symlink"):
config_info_query = self._query_lookup_symlink_config_info
# Look up the config info first
h = rhnSQL.prepare(config_info_query)
h.execute(**file)
row = h.fetchone_dict()
if not row:
# Hmm
raise rhnException("This query should always return a row")
config_info_id = row['id']
file['config_info_id'] = config_info_id
# Look up the config file itself
h = rhnSQL.prepare(self._query_lookup_config_file)
h.execute(**file)
row = h.fetchone_dict()
if row:
# Yay we already have this file
# Later down the road, we're going to update modified for this
# table
file['config_file_id'] = row['id']
return
# Have to insert this config file, gotta use the api to keep quotas up2date...
insert_call = rhnSQL.Function("rhn_config.insert_file",
rhnSQL.types.NUMBER())
file['config_file_id'] = insert_call(file['config_channel_id'], file['path'])
开发者ID:TJM,项目名称:spacewalk,代码行数:30,代码来源:configFilesHandler.py
示例8: __create_server_group
def __create_server_group(group_label, org_id, maxnum=''):
""" create the initial server groups for a new server """
# Add this new server to the pending group
h = rhnSQL.prepare("""
select sg.id, sg.current_members
from rhnServerGroup sg
where sg.group_type = ( select id from rhnServerGroupType
where label = :group_label )
and sg.org_id = :org_id
""")
h.execute(org_id=org_id, group_label=group_label)
data = h.fetchone_dict()
if not data:
# create the requested group
ret_id = rhnSQL.Sequence("rhn_server_group_id_seq")()
h = rhnSQL.prepare("""
insert into rhnServerGroup
( id, name, description, max_members,
group_type, org_id)
select
:new_id, sgt.name, sgt.name, :maxnum,
sgt.id, :org_id
from rhnServerGroupType sgt
where sgt.label = :group_label
""")
rownum = h.execute(new_id=ret_id, org_id=org_id,
group_label=group_label, maxnum=str(maxnum))
if rownum == 0:
# No rows were created, probably invalid label
raise rhnException("Could not create new group for org=`%s'"
% org_id, group_label)
else:
ret_id = data["id"]
return ret_id
开发者ID:flavio,项目名称:spacewalk,代码行数:34,代码来源:server_lib.py
示例9: _execute_wrapper
def _execute_wrapper(self, function, *p, **kw):
params = ",".join(["%s: %s" % (repr(key), repr(value)) for key, value in kw.items()])
log_debug(5, 'Executing SQL: "%s" with bind params: {%s}' % (self.sql, params))
if self.sql is None:
raise rhnException("Cannot execute empty cursor")
if self.blob_map:
blob_content = {}
for orig_blob_var in self.blob_map.keys():
new_blob_var = orig_blob_var + "_blob"
blob_content[new_blob_var] = kw[orig_blob_var]
kw[new_blob_var] = self.var(cx_Oracle.BLOB)
del kw[orig_blob_var]
modified_params = self._munge_args(kw)
try:
retval = apply(function, p, kw)
except self.OracleError, e:
ret = self._get_oracle_error_info(e)
if isinstance(ret, types.StringType):
raise sql_base.SQLError(self.sql, p, kw, ret), None, sys.exc_info()[2]
(errno, errmsg) = ret[:2]
if 900 <= errno <= 999:
# Per Oracle's documentation, SQL parsing error
raise sql_base.SQLStatementPrepareError(errno, errmsg, self.sql), None, sys.exc_info()[2]
if errno == 1475: # statement needs to be reparsed; force a prepare again
if self.reparsed: # useless, tried that already. give up
log_error("Reparsing cursor did not fix it", self.sql)
args = ("Reparsing tried and still got this",) + tuple(ret)
raise sql_base.SQLError(*args), None, sys.exc_info()[2]
self._real_cursor = self.dbh.prepare(self.sql)
self.reparsed = 1
apply(self._execute_wrapper, (function,) + p, kw)
elif 20000 <= errno <= 20999: # error codes we know we raise as schema errors
raise sql_base.SQLSchemaError(*ret), None, sys.exc_info()[2]
raise apply(sql_base.SQLError, ret), None, sys.exc_info()[2]
开发者ID:pombredanne,项目名称:spacewalk-2,代码行数:35,代码来源:driver_cx_Oracle.py
示例10: check_password
def check_password(username, password, service):
global __username, __password
auth = PAM.pam()
auth.start(service, username, __pam_conv)
# Save the username and passwords in the globals, the conversation
# function needs access to them
__username = username
__password = password
try:
try:
auth.authenticate()
auth.acct_mgmt()
finally:
# Something to be always executed - cleanup
__username = __password = None
except PAM.error:
e = sys.exc_info()[1]
resp, code = e.args[:2]
log_error("Password check failed (%s): %s" % (code, resp))
return 0
except:
raise_with_tb(rhnException('Internal PAM error'), sys.exc_info()[2])
else:
# Good password
return 1
开发者ID:dewayneHat,项目名称:spacewalk,代码行数:27,代码来源:rhnAuthPAM.py
示例11: _execute_wrapper
def _execute_wrapper(self, function, *p, **kw):
params = ','.join(["%s: %s" % (key, value) for key, value
in list(kw.items())])
log_debug(5, "Executing SQL: \"%s\" with bind params: {%s}"
% (self.sql, params))
if self.sql is None:
raise rhnException("Cannot execute empty cursor")
if self.blob_map:
for blob_var in list(self.blob_map.keys()):
kw[blob_var] = BufferType(kw[blob_var])
try:
retval = function(*p, **kw)
except psycopg2.InternalError:
e = sys.exc_info()[1]
error_code = 99999
m = re.match('ERROR: +-([0-9]+)', e.pgerror)
if m:
error_code = int(m.group(1))
raise sql_base.SQLSchemaError(error_code, e.pgerror, e)
except psycopg2.ProgrammingError:
e = sys.exc_info()[1]
raise sql_base.SQLStatementPrepareError(self.dbh, e.pgerror, self.sql)
except KeyError:
e = sys.exc_info()[1]
raise sql_base.SQLError("Unable to bound the following variable(s): %s"
% (string.join(e.args, " ")))
return retval
开发者ID:BlackSmith,项目名称:spacewalk,代码行数:28,代码来源:driver_postgresql.py
示例12: update_kickstart_session
def update_kickstart_session(server_id, action_id, action_status,
kickstart_state, next_action_type):
log_debug(3, server_id, action_id, action_status, kickstart_state, next_action_type)
# Is this a kickstart-related action?
ks_session_id = get_kickstart_session_id(server_id, action_id)
if ks_session_id is None:
# Nothing more to do
log_debug(4, "Kickstart session not found")
return None
# Check the current action state
if action_status == 2:
# Completed
ks_status = kickstart_state
# Get the next action - it has to be of the right type
next_action_id = get_next_action_id(action_id, next_action_type)
elif action_status == 3:
# Failed
ks_status = 'failed'
next_action_id = None
else:
raise rhnException("Invalid action state %s" % action_status)
update_ks_session_table(ks_session_id, ks_status, next_action_id,
server_id)
return ks_session_id
开发者ID:m47ik,项目名称:uyuni,代码行数:27,代码来源:server_kickstart.py
示例13: getSourcePackagePath
def getSourcePackagePath(self, _pkgFilename):
"""Returns the path to a package.
OVERLOAD this in server and proxy rhnRepository.
I.e.: they construct the path differently.
"""
# pylint: disable=R0201
raise rhnException("This function should be overloaded.")
开发者ID:hlawatschek,项目名称:spacewalk,代码行数:7,代码来源:rhnRepository.py
示例14: initDB
def initDB(backend=None, host=None, port=None, username=None,
password=None, database=None, sslmode=None, sslrootcert=None, initsecond=False):
"""
Initialize the database.
Either we get backend and all parameter which means the caller
knows what they are doing, or we populate everything from the
config files.
initsecond: If set to True it initialize a second DB connection.
By default only one DB connection is needed.
"""
if backend is None:
if CFG is None or not CFG.is_initialized():
initCFG('server')
backend = CFG.DB_BACKEND
host = CFG.DB_HOST
port = CFG.DB_PORT
database = CFG.DB_NAME
username = CFG.DB_USER
password = CFG.DB_PASSWORD
sslmode = None
sslrootcert = None
if CFG.DB_SSL_ENABLED:
sslmode = 'verify-full'
sslrootcert = CFG.DB_SSLROOTCERT
if backend not in SUPPORTED_BACKENDS:
raise rhnException("Unsupported database backend", backend)
if port:
port = int(port)
# Hide the password
add_to_seclist(password)
try:
if initsecond == False:
__init__DB(backend, host, port, username, password, database, sslmode, sslrootcert)
else:
__init__DB2(backend, host, port, username, password, database, sslmode, sslrootcert)
# except (rhnException, SQLError):
# raise # pass on, we know those ones
# except (KeyboardInterrupt, SystemExit):
# raise
except SQLConnectError:
e = sys.exc_info()[1]
try:
closeDB()
except NameError:
pass
raise e
except:
raise
#e_type, e_value = sys.exc_info()[:2]
# raise rhnException("Could not initialize Oracle database connection",
# str(e_type), str(e_value))
return 0
开发者ID:dewayneHat,项目名称:spacewalk,代码行数:58,代码来源:__init__.py
示例15: set_log_auth_login
def set_log_auth_login(login):
h = prepare("select id from web_contact_all where login = :login")
h.execute(login=login)
row = h.fetchone_dict()
if row:
user_id = row['id']
set_log_auth(user_id)
else:
raise rhnException("No such log user", login)
开发者ID:dewayneHat,项目名称:spacewalk,代码行数:9,代码来源:__init__.py
示例16: get_kickstart_session_info
def get_kickstart_session_info(kickstart_session_id, server_id):
h = rhnSQL.prepare(_query_get_kickstart_session_info)
h.execute(kickstart_session_id=kickstart_session_id)
row = h.fetchone_dict()
if not row:
raise rhnException("Could not fetch kickstart session id %s "
"for server %s" % (kickstart_session_id, server_id))
return row
开发者ID:m47ik,项目名称:uyuni,代码行数:9,代码来源:server_kickstart.py
示例17: configure
def configure(serverId, actionId, dry_run=0):
log_debug(3, dry_run)
h = rhnSQL.prepare(_query_lookup_interval)
h.execute(action_id=actionId)
row = h.fetchone_dict()
if not row:
raise rhnException("rhnsd reconfig action scheduled, but no entries "
"in rhnActionDaemonConfig found")
# Format: (interval, restart)
return (row['interval'], row['restart'])
开发者ID:Kilian-Petsch,项目名称:spacewalk,代码行数:10,代码来源:rhnsd.py
示例18: check_password
def check_password(username, password, service):
try:
auth = pam.pam()
if not auth.authenticate(username, password, service=service):
log_error("Password check failed (%s): %s" % (auth.code, auth.reason))
return 0
else:
return 1
except:
raise_with_tb(rhnException('Internal PAM error'), sys.exc_info()[2])
开发者ID:m47ik,项目名称:uyuni,代码行数:10,代码来源:rhnAuthPAM.py
示例19: insert
def insert(self, rows):
# insert a single row into the table
def insert_row(row, self=self):
if self.__cache is not None:
self.__cache[row[self.__hashid]] = row
return self.__setitem__(None, row)
if isinstance(rows, dict) or isinstance(rows, UserDictCase):
return insert_row(rows)
if isinstance(rows, list):
for x in rows:
insert_row(x)
return None
raise rhnException("Invalid data %s passed" % type(rows), rows)
开发者ID:cliffy94,项目名称:spacewalk,代码行数:13,代码来源:sql_table.py
示例20: reload
def reload(self, user_id):
""" Reload the current data from the SQL database using the given id """
log_debug(3, user_id)
# If we can not load these we have a fatal condition
if not self.contact.load(user_id):
raise rhnException("Could not find contact record for id", user_id)
if not self.customer.load(self.contact["org_id"]):
raise rhnException(
"Could not find org record", "user_id = %s" % user_id, "org_id = %s" % self.contact["org_id"]
)
# These other ones are non fatal because we can create dummy records
if not self.info.load(user_id):
self.__init_info()
if not self.perms.load(user_id):
self.__init_perms()
# The site info is trickier, we need to find it first
if not self.site.load_sql("web_user_id = :userid and type = 'M'", {"userid": user_id}):
self.__init_site()
# Fix the username
self.username = self.contact["login"]
return 0
开发者ID:shastah,项目名称:spacewalk,代码行数:22,代码来源:rhnUser.py
注:本文中的spacewalk.common.rhnException.rhnException函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论