Example #1
0
def test_send_checkin(proxy_cloud_connections=True):
    """Send checkin using either proxy or direct to cloud connection"""
    chan = ServiceRegistry.get_rpc_channel(
            'checkind', ServiceRegistry.CLOUD,
            proxy_cloud_connections=proxy_cloud_connections)
    client = CheckindStub(chan)
    request = create_checkin_request()

    checkin_timeout = 1000
    client.Checkin(request, checkin_timeout)
Example #2
0
    async def _checkin(self, service_statusmeta):
        """
        if previous checkin is successful, create a new channel
        (to make sure the channel does't become stale). Otherwise,
        keep the existing channel.
        """
        if self._checkin_client is None:
            chan = ServiceRegistry.get_rpc_channel(
                    'checkind', ServiceRegistry.CLOUD)
            self._checkin_client = CheckindStub(chan)

        mconfig = self._service.mconfig

        request = CheckinRequest(
            gateway_id=snowflake.snowflake(),
            system_status=self._system_status(),
            platform_info=self._platform_info(),
            machine_info=self._machine_info(),
        )
        logging.debug('Checkin request:\n%s', request)

        for statusmeta in service_statusmeta.values():
            request.status.meta.update(statusmeta)

        try:
            await grpc_async_wrapper(
                self._checkin_client.Checkin.future(
                    request, mconfig.checkin_timeout,
                ),
                self._loop)
            self._checkin_done()
        except grpc.RpcError as err:
            self._checkin_error(err)
Example #3
0
    async def _checkin(self, service_statusmeta):
        """
        if previous checkin is successful, create a new channel
        (to make sure the channel does't become stale). Otherwise,
        keep the existing channel.
        """
        if self._checkin_client is None:
            chan = ServiceRegistry.get_rpc_channel('checkind',
                                                   ServiceRegistry.CLOUD)
            self._checkin_client = CheckindStub(chan)

        mconfig = self._service.mconfig
        cpu = psutil.cpu_times()
        mem = psutil.virtual_memory()
        try:
            gw_ip = get_ip_from_if('tun0')  # look for tun0 interface
        except ValueError:
            gw_ip = 'N/A'

        request = CheckinRequest(
            gateway_id=snowflake.snowflake(),
            magma_pkg_version=self._service.version,
            system_status=SystemStatus(
                cpu_user=int(cpu.user * 1000),  # convert second to millisecond
                cpu_system=int(cpu.system * 1000),
                cpu_idle=int(cpu.idle * 1000),
                mem_total=mem.total,
                mem_available=mem.available,
                mem_used=mem.used,
                mem_free=mem.free,
                uptime_secs=int(time.time() - self._boot_time),
            ),
            vpn_ip=gw_ip,
            kernel_version=self._kernel_version,
            kernel_versions_installed=self._kernel_versions_installed,
        )

        for statusmeta in service_statusmeta.values():
            request.status.meta.update(statusmeta)

        try:
            await grpc_async_wrapper(
                self._checkin_client.Checkin.future(
                    request,
                    mconfig.checkin_timeout,
                ), self._loop)
            self._checkin_done()
        except grpc.RpcError as err:
            self._checkin_error(err)