def PoolAttach(self, pools, quantity, proxy_options, locale, sender=None): self.ensure_registered() pools = dbus_utils.dbus_to_python(pools, expected_type=list) quantity = dbus_utils.dbus_to_python(quantity, expected_type=int) proxy_options = dbus_utils.dbus_to_python(proxy_options, expected_type=dict) locale = dbus_utils.dbus_to_python(locale, expected_type=str) Locale.set(locale) if quantity < 1: raise dbus.DBusException("Quantity must be a positive number.") cp = self.build_uep(proxy_options, proxy_only=True) attach_service = AttachService(cp) try: results = [] for pool in pools: resp = attach_service.attach_pool(pool, quantity) results.append(json.dumps(resp)) except Exception as e: log.exception(e) raise dbus.DBusException(str(e)) # TODO Likely should only call this if something is actually attached entcertlib.EntCertActionInvoker().update() return results
def AutoAttach(self, service_level, proxy_options, locale, sender=None): self.ensure_registered() service_level = dbus_utils.dbus_to_python(service_level, expected_type=str) or None proxy_options = dbus_utils.dbus_to_python(proxy_options, expected_type=dict) locale = dbus_utils.dbus_to_python(locale, expected_type=str) Locale.set(locale) cp = self.build_uep(proxy_options, proxy_only=True) # TODO: Change log.info() to: # raise dbus.DBusException('Auto-attaching is not allowed in simple content access mode') # in the next minor release of subscription-manager if is_simple_content_access(uep=cp) is True: log.info( "Calling D-Bus method AutoAttach() is deprecated, when Simple Content Access mode " "is used and it will be not be supported in the next minor release of " "subscription-manager") attach_service = AttachService(cp) try: resp = attach_service.attach_auto(service_level) except Exception as e: log.exception(e) raise dbus.DBusException(str(e)) # TODO Likely should only call this if something is actually attached entcertlib.EntCertActionInvoker().update() return json.dumps(resp)
def AutoAttach(self, service_level, proxy_options, sender=None): self.ensure_registered() service_level = dbus_utils.dbus_to_python(service_level, str) cp = self.build_uep(proxy_options, proxy_only=True) attach_service = AttachService(cp) try: resp = attach_service.attach_auto(service_level) except Exception as e: log.exception(e) raise dbus.DBusException(str(e)) # TODO Likely should only call this if something is actually attached entcertlib.EntCertActionInvoker().update() return json.dumps(resp)
def PoolAttach(self, pools, quantity, proxy_options, locale, sender=None): self.ensure_registered() pools = dbus_utils.dbus_to_python(pools, expected_type=list) quantity = dbus_utils.dbus_to_python(quantity, expected_type=int) proxy_options = dbus_utils.dbus_to_python(proxy_options, expected_type=dict) locale = dbus_utils.dbus_to_python(locale, expected_type=str) Locale.set(locale) if quantity < 1: raise dbus.DBusException("Quantity must be a positive number.") cp = self.build_uep(proxy_options, proxy_only=True) # TODO: Change log.info() to: # raise dbus.DBusException('Attaching of pool(s) is not allowed in simple content access mode') # in the next minor release of subscription-manager if is_simple_content_access(uep=cp) is True: log.info( "Calling D-Bus method PoolAttach() is deprecated, when Simple Content Access mode " "is used and it will be not be supported in the next minor release of " "subscription-manager") attach_service = AttachService(cp) try: results = [] for pool in pools: resp = attach_service.attach_pool(pool, quantity) results.append(json.dumps(resp)) except Exception as e: log.exception(e) raise dbus.DBusException(str(e)) # TODO Likely should only call this if something is actually attached entcertlib.EntCertActionInvoker().update() return results
def perform(self): # inject identity = inj.require(inj.IDENTITY) uuid = identity.getConsumerId() consumer = self.uep.getConsumer(uuid) if 'autoheal' not in consumer or not consumer['autoheal']: log.info("Auto-heal disabled on server, skipping.") return 0 try: log.info("Checking if system requires healing.") today = datetime.datetime.now(certificate.GMT()) tomorrow = today + datetime.timedelta(days=1) # Check if we're invalid today and heal if so. If we are # valid, see if 24h from now is greater than our "valid until" # date, and heal for tomorrow if so. cs = inj.require(inj.CERT_SORTER) cert_updater = entcertlib.EntCertActionInvoker() if not cs.is_valid(): log.warn("Found invalid entitlements for today: %s" % today) self.plugin_manager.run("pre_auto_attach", consumer_uuid=uuid) ents = self.uep.bind(uuid, today) self.plugin_manager.run("post_auto_attach", consumer_uuid=uuid, entitlement_data=ents) # NOTE: we need to call EntCertActionInvoker.update after Healing.update # otherwise, the locking get's crazy # hmm, we use RLock, maybe we could use it here self.report = cert_updater.update() else: log.info("Entitlements are valid for today: %s" % today) if cs.compliant_until is None: # Edge case here, not even sure this can happen as we # should have a compliant until date if we're valid # today, but just in case: log.warn("Got valid status from server but no valid until date.") elif tomorrow > cs.compliant_until: log.warn("Entitlements will be invalid by tomorrow: %s" % tomorrow) self.plugin_manager.run("pre_auto_attach", consumer_uuid=uuid) ents = self.uep.bind(uuid, tomorrow) self.plugin_manager.run("post_auto_attach", consumer_uuid=uuid, entitlement_data=ents) self.report = cert_updater.update() else: log.info("Entitlements are valid for tomorrow: %s" % tomorrow) except Exception, e: log.error("Error attempting to auto-heal:") log.exception(e) self.report._exceptions.append(e) return self.report