Ejemplo n.º 1
0
    def RegisterWithActivationKeys(self, org, activation_keys, options,
                                   connection_options, locale):
        """
        Note this method is registration ONLY.  Auto-attach is a separate process.
        """
        connection_options = dbus_utils.dbus_to_python(connection_options,
                                                       expected_type=dict)
        options = dbus_utils.dbus_to_python(options, expected_type=dict)
        options["activation_keys"] = dbus_utils.dbus_to_python(
            activation_keys, expected_type=list)
        org = dbus_utils.dbus_to_python(org, expected_type=str)
        locale = dbus_utils.dbus_to_python(locale, expected_type=str)

        with DBusSender() as dbus_sender:
            dbus_sender.set_cmd_line(sender=self.sender,
                                     cmd_line=self.cmd_line)
            Locale.set(locale)
            cp = self.build_uep(connection_options)

            register_service = RegisterService(cp)
            consumer = register_service.register(org, **options)

            log.debug("System registered, updating entitlements if needed")
            ent_cert_lib = EntCertActionInvoker()
            ent_cert_lib.update()

            dbus_sender.reset_cmd_line()

        return json.dumps(consumer)
Ejemplo n.º 2
0
    def Register(self, org, username, password, options, connection_options, locale):
        """
        This method registers the system using basic auth
        (username and password for a given org).
        For any option that is required but not included the default will be
        used.

        Options is a dict of strings that modify the outcome of this method.

        Note this method is registration ONLY.  Auto-attach is a separate process.
        """
        if self.is_registered():
            raise dbus.DBusException("This system is already registered")

        org = dbus_utils.dbus_to_python(org, expected_type=str)
        connection_options = dbus_utils.dbus_to_python(connection_options, expected_type=dict)
        connection_options['username'] = dbus_utils.dbus_to_python(username, expected_type=str)
        connection_options['password'] = dbus_utils.dbus_to_python(password, expected_type=str)
        options = dbus_utils.dbus_to_python(options, expected_type=dict)
        locale = dbus_utils.dbus_to_python(locale, expected_type=str)

        Locale.set(locale)
        cp = self.build_uep(connection_options)

        register_service = RegisterService(cp)
        consumer = register_service.register(org, **options)
        return json.dumps(consumer)
Ejemplo n.º 3
0
    def Register(self, org, username, password, options, connection_options):
        """
        This method registers the system using basic auth
        (username and password for a given org).
        For any option that is required but not included the default will be
        used.

        Options is a dict of strings that modify the outcome of this method.

        Note this method is registration ONLY.  Auto-attach is a separate process.
        """
        if self.is_registered():
            raise dbus.DBusException("This system is already registered")

        connection_options = dbus_utils.dbus_to_python(connection_options)
        connection_options['username'] = dbus_utils.dbus_to_python(username)
        connection_options['password'] = dbus_utils.dbus_to_python(password)
        cp = self.build_uep(connection_options)

        options = dbus_utils.dbus_to_python(options)
        org = dbus_utils.dbus_to_python(org)

        register_service = RegisterService(cp)
        consumer = register_service.register(org, **options)
        return json.dumps(consumer)
Ejemplo n.º 4
0
def _auto_register(cp_provider, log):
    """
    Try to perform auto-registration
    :param cp_provider: provider of connection to candlepin server
    :param log: logging object
    :return: None
    """
    log.debug("Trying to do auto-registration of this system")

    identity = inj.require(inj.IDENTITY)
    if identity.is_valid() is True:
        log.debug("System already registered. Skipping auto-registration")
        return

    log.debug("Trying to detect cloud provider")

    # Try to detect cloud provider first. Use lower threshold in this case,
    # because we want to have more sensitive detection in this case
    # (automatic registration is more important than reporting of facts)
    cloud_list = detect_cloud_provider(threshold=0.3)
    if len(cloud_list) == 0:
        log.warning("This system does not run on any supported cloud provider. Skipping auto-registration")
        sys.exit(-1)

    # When some cloud provider(s) was detected, then try to collect metadata
    # and signature
    cloud_info = _collect_cloud_info(cloud_list, log)
    if len(cloud_info) == 0:
        log.warning("It was not possible to collect any cloud metadata. Unable to perform auto-registration")
        sys.exit(-1)

    # Get connection not using any authentication
    cp = cp_provider.get_no_auth_cp()

    # Try to get JWT token from candlepin (cloud registration adapter)
    try:
        jwt_token = cp.getJWToken(
            cloud_id=cloud_info["cloud_id"],
            metadata=cloud_info["metadata"],
            signature=cloud_info["signature"],
        )
    except Exception as err:
        log.error("Unable to get JWT token: {err}".format(err=str(err)))
        log.warning("Canceling auto-registration")
        sys.exit(-1)

    # Try to register using JWT token
    register_service = RegisterService(cp=cp)
    # Organization ID is set to None, because organization ID is
    # included in JWT token
    try:
        register_service.register(org=None, jwt_token=jwt_token)
    except Exception as err:
        log.error("Unable to auto-register: {err}".format(err=err))
        sys.exit(-1)
    else:
        log.debug("Auto-registration performed successfully")
        sys.exit(0)
def _auto_register(cp_provider, log):
    """
    Try to perform auto-registration
    :param cp_provider: provider of connection to candlepin server
    :param log: logging object
    :return: None
    """
    log.debug("Trying to do auto-registration of this system")

    identity = inj.require(inj.IDENTITY)
    if identity.is_valid() is True:
        log.debug('System already registered. Skipping auto-registration')
        return

    log.debug('Trying to detect cloud provider')

    # Try to detect cloud provider first
    cloud_list = detect_cloud_provider()
    if len(cloud_list) == 0:
        log.warning('This system does not run on any supported cloud provider. Skipping auto-registration')
        sys.exit(-1)

    # When some cloud provider(s) was detected, then try to collect metadata
    # and signature
    cloud_info = collect_cloud_info(cloud_list)
    if len(cloud_info) == 0:
        log.warning('It was not possible to collect any cloud metadata. Unable to perform auto-registration')
        sys.exit(-1)

    # Get connection not using any authentication
    cp = cp_provider.get_no_auth_cp()

    # Try to get JWT token from candlepin (cloud registration adapter)
    try:
        jwt_token = cp.getJWToken(
            cloud_id=cloud_info['cloud_id'],
            metadata=cloud_info['metadata'],
            signature=cloud_info['signature']
        )
    except Exception as err:
        log.error('Unable to get JWT token: {err}'.format(err=str(err)))
        log.warning('Canceling auto-registration')
        sys.exit(-1)

    # Try to register using JWT token
    register_service = RegisterService(cp=cp)
    # Organization ID is set to None, because organization ID is
    # included in JWT token
    try:
        register_service.register(org=None, jwt_token=jwt_token)
    except Exception as err:
        log.error("Unable to auto-register: {err}".format(err=err))
        sys.exit(-1)
    else:
        log.debug("Auto-registration performed successfully")
        sys.exit(0)
Ejemplo n.º 6
0
    def RegisterWithActivationKeys(self, org, activation_keys, options, connection_options):
        """
        Note this method is registration ONLY.  Auto-attach is a separate process.
        """
        connection_options = dbus_utils.dbus_to_python(connection_options)
        cp = self.build_uep(connection_options)

        options = dbus_utils.dbus_to_python(options)
        options['activation_keys'] = dbus_utils.dbus_to_python(activation_keys)
        org = dbus_utils.dbus_to_python(org)

        register_service = RegisterService(cp)
        consumer = register_service.register(org, **options)
        return json.dumps(consumer)
Ejemplo n.º 7
0
    def RegisterWithActivationKeys(self, org, activation_keys, options, connection_options, locale):
        """
        Note this method is registration ONLY.  Auto-attach is a separate process.
        """
        connection_options = dbus_utils.dbus_to_python(connection_options, expected_type=dict)
        options = dbus_utils.dbus_to_python(options, expected_type=dict)
        options['activation_keys'] = dbus_utils.dbus_to_python(activation_keys, expected_type=list)
        org = dbus_utils.dbus_to_python(org, expected_type=str)
        locale = dbus_utils.dbus_to_python(locale, expected_type=str)

        Locale.set(locale)
        cp = self.build_uep(connection_options)

        register_service = RegisterService(cp)
        consumer = register_service.register(org, **options)
        return json.dumps(consumer)
Ejemplo n.º 8
0
    def Register(self, org, username, password, options, connection_options,
                 locale):
        """
        This method registers the system using basic auth
        (username and password for a given org).
        For any option that is required but not included the default will be
        used.

        Options is a dict of strings that modify the outcome of this method.

        Note this method is registration ONLY.  Auto-attach is a separate process.
        """
        if self.is_registered():
            raise dbus.DBusException("This system is already registered")

        org = dbus_utils.dbus_to_python(org, expected_type=str)
        connection_options = dbus_utils.dbus_to_python(connection_options,
                                                       expected_type=dict)
        connection_options['username'] = dbus_utils.dbus_to_python(
            username, expected_type=str)
        connection_options['password'] = dbus_utils.dbus_to_python(
            password, expected_type=str)
        options = dbus_utils.dbus_to_python(options, expected_type=dict)
        locale = dbus_utils.dbus_to_python(locale, expected_type=str)

        Locale.set(locale)
        cp = self.build_uep(connection_options)

        register_service = RegisterService(cp)

        # Try to get organization from the list available organizations, when the list contains
        # only one item, then register_service.determine_owner_key will return this organization
        if not org:
            org = register_service.determine_owner_key(
                username=connection_options['username'],
                get_owner_cb=self._get_owner_cb,
                no_owner_cb=self._no_owner_cb)

        # When there is more organizations, then signal was triggered in callback method
        # _get_owner_cb, but some exception has to be raised here to not try registration process
        if not org:
            raise OrgNotSpecifiedException(
                username=connection_options['username'])

        consumer = register_service.register(org, **options)

        return json.dumps(consumer)
Ejemplo n.º 9
0
    def Register(self, org, username, password, options, connection_options,
                 locale):
        """
        This method registers the system using basic auth
        (username and password for a given org).
        For any option that is required but not included the default will be
        used.

        Options is a dict of strings that modify the outcome of this method.

        Note this method is registration ONLY.  Auto-attach is a separate process.
        """
        if self.is_registered():
            raise dbus.DBusException("This system is already registered")

        org = dbus_utils.dbus_to_python(org, expected_type=str)
        connection_options = dbus_utils.dbus_to_python(connection_options,
                                                       expected_type=dict)
        connection_options["username"] = dbus_utils.dbus_to_python(
            username, expected_type=str)
        connection_options["password"] = dbus_utils.dbus_to_python(
            password, expected_type=str)
        options = dbus_utils.dbus_to_python(options, expected_type=dict)
        locale = dbus_utils.dbus_to_python(locale, expected_type=str)

        with DBusSender() as dbus_sender:
            dbus_sender.set_cmd_line(sender=self.sender,
                                     cmd_line=self.cmd_line)
            Locale.set(locale)
            cp = self.build_uep(connection_options)

            register_service = RegisterService(cp)

            # Try to get organization from the list available organizations, when the list contains
            # only one item, then register_service.determine_owner_key will return this organization
            if not org:
                org = register_service.determine_owner_key(
                    username=connection_options["username"],
                    get_owner_cb=self._get_owner_cb,
                    no_owner_cb=self._no_owner_cb,
                )

            # When there is more organizations, then signal was triggered in callback method
            # _get_owner_cb, but some exception has to be raised here to not try registration process
            if not org:
                raise OrgNotSpecifiedException(
                    username=connection_options["username"])

            # Remove 'enable_content' option, because it will not be proceed in register service
            enable_content = self._remove_enable_content_option(options)

            consumer = register_service.register(org, **options)

            # When consumer is created, then we can try to enabled content, when it was
            # requested in options.
            if enable_content is True:
                self._enable_content(cp, consumer)

            dbus_sender.reset_cmd_line()

        return json.dumps(consumer)