예제 #1
0
    def __init__(self):
        """
        Create a new firstboot Module for the 'register' screen.
        """
        RhsmFirstbootModule.__init__(self,
                                     _("Entitlement Platform Registration"),
                                     _("Entitlement Registration"), 200.1,
                                     109.10)

        self.pages = {
            "rhsm_manually_subscribe": _("Manual Configuraton Required"),
            "rhsm_select_sla": _("Service Level"),
            "rhsm_confirm_subs": _("Confirm Subscriptions"),
        }

        backend = managergui.Backend()

        registergui.RegisterScreen.__init__(self, backend,
                                            managergui.Consumer(), Facts())

        self._skip_apply_for_page_jump = False
        self._cached_credentials = None
        self._registration_finished = False
        self._offline = False

        # In firstboot, we leverage the RHN setup proxy settings already
        # presented to the user, so hide the choose server screen's proxy
        # text and button.
        self.proxy_label.destroy()
        self.proxy_config_button.destroy()
예제 #2
0
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
예제 #3
0
def getInstalledProductStatus(product_directory,
                              entitlement_directory,
                              facts=None):
    """
     Returns the Installed products and their subscription states
    """
    # allow us to stub this out for testing
    if facts is None:
        facts = Facts().get_facts()

    product_status = []

    sorter = CertSorter(product_directory, entitlement_directory, facts)

    for installed_product in sorter.installed_products:
        product_cert = sorter.installed_products[installed_product]
        for product in product_cert.products:
            begin = ""
            end = ""
            calculator = ValidProductDateRangeCalculator(sorter)
            prod_status_range = calculator.calculate(product.id)
            if prod_status_range:
                # Format the date in user's local time as the date
                # range is returned in GMT.
                begin = formatDate(prod_status_range.begin())
                end = formatDate(prod_status_range.end())
            data = (product.name, installed_product, product.version,
                    ",".join(product.architectures),
                    sorter.get_status(product.id), begin, end)
            product_status.append(data)

    return product_status
예제 #4
0
    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
예제 #5
0
    def test_partial_and_invalid_fact(self, mock_sorter):

        ents = []
        stub_product = StubProduct('1005')

        stub_ent_cert = StubEntitlementCertificate(stub_product, quantity=2, stacking_id='stack1', sockets=2)

        ents.append(stub_ent_cert)
        entitlement_directory = StubCertificateDirectory(ents)

        product = StubProduct("product1")
        product_directory = StubCertificateDirectory([
                StubProductCertificate(product)])

        mock_sorter_instance = mock_sorter.return_value
        mock_sorter_instance.partially_valid_products = {'foo': 'blah'}
        mock_sorter_instance.unentitled_products = {'bar': 'apple'}
        mock_sorter_instance.expired_products = {}
        mock_sorter_instance.partial_stacks = {}

        facts = Facts(None)
        facts.product_dir = product_directory
        facts.entitlement_dir = entitlement_directory
        facts_dict = facts.get_facts()
        self.assertEquals("invalid", facts_dict['system.entitlements_valid'])
예제 #6
0
def get_available_entitlements(facts,
                               get_all=False,
                               active_on=None,
                               overlapping=False,
                               uninstalled=False,
                               text=None,
                               filter_string=None):
    """
    Returns a list of entitlement pools from the server.

    Facts will be updated if appropriate before making the request, to ensure
    the rules on the server will pass if appropriate.

    The 'all' setting can be used to return all pools, even if the rules do
    not pass. (i.e. show pools that are incompatible for your hardware)
    """
    columns = [
        'id', 'quantity', 'consumed', 'endDate', 'productName',
        'providedProducts', 'productId', 'attributes', 'pool_type',
        'service_level', 'service_type', 'suggested', 'contractNumber',
        'management_enabled'
    ]

    pool_stash = PoolStash(Facts(require(ENT_DIR), require(PROD_DIR)))
    dlist = pool_stash.get_filtered_pools_list(active_on, not get_all,
                                               overlapping, uninstalled, text,
                                               filter_string)

    for pool in dlist:
        pool_wrapper = PoolWrapper(pool)
        pool['providedProducts'] = pool_wrapper.get_provided_products()
        if allows_multi_entitlement(pool):
            pool['multi-entitlement'] = "Yes"
        else:
            pool['multi-entitlement'] = "No"

        support_attrs = pool_wrapper.get_product_attributes(
            "support_level", "support_type")
        pool['service_level'] = support_attrs['support_level']
        pool['service_type'] = support_attrs['support_type']
        pool['suggested'] = pool_wrapper.get_suggested_quantity()
        pool['pool_type'] = pool_wrapper.get_pool_type()
        pool['management_enabled'] = pool_wrapper.management_enabled()

        if pool['suggested'] is None:
            pool['suggested'] = ""

    # no default, so default is None if key not found
    data = [_sub_dict(pool, columns) for pool in dlist]
    for d in data:
        if int(d['quantity']) < 0:
            d['quantity'] = _('Unlimited')
        else:
            d['quantity'] = str(int(d['quantity']) - int(d['consumed']))

        d['endDate'] = format_date(isodate.parse_date(d['endDate']))
        del d['consumed']

    return data
예제 #7
0
    def test_no_entitlement_for_installed_product_shows_invalid(self):
        product = StubProduct("product1")
        product_directory = StubCertificateDirectory([
            StubProductCertificate(product)])
        entitlement_directory = StubCertificateDirectory([])

        facts = Facts(None)
        facts.product_dir = product_directory
        facts.entitlement_dir = entitlement_directory
        facts_dict = facts.get_facts()
        self.assertEquals("invalid", facts_dict['system.entitlements_valid'])
예제 #8
0
 def __init__(self, lock=ActionLock(), uep=None):
     self.lock = lock
     self.uep = uep
     self.certlib = CertLib(self.lock, uep=self.uep)
     self.repolib = RepoLib(self.lock, uep=self.uep)
     self.factlib = FactLib(self.lock, uep=self.uep)
     self.profilelib = PackageProfileLib(self.lock, uep=self.uep)
     self.installedprodlib = InstalledProductsLib(self.lock, uep=self.uep)
     #healinglib requires a fact set in order to get socket count
     facts = Facts()
     self.healinglib = HealingLib(self.lock,
                                  uep=self.uep,
                                  facts_dict=facts.to_dict())
예제 #9
0
    def test_future_dated_entitlement_shows_invalid(self):
        product = StubProduct("product1")
        product_directory = StubCertificateDirectory([
                StubProductCertificate(product)])
        entitlement_directory = StubCertificateDirectory([
                StubEntitlementCertificate(product,
                                           start_date=(datetime.now() + timedelta(days=1365)))])

        facts = Facts(None)
        facts.product_dir = product_directory
        facts.entitlement_dir = entitlement_directory
        facts_dict = facts.get_facts()
        self.assertEquals("invalid", facts_dict['system.entitlements_valid'])
예제 #10
0
    def __init__(self):
        """
        Create a new firstboot Module for the 'register' screen.
        """
        RhsmFirstbootModule.__init__(self,        # Firstboot module title
        # Note: translated title needs to be unique across all
        # firstboot modules, not just the rhsm ones. See bz #828042
                _("Subscription Management Registration"),
                _("Subscription Registration"),
                200.1, 109.10)

        backend = managergui.Backend()
        self.plugin_manager = require(PLUGIN_MANAGER)
        registergui.RegisterScreen.__init__(self, backend, Facts())

        #insert our new screens
        screen = SelectSLAScreen(self, backend)
        screen.index = self._screens[registergui.SELECT_SLA_PAGE].index
        self._screens[registergui.SELECT_SLA_PAGE] = screen
        self.register_notebook.remove_page(screen.index)
        self.register_notebook.insert_page(screen.container,
                                           position=screen.index)

        screen = PerformRegisterScreen(self, backend)
        self._screens[registergui.PERFORM_REGISTER_PAGE] = screen

        screen = ManuallySubscribeScreen(self, backend)
        self._screens.append(screen)
        screen.index = self.register_notebook.append_page(screen.container)

        # Will be False if we are on an older RHEL version where
        # rhn-client-tools already does some things so we don't have to.
        self.standalone = True
        distribution = Hardware().get_distribution()
        log.debug("Distribution: %s" % str(distribution))
        try:
            dist_version = float(distribution[1])
            # We run this for Fedora as well, but all we really care about here
            # is if this is prior to RHEL 7, so this comparison should be safe.
            if dist_version < 7:
                self.standalone = False
        except Exception, e:
            log.error("Unable to parse a distribution version.")
            log.exception(e)
예제 #11
0
    def __init__(self):
        """
        Create a new firstboot Module for the 'register' screen.
        """
        super(moduleClass, self).__init__()

        self.mode = constants.MODE_REGULAR
        self.title = _("Subscription Management Registration")
        self.sidebarTitle = _("Subscription Registration")
        self.priority = 200.1

        # NOTE: all of this is copied form former firstboot_base module
        # and may no longer be needed
        # set this so subclasses can override behaviour if needed
        self._is_compat = False

        reg_info = registergui.RegisterInfo()
        self.backend = managergui.Backend()
        self.plugin_manager = inj.require(inj.PLUGIN_MANAGER)
        self.register_widget = registergui.FirstbootWidget(
            self.backend, Facts(), reg_info)
        self.register_widget.connect("notify::screen-ready",
                                     self._on_screen_ready_change)

        # Will be False if we are on an older RHEL version where
        # rhn-client-tools already does some things so we don't have to.
        self.standalone = True
        distribution = Hardware().get_distribution()
        log.debug("Distribution: %s" % str(distribution))

        try:
            dist_version = float(distribution[1])
            # We run this for Fedora as well, but all we really care about here
            # is if this is prior to RHEL 7, so this comparison should be safe.
            if dist_version < 7:
                self.standalone = False
        except Exception, e:
            log.error("Unable to parse a distribution version.")
            log.exception(e)
예제 #12
0
    def __init__(self):
        """
        Create a new firstboot Module for the 'register' screen.
        """
        RhsmFirstbootModule.__init__(
            self,  # Firstboot module title
            # Note: translated title needs to be unique across all
            # firstboot modules, not just the rhsm ones. See bz #828042
            _("Subscription Management Registration"),
            _("Subscription Registration"),
            200.1,
            109.10)

        backend = managergui.Backend()
        self.plugin_manager = require(PLUGIN_MANAGER)
        registergui.RegisterScreen.__init__(self, backend, Facts())

        #insert our new screens
        screen = SelectSLAScreen(self, backend)
        screen.index = self._screens[registergui.SELECT_SLA_PAGE].index
        self._screens[registergui.SELECT_SLA_PAGE] = screen
        self.register_notebook.remove_page(screen.index)
        self.register_notebook.insert_page(screen.container,
                                           position=screen.index)

        screen = PerformRegisterScreen(self, backend)
        self._screens[registergui.PERFORM_REGISTER_PAGE] = screen

        screen = ManuallySubscribeScreen(self, backend)
        self._screens.append(screen)
        screen.index = self.register_notebook.append_page(screen.container)

        self.manual_message = None

        self._skip_apply_for_page_jump = False
        self._cached_credentials = None
        self._registration_finished = False

        self.interface = None
예제 #13
0
    def _init_sla(self):
        if self.skip_auto_subscribe():
            return self._move_to_manual_install(
                _("You have opted to skip auto-subscribe."))

        # sla autosubscribe time. load up the possible slas, to decide if
        # we need to display the selection screen, or go to the confirm
        # screen.
        # XXX this should really be done async.

        controller = autobind.init_controller(self.backend, self.consumer,
                                              Facts())

        # XXX see autobind.AutobindWizard load() and _show_initial_screen
        # for matching error handling.
        try:
            controller.load()
        except autobind.ServiceLevelNotSupportedException:
            message = _(
                "Unable to auto-subscribe, server does not support service levels. Please run 'Subscription Manager' to manually subscribe."
            )
            return self._move_to_manual_install(message)

        except autobind.NoProductsException:
            message = _(
                "No installed products on system. No need to update certificates at this time."
            )
            return self._move_to_manual_install(message)

        except autobind.AllProductsCoveredException:
            message = _(
                "All installed products are covered by valid entitlements. Please run 'Subscription Manager' to subscribe to additional products."
            )
            return self._move_to_manual_install(message)

        except socket.error, e:
            handle_gui_exception(e, None, self.registerWin)
            return
예제 #14
0
def getInstalledProductStatus(product_directory=None,
                              entitlement_directory=None,
                              facts=None):
    """
     Returns the Installed products and their subscription states
    """
    # allow us to stub these out for testing
    if product_directory is None:
        product_directory = certdirectory.ProductDirectory()
    if entitlement_directory is None:
        entitlement_directory = certdirectory.EntitlementDirectory()
    if facts is None:
        facts = Facts().get_facts()

    product_status = []

    sorter = CertSorter(product_directory, entitlement_directory, facts)

    for installed_product in sorter.installed_products:
        product_cert = sorter.installed_products[installed_product]
        for product in product_cert.getProducts():
            begin = ""
            end = ""
            calculator = ValidProductDateRangeCalculator(sorter)
            prod_status_range = calculator.calculate(product.getHash())
            if prod_status_range:
                # Format the date in user's local time as the date
                # range is returned in GMT.
                begin = formatDate(prod_status_range.begin())
                end = formatDate(prod_status_range.end())
            data = (product.getName(), installed_product, product.getVersion(),
                    product.getArch(), sorter.get_status(product.getHash()),
                    begin, end)
            product_status.append(data)

    return product_status
예제 #15
0
    def __init__(self,
                 backend=None,
                 facts=None,
                 ent_dir=None,
                 prod_dir=None,
                 auto_launch_registration=False):
        super(MainWindow, self).__init__()

        self.backend = backend or Backend()
        self.identity = require(IDENTITY)

        self.facts = facts or Facts(self.backend.entitlement_dir,
                                    self.backend.product_dir)
        # We need to make sure facts are loaded immediately, some GUI operations
        # are done in separate threads, and if facts try to load in another
        # thread the virt guest detection code breaks due to hwprobe's use of
        # signals.
        self.facts.get_facts()

        log.debug("Client Versions: %s " % get_client_versions())
        # Log the server version asynchronously
        ga_GLib.idle_add(self.log_server_version,
                         self.backend.cp_provider.get_consumer_auth_cp())

        settings = self.main_window.get_settings()

        # prevent gtk from trying to save a list of recently used files, which
        # as root, causes gtk warning:
        #  "Attempting to set the permissions of `/root/.local/share/recently-used.xbel'
        # The __name__ use is just for the 'origin' value gtk uses to store
        # where a Gtk.Settings value was set.
        settings.set_long_property('gtk-recent-files-max-age', 0,
                                   "%s:%s" % (__name__, type(self).__name__))

        self.product_dir = prod_dir or self.backend.product_dir
        self.entitlement_dir = ent_dir or self.backend.entitlement_dir

        self.system_facts_dialog = factsgui.SystemFactsDialog(self.facts)

        self.preferences_dialog = PreferencesDialog(self.backend,
                                                    self._get_window())

        self.repos_dialog = RepositoriesDialog(self.backend,
                                               self._get_window())

        self.import_sub_dialog = ImportSubDialog()

        self.network_config_dialog = networkConfig.NetworkConfigDialog()
        self.network_config_dialog.saveButton.connect("clicked",
                                                      self._config_changed)

        self.redeem_dialog = redeem.RedeemDialog(self.backend)

        self.installed_tab_icon = ga_Gtk.Image()
        self.installed_tab_icon.set_from_stock(ga_Gtk.STOCK_YES,
                                               ga_Gtk.IconSize.MENU)

        self.installed_tab = InstalledProductsTab(self.backend,
                                                  self.facts,
                                                  self.installed_tab_icon,
                                                  self,
                                                  ent_dir=self.entitlement_dir,
                                                  prod_dir=self.product_dir)
        self.my_subs_tab = MySubscriptionsTab(self.backend,
                                              self.main_window,
                                              ent_dir=self.entitlement_dir,
                                              prod_dir=self.product_dir)

        self.all_subs_tab = AllSubscriptionsTab(self.backend, self.facts,
                                                self.main_window)

        hbox = ga_Gtk.HBox(spacing=6)
        hbox.pack_start(self.installed_tab_icon, False, False, 0)
        hbox.pack_start(ga_Gtk.Label(self.installed_tab.get_label()), False,
                        False, 0)
        self.notebook.append_page(self.installed_tab.get_content(), hbox)
        hbox.show_all()

        self.notebook.append_page(self.my_subs_tab.get_content(),
                                  ga_Gtk.Label(self.my_subs_tab.get_label()))

        self.connect_signals({
            "on_register_menu_item_activate": self._register_item_clicked,
            "on_unregister_menu_item_activate": self._unregister_item_clicked,
            "on_import_cert_menu_item_activate":
            self._import_cert_item_clicked,
            "on_view_facts_menu_item_activate": self._facts_item_clicked,
            "on_proxy_config_menu_item_activate":
            self._proxy_config_item_clicked,
            "on_redeem_menu_item_activate": self._redeem_item_clicked,
            "on_preferences_menu_item_activate":
            self._preferences_item_clicked,
            "on_repos_menu_item_activate": self._repos_item_clicked,
            "on_about_menu_item_activate": self._about_item_clicked,
            "on_getting_started_menu_item_activate":
            self._getting_started_item_clicked,
            "on_online_docs_menu_item_activate":
            self._online_docs_item_clicked,
            "on_quit_menu_item_activate": ga_Gtk.main_quit,
        })

        # TODO: why is this defined in the init scope?
        # When something causes cert_sorter to upate it's state, refresh the gui
        # The cert directories being updated will cause this (either noticed
        # from a timer, or via cert_sort.force_cert_check).
        def on_cert_sorter_cert_change():
            # Update installed products
            self.installed_tab.update_products()
            self.installed_tab._set_validity_status()
            # Update attached subs
            self.my_subs_tab.update_subscriptions()
            # Update main window
            self.refresh()
            # Reset repos dialog, see bz 1132919
            self.repos_dialog = RepositoriesDialog(self.backend,
                                                   self._get_window())

        self.backend.cs.add_callback(on_cert_sorter_cert_change)

        self.main_window.show_all()

        # Check to see if already registered to old RHN/Spacewalk
        # and show dialog if so
        self._check_rhn_classic()

        # Update everything with compliance data
        self.backend.cs.notify()

        # managergui needs cert_sort.cert_monitor.run_check() to run
        # on a timer to detect cert changes from outside the gui
        # (via rhsmdd for example, or manually provisioned).
        ga_GLib.timeout_add(2000, self._on_cert_check_timer)

        if auto_launch_registration and not self.registered():
            self._register_item_clicked(None)
예제 #16
0
 def __init__(self, lock=None, uep=None, facts=None):
     DataLib.__init__(self, lock, uep)
     self.facts = facts
     if not self.facts:
         self.facts = Facts()
예제 #17
0
    def __init__(self,
                 backend=None,
                 consumer=None,
                 facts=None,
                 ent_dir=None,
                 prod_dir=None,
                 auto_launch_registration=False):
        super(MainWindow, self).__init__('mainwindow.glade')

        self.backend = backend or Backend()
        self.consumer = consumer or Consumer()
        self.facts = facts or Facts(self.backend.entitlement_dir,
                                    self.backend.product_dir)

        log.debug("Client Versions: %s " % get_client_versions())
        log.debug("Server Versions: %s " %
                  get_server_versions(self.backend.uep))

        self.product_dir = prod_dir or self.backend.product_dir
        self.entitlement_dir = ent_dir or self.backend.entitlement_dir

        self.system_facts_dialog = factsgui.SystemFactsDialog(
            self.backend, self.consumer, self.facts)

        self.registration_dialog = registergui.RegisterScreen(
            self.backend,
            self.consumer,
            self.facts,
            callbacks=[self.registration_changed])

        self.preferences_dialog = PreferencesDialog(self.backend,
                                                    self.consumer,
                                                    self._get_window())

        self.import_sub_dialog = ImportSubDialog()

        self.network_config_dialog = networkConfig.NetworkConfigDialog()
        self.network_config_dialog.xml.get_widget("closeButton").connect(
            "clicked", self._config_changed)

        self.redeem_dialog = redeem.RedeemDialog(self.backend, self.consumer)

        self.installed_tab_icon = gtk.Image()
        self.installed_tab_icon.set_from_stock(gtk.STOCK_YES,
                                               gtk.ICON_SIZE_MENU)

        self.installed_tab = InstalledProductsTab(self.backend,
                                                  self.consumer,
                                                  self.facts,
                                                  self.installed_tab_icon,
                                                  self,
                                                  ent_dir=self.entitlement_dir,
                                                  prod_dir=self.product_dir)
        self.my_subs_tab = MySubscriptionsTab(self.backend,
                                              self.consumer,
                                              self.facts,
                                              self.main_window,
                                              ent_dir=self.entitlement_dir,
                                              prod_dir=self.product_dir)

        self.all_subs_tab = AllSubscriptionsTab(self.backend, self.consumer,
                                                self.facts, self.main_window)

        hbox = gtk.HBox(spacing=6)
        hbox.pack_start(self.installed_tab_icon, False, False)
        hbox.pack_start(gtk.Label(self.installed_tab.get_label()), False,
                        False)
        self.notebook.append_page(self.installed_tab.get_content(), hbox)
        hbox.show_all()

        self.notebook.append_page(self.my_subs_tab.get_content(),
                                  gtk.Label(self.my_subs_tab.get_label()))

        self.glade.signal_autoconnect({
            "on_register_menu_item_activate":
            self._register_item_clicked,
            "on_unregister_menu_item_activate":
            self._unregister_item_clicked,
            "on_import_cert_menu_item_activate":
            self._import_cert_item_clicked,
            "on_view_facts_menu_item_activate":
            self._facts_item_clicked,
            "on_proxy_config_menu_item_activate":
            self._proxy_config_item_clicked,
            "on_redeem_menu_item_activate":
            self._redeem_item_clicked,
            "on_preferences_menu_item_activate":
            self._preferences_item_clicked,
            "on_about_menu_item_activate":
            self._about_item_clicked,
            "on_getting_started_menu_item_activate":
            self._getting_started_item_clicked,
            "on_online_docs_menu_item_activate":
            self._online_docs_item_clicked,
            "on_quit_menu_item_activate":
            gtk.main_quit,
        })

        def on_identity_change(filemonitor):
            self.consumer.reload()
            self.refresh()

        self.backend.monitor_identity(on_identity_change)

        self.main_window.show_all()
        self.refresh()

        # Check to see if already registered to old RHN/Spacewalk
        # and show dialog if so
        self._check_rhn_classic()

        if auto_launch_registration and not self.registered():
            self._register_item_clicked(None)
예제 #18
0
 def _get_facts(self):
     return Facts()
예제 #19
0
def find_first_invalid_date(ent_dir=None, product_dir=None, facts_dict=None):
    """
    Find the first date when the system is invalid at midnight
    GMT.

    WARNING: This method does *not* return the exact first datetime when
    we're invalid. Due to it's uses in the GUI it needs to
    return a datetime into the first day of being completely invalid, so
    the subscription assistant can search for that time and find expired
    products.

    If there are no products installed, return None, as there technically
    is no first invalid date.
    """
    if not ent_dir:
        ent_dir = EntitlementDirectory()
    if not product_dir:
        product_dir = ProductDirectory()
    if facts_dict is None:
        facts_dict = Facts().get_facts()

    current_date = datetime.now(GMT())

    if not product_dir.list():
        # If there are no products installed, return None, there is no
        # invalid date:
        log.debug("Unable to determine first invalid date, no products "
                  "installed.")
        return None

    # change _scan_entitlement_certs to take product lists,
    # run it for the future to figure this out
    # First check if we have anything installed but not entitled *today*:
    cs = cert_sorter.CertSorter(product_dir,
                                ent_dir,
                                facts_dict,
                                on_date=current_date)
    if not cs.is_valid():
        log.debug("Found unentitled products or partial stacks.")
        return current_date

    # Sort all the ent certs by end date. (ascending)
    all_ent_certs = ent_dir.list()

    def get_date(ent_cert):
        return ent_cert.validRange().end()

    all_ent_certs.sort(key=get_date)

    # Loop through all current and future entitlement certs, check validity
    # status on their end date, and return the first date where we're not
    # valid.
    for ent_cert in all_ent_certs:
        # Adding a timedelta of one day here so we can be sure we get a date
        # the subscription assitant (which does not use time) can use to search
        # for.
        end_date = ent_cert.validRange().end() + timedelta(days=1)
        if end_date < current_date:
            # This cert is expired, ignore it:
            continue
        log.debug("Checking cert: %s, end date: %s" %
                  (ent_cert.serialNumber(), end_date))

        # new cert_sort stuff, use _scan_for_entitled_products, since
        # we just need to know if stuff is expired
        cs = cert_sorter.CertSorter(product_dir,
                                    ent_dir,
                                    facts_dict,
                                    on_date=end_date)
        if not cs.is_valid():
            log.debug("Found non-valid status on %s" % end_date)
            return end_date
        else:
            log.debug("Valid status on %s" % end_date)

    # Should never hit this:
    raise Exception("Unable to determine first invalid date.")
예제 #20
0
    def __init__(self,
                 backend=None,
                 facts=None,
                 ent_dir=None,
                 prod_dir=None,
                 auto_launch_registration=False):
        super(MainWindow, self).__init__('mainwindow.glade')

        self.backend = backend or Backend()
        self.identity = require(IDENTITY)

        self.facts = facts or Facts(self.backend.entitlement_dir,
                                    self.backend.product_dir)
        # We need to make sure facts are loaded immediately, some GUI operations
        # are done in separate threads, and if facts try to load in another
        # thread the virt guest detection code breaks due to hwprobe's use of
        # signals.
        self.facts.get_facts()

        log.debug("Client Versions: %s " % get_client_versions())
        log.debug("Server Versions: %s " % get_server_versions(
            self.backend.cp_provider.get_consumer_auth_cp()))

        self.product_dir = prod_dir or self.backend.product_dir
        self.entitlement_dir = ent_dir or self.backend.entitlement_dir

        self.system_facts_dialog = factsgui.SystemFactsDialog(
            self.backend, self.facts)

        self.registration_dialog = registergui.RegisterScreen(
            self.backend, self.facts, self._get_window())

        self.preferences_dialog = PreferencesDialog(self.backend,
                                                    self._get_window())

        self.import_sub_dialog = ImportSubDialog()

        self.network_config_dialog = networkConfig.NetworkConfigDialog()
        self.network_config_dialog.xml.get_widget("closeButton").connect(
            "clicked", self._config_changed)

        self.redeem_dialog = redeem.RedeemDialog(self.backend)

        self.installed_tab_icon = gtk.Image()
        self.installed_tab_icon.set_from_stock(gtk.STOCK_YES,
                                               gtk.ICON_SIZE_MENU)

        self.installed_tab = InstalledProductsTab(self.backend,
                                                  self.facts,
                                                  self.installed_tab_icon,
                                                  self,
                                                  ent_dir=self.entitlement_dir,
                                                  prod_dir=self.product_dir)
        self.my_subs_tab = MySubscriptionsTab(self.backend,
                                              self.main_window,
                                              ent_dir=self.entitlement_dir,
                                              prod_dir=self.product_dir)

        self.all_subs_tab = AllSubscriptionsTab(self.backend, self.facts,
                                                self.main_window)

        hbox = gtk.HBox(spacing=6)
        hbox.pack_start(self.installed_tab_icon, False, False)
        hbox.pack_start(gtk.Label(self.installed_tab.get_label()), False,
                        False)
        self.notebook.append_page(self.installed_tab.get_content(), hbox)
        hbox.show_all()

        self.notebook.append_page(self.my_subs_tab.get_content(),
                                  gtk.Label(self.my_subs_tab.get_label()))

        self.glade.signal_autoconnect({
            "on_register_menu_item_activate":
            self._register_item_clicked,
            "on_unregister_menu_item_activate":
            self._unregister_item_clicked,
            "on_import_cert_menu_item_activate":
            self._import_cert_item_clicked,
            "on_view_facts_menu_item_activate":
            self._facts_item_clicked,
            "on_proxy_config_menu_item_activate":
            self._proxy_config_item_clicked,
            "on_redeem_menu_item_activate":
            self._redeem_item_clicked,
            "on_preferences_menu_item_activate":
            self._preferences_item_clicked,
            "on_about_menu_item_activate":
            self._about_item_clicked,
            "on_getting_started_menu_item_activate":
            self._getting_started_item_clicked,
            "on_online_docs_menu_item_activate":
            self._online_docs_item_clicked,
            "on_quit_menu_item_activate":
            gtk.main_quit,
        })

        def on_cert_change():
            # Update installed products
            self.installed_tab.update_products()
            self.installed_tab._set_validity_status()
            # Update attached subs
            self.my_subs_tab.update_subscriptions()
            # Update main window
            self.refresh()

        self.backend.cs.add_callback(on_cert_change)

        self.main_window.show_all()

        # Check to see if already registered to old RHN/Spacewalk
        # and show dialog if so
        self._check_rhn_classic()

        # Update everything with compliance data
        self.backend.cs.notify()

        if auto_launch_registration and not self.registered():
            self._register_item_clicked(None)