Example #1
0
def link_channel_packages(batch, strict=1):
    importer = packageImport.ChannelPackageSubscription(batch,
        diskImportLib.get_backend(),
        caller="satsync.linkPackagesToChannels", strict=strict)
    importer.run()
    importer.status()
    return importer
Example #2
0
def import_packages(batch, sources=0):
    importer = packageImport.PackageImport(batch, diskImportLib.get_backend(),
                                           sources)
    importer.setUploadForce(4)
    importer.run()
    importer.status()
    return importer
Example #3
0
def import_channels(channels, orgid=None, master=None):
    collection = ChannelCollection()
    batch = []
    import satCerts
    orgs = map(lambda a: a['id'], satCerts.get_all_orgs())
    org_map = None
    my_backend = diskImportLib.get_backend()
    if master:
        org_map = my_backend.lookupOrgMap(master)['master-id-to-local-id']
    for c in channels:
        try:
            timestamp = collection.get_channel_timestamp(c)
        except KeyError:
            raise Exception, "Could not find channel %s" % c, sys.exc_info()[2]
        c_obj = collection.get_channel(c, timestamp)
        if c_obj is None:
            raise Exception, "Channel not found in cache: %s" % c

        # Check to see if we're asked to sync to an orgid,
        # make sure the org from the export is not null org,
        # finally if the orgs differ so we might wanna use
        # requested org's channel-family.
        # TODO: Move these checks somewhere more appropriate
        if not orgid and c_obj['org_id'] is not None:
            #If the src org is not present default to org 1
            orgid = DEFAULT_ORG
        if orgid is not None and c_obj['org_id'] is not None and \
            c_obj['org_id'] != orgid:
            #If we know the master this is coming from and the master org
            #has been mapped to a local org, transform org_id to the local
            #org_id. Otherwise just put it in the default org.
            if (org_map and c_obj['org_id'] in org_map.keys()
                    and org_map[c_obj['org_id']]):
                c_obj['org_id'] = org_map[c_obj['org_id']]
            else:
                c_obj['org_id'] = orgid
                if c_obj.has_key('trust_list'):
                    del(c_obj['trust_list'])
            for family in c_obj['families']:
                family['label'] = 'private-channel-family-' + \
                                           str(c_obj['org_id'])
        # If there's a trust list on the channel, transform the org ids to
        # the local ones
        if c_obj.has_key('trust_list') and c_obj['trust_list']:
            trusts = []
            for trust in c_obj['trust_list']:
                if org_map.has_key(trust['org_trust_id']):
                    trust['org_trust_id'] = org_map[trust['org_trust_id']]
                    trusts.append(trust)
            c_obj['trust_list'] = trusts

        syncLib.log(6, "Syncing Channel %s to Org %s " % \
                       (c_obj['label'], c_obj['org_id']))
        batch.append(c_obj)

    importer = channelImport.ChannelImport(batch, my_backend)
    # Don't commit just yet
    importer.will_commit = 0
    importer.run()
    return importer
Example #4
0
    def endContainerCallback(self):
        batch = self.batch
        # use the copy only; don't want a persistent self.batch
        self.batch = []

        importer = channelImport.ChannelFamilyImport(batch, diskImportLib.get_backend())
        importer.run()
Example #5
0
    def endContainerCallback(self):
        batch = self.batch
        # use the copy only; don't want a persistent self.batch
        self.batch = []

        importer = channelImport.ChannelFamilyImport(
            batch, diskImportLib.get_backend())
        importer.run()
Example #6
0
def import_channels(channels, orgid=None):
    collection = ChannelCollection()
    batch = []
    import satCerts
    orgs = map(lambda a: a['id'], satCerts.get_all_orgs())
    for c in channels:
        try:
            timestamp = collection.get_channel_timestamp(c)
        except KeyError:
            raise Exception, "Could not find channel %s" % c
        c_obj = collection.get_channel(c, timestamp)
        if c_obj is None:
            raise Exception, "Channel not found in cache: %s" % c

        # Check to see if we're asked to sync to an orgid,
        # make sure the org from the export is not null org,
        # finally if the orgs differ so we might wanna use
        # requested org's channel-family.
        # TODO: Move these checks somewhere more appropriate
        if not orgid and c_obj['org_id'] is not None:
            #If the src org is not present default to org 1
            orgid = DEFAULT_ORG
        if orgid is not None and c_obj['org_id'] is not None and \
            c_obj['org_id'] != orgid:
            #Only set the channel family if its a custom channel
            c_obj['org_id'] = orgid
            for family in c_obj['families']:
                family['label'] = 'private-channel-family-' + \
                                           str(c_obj['org_id'])

        syncLib.log(6, "Syncing Channel %s to Org %s " % \
                       (c_obj['label'], c_obj['org_id']))
        batch.append(c_obj)

    importer = channelImport.ChannelImport(batch, diskImportLib.get_backend())
    # Don't commit just yet
    importer.will_commit = 0
    importer.run()
    return importer
Example #7
0
def populate_channel_family_permissions(cert):
    # Find channel families that we have imported
    current_cfs = _fetch_existing_channel_families()

    # Put the channel families coming from the cert into a hash
    # Add rh-public with unlimited subscriptions
    # Filter channel families that do not exist locally (this is possible with
    # channel dumps, where not all channel families have been dumped and
    # available for the satellite to import)

    # XXX hardcoding rh-public bad bad bad - but we committed to have
    # rh-public the only implied channel family. If we ever have to have a
    # different public channel family, it will have to be in the cert
    cert_chfam_hash = {}

    # Bugs 171160, 183365: We can't assume that the satellite already knows
    # about rh-public (it may not yet know about any channels).
    if current_cfs.has_key("rh-public"):
        cert_chfam_hash["rh-public"] = None

    for cf in cert.channel_families:
        if not current_cfs.has_key(cf.name):
            # Ignoring unavailable channel family at this point,
            # we'll create it at sync time.
            continue

        quant = cf.quantity
        if quant is not None:
            quant = int(quant)
        flex = cf.flex
        if flex == '':
            flex = 0
        if flex is not None:
            flex = int(flex)

        #we subtract flex from quantity since flex count is included
        #   in the full quantity for backwards compatibility
        cert_chfam_hash[cf.name] = [quant - flex, flex]

    # Generate the channel family permissions data structure
    cfps = {}
    for cfp in _fetch_channel_family_permissions():
        cf_name = cfp['channel_family']

        # org_id is the org_id which is given permission
        org_id = cfp['org_id']

        # Initially populate cf info with old limits from db
        cfps[(cf_name, org_id)] = [cfp['max_members'], cfp['max_flex']]

    # Now set max_members based on the cert's max_members
    for cf_name, max_tuple in cert_chfam_hash.items():
        # Make the channel families with null max_members public
        if max_tuple is None:
            max_tuple = [0, 0]
            org_id = None
        else:
            max_members, max_flex = max_tuple
            # default the org to 1 for channel families from cert
            org_id = 1

        cf_name = to_string(cf_name)
        try:
            _old_max_tuple = cfps[(cf_name, org_id)]
        except KeyError:
            # New channel family, populate the db from cert
            cfps[(cf_name, org_id)] = max_tuple
            _old_max_tuple = None

    sum_max_values = compute_sum_max_members(cfps)
    for (cf_name, org_id), (max_members, max_flex) in cfps.items():
        if org_id == 1:
            if cert_chfam_hash.has_key(cf_name):
                cert_max_value = cert_chfam_hash[cf_name][0] or 0
                cert_max_flex = cert_chfam_hash[cf_name][1] or 0
            else:
                # remove entitlements on extra slots
                cfps[(cf_name, org_id)] = None
                continue
            if not max_members:
                max_members = 0
            if not max_flex:
                max_flex = 0

            (sum_max_mem, sum_max_flex) = sum_max_values[cf_name]
            if cert_max_value >= sum_max_mem:
                cfps[(cf_name, 1)][0] = max_members + \
                                  (cert_max_value - sum_max_mem)
            else:
                purge_count = sum_max_mem - cert_max_value
                cfps[(cf_name, 1)][0] = max_members - purge_count

            if cert_max_flex >= sum_max_flex:
                cfps[(cf_name, 1)][1] = max_flex +\
                                  (cert_max_flex - sum_max_flex)
            else:
                # lowering entitlements
                flex_purge_count = sum_max_flex - cert_max_flex
                cfps[(cf_name, 1)][1] = max_flex - flex_purge_count

    # Cleanup left out suborgs
    for (cf_name, org_id), max_list in cfps.items():
        if cfps.has_key(
            (cf_name, 1)) and cfps[(cf_name, 1)] == None:  #is None:
            cfps[(cf_name, org_id)] = None

    batch = []
    for (cf_name, org_id), max_list in cfps.items():
        if max_list is None:
            max_members = None
            max_flex = None
        else:
            (max_members, max_flex) = max_list
        cfperm = importLib.ChannelFamilyPermissions()
        batch.append(
            cfperm.populate({
                'channel_family': cf_name,
                'org_id': org_id,
                'max_members': max_members,
                'max_flex': max_flex,
            }))

    importer = channelImport.ChannelFamilyPermissionsImport(
        batch, diskImportLib.get_backend())
    importer.will_commit = 0
    importer.run()
Example #8
0
def import_kickstarts(batch):
    importer = kickstartImport.KickstartableTreeImport(
        batch, diskImportLib.get_backend())
    importer.run()
    importer.status()
    return importer
Example #9
0
def import_errata(batch):
    importer = errataImport.ErrataImport(batch, diskImportLib.get_backend())
    importer.ignoreMissing = 1
    importer.run()
    importer.status()
    return importer
Example #10
0
def populate_channel_family_permissions(cert):
    # Find channel families that we have imported
    current_cfs = _fetch_existing_channel_families()

    # Put the channel families coming from the cert into a hash
    # Add rh-public with unlimited subscriptions
    # Filter channel families that do not exist locally (this is possible with
    # channel dumps, where not all channel families have been dumped and
    # available for the satellite to import)

    # XXX hardcoding rh-public bad bad bad - but we committed to have
    # rh-public the only implied channel family. If we ever have to have a
    # different public channel family, it will have to be in the cert
    cert_chfam_hash = {}

    # Bugs 171160, 183365: We can't assume that the satellite already knows
    # about rh-public (it may not yet know about any channels).
    if current_cfs.has_key("rh-public"):
        cert_chfam_hash["rh-public"] = None

    for cf in cert.channel_families:
        if not current_cfs.has_key(cf.name):
            # Ignoring unavailable channel family at this point,
            # we'll create it at sync time.
            continue

        quant = cf.quantity
        if quant is not None:
            quant = int(quant)
        flex = cf.flex
        if flex == '':
            flex = 0
        if flex is not None:
            flex = int(flex)

        #we subtract flex from quantity since flex count is included
        #   in the full quantity for backwards compatibility
        cert_chfam_hash[cf.name] = [quant - flex, flex]

    # Generate the channel family permissions data structure
    cfps = {}
    for cfp in _fetch_channel_family_permissions():
        cf_name = cfp['channel_family']

        # org_id is the org_id which is given permission
        org_id = cfp['org_id']

        # Initially populate cf info with old limits from db
        cfps[(cf_name, org_id)] = [cfp['max_members'], cfp['max_flex']]

    # Now set max_members based on the cert's max_members
    for cf_name, max_tuple in cert_chfam_hash.items():
        # Make the channel families with null max_members public
        if max_tuple is None:
            max_tuple = [0,0]
            org_id = None
        else:
            max_members, max_flex = max_tuple
            # default the org to 1 for channel families from cert
            org_id = 1

        cf_name = to_string(cf_name)
        try:
            old_max_tuple = cfps[(cf_name, org_id)]
        except KeyError:
            # New channel family, populate the db from cert
            cfps[(cf_name, org_id)] = max_tuple
            old_max_tuple = None


    sum_max_values = compute_sum_max_members(cfps)
    for (cf_name, org_id), (max_members, max_flex) in cfps.items():
        if org_id == 1:
            if cert_chfam_hash.has_key(cf_name):
                cert_max_value = cert_chfam_hash[cf_name][0] or 0
                cert_max_flex = cert_chfam_hash[cf_name][1] or 0
            else:
                # remove entitlements on extra slots
                cfps[(cf_name, org_id)] = None
                continue
            if not max_members:
                max_members = 0
            if not max_flex:
                max_flex = 0

            (sum_max_mem, sum_max_flex) = sum_max_values[cf_name]
            if cert_max_value >= sum_max_mem:
                cfps[(cf_name, 1)][0] = max_members + \
                                  (cert_max_value - sum_max_mem)
            else:
                purge_count = sum_max_mem - cert_max_value
                cfps[(cf_name, 1)][0] = max_members - purge_count

            if cert_max_flex >= sum_max_flex:
                cfps[(cf_name, 1)][1] = max_flex +\
                                  (cert_max_flex - sum_max_flex)
            else:
                # lowering entitlements
                flex_purge_count = sum_max_flex - cert_max_flex
                cfps[(cf_name, 1)][1] = max_flex - flex_purge_count

    # Cleanup left out suborgs
    for (cf_name, org_id), max_list in cfps.items():
        if cfps.has_key((cf_name, 1)) and cfps[(cf_name, 1)] == None: #is None:
            cfps[(cf_name, org_id)] = None


    batch = []
    for (cf_name, org_id), max_list  in cfps.items():
        if max_list is None:
            max_members = None
            max_flex = None
        else:
            (max_members, max_flex) = max_list
        cfperm = importLib.ChannelFamilyPermissions()
        batch.append(cfperm.populate({
            'channel_family'    : cf_name,
            'org_id'            : org_id,
            'max_members'       : max_members,
            'max_flex'          : max_flex,
        }))

    importer = channelImport.ChannelFamilyPermissionsImport(batch,
        diskImportLib.get_backend())
    importer.will_commit = 0
    importer.run()
Example #11
0
def import_kickstarts(batch):
    importer = kickstartImport.KickstartableTreeImport(batch,
        diskImportLib.get_backend())
    importer.run()
    importer.status()
    return importer
Example #12
0
def import_errata(batch):
    importer = errataImport.ErrataImport(batch, diskImportLib.get_backend())
    importer.ignoreMissing = 1
    importer.run()
    importer.status()
    return importer
Example #13
0
def import_packages(batch, sources=0):
    importer = packageImport.PackageImport(batch, diskImportLib.get_backend(), sources)
    importer.setUploadForce(4)
    importer.run()
    importer.status()
    return importer