Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
    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)
Пример #4
0
    def _enable_content(cp, consumer: dict) -> None:
        """
        Try to enable content. Try to do auto-attach in non-SCA mode or try to do refresh SCA mode.
        :param cp: Object representing connection to candlepin server
        :param consumer: Dictionary representing consumer
        :return: None
        """
        content_access_mode = consumer["owner"]["contentAccessMode"]
        enabled_content = None

        if content_access_mode == "entitlement":
            log.debug("Auto-attaching due to enable_content option")
            attach_service = AttachService(cp)
            enabled_content = attach_service.attach_auto()
        elif content_access_mode == "org_environment":
            log.debug(
                "Refreshing due to enabled_content option and simple content access mode"
            )
            entitlement_service = EntitlementService(cp)
            # TODO: try get anything useful from refresh result. It is not possible atm.
            entitlement_service.refresh(remove_cache=False, force=False)
        else:
            log.error(
                f"Unable to enable content due to unsupported content access mode: "
                f"{content_access_mode}")

        # When it was possible to enable content, then extend consumer
        # with information about enabled content
        if enabled_content is not None:
            consumer["enabledContent"] = enabled_content
Пример #5
0
    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)
Пример #6
0
    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)
        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)
Пример #7
0
    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