Пример #1
0
    async def _bootstrap_now(self):
        """Main entrance to bootstrapping

        1. set self._state to BOOTSTRAPPING
        2. set up a gPRC channel and get a challenge (async)
        3. call _get_challenge_done_success  to deal with the response
        If any steps fails, a new _bootstrap_now call will be scheduled.
        """
        assert self._state != BootstrapState.BOOTSTRAPPING, \
                              'At most one bootstrap is happening'
        self._state = BootstrapState.BOOTSTRAPPING

        try:
            chan = ServiceRegistry.get_bootstrap_rpc_channel()
        except ValueError as exp:
            logging.error('Failed to get rpc channel: %s', exp)
            self._schedule_next_bootstrap(hard_failure=False)
            return

        client = BootstrapperStub(chan)
        try:
            result = await grpc_async_wrapper(
                client.GetChallenge.future(AccessGatewayID(id=self._hw_id)),
                self._loop)
            await self._get_challenge_done_success(result)

        except grpc.RpcError as err:
            self._get_challenge_done_fail(err)
Пример #2
0
    def _bootstrap_now(self):
        """Main entrance to bootstrapping

        1. set self._state to BOOTSTRAPPING
        2. set up a gPRC channel and get a challenge (async)
        3. setup _get_challenge_done callback
        If any steps fails, a new _bootstrap_now call will be scheduled.
        """
        assert self._state != BootstrapState.BOOTSTRAPPING, \
                              'At most one bootstrap is happening'
        self._state = BootstrapState.BOOTSTRAPPING

        try:
            chan = ServiceRegistry.get_bootstrap_rpc_channel()
        except ValueError as exp:
            logging.error('Failed to get rpc channel: %s', exp)
            self._retry_bootstrap(hard_failure=False)
            return

        logging.info('Beginning bootstrap process')
        client = BootstrapperStub(chan)
        future = client.GetChallenge.future(AccessGatewayID(id=self._hw_id))
        future.add_done_callback(
            lambda future: self._loop.call_soon_threadsafe(
                self._get_challenge_done, future))
Пример #3
0
    async def _request_sign(self, response):
        """Request a signed certificate

        set up a gPRC channel and set the response

        If it fails, schedule the next bootstrap,
        Otherwise _request_sign_done callback is called
        """
        try:
            chan = ServiceRegistry.get_bootstrap_rpc_channel()
        except ValueError as exp:
            logging.error('Failed to get rpc channel: %s', exp)
            BOOTSTRAP_EXCEPTION.labels(cause='RequestSignGetRPC').inc()
            self._schedule_next_bootstrap(hard_failure=False)
            return

        try:
            client = BootstrapperStub(chan)
            result = await grpc_async_wrapper(
                client.RequestSign.future(response),
                self._loop
            )
            await self._request_sign_done_success(result)

        except grpc.RpcError as err:
            self._request_sign_done_fail(err)
Пример #4
0
    def _request_sign(self, response):
        """Request a signed certificate

        set up a gPRC channel and set the response

        If it fails, call _retry_bootstrap,
        Otherwise _request_sign_done callback is added to the future
        """
        try:
            chan = ServiceRegistry.get_bootstrap_rpc_channel()
        except ValueError as exp:
            logging.error('Failed to get rpc channel: %s', exp)
            BOOTSTRAP_EXCEPTION.labels(cause='RequestSignGetRPC').inc()
            self._retry_bootstrap(hard_failure=False)
            return

        client = BootstrapperStub(chan)
        future = client.RequestSign.future(response)
        future.add_done_callback(
            lambda future: self._loop.call_soon_threadsafe(
                self._request_sign_done, future))