예제 #1
0
    def print_cdn_certificates_info(self, repos=False):
        keys = self._get_cdn_certificate_keys_and_certs()
        if not keys:
            log2(
                0,
                0,
                "No SSL certificates were found. Is your %s activated for CDN?"
                % PRODUCT_NAME,
                stream=sys.stderr)
            sys.exit(1)

        for key in keys:
            log(0, "======================================")
            log(0, "| Certificate/Key: %s" % key['description'])
            log(0, "======================================")
            if constants.CA_CERT_NAME == key[
                    'description'] or constants.CLIENT_CERT_PREFIX in key[
                        'description']:
                if not verify_certificate_dates(str(key['key'])):
                    log(0, "WARNING: This certificate is not valid.")
                cn, serial_number, not_before, not_after = get_certificate_info(
                    str(key['key']))
                log(0, "Common name:   %s" % str(cn))
                log(0, "Serial number: %s" % str(serial_number))
                log(0, "Valid from:    %s" % str(not_before))
                log(0, "Valid to:      %s" % str(not_after))
            if constants.CLIENT_CERT_PREFIX in key['description']:
                manager = CdnRepositoryManager(client_cert_id=int(key['id']))
                self.cdn_repository_manager = manager
                log(0, "Provided channels:")
                channel_tree, not_available_channels = self._tree_available_channels(
                )
                if not channel_tree:
                    log(0, "    NONE")
                for base_channel in sorted(channel_tree):
                    if base_channel not in not_available_channels:
                        log(0, "    * %s" % base_channel)
                    elif channel_tree[base_channel]:
                        log(
                            0, "    * %s (only child channels provided)" %
                            base_channel)
                    for child_channel in sorted(channel_tree[base_channel]):
                        log(0, "        * %s" % child_channel)
                if repos:
                    log(0, "Provided repositories:")
                    provided_repos = self.cdn_repository_manager.list_provided_repos(
                        key['id'])
                    for repo in sorted(provided_repos):
                        log(0, "    %s" % repo)
            log(0, "")
예제 #2
0
    def print_cdn_certificates_info(self, repos=False):
        h = rhnSQL.prepare("""
            SELECT ck.id, ck.description, ck.key
            FROM rhnCryptoKeyType ckt,
                 rhnCryptoKey ck
            WHERE ckt.label = 'SSL'
              AND ckt.id = ck.crypto_key_type_id
              AND ck.description LIKE 'CDN_%'
              AND ck.org_id is NULL
            ORDER BY ck.description
        """)
        h.execute()
        keys = h.fetchall_dict() or []
        if not keys:
            log2(
                0,
                0,
                "No SSL certificates were found. Is your %s activated for CDN?"
                % PRODUCT_NAME,
                stream=sys.stderr)
            return

        for key in keys:
            log(0, "======================================")
            log(0, "| Certificate/Key: %s" % key['description'])
            log(0, "======================================")
            if constants.CA_CERT_NAME == key[
                    'description'] or constants.CLIENT_CERT_PREFIX in key[
                        'description']:
                if not verify_certificate_dates(str(key['key'])):
                    log(0, "WARNING: This certificate is not valid.")
                cn, serial_number, not_before, not_after = get_certificate_info(
                    str(key['key']))
                log(0, "Common name:   %s" % str(cn))
                log(0, "Serial number: %s" % str(serial_number))
                log(0, "Valid from:    %s" % str(not_before))
                log(0, "Valid to:      %s" % str(not_after))
            if constants.CLIENT_CERT_PREFIX in key['description']:
                manager = CdnRepositoryManager(client_cert_id=int(key['id']))
                self.cdn_repository_manager = manager
                log(0, "Provided channels:")
                channel_tree, not_available_channels = self._tree_available_channels(
                )
                if not channel_tree:
                    log(0, "    NONE")
                for base_channel in sorted(channel_tree):
                    if base_channel not in not_available_channels:
                        log(0, "    * %s" % base_channel)
                    elif channel_tree[base_channel]:
                        log(
                            0, "    * %s (only child channels provided)" %
                            base_channel)
                    for child_channel in sorted(channel_tree[base_channel]):
                        log(0, "        * %s" % child_channel)
                if repos:
                    log(0, "Provided repositories:")
                    provided_repos = self.cdn_repository_manager.list_provided_repos(
                        key['id'])
                    for repo in sorted(provided_repos):
                        log(0, "    %s" % repo)
            log(0, "")
예제 #3
0
    def __init__(self,
                 no_packages=False,
                 no_errata=False,
                 no_rpms=False,
                 no_kickstarts=False,
                 log_level=None,
                 mount_point=None,
                 consider_full=False,
                 force_kickstarts=False,
                 force_all_errata=False,
                 email=False,
                 import_batch_size=None):

        if log_level is None:
            log_level = 0
        self.log_level = log_level
        CFG.set('DEBUG', log_level)
        self.email = email
        if self.email:
            initEMAIL_LOG()
        rhnLog.initLOG(self.log_path, self.log_level)
        log2disk(0, "Command: %s" % str(sys.argv))

        rhnSQL.initDB()
        initCFG('server.satellite')

        self.cdn_repository_manager = CdnRepositoryManager(mount_point)
        self.no_packages = no_packages
        self.no_errata = no_errata
        self.no_rpms = no_rpms
        if self.no_packages and self.no_rpms:
            log(0, "Parameter --no-rpms has no effect.")
        self.no_kickstarts = no_kickstarts
        self.force_all_errata = force_all_errata
        self.force_kickstarts = force_kickstarts
        if self.no_kickstarts and self.force_kickstarts:
            log(0, "Parameter --force-kickstarts has no effect.")

        if mount_point:
            self.mount_point = "file://" + mount_point
            self.consider_full = consider_full
        else:
            self.mount_point = CFG.CDN_ROOT
            self.consider_full = True

        verify_mappings()

        f = None
        # try block in try block - this is hack for python 2.4 compatibility
        # to support finally
        try:
            try:
                # Channel families mapping to channels
                f = open(constants.CHANNEL_FAMILY_MAPPING_PATH, 'r')
                self.families = json.load(f)
                f.close()

                # Channel metadata
                f = open(constants.CHANNEL_DEFINITIONS_PATH, 'r')
                self.channel_metadata = json.load(f)
                f.close()

                # Dist/Release channel mapping
                f = open(constants.CHANNEL_DIST_MAPPING_PATH, 'r')
                self.channel_dist_mapping = json.load(f)
                f.close()

                # Kickstart metadata
                f = open(constants.KICKSTART_DEFINITIONS_PATH, 'r')
                self.kickstart_metadata = json.load(f)
                f.close()
            except IOError:
                e = sys.exc_info()[1]
                log(1, "Ignoring channel mappings: %s" % e)
                self.families = {}
                self.channel_metadata = {}
                self.channel_dist_mapping = {}
                self.kickstart_metadata = {}
        finally:
            if f is not None:
                f.close()

        # Map channels to their channel family
        self.channel_to_family = {}
        for family in self.families:
            for channel in self.families[family]['channels']:
                self.channel_to_family[channel] = family

        # Set already synced channels, entitled null-org channels and custom channels with associated
        # CDN repositories
        h = rhnSQL.prepare("""
            select distinct c.label, c.org_id
            from rhnChannelFamilyPermissions cfp inner join
                 rhnChannelFamily cf on cfp.channel_family_id = cf.id inner join
                 rhnChannelFamilyMembers cfm on cf.id = cfm.channel_family_id inner join
                 rhnChannel c on cfm.channel_id = c.id
            where c.org_id is null
              or (c.org_id is not null and 
                  exists (
                          select cs.id
                          from rhnContentSource cs inner join
                               rhnChannelContentSource ccs on ccs.source_id = cs.id
                          where ccs.channel_id = c.id
                            and cs.org_id is null
                         )
                 )
            order by c.org_id nulls first, label
        """)
        h.execute()
        channels = h.fetchall_dict() or []
        self.synced_channels = {}
        for channel in channels:
            # Custom channel repositories not available, don't mark as synced
            if channel['org_id']:
                repos = self.cdn_repository_manager.list_associated_repos(
                    channel['label'])
                if not all([
                        self.cdn_repository_manager.
                        check_repository_availability(r) for r in repos
                ]):
                    continue
            self.synced_channels[channel['label']] = channel['org_id']

        # Select available channel families from DB
        h = rhnSQL.prepare("""
            select distinct label
            from rhnChannelFamilyPermissions cfp inner join
                 rhnChannelFamily cf on cfp.channel_family_id = cf.id
            where cf.org_id is null
        """)
        h.execute()
        families = h.fetchall_dict() or []
        self.entitled_families = [f['label'] for f in families]
        self.import_batch_size = import_batch_size
예제 #4
0
    def __init__(self, no_packages=False, no_errata=False, no_rpms=False, no_kickstarts=False,
                 log_level=None, mount_point=None, consider_full=False):

        self.cdn_repository_manager = CdnRepositoryManager(mount_point)
        self.no_packages = no_packages
        self.no_errata = no_errata
        self.no_rpms = no_rpms
        self.no_kickstarts = no_kickstarts
        if log_level is None:
            log_level = 0
        self.log_level = log_level

        if mount_point:
            self.mount_point = "file://" + mount_point
            self.consider_full = consider_full
        else:
            self.mount_point = CFG.CDN_ROOT
            self.consider_full = True

        CFG.set('DEBUG', log_level)
        rhnLog.initLOG(self.log_path, self.log_level)
        log2disk(0, "Command: %s" % str(sys.argv))

        rhnSQL.initDB()
        initCFG('server.satellite')

        verify_mappings()

        f = None
        # try block in try block - this is hack for python 2.4 compatibility
        # to support finally
        try:
            try:
                # Channel families mapping to channels
                f = open(constants.CHANNEL_FAMILY_MAPPING_PATH, 'r')
                self.families = json.load(f)
                f.close()

                # Channel metadata
                f = open(constants.CHANNEL_DEFINITIONS_PATH, 'r')
                self.channel_metadata = json.load(f)
                f.close()

                # Dist/Release channel mapping
                f = open(constants.CHANNEL_DIST_MAPPING_PATH, 'r')
                self.channel_dist_mapping = json.load(f)
                f.close()

                # Kickstart metadata
                f = open(constants.KICKSTART_DEFINITIONS_PATH, 'r')
                self.kickstart_metadata = json.load(f)
                f.close()
            except IOError:
                e = sys.exc_info()[1]
                raise CdnMappingsLoadError("Problem with loading file: %s" % e)
        finally:
            if f is not None:
                f.close()

        # Map channels to their channel family
        self.channel_to_family = {}
        for family in self.families:
            for channel in self.families[family]['channels']:
                self.channel_to_family[channel] = family

        # Set already synced channels
        h = rhnSQL.prepare("""
            select label from rhnChannel where org_id is null
        """)
        h.execute()
        channels = h.fetchall_dict() or []
        self.synced_channels = [ch['label'] for ch in channels]