本文整理汇总了Python中manifest.Manifest.get_all_entitlements方法的典型用法代码示例。如果您正苦于以下问题:Python Manifest.get_all_entitlements方法的具体用法?Python Manifest.get_all_entitlements怎么用?Python Manifest.get_all_entitlements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类manifest.Manifest
的用法示例。
在下文中一共展示了Manifest.get_all_entitlements方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Activation
# 需要导入模块: from manifest import Manifest [as 别名]
# 或者: from manifest.Manifest import get_all_entitlements [as 别名]
class Activation(object):
"""Class inserting channel families and SSL metadata into DB."""
def __init__(self, manifest_path):
rhnSQL.initDB()
self.manifest = Manifest(manifest_path)
self.sat5_cert = SatelliteCert()
self.sat5_cert.load(self.manifest.get_satellite_certificate())
verify_mappings()
# Channel families metadata
f = open(constants.CHANNEL_FAMILY_MAPPING_PATH, 'r')
try:
self.families = json.load(f)
finally:
if f is not None:
f.close()
self.families_to_import = []
@staticmethod
def _remove_certificates():
for description_prefix in (constants.CA_CERT_NAME,
constants.CLIENT_CERT_PREFIX,
constants.CLIENT_KEY_PREFIX):
satCerts.delete_rhnCryptoKey_null_org(description_prefix)
def _update_certificates(self):
"""Delete and insert certificates needed for syncing from CDN repositories."""
# Remove all previously used certs/keys
self._remove_certificates()
# Read RHSM cert
f = open(constants.CA_CERT_PATH, 'r')
try:
ca_cert = f.read()
finally:
if f is not None:
f.close()
# Insert RHSM cert and certs from manifest into DB
satCerts.store_rhnCryptoKey(
constants.CA_CERT_NAME, ca_cert, None)
for entitlement in self.manifest.get_all_entitlements():
creds = entitlement.get_credentials()
satCerts.store_rhnCryptoKey(
constants.CLIENT_CERT_PREFIX + creds.get_id(), creds.get_cert(), None)
satCerts.store_rhnCryptoKey(
constants.CLIENT_KEY_PREFIX + creds.get_id(), creds.get_key(), None)
def import_channel_families(self):
"""Insert channel family data into DB."""
# Debug
print("Channel families in cert: %d" % len(self.sat5_cert.channel_families)) # pylint: disable=E1101
batch = []
for cf in self.sat5_cert.channel_families: # pylint: disable=E1101
label = cf.name
try:
family = self.families[label]
family_object = ChannelFamily()
for k in family.keys():
family_object[k] = family[k]
family_object['label'] = label
batch.append(family_object)
self.families_to_import.append(label)
except KeyError:
print("ERROR: Channel family '%s' was not found in mapping" % label)
# Perform import
backend = SQLBackend()
importer = ChannelFamilyImport(batch, backend)
importer.run()
@staticmethod
def _remove_repositories():
"""This method removes repositories obtained from manifest"""
hdel_repos = rhnSQL.prepare("""
delete from rhnContentSource where
label like :prefix || '%%'
and org_id is null
""")
hdel_repos.execute(prefix=constants.MANIFEST_REPOSITORY_DB_PREFIX)
rhnSQL.commit()
def _update_repositories(self):
"""Setup SSL credential to access repositories
We do this in 2 steps:
1. Fetching provided repositories from manifest - URL contains variables to substitute
2. Assigning one certificate/key set to each repository"""
# First delete all repositories from previously used manifests
self._remove_repositories()
backend = SQLBackend()
#.........这里部分代码省略.........
示例2: Activation
# 需要导入模块: from manifest import Manifest [as 别名]
# 或者: from manifest.Manifest import get_all_entitlements [as 别名]
class Activation(object):
"""Class inserting channel families and SSL metadata into DB."""
def __init__(self, manifest_path, cert_path):
rhnSQL.initDB()
self.manifest = Manifest(manifest_path)
# Satellite 5 certificate
with open(cert_path, 'r') as f:
self.sat5_cert = SatelliteCert()
content = f.read()
self.sat5_cert.load(content)
# Channel families metadata
with open(constants.CHANNEL_FAMILY_MAPPING_PATH, 'r') as f:
self.families = json.load(f)
with open(constants.PRODUCT_FAMILY_MAPPING_PATH, 'r') as f:
self.products = json.load(f)
self.families_to_import = []
def _update_certificates(self):
"""Delete and insert certificates needed for syncing from CDN repositories."""
# Read RHSM cert
with open(constants.CA_CERT_PATH, 'r') as f:
ca_cert = f.read()
# Insert RHSM cert and certs from manifest into DB
satCerts.store_rhnCryptoKey(
constants.CA_CERT_NAME, ca_cert, None)
for entitlement in self.manifest.get_all_entitlements():
creds = entitlement.get_credentials()
satCerts.store_rhnCryptoKey(
constants.CLIENT_CERT_PREFIX + creds.get_id(), creds.get_cert(), None)
satCerts.store_rhnCryptoKey(
constants.CLIENT_KEY_PREFIX + creds.get_id(), creds.get_key(), None)
def _update_channel_families(self):
"""Insert channel family data into DB"""
families_in_mapping = []
for entitlement in self.manifest.get_all_entitlements():
for product_id in entitlement.get_product_ids():
try:
product = self.products[product_id]
families_in_mapping.extend(product['families'])
# Some product cannot be mapped into channel families
except KeyError:
print("Cannot map product '%s' into channel families" % product_id)
families_in_mapping = set(families_in_mapping)
# Debug
print("Channel families mapped from products: %d" % len(self.families_to_import))
print("Channel families in cert: %d" % len(self.sat5_cert.channel_families)) # pylint: disable=E1101
batch = []
for cf in self.sat5_cert.channel_families: # pylint: disable=E1101
label = cf.name
if label not in families_in_mapping:
print("Skipping channel family from certificate, not in the mapping: %s" % label)
continue
try:
family = self.families[label]
family_object = ChannelFamily()
for k in family.keys():
family_object[k] = family[k]
family_object['label'] = label
batch.append(family_object)
self.families_to_import.append(label)
except KeyError:
print("ERROR: Channel family '%s' was not found in mapping" % label)
# Perform import
backend = SQLBackend()
importer = ChannelFamilyImport(batch, backend)
importer.run()
def _update_families_ssl(self):
"""Link channel families with certificates inserted in _update_certificates method"""
family_ids = {}
for family in self.families_to_import:
family_ids[family] = None
# Populate with IDs
backend = SQLBackend()
backend.lookupChannelFamilies(family_ids)
# Lookup CA cert
ca_cert = satCerts.lookup_cert(constants.CA_CERT_NAME, None)
ca_cert_id = int(ca_cert['id'])
# Queries for updating relation between channel families and certificates
hdel = rhnSQL.prepare("""
delete from rhnContentSsl where
channel_family_id = :cfid
""")
#.........这里部分代码省略.........