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
def warnOrGiveUsageMessage(conduit): # XXX: Importing inline as you must be root to read the config file """ either output a warning, or a usage message """ msg = "" # TODO: refactor so there are not two checks for this if os.getuid() != 0: return if ClassicCheck().is_registered_with_classic(): return try: identity = inj.require(inj.IDENTITY) ent_dir = inj.require(inj.ENT_DIR) # Don't warn people to register if we see entitelements, but no identity: if not identity.is_valid() and len(ent_dir.list_valid()) == 0: msg = not_registered_warning elif len(ent_dir.list_valid()) == 0: msg = no_subs_warning if config.in_container() and len(ent_dir.list_valid()) == 0: msg = no_subs_container_warning finally: if msg: conduit.info(2, msg)
def _set_validity_status(self): """ Updates the entitlement validity status portion of the UI. """ if ClassicCheck().is_registered_with_classic(): self._set_status_icons(VALID) self.subscription_status_label.set_text( get_branding().RHSMD_REGISTERED_TO_OTHER) return is_registered = self.consumer.is_valid() self.set_registered(is_registered) # Look for products which have invalid entitlements sorter = CertSorter(self.product_dir, self.entitlement_dir, self.facts.get_facts()) warn_count = len(sorter.expired_products) + \ len(sorter.unentitled_products) partial_count = len(sorter.partially_valid_products) if warn_count > 0: self._set_status_icons(INVALID) # Change wording slightly for just one product if warn_count > 1: self.subscription_status_label.set_markup( _("%s installed products do not have valid subscriptions.") % warn_count) else: self.subscription_status_label.set_markup( _("1 installed product does not have a valid subscription." )) elif partial_count > 0: self._set_status_icons(PARTIAL) self.subscription_status_label.set_markup( _("This system does not match subscription limits.")) else: first_invalid = find_first_invalid_date(self.entitlement_dir, self.product_dir, self.facts.get_facts()) self._set_status_icons(VALID) if first_invalid: self.subscription_status_label.set_markup( _("System is properly subscribed through %s.") % \ managerlib.formatDate(first_invalid)) else: # No product certs installed, no first invalid date, and # the subscription assistant can't do anything, so we'll disable # the button to launch it: self.subscription_status_label.set_text( _("No installed products detected.")) if not is_registered: self.subscription_status_label.set_text( _("Keep your system up to date by registering."))
def _set_validity_status(self): """ Updates the entitlement validity status portion of the UI. """ if ClassicCheck().is_registered_with_classic(): self._set_status_icons(VALID_STATUS) self.subscription_status_label.set_text( get_branding().RHSMD_REGISTERED_TO_OTHER) return is_registered = self.identity.is_valid() self.set_registered(is_registered) warn_count = len(self.backend.cs.unentitled_products) if self.backend.cs.system_status == 'valid': self._set_status_icons(VALID_STATUS) if len(self.backend.cs.installed_products.keys()) == 0: # No product certs installed, thus no compliant until date: self.subscription_status_label.set_text( # I18N: Please add newlines if translation is longer: _("No installed products detected.")) elif self.backend.cs.compliant_until: self.subscription_status_label.set_markup( # I18N: Please add newlines if translation is longer: _("System is properly subscribed through %s.") % managerlib.format_date(self.backend.cs.compliant_until)) else: log.warn("Server did not provide a compliant until date.") self.subscription_status_label.set_text( _("System is properly subscribed.")) elif self.backend.cs.system_status == 'partial': self._set_status_icons(PARTIAL_STATUS) self.subscription_status_label.set_markup( # I18N: Please add newlines if translation is longer: _("This system does not match subscription limits.")) elif self.backend.cs.system_status == 'invalid': self._set_status_icons(INVALID_STATUS) if warn_count > 1: self.subscription_status_label.set_markup( # I18N: Please add newlines if translation is longer: _("%s installed products do not have valid subscriptions.") % warn_count) else: self.subscription_status_label.set_markup( # I18N: Please add newlines if translation is longer: _("1 installed product does not have a valid subscription." )) elif self.backend.cs.system_status == 'unknown': self._set_status_icons(UNKNOWN_STATUS) self.subscription_status_label.set_text( # I18N: Please add newlines if translation is longer: _("Keep your system up to date by registering."))
def pre_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 return None
def _get_validity_facts(self, facts_dict): validity_facts = {'system.entitlements_valid': 'valid'} if not ClassicCheck().is_registered_with_classic(): sorter = cert_sorter.CertSorter(self.product_dir, self.entitlement_dir, facts_dict) if (len(sorter.partially_valid_products) > 0) or \ (len(sorter.partial_stacks) > 0): validity_facts['system.entitlements_valid'] = 'partial' if ((len(sorter.expired_products) + len(sorter.unentitled_products)) > 0): validity_facts['system.entitlements_valid'] = 'invalid' return validity_facts
def config_hook(conduit): """ update """ # register rpm name for yum history recording" # yum on 5.7 doesn't have this method, so check for it if hasattr(conduit, 'registerPackageName'): conduit.registerPackageName("subscription-manager") logutil.init_logger_for_yum() try: update(conduit) if not ClassicCheck().is_registered_with_classic(): warnOrGiveUsageMessage(conduit) warnExpired(conduit) except Exception, e: conduit.error(2, str(e))
def get_server_versions(cp, exception_on_timeout=False): cp_version = _("Unknown") server_type = _("This system is currently not registered.") rules_version = _("Unknown") identity = inj.require(inj.IDENTITY) # check for Classic before doing anything else if ClassicCheck().is_registered_with_classic(): if identity.is_valid(): server_type = get_branding().REGISTERED_TO_BOTH_SUMMARY else: server_type = get_branding().REGISTERED_TO_OTHER_SUMMARY else: if identity.is_valid(): server_type = get_branding( ).REGISTERED_TO_SUBSCRIPTION_MANAGEMENT_SUMMARY if cp: try: if cp.supports_resource("status"): status = cp.getStatus() cp_version = '-'.join([ status.get('version', _("Unknown")), status.get('release', _("Unknown")) ]) rules_version = status.get('rulesVersion', _("Unknown")) except socket.timeout, e: log.error("Timeout error while checking server version") log.exception(e) # for cli, we can assume if we get a timeout here, the rest # of the calls will timeout as well, so raise exception here # instead of waiting for all the calls to timeout if exception_on_timeout: log.error("Timeout error while checking server version") raise # otherwise, ignore the timeout exception except Exception, e: if isinstance(e, GoneException): log.info( "Server Versions: Error: consumer has been deleted, unable to check server version" ) else: # a more useful error would be handy here log.error(("Error while checking server version: %s") % e) log.exception(e) cp_version = _("Unknown")
def pre_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 identity = require(IDENTITY) sorter = require(CERT_SORTER) if not identity.is_valid() and not sorter.has_entitlements(): debug("The system is not currently registered.") return RHSM_REGISTRATION_REQUIRED return None
def _warnOrGiveUsageMessage(self): """ either output a warning, or a usage message """ msg = "" if ClassicCheck().is_registered_with_classic(): return try: identity = inj.require(inj.IDENTITY) ent_dir = inj.require(inj.ENT_DIR) # Don't warn people to register if we see entitelements, but no identity: if not identity.is_valid() and len(ent_dir.list_valid()) == 0: msg = not_registered_warning elif len(ent_dir.list_valid()) == 0: msg = no_subs_warning finally: if msg: logger.info(msg)
def _check_rhn_classic(self): if ClassicCheck().is_registered_with_classic(): prompt = messageWindow.ContinueDialog( linkify(get_branding().REGISTERED_TO_OTHER_WARNING), self.main_window, _("System Already Registered")) prompt.connect('response', self._on_rhn_classic_response)
def _set_validity_status(self): """ Updates the entitlement validity status portion of the UI. """ if ClassicCheck().is_registered_with_classic(): self._set_status_icons(VALID) self.subscription_status_label.set_text( _("This system is registered to RHN Classic")) return is_registered = ConsumerIdentity.existsAndValid() self.set_registered(is_registered) # Look for products which have invalid entitlements sorter = CertSorter(self.product_dir, self.entitlement_dir, self.facts.get_facts()) warn_count = len(sorter.expired_products) + \ len(sorter.unentitled_products) partial_count = len(sorter.partially_valid_products) if warn_count > 0: self._set_status_icons(INVALID) # Change wording slightly for just one product if warn_count > 1: self.subscription_status_label.set_markup( _("You have <b>%s</b> products with <i>invalid</i> entitlement certificates." ) % warn_count) else: self.subscription_status_label.set_markup( _("You have <b>1</b> product with an <i>invalid</i> entitlement certificate." )) elif partial_count > 0: self._set_status_icons(PARTIAL) # Change wording slightly for just one product if partial_count > 1: self.subscription_status_label.set_markup( _("You have <b>%s</b> products in need of <i>additional</i> entitlement certificates." ) % partial_count) else: self.subscription_status_label.set_markup( _("You have <b>1</b> product in need of <i>additional</i> entitlement certificates." )) else: first_invalid = find_first_invalid_date(self.entitlement_dir, self.product_dir, self.facts.get_facts()) self._set_status_icons(VALID) if first_invalid: self.subscription_status_label.set_markup( _("Product entitlement certificates <i>valid</i> until %s") % \ managerlib.formatDate(first_invalid)) else: # No product certs installed, no first invalid date, and # the subscription assistant can't do anything, so we'll disable # the button to launch it: self.subscription_status_label.set_text( _("No product certificates installed.")) if not is_registered: self.subscription_status_label.set_text( _("You must register this system before subscribing."))
log.info( "Server Versions: Error: consumer has been deleted, unable to check server version" ) log.info(e) raise except Exception, e: # a more useful error would be handy here log.error(("Error while checking server version: %s") % e) log.exception(e) server_type = _("Unknown") cp_version = _("Unknown") # this isn't particularly important, so log any exceptions and carry on try: if ClassicCheck().is_registered_with_classic(): server_type = _("RHN Classic") cp_version = _("Unknown") except Exception, e: log.debug("Server Versions: Unable to check RHN Classic version") log.exception(e) return {"candlepin": cp_version, "server-type": server_type} def restart_virt_who(): """ Send a SIGHUP signal to virt-who if it running on the same machine. """ try: pidfile = open('/var/run/virt-who.pid', 'r')