def __init__(self, parent, backend): super(CredentialsScreen, self).__init__("credentials.glade", parent, backend) self._initialize_consumer_name() register_tip_label = self.glade.get_widget("registration_tip_label") register_tip_label.set_label("<small>%s</small>" % get_branding().GUI_FORGOT_LOGIN_TIP) register_header_label = self.glade.get_widget("registration_header_label") register_header_label.set_label("<b>%s</b>" % get_branding().GUI_REGISTRATION_HEADER)
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: supported_resources = get_supported_resources() if "status" in supported_resources: status = cp.getStatus() cp_version = "-".join([ status.get("version", _("Unknown")), status.get("release", _("Unknown")) ]) rules_version = status.get("rulesVersion", _("Unknown")) except socket.timeout as 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 as e: if isinstance(e, GoneException): log.warn( "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") return { "candlepin": cp_version, "server-type": server_type, "rules-version": rules_version }
def __init__(self, parent, backend): super(CredentialsScreen, self).__init__("credentials.glade", parent, backend) self._initialize_consumer_name() register_tip_label = self.glade.get_widget("registration_tip_label") register_tip_label.set_label("<small>%s</small>" % get_branding().GUI_FORGOT_LOGIN_TIP) register_header_label = \ self.glade.get_widget("registration_header_label") register_header_label.set_label("<b>%s</b>" % get_branding().GUI_REGISTRATION_HEADER)
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 as 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 as 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") return {"candlepin": cp_version, "server-type": server_type, "rules-version": rules_version}
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 get_server_versions(cp, exception_on_timeout=False): cp_version = _("Unknown") server_type = _("This system is currently not registered.") # check for Classic before doing anything else if ClassicCheck().is_registered_with_classic(): if ConsumerIdentity.existsAndValid(): server_type = get_branding().REGISTERED_TO_BOTH_SUMMARY else: server_type = get_branding().REGISTERED_TO_OTHER_SUMMARY else: if ConsumerIdentity.existsAndValid(): server_type = get_branding( ).REGISTERED_TO_SUBSCRIPTION_MANAGEMENT_SUMMARY if cp: try: if cp.supports_resource("status"): status = cp.getStatus() cp_version = '-'.join([status['version'], status['release']]) else: cp_version = _("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 _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 _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 _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.expired_products) + \ len(self.backend.cs.unentitled_products) if self.backend.cs.system_status == 'valid': self._set_status_icons(VALID_STATUS) if self.backend.cs.first_invalid_date: 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.first_invalid_date)) 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( # I18N: Please add newlines if translation is longer: _("No installed products detected.")) 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 _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 __init__(self, backend, consumer, facts=None, callbacks=None): """ Callbacks will be executed when registration status changes. """ self.backend = backend self.consumer = consumer self.facts = facts self.callbacks = callbacks self. async = AsyncBackend(self.backend) dic = { "on_register_cancel_button_clicked": self.cancel, "on_register_button_clicked": self.on_register_button_clicked, "on_proxy_config_button_clicked": self._on_proxy_config_button_clicked, "on_import_certs_button_clicked": self._on_import_certs_button_clicked, "on_rhn_radio_toggled": self._server_radio_toggled, "on_local_radio_toggled": self._server_radio_toggled, "on_offline_radio_toggled": self._server_radio_toggled, } registration_xml.signal_autoconnect(dic) self.registerWin = registration_xml.get_widget("register_dialog") self.registerWin.connect("hide", self.cancel) self.registerWin.connect("delete_event", self.delete_event) self.initializeConsumerName() self.uname = registration_xml.get_widget("account_login") self.passwd = registration_xml.get_widget("account_password") self.consumer_name = registration_xml.get_widget("consumer_name") self.skip_auto_bind = registration_xml.get_widget("skip_auto_bind") self.register_notebook = \ registration_xml.get_widget("register_notebook") self.register_progressbar = \ registration_xml.get_widget("register_progressbar") self.register_details_label = \ registration_xml.get_widget("register_details_label") self.owner_treeview = registration_xml.get_widget("owner_treeview") renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Organization"), renderer, text=1) self.owner_treeview.set_property("headers-visible", False) self.owner_treeview.append_column(column) self.environment_treeview = registration_xml.get_widget( "environment_treeview") renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Environment"), renderer, text=1) self.environment_treeview.set_property("headers-visible", False) self.environment_treeview.append_column(column) self.cancel_button = registration_xml.get_widget("cancel_button") self.register_button = registration_xml.get_widget("register_button") register_tip_label = registration_xml.get_widget("registrationTip") register_tip_label.set_label("<small>%s</small>" % \ get_branding().GUI_FORGOT_LOGIN_TIP) register_header_label = \ registration_xml.get_widget("registrationHeader") register_header_label.set_label("<b>%s</b>" % \ get_branding().GUI_REGISTRATION_HEADER) self.rhn_radio = registration_xml.get_widget("rhn_radio") self.local_radio = registration_xml.get_widget("local_radio") self.offline_radio = registration_xml.get_widget("offline_radio") self.local_entry = registration_xml.get_widget("local_entry") self.import_certs_button = registration_xml.get_widget( "import_certs_button") self.proxy_label = registration_xml.get_widget("proxy_label") self.proxy_config_button = registration_xml.get_widget( "proxy_config_button") self.network_config_dialog = networkConfig.NetworkConfigDialog() self.import_certs_dialog = ImportSubDialog()
def main(): parser = OptionParser() parser.add_option("-d", "--debug", dest="debug", help="Display debug messages", action="store_true", default=False) parser.add_option("-k", "--keep-alive", dest="keep_alive", help="Stay running (don't shut down after the first dbus call)", action="store_true", default=False) parser.add_option("-s", "--syslog", dest="syslog", help="Run standalone and log result to syslog", action="store_true", default=False) parser.add_option("-f", "--force-signal", dest="force_signal", help="Force firing of a signal " + "(valid, expired, warning, partial, classic or registration_required)") options, args = parser.parse_args() force_signal = parse_force_signal(options.force_signal) global enable_debug enable_debug = options.debug # short-circuit dbus initialization if options.syslog: status = check_status(force_signal) if status == RHSM_EXPIRED: syslog.openlog("rhsmd") syslog.syslog(syslog.LOG_NOTICE, "This system is missing one or more valid entitlement " + "certificates. " + "Please run subscription-manager for more information.") elif status == RHSM_PARTIALLY_VALID: syslog.openlog("rhsmd") syslog.syslog(syslog.LOG_NOTICE, "This system is missing one or more valid entitlement " + "certificates to fully cover its products. " + "Please run subscription-manager for more information.") elif status == RHSM_WARNING: syslog.openlog("rhsmd") syslog.syslog(syslog.LOG_NOTICE, "This system's entitlements are about to expire. " + "Please run subscription-manager for more information.") elif status == RHN_CLASSIC: syslog.openlog("rhsmd") syslog.syslog(syslog.LOG_NOTICE, get_branding().RHSMD_REGISTERED_TO_OTHER) elif status == RHSM_REGISTRATION_REQUIRED: syslog.openlog("rhsmd") syslog.syslog(syslog.LOG_NOTICE, "In order for Subscription Manager to provide your " + "system with updates, your system must be registered " + "with RHN. Please enter your Red Hat login to ensure " + "your system is up-to-date.") # Return an exit code for the program. having valid entitlements is # good, so it gets an exit status of 0. return status system_bus = dbus.SystemBus() loop = gobject.MainLoop() StatusChecker(system_bus, options.keep_alive, force_signal, loop) loop.run()
def __init__(self, backend, consumer, facts=None, callbacks=None): """ Callbacks will be executed when registration status changes. """ self.backend = backend self.consumer = consumer self.facts = facts self.callbacks = callbacks self.async = AsyncBackend(self.backend) dic = {"on_register_cancel_button_clicked": self.cancel, "on_register_button_clicked": self.on_register_button_clicked, "on_proxy_config_button_clicked": self._on_proxy_config_button_clicked, "on_import_certs_button_clicked": self._on_import_certs_button_clicked, "on_rhn_radio_toggled": self._server_radio_toggled, "on_local_radio_toggled": self._server_radio_toggled, "on_offline_radio_toggled": self._server_radio_toggled, } registration_xml.signal_autoconnect(dic) self.registerWin = registration_xml.get_widget("register_dialog") self.registerWin.connect("hide", self.cancel) self.registerWin.connect("delete_event", self.delete_event) self.initializeConsumerName() self.uname = registration_xml.get_widget("account_login") self.passwd = registration_xml.get_widget("account_password") self.consumer_name = registration_xml.get_widget("consumer_name") self.skip_auto_bind = registration_xml.get_widget("skip_auto_bind") self.register_notebook = \ registration_xml.get_widget("register_notebook") self.register_progressbar = \ registration_xml.get_widget("register_progressbar") self.register_details_label = \ registration_xml.get_widget("register_details_label") self.owner_treeview = registration_xml.get_widget("owner_treeview") renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Organization"), renderer, text=1) self.owner_treeview.set_property("headers-visible", False) self.owner_treeview.append_column(column) self.environment_treeview = registration_xml.get_widget("environment_treeview") renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_("Environment"), renderer, text=1) self.environment_treeview.set_property("headers-visible", False) self.environment_treeview.append_column(column) self.cancel_button = registration_xml.get_widget("cancel_button") self.register_button = registration_xml.get_widget("register_button") register_tip_label = registration_xml.get_widget("registrationTip") register_tip_label.set_label("<small>%s</small>" % \ get_branding().GUI_FORGOT_LOGIN_TIP) register_header_label = \ registration_xml.get_widget("registrationHeader") register_header_label.set_label("<b>%s</b>" % \ get_branding().GUI_REGISTRATION_HEADER) self.rhn_radio = registration_xml.get_widget("rhn_radio") self.local_radio = registration_xml.get_widget("local_radio") self.offline_radio = registration_xml.get_widget("offline_radio") self.local_entry = registration_xml.get_widget("local_entry") self.import_certs_button = registration_xml.get_widget( "import_certs_button") self.proxy_label = registration_xml.get_widget("proxy_label") self.proxy_config_button = registration_xml.get_widget( "proxy_config_button") self.network_config_dialog = networkConfig.NetworkConfigDialog() self.import_certs_dialog = ImportSubDialog()
def _do_command(self): """ Executes the command. """ self.log_client_version() # Always warn the user if registered to old RHN/Spacewalk if ClassicCheck().is_registered_with_classic(): print(get_branding().REGISTERED_TO_OTHER_WARNING) self._validate_options() # gather installed products info self.installed_mgr = inj.require(inj.INSTALLED_PRODUCTS_MANAGER) previously_registered = False if self.is_registered() and self.options.force: previously_registered = True # First let's try to un-register previous consumer; if this fails # we'll let the error bubble up, so that we don't blindly re-register. # managerlib.unregister handles the special case that the consumer has already been removed. old_uuid = self.identity.uuid print( _("Unregistering from: {hostname}:{port}{prefix}").format( hostname=conf["server"]["hostname"], port=conf["server"]["port"], prefix=conf["server"]["prefix"], ) ) try: unregister.UnregisterService(self.cp).unregister() self.entitlement_dir.__init__() self.product_dir.__init__() log.info("--force specified, unregistered old consumer: {old_uuid}".format(old_uuid=old_uuid)) print(_("The system with UUID {old_uuid} has been unregistered").format(old_uuid=old_uuid)) except ssl.SSLError as e: # since the user can override serverurl for register, a common use case is to try to switch servers # using register --force... However, this normally cannot successfully unregister since the servers # are different. handle_exception("Unregister failed: {e}".format(e=e), e) except Exception as e: handle_exception("Unregister failed", e) self.cp_provider.clean() if previously_registered: print(_("All local data removed")) # Proceed with new registration: try: if self.options.token: admin_cp = self.cp_provider.get_keycloak_auth_cp(self.options.token) elif not self.options.activation_keys: hostname = conf["server"]["hostname"] if ":" in hostname: normalized_hostname = "[{hostname}]".format(hostname=hostname) else: normalized_hostname = hostname print( _("Registering to: {hostname}:{port}{prefix}").format( hostname=normalized_hostname, port=conf["server"]["port"], prefix=conf["server"]["prefix"], ) ) self.cp_provider.set_user_pass(self.username, self.password) admin_cp = self.cp_provider.get_basic_auth_cp() else: admin_cp = self.cp_provider.get_no_auth_cp() # This is blocking and not async, which aside from blocking here, also # means things like following name owner changes gets weird. service = register.RegisterService(admin_cp) if self.options.consumerid: log.debug("Registering as existing consumer: {id}".format(id=self.options.consumerid)) consumer = service.register(None, consumerid=self.options.consumerid) else: if self.options.org: owner_key = self.options.org else: owner_key = service.determine_owner_key( username=self.username, get_owner_cb=self._get_owner_cb, no_owner_cb=self._no_owner_cb ) environment_ids = self._process_environments(admin_cp, owner_key) consumer = service.register( owner_key, activation_keys=self.options.activation_keys, environments=environment_ids, force=self.options.force, name=self.options.consumername, type=self.options.consumertype, service_level=self.options.service_level, ) except (connection.RestlibException, exceptions.ServiceError) as re: log.exception(re) mapped_message: str = ExceptionMapper().get_message(re) system_exit(os.EX_SOFTWARE, mapped_message) except Exception as e: handle_exception(_("Error during registration: {e}").format(e=e), e) else: consumer_info = identity.ConsumerIdentity(consumer["idCert"]["key"], consumer["idCert"]["cert"]) print(_("The system has been registered with ID: {id}").format(id=consumer_info.getConsumerId())) print(_("The registered system name is: {name}").format(name=consumer_info.getConsumerName())) if self.options.service_level: print(_("Service level set to: {level}").format(level=self.options.service_level)) # We have new credentials, restart virt-who restart_virt_who() # get a new UEP as the consumer self.cp = self.cp_provider.get_consumer_auth_cp() # log the version of the server we registered to self.log_server_version() facts = inj.require(inj.FACTS) # FIXME: can these cases be replaced with invoking # FactsLib (or a FactsManager?) # Must update facts to clear out the old ones: if self.options.consumerid: log.debug("Updating facts") # # FIXME: Need a ConsumerFacts.sync or update or something # TODO: We register, with facts, then update facts again...? # Are we trying to sync potential new or dynamic facts? facts.update_check(self.cp, consumer["uuid"], force=True) # Facts and installed products went out with the registration request, # manually write caches to disk: # facts service job now(soon) facts.write_cache() self.installed_mgr.update_check(self.cp, consumer["uuid"]) if self.options.release: # TODO: grab the list of valid options, and check self.cp.updateConsumer(consumer["uuid"], release=self.options.release) if self.autoattach: self._do_auto_attach(consumer) if ( self.options.consumerid or self.options.activation_keys or self.autoattach or self.cp.has_capability(CONTENT_ACCESS_CERT_CAPABILITY) ): log.debug("System registered, updating entitlements if needed") # update certs, repos, and caches. # FIXME: aside from the overhead, should this be cert_action_client.update? self.entcertlib.update() try: profile_mgr = inj.require(inj.PROFILE_MANAGER) # 767265: always force an upload of the packages when registering profile_mgr.update_check(self.cp, consumer["uuid"], True) except RemoteServerException as err: # When it is not possible to upload profile ATM, then print only error about this # to rhsm.log. The rhsmcertd will try to upload it next time. log.error("Unable to upload profile: {err}".format(err=str(err))) subscribed = 0 if self.options.activation_keys or self.autoattach: # update with latest cert info self.sorter = inj.require(inj.CERT_SORTER) self.sorter.force_cert_check() subscribed = show_autosubscribe_output(self.cp, self.identity) self._request_validity_check() return subscribed
def _do_command(self): # get current consumer identity identity = inj.require(inj.IDENTITY) # check for Classic before doing anything else if ClassicCheck().is_registered_with_classic(): if identity.is_valid(): print( _("server type: {type}").format( type=get_branding().REGISTERED_TO_BOTH_SUMMARY)) else: # no need to continue if user is only registered to Classic print( _("server type: {type}").format( type=get_branding().REGISTERED_TO_OTHER_SUMMARY)) return try: self._validate_options() consumerid = self.identity.uuid consumer_name = self.identity.name if not self.options.regenerate: owner = get_current_owner(self.cp, self.identity) ownername = owner['displayName'] ownerid = owner['key'] print( _('system identity: {consumerid}').format( consumerid=consumerid)) print( _('name: {consumer_name}').format( consumer_name=consumer_name)) print(_('org name: {ownername}').format(ownername=ownername)) print(_('org ID: {ownerid}').format(ownerid=ownerid)) supported_resources = get_supported_resources( self.cp, self.identity) if 'environments' in supported_resources: consumer = self.cp.getConsumer(consumerid) environment = consumer['environment'] if environment: environment_name = environment['name'] else: environment_name = _("None") print( _('environment name: {environment_name}').format( environment_name=environment_name)) else: if self.options.force: # get an UEP with basic auth or keycloak auth if self.options.token: self.cp = self.cp_provider.get_keycloak_auth_cp( self.options.token) else: self.cp_provider.set_user_pass(self.username, self.password) self.cp = self.cp_provider.get_basic_auth_cp() consumer = self.cp.regenIdCertificate(consumerid) managerlib.persist_consumer_cert(consumer) # do this in persist_consumer_cert? or some other # high level, "I just registered" thing self.identity.reload() print(_("Identity certificate has been regenerated.")) log.debug("Successfully generated a new identity from server.") except connection.GoneException as ge: # Gone exception is caught in CliCommand and a consistent message # is printed there for all commands raise ge except connection.RestlibException as re: log.exception(re) log.error( u"Error: Unable to generate a new identity for the system: {re}" ).format(re=re) system_exit(os.EX_SOFTWARE, str(re)) except Exception as e: handle_exception( _("Error: Unable to generate a new identity for the system"), e)
def __init__(self): shortdesc = get_branding().CLI_REGISTER super(RegisterCommand, self).__init__("register", shortdesc, True) self._add_url_options() self.parser.add_argument( "--baseurl", dest="base_url", default=None, help=_("base URL for content in form of https://hostname:port/prefix"), ) self.parser.add_argument( "--type", dest="consumertype", default="system", metavar="UNITTYPE", help=SUPPRESS, ) self.parser.add_argument( "--name", dest="consumername", metavar="SYSTEMNAME", help=_("name of the system to register, defaults to the hostname"), ) self.parser.add_argument( "--consumerid", dest="consumerid", metavar="SYSTEMID", help=_("the existing system data is pulled from the server"), ) self.parser.add_argument( "--org", dest="org", metavar="ORG_KEY", help=_("register with one of multiple organizations for the user, using organization key"), ) self.parser.add_argument( "--environments", dest="environments", help=_( "register with a specific environment (single value) or multiple environments " "(a comma-separated list) in the destination org. The ability to use multiple " "environments is controlled by the entitlement server" ), ) self.parser.add_argument( "--release", dest="release", help=_("set a release version"), ) self.parser.add_argument( "--autosubscribe", action="store_true", help=_("Deprecated, see --auto-attach"), ) self.parser.add_argument( "--auto-attach", action="store_true", dest="autoattach", help=_("automatically attach compatible subscriptions to this system"), ) self.parser.add_argument( "--force", action="store_true", help=_("include an implicit attempt to unregister before registering a new system identity"), ) self.parser.add_argument( "--activationkey", action="append", dest="activation_keys", help=_("activation key to use for registration (can be specified more than once)"), ) self.parser.add_argument( "--servicelevel", dest="service_level", help=_("system preference used when subscribing automatically, requires --auto-attach"), )
def main(): log.info("rhsmd started") parser = OptionParser(usage=USAGE, formatter=WrappedIndentedHelpFormatter()) parser.add_option("-d", "--debug", dest="debug", help="Display debug messages", action="store_true", default=False) parser.add_option("-k", "--keep-alive", dest="keep_alive", help="Stay running (don't shut down after the first dbus call)", action="store_true", default=False) parser.add_option("-s", "--syslog", dest="syslog", help="Run standalone and log result to syslog", action="store_true", default=False) parser.add_option("-f", "--force-signal", dest="force_signal", help="Force firing of a signal " + "(valid, expired, warning, partial, classic or registration_required)") parser.add_option("-i", "--immediate", dest="immediate", action="store_true", default=False, help="Fire forced signal immediately (requires --force-signal)") options, args = parser.parse_args() force_signal = parse_force_signal(options.force_signal) if options.immediate and force_signal is None: print_error("--immediate must be used with --force-signal") sys.exit(-2) global enable_debug enable_debug = options.debug # short-circuit dbus initialization if options.syslog: log.info("logging subscription status to syslog") status = check_status(force_signal) if status == RHSM_EXPIRED: log_syslog(syslog.LOG_NOTICE, "This system is missing one or more subscriptions. " + "Please run subscription-manager for more information.") elif status == RHSM_PARTIALLY_VALID: log_syslog(syslog.LOG_NOTICE, "This system is missing one or more subscriptions " + "to fully cover its products. " + "Please run subscription-manager for more information.") elif status == RHSM_WARNING: log_syslog(syslog.LOG_NOTICE, "This system's subscriptions are about to expire. " + "Please run subscription-manager for more information.") elif status == RHN_CLASSIC: log_syslog(syslog.LOG_INFO, get_branding().RHSMD_REGISTERED_TO_OTHER) elif status == RHSM_REGISTRATION_REQUIRED: log_syslog(syslog.LOG_NOTICE, "In order for Subscription Manager to provide your " + "system with updates, your system must be registered " + "with the Customer Portal. Please enter your Red Hat " + "login to ensure your system is up-to-date.") # Return an exit code for the program. having valid entitlements is # good, so it gets an exit status of 0. return status # we are not running from cron here, so unset the excepthook # though, we may be running from cli, or as a dbus activation. For # cli, we should traceback. For dbus, we should try to log it and # raise dbus exception? sys.excepthook = sys.__excepthook__ system_bus = dbus.SystemBus() loop = ga_GObject.MainLoop() checker = StatusChecker(system_bus, options.keep_alive, force_signal, loop) if options.immediate: checker.entitlement_status_changed(force_signal) loop.run()
def __init__(self): shortdesc = get_branding().CLI_UNREGISTER super(UnRegisterCommand, self).__init__("unregister", shortdesc, True)
def main(): log.info("rhsmd started") parser = OptionParser(usage=USAGE, formatter=WrappedIndentedHelpFormatter()) parser.add_option("-d", "--debug", dest="debug", help="Display debug messages", action="store_true", default=False) parser.add_option( "-k", "--keep-alive", dest="keep_alive", help="Stay running (don't shut down after the first dbus call)", action="store_true", default=False) parser.add_option("-s", "--syslog", dest="syslog", help="Run standalone and log result to syslog", action="store_true", default=False) parser.add_option( "-f", "--force-signal", dest="force_signal", help="Force firing of a signal " + "(valid, expired, warning, partial, classic or registration_required)") parser.add_option( "-i", "--immediate", dest="immediate", action="store_true", default=False, help="Fire forced signal immediately (requires --force-signal)") options, args = parser.parse_args() force_signal = parse_force_signal(options.force_signal) if options.immediate and force_signal is None: print_error("--immediate must be used with --force-signal") sys.exit(-2) global enable_debug enable_debug = options.debug # short-circuit dbus initialization if options.syslog: log.info("logging subscription status to syslog") status = check_status(force_signal) if status == RHSM_EXPIRED: log_syslog( syslog.LOG_NOTICE, "This system is missing one or more subscriptions. " + "Please run subscription-manager for more information.") elif status == RHSM_PARTIALLY_VALID: log_syslog( syslog.LOG_NOTICE, "This system is missing one or more subscriptions " + "to fully cover its products. " + "Please run subscription-manager for more information.") elif status == RHSM_WARNING: log_syslog( syslog.LOG_NOTICE, "This system's subscriptions are about to expire. " + "Please run subscription-manager for more information.") elif status == RHN_CLASSIC: log_syslog(syslog.LOG_INFO, get_branding().RHSMD_REGISTERED_TO_OTHER) elif status == RHSM_REGISTRATION_REQUIRED: log_syslog( syslog.LOG_NOTICE, "In order for Subscription Manager to provide your " + "system with updates, your system must be registered " + "with the Customer Portal. Please enter your Red Hat " + "login to ensure your system is up-to-date.") # Return an exit code for the program. having valid entitlements is # good, so it gets an exit status of 0. return status # we are not running from cron here, so unset the excepthook # though, we may be running from cli, or as a dbus activation. For # cli, we should traceback. For dbus, we should try to log it and # raise dbus exception? sys.excepthook = sys.__excepthook__ system_bus = dbus.SystemBus() loop = ga_GObject.MainLoop() checker = StatusChecker(system_bus, options.keep_alive, force_signal, loop) if options.immediate: checker.entitlement_status_changed(force_signal) loop.run()
def main(): parser = OptionParser() parser.add_option("-d", "--debug", dest="debug", help="Display debug messages", action="store_true", default=False) parser.add_option( "-k", "--keep-alive", dest="keep_alive", help="Stay running (don't shut down after the first dbus call)", action="store_true", default=False) parser.add_option("-s", "--syslog", dest="syslog", help="Run standalone and log result to syslog", action="store_true", default=False) parser.add_option( "-f", "--force-signal", dest="force_signal", help="Force firing of a signal " + "(valid, expired, warning, partial, classic or registration_required)") options, args = parser.parse_args() force_signal = parse_force_signal(options.force_signal) global enable_debug enable_debug = options.debug # short-circuit dbus initialization if options.syslog: status = check_status(force_signal) if status == RHSM_EXPIRED: syslog.openlog("rhsmd") syslog.syslog( syslog.LOG_NOTICE, "This system is missing one or more valid entitlement " + "certificates. " + "Please run subscription-manager for more information.") elif status == RHSM_PARTIALLY_VALID: syslog.openlog("rhsmd") syslog.syslog( syslog.LOG_NOTICE, "This system is missing one or more valid entitlement " + "certificates to fully cover its products. " + "Please run subscription-manager for more information.") elif status == RHSM_WARNING: syslog.openlog("rhsmd") syslog.syslog( syslog.LOG_NOTICE, "This system's entitlements are about to expire. " + "Please run subscription-manager for more information.") elif status == RHN_CLASSIC: syslog.openlog("rhsmd") syslog.syslog(syslog.LOG_NOTICE, get_branding().RHSMD_REGISTERED_TO_OTHER) elif status == RHSM_REGISTRATION_REQUIRED: syslog.openlog("rhsmd") syslog.syslog( syslog.LOG_NOTICE, "In order for Subscription Manager to provide your " + "system with updates, your system must be registered " + "with RHN. Please enter your Red Hat login to ensure " + "your system is up-to-date.") # Return an exit code for the program. having valid entitlements is # good, so it gets an exit status of 0. return status system_bus = dbus.SystemBus() loop = gobject.MainLoop() StatusChecker(system_bus, options.keep_alive, force_signal, loop) loop.run()