本文整理汇总了Python中spacewalk.server.rhnSQL.commit函数的典型用法代码示例。如果您正苦于以下问题:Python commit函数的具体用法?Python commit怎么用?Python commit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了commit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: store_rhnCryptoKey
def store_rhnCryptoKey(description, cert, org_id, verbosity=0):
""" stores cert in rhnCryptoKey
uses:
_checkCertMatch_rhnCryptoKey
_delete_rhnCryptoKey - not currently used
_insertPrep_rhnCryptoKey
_lobUpdate_rhnCryptoKey
"""
try:
# look for a cert match in the database
rhn_cryptokey_id = _checkCertMatch_rhnCryptoKey(cert, description,
org_id, deleteRowYN=1,
verbosity=verbosity)
if rhn_cryptokey_id is None:
# nothing to do - cert matches
return
# insert into the database
if rhn_cryptokey_id == -1:
rhn_cryptokey_id = _insertPrep_rhnCryptoKey(rhn_cryptokey_id,
description, org_id)
# write/update
_lobUpdate_rhnCryptoKey(rhn_cryptokey_id, cert)
rhnSQL.commit()
except rhnSQL.sql_base.SQLError:
raise_with_tb(CaCertInsertionError(
"...the traceback: %s" % fetchTraceback()), sys.exc_info()[2])
示例2: _delete_rpm_group
def _delete_rpm_group(packageIds):
references = [
'rhnChannelPackage',
'rhnErrataPackage',
'rhnErrataPackageTMP',
'rhnPackageChangelogRec',
'rhnPackageConflicts',
'rhnPackageFile',
'rhnPackageObsoletes',
'rhnPackageProvides',
'rhnPackageRequires',
'rhnPackageRecommends',
'rhnPackageSuggests',
'rhnPackageSupplements',
'rhnPackageEnhances',
'rhnPackageBreaks',
'rhnPackagePredepends',
'rhnServerNeededCache',
]
deleteStatement = "delete from %s where package_id = :package_id"
for table in references:
h = rhnSQL.prepare(deleteStatement % table)
count = h.executemany(package_id=packageIds)
log_debug(3, "Deleted from %s: %d rows" % (table, count))
deleteStatement = "delete from rhnPackage where id = :package_id"
h = rhnSQL.prepare(deleteStatement)
count = h.executemany(package_id=packageIds)
if count:
log_debug(2, "DELETED package id %s" % str(packageIds))
else:
log_error("No such package id %s" % str(packageIds))
rhnSQL.commit()
示例3: _register_dispatcher
def _register_dispatcher(self, jabber_id, hostname, port):
h = rhnSQL.prepare(self._query_update_register_dispatcher)
rowcount = h.execute(jabber_id_in=jabber_id, hostname_in=hostname, port_in=port, password_in=self._password)
if not rowcount:
h = rhnSQL.prepare(self._query_insert_register_dispatcher)
h.execute(jabber_id_in=jabber_id, hostname_in=hostname, port_in=port, password_in=self._password)
rhnSQL.commit()
示例4: save_packages
def save_packages(self, schedule=1):
""" wrapper for the Packages.save_packages_byid() which requires the sysid """
ret = self.save_packages_byid(self.server["id"], schedule=schedule)
# this function is primarily called from outside
# so we have to commit here
rhnSQL.commit()
return ret
示例5: client_set_namespaces
def client_set_namespaces(self, systemid, namespaces):
self.auth_system(systemid)
server_id = self.server.getid()
org_id = self.server.server['org_id']
h = rhnSQL.prepare("""
delete from rhnServerConfigChannel where server_id = :server_id
""")
h.execute(server_id=server_id)
h = rhnSQL.prepare("""
insert into rhnServerConfigChannel (server_id, config_channel_id, position)
select :server_id, id, :position
from rhnConfigChannel
where name = :config_channel
and org_id = :org_id
""")
position = 0
for config_channel in namespaces:
rowcount = h.execute(server_id=server_id, position=position,
config_channel=config_channel, org_id=org_id)
if not rowcount:
raise rhnFault(4009, "Unable to find config channel %s" %
config_channel, explain=0)
position = position + 1
rhnSQL.commit()
return 0
示例6: _update_package_data
def _update_package_data(self, crash_id, pkg_data):
log_debug(1, "_update_package_data: %s, %s" % (crash_id, pkg_data))
# Older versions of abrt used to store the package info in a single 'package' file
if pkg_data and 'package' in pkg_data:
(n, e, v, r) = parseRPMName(pkg_data['package'])
if not all((n, e, v, r)):
return 0
h = rhnSQL.prepare(_query_update_pkg_data1)
r = h.execute(
crash_id=crash_id,
pkg_name=n,
pkg_epoch=e,
pkg_version=v,
pkg_release=r)
rhnSQL.commit()
return r
for item in ['pkg_name', 'pkg_epoch', 'pkg_version', 'pkg_release', 'pkg_arch']:
if not (item in pkg_data and pkg_data[item]):
return 0
h = rhnSQL.prepare(_query_update_pkg_data2)
r = h.execute(
crash_id=crash_id,
pkg_name=pkg_data['pkg_name'],
pkg_epoch=pkg_data['pkg_epoch'],
pkg_version=pkg_data['pkg_version'],
pkg_release=pkg_data['pkg_release'],
pkg_arch=pkg_data['pkg_arch'])
rhnSQL.commit()
return r
示例7: update_client_message_received
def update_client_message_received(self, jid):
jid = str(jid)
state_id = self._get_push_state_id('online')
h = rhnSQL.prepare(self._query_update_client_message_received)
ret = h.execute(jid=jid, state_id=state_id)
if ret:
rhnSQL.commit()
示例8: test_new_server_1
def test_new_server_1(self):
"Test normal server registration, with username/password"
u, password = self._create_new_user()
username = u.contact['login']
org_id = u.contact['org_id']
entitlements = self._entitlements
os_release = "2.1as"
t = misc_functions.create_activation_key(
org_id=u.contact['org_id'],
entitlement_level=entitlements,
user_id=u.getid(),
release=os_release
)
params = build_new_system_params_with_username(username=username,
password=password, os_release=os_release)
system_id = register_new_system(params)
rhnSQL.commit()
s = rhnServer.get(system_id)
self.assertNotEqual(s, None)
server_id = s.getid()
channels = rhnChannel.channels_for_server(server_id)
self.assertEqual(len(channels), 1)
self.assertEqual(channels[0]['label'], self._channel)
示例9: test_new_server_token_1
def test_new_server_token_1(self):
"test registration with token"
u, _ = self._create_new_user()
org_id = u.contact['org_id']
entitlements = self._entitlements
os_release = "2.1as"
t = misc_functions.create_activation_key(
org_id=u.contact['org_id'],
entitlement_level=entitlements,
user_id=u.getid(),
release=os_release
)
token = t.get_token()
params = build_new_system_params_with_token(
token=token,
os_release=os_release
)
system_id = register_new_system(params)
rhnSQL.commit()
s = rhnServer.get(system_id)
self.assertNotEqual(s, None)
示例10: test_execute_rowcount
def test_execute_rowcount(self):
"""Tests row counts"""
table_name = "misatest"
try:
tables = self._list_tables()
if not table_name in tables:
rhnSQL.execute("create table %s (id int, value int)" % table_name)
else:
rhnSQL.execute("delete from %s" % table_name)
insert_statement = rhnSQL.Statement(
"insert into %s values (:item_id, :value)" % table_name
)
h = rhnSQL.prepare(insert_statement)
ret = h.execute(item_id=1, value=2)
self.assertEqual(ret, 1)
ret = h.execute(item_id=2, value=2)
self.assertEqual(ret, 1)
delete_statement = rhnSQL.Statement("delete from %s" % table_name)
h = rhnSQL.prepare(delete_statement)
ret = h.execute()
self.assertEqual(ret, 2)
rhnSQL.commit()
finally:
rhnSQL.execute("drop table %s" % table_name)
示例11: test_new_server_token_2
def test_new_server_token_2(self):
"Test registration with token that specifies a base channel"
# FIXME: the test fails because there's no channel associated with the
# freshly created Server: rhnServerChannel is not populated by the
# registration code.
u, _ = self._create_new_user()
org_id = u.contact['org_id']
base_channel = 'rhel-i386-as-3'
entitlements = self._entitlements
os_release = "2.1as"
t = misc_functions.create_activation_key(org_id=u.contact['org_id'],
entitlement_level=entitlements, user_id=u.getid(),
channels=[base_channel], release=os_release)
token = t.get_token()
params = build_new_system_params_with_token(
token=token,
os_release=os_release
)
system_id = register_new_system(params)
rhnSQL.commit()
s = rhnServer.get(system_id)
self.assertNotEqual(s, None)
server_id = s.getid()
channels = rhnChannel.channels_for_server(server_id)
self.assertEqual(len(channels), 1)
self.assertEqual(channels[0]['label'], base_channel)
示例12: store_rhnCryptoKey
def store_rhnCryptoKey(description, caCert, verbosity=0):
""" stores CA cert in rhnCryptoKey
uses:
_checkCertMatch_rhnCryptoKey
_delete_rhnCryptoKey - not currently used
_insertPrep_rhnCryptoKey
_lobUpdate_rhnCryptoKey
"""
org_ids = get_all_orgs()
for org_id in org_ids:
org_id = org_id['id']
try:
## look for a cert match in the database
rhn_cryptokey_id = _checkCertMatch_rhnCryptoKey(caCert, description,
org_id, deleteRowYN=1,
verbosity=verbosity)
if rhn_cryptokey_id is None:
# nothing to do - cert matches
continue
## insert into the database
if rhn_cryptokey_id == -1:
rhn_cryptokey_id = _insertPrep_rhnCryptoKey(rhn_cryptokey_id,
description, org_id)
## write/update
_lobUpdate_rhnCryptoKey(rhn_cryptokey_id, caCert)
rhnSQL.commit()
except rhnSQL.sql_base.SQLError:
raise CaCertInsertionError(
"...the traceback: %s" % fetchTraceback()), None, sys.exc_info()[2]
示例13: delete_guests
def delete_guests(server_id):
"""
Callback used after a successful kickstart to remove any guest virtual
instances, as well as their associated servers.
"""
# First delete all the guest server objects:
h = rhnSQL.prepare(_query_lookup_guests_for_host)
h.execute(server_id=server_id)
delete_server = rhnSQL.Procedure("delete_server")
log_debug(4, "Deleting guests")
while 1:
row = h.fetchone_dict()
if not row:
break
guest_id = row['virtual_system_id']
log_debug(4, 'Deleting guest server: %s' % guest_id)
try:
if guest_id is not None:
delete_server(guest_id)
except rhnSQL.SQLError:
log_error("Error deleting server: %s" % guest_id)
# Finally delete all the virtual instances:
log_debug(4, "Deleting all virtual instances for host")
h = rhnSQL.prepare(_query_delete_virtual_instances)
h.execute(server_id=server_id)
# Commit all changes:
try:
rhnSQL.commit()
except rhnSQL.SQLError:
e = sys.exc_info()[1]
log_error("Error committing transaction: %s" % e)
rhnSQL.rollback()
示例14: install_missing_product_packages
def install_missing_product_packages(self):
'''
Find missing products and schedule an action to install them
'''
h = rhnSQL.prepare(self._query_product_packages)
package_names = {}
h.execute(server_id=self.server['id'])
while True:
row = h.fetchone_dict()
if not row:
break
pn_id = row['name_id']
pa_id = row['arch_id']
package_names[(pn_id, pa_id)] = row['name']
if not package_names:
return None
package_arch_ids = package_names.keys()
action_id = rhnAction.schedule_server_packages_update_by_arch(self.server['id'],
package_arch_ids,
org_id=self.server['org_id'],
action_name="Product Package Auto-Install")
for p in package_names.values():
log_debug(1, "Scheduled for install: '%s'" % p)
rhnSQL.commit()
return action_id
示例15: find_or_create_channel_arch
def find_or_create_channel_arch(name, label):
lookup = """
SELECT id from rhnChannelArch
WHERE label='%s' AND name = '%s'
""" % (label, name)
h = rhnSQL.prepare(lookup)
h.execute()
row = h.fetchone_dict()
if row:
return row['id']
query_create = """
INSERT INTO rhnChannelArch
(id, arch_type_id, label, name)
VALUES (sequence_nextval('rhn_channel_arch_id_seq'), :arch_type_id, :label, :name)
"""
arch_type_id = find_or_create_arch_type(name = name, label = label)
h = rhnSQL.prepare(query_create)
try:
h.execute(
arch_type_id = arch_type_id,
label = label,
name = name
)
rhnSQL.commit()
except rhnSQL.SQLError, e:
# if we're here that means we're voilating something
raise