コード例 #1
0
ファイル: rhsm_d.py プロジェクト: beav/subscription-manager
def check_status(force_signal):

    if force_signal is not None:
        debug("forcing status signal from cli arg")
        return force_signal

    if ClassicCheck().is_registered_with_classic():
        debug("System is already registered to another entitlement system")
        return RHN_CLASSIC

    if not ConsumerIdentity.existsAndValid():
        debug("The system is not currently registered.")
        return RHSM_REGISTRATION_REQUIRED

    facts = Facts()
    sorter = CertSorter(certdirectory.ProductDirectory(),
            certdirectory.EntitlementDirectory(), facts.get_facts())

    if len(sorter.unentitled_products.keys()) > 0 or len(sorter.expired_products.keys()) > 0:
        debug("System has one or more certificates that are not valid")
        debug(sorter.unentitled_products.keys())
        debug(sorter.expired_products.keys())
        return RHSM_EXPIRED
    elif len(sorter.partially_valid_products) > 0:
        debug("System has one or more partially entitled products")
        return RHSM_PARTIALLY_VALID
    elif in_warning_period(sorter):
        debug("System has one or more entitlements in their warning period")
        return RHSM_WARNING
    else:
        debug("System entitlements appear valid")
        return RHSM_VALID
コード例 #2
0
def main(options, log):

    if RhicCertificate.existsAndValid():
        facts = Facts(ent_dir=EntitlementDirectory(),
                              prod_dir=ProductDirectory())
        iproducts = managerlib.getInstalledProductStatus(ProductDirectory(),
                EntitlementDirectory(), facts.get_facts())

        product_certs = []
        for product in iproducts:
            product_certs.append(product[1])

        certs = []
        try:
            certs = rhiclib.getCerts(facts.to_dict(), product_certs)
        except connection.NetworkException, e:
            if e.code == 410:
                print _("RHIC was deleted by upstream server. See rhsm.log for more detail.")
                RhicCertificate.move()
                sys.exit(-1)
            else:
                raise
        except connection.RemoteServerException, e:
            if e.code == 404:
                print _("RHIC was not found by upstream server. See rhsm.log for more detail.")
                RhicCertificate.move()
                sys.exit(-1)
            else:
                raise
コード例 #3
0
ファイル: rhsm_d.py プロジェクト: beav/subscription-manager
def check_status(force_signal):

    if force_signal is not None:
        debug("forcing status signal from cli arg")
        return force_signal

    if ClassicCheck().is_registered_with_classic():
        debug("System is already registered to another entitlement system")
        return RHN_CLASSIC

    if not ConsumerIdentity.existsAndValid():
        debug("The system is not currently registered.")
        return RHSM_REGISTRATION_REQUIRED

    facts = Facts()
    sorter = CertSorter(certdirectory.ProductDirectory(),
                        certdirectory.EntitlementDirectory(),
                        facts.get_facts())

    if len(sorter.unentitled_products.keys()) > 0 or len(
            sorter.expired_products.keys()) > 0:
        debug("System has one or more certificates that are not valid")
        debug(sorter.unentitled_products.keys())
        debug(sorter.expired_products.keys())
        return RHSM_EXPIRED
    elif len(sorter.partially_valid_products) > 0:
        debug("System has one or more partially entitled products")
        return RHSM_PARTIALLY_VALID
    elif in_warning_period(sorter):
        debug("System has one or more entitlements in their warning period")
        return RHSM_WARNING
    else:
        debug("System entitlements appear valid")
        return RHSM_VALID
コード例 #4
0
class FactLib(DataLib):
    """
    Used by CertManager to update a system's facts with the server, used
    primarily by the cron job but in a couple other places as well.

    Makes use of the facts module as well.
    """
    def __init__(self, lock=None, uep=None, facts=None):
        DataLib.__init__(self, lock, uep)
        self.facts = facts
        if not self.facts:
            self.facts = Facts()

    def _do_update(self):
        updates = 0

        # figure out the diff between latest facts and
        # report that as updates

        if self.facts.has_changed():
            updates = len(self.facts.get_facts())
            if not ConsumerIdentity.exists():
                return updates
            consumer = ConsumerIdentity.read()
            consumer_uuid = consumer.getConsumerId()

            self.facts.update_check(self.uep, consumer_uuid)
        else:
            log.info("Facts have not changed, skipping upload.")
        return updates
コード例 #5
0
class ReleaseBackend(object):

    # all the proxy info too?
    def __init__(self,
                 ent_dir=None,
                 prod_dir=None,
                 content_connection=None,
                 facts=None):
        self.entitlement_dir = ent_dir
        self.product_dir = prod_dir
        self.content_connection = content_connection
        self.facts = facts

    def get_releases(self):
        # cdn base url

        # let us pass in a facts object for testing
        if not self.facts:
            self.facts = Facts(ent_dir=self.entitlement_dir,
                               prod_dir=self.product_dir)

    # find entitlements for rhel product? (or vice versa)
        sorter = CertSorter(self.product_dir, self.entitlement_dir,
                            self.facts.get_facts())

        # find the rhel product
        rhel_product = None
        for product_hash in sorter.installed_products:
            product_cert = sorter.installed_products[product_hash]
            products = product_cert.getProducts()
            for product in products:
                product_tags = product.getProvidedTags()

                if self._is_rhel(product_tags):
                    rhel_product = product

        if rhel_product is None:
            return []

        entitlements = sorter.get_entitlements_for_product(
            rhel_product.getHash())
        listings = []
        for entitlement in entitlements:
            contents = entitlement.getContentEntitlements()
            for content in contents:
                # ignore content that is not enabled
                # see bz #820639
                if content.getEnabled() != '1':
                    continue
                if self._is_correct_rhel(rhel_product.getProvidedTags(),
                                         content.getRequiredTags()):
                    content_url = content.getUrl()
                    listing_parts = content_url.split('$releasever', 1)
                    listing_base = listing_parts[0]
                    listing_path = "%s/listing" % listing_base
                    listings.append(listing_path)

        # FIXME: not sure how to get the "base" content if we have multiple
        # entitlements for a product

        # for a entitlement, gran the corresponding entitlement cert
        # use it for this connection

        # hmm. We are really only supposed to have one product
        # with one content with one listing file. We shall see.
        releases = []
        listings = sorted(set(listings))
        for listing_path in listings:
            data = self.content_connection.get_versions(listing_path)
            ver_listing = listing.ListingFile(data=data)
            releases = releases + ver_listing.get_releases()

        releases_set = sorted(set(releases))
        return releases_set

    def _is_rhel(self, product_tags):
        #easy to pass a string instead of a list
        assert not isinstance(product_tags, basestring)

        for product_tag in product_tags:
            # so in theory, we should only have one rhel
            # product. Not sure what to do if we have
            # more than one. Probably throw an error
            # TESTME
            if product_tag.split('-', 1)[0] == "rhel":
                # we only need to match the first hit
                return True
        log.info("No products with RHEL product tags found")
        return False

    #required tags provided by installed products?
    def _is_correct_rhel(self, product_tags, content_tags):
        #easy to pass a string instead of a list
        assert not isinstance(product_tags, basestring)
        assert not isinstance(content_tags, basestring)

        for product_tag in product_tags:
            # we are comparing the lists to see if they
            # have a matching rhel-#
            # TESTME
            product_split = product_tag.split('-', 2)
            if product_split[0] == "rhel":
                # look for match in content tags
                for content_tag in content_tags:
                    content_split = content_tag.split('-', 2)
                    if content_split[0] == "rhel" and \
                       content_split[1] == product_split[1]:
                        return True
        log.info("No matching products with RHEL product tags found")
        return False
コード例 #6
0
ファイル: release.py プロジェクト: beav/subscription-manager
class ReleaseBackend(object):

    # all the proxy info too?
    def __init__(self, ent_dir=None, prod_dir=None,
                 content_connection=None, facts=None):
        self.entitlement_dir = ent_dir
        self.product_dir = prod_dir
        self.content_connection = content_connection
        self.facts = facts

    def get_releases(self):
        # cdn base url

        # let us pass in a facts object for testing
        if not self.facts:
            self.facts = Facts(ent_dir=self.entitlement_dir,
                               prod_dir=self.product_dir)

       # find entitlements for rhel product? (or vice versa)
        sorter = CertSorter(self.product_dir,
                            self.entitlement_dir,
                            self.facts.get_facts())

        # find the rhel product
        rhel_product = None
        for product_hash in sorter.installed_products:
            product_cert = sorter.installed_products[product_hash]
            products = product_cert.products
            for product in products:
                product_tags = product.provided_tags

                if self._is_rhel(product_tags):
                    rhel_product = product

        if rhel_product is None:
            return []

        entitlements = sorter.get_entitlements_for_product(rhel_product.id)
        listings = []
        for entitlement in entitlements:
            contents = entitlement.content
            for content in contents:
                # ignore content that is not enabled
                # see bz #820639
                if not content.enabled:
                    continue
                if self._is_correct_rhel(rhel_product.provided_tags,
                                     content.required_tags):
                    content_url = content.url
                    listing_parts = content_url.split('$releasever', 1)
                    listing_base = listing_parts[0]
                    listing_path = "%s/listing" % listing_base
                    listings.append(listing_path)

        # FIXME: not sure how to get the "base" content if we have multiple
        # entitlements for a product

        # for a entitlement, gran the corresponding entitlement cert
        # use it for this connection

        # hmm. We are really only supposed to have one product
        # with one content with one listing file. We shall see.
        releases = []
        listings = sorted(set(listings))
        for listing_path in listings:
            data = self.content_connection.get_versions(listing_path)
            ver_listing = listing.ListingFile(data=data)
            releases = releases + ver_listing.get_releases()

        releases_set = sorted(set(releases))
        return releases_set

    def _is_rhel(self, product_tags):
        #easy to pass a string instead of a list
        assert not isinstance(product_tags, basestring)

        for product_tag in product_tags:
            # so in theory, we should only have one rhel
            # product. Not sure what to do if we have
            # more than one. Probably throw an error
            # TESTME
            if product_tag.split('-', 1)[0] == "rhel":
                # we only need to match the first hit
                return True
        log.info("No products with RHEL product tags found")
        return False

    #required tags provided by installed products?
    def _is_correct_rhel(self, product_tags, content_tags):
        #easy to pass a string instead of a list
        assert not isinstance(product_tags, basestring)
        assert not isinstance(content_tags, basestring)

        for product_tag in product_tags:
            # we are comparing the lists to see if they
            # have a matching rhel-#
            # TESTME
            product_split = product_tag.split('-', 2)
            if product_split[0] == "rhel":
                # look for match in content tags
                for content_tag in content_tags:
                    content_split = content_tag.split('-', 2)
                    if content_split[0] == "rhel" and \
                       content_split[1] == product_split[1]:
                        return True
        log.info("No matching products with RHEL product tags found")
        return False