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)
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)
def create_checkin_request(): """Create request object to send with Checkin""" cpu = psutil.cpu_times() mem = psutil.virtual_memory() request = CheckinRequest( gateway_id=snowflake.snowflake(), magma_pkg_version='fake_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, ), ) return request