[docs]classAsyncPodClient(AsyncBaseClient):"""Async Client to create/update/delete Pods on remote JinaD"""_kind='pod'_endpoint='/pods'@if_aliveasyncdefarguments(self)->Optional[Dict]:"""Get all arguments accepted by a remote Pod/Deployment :return: dict arguments of remote JinaD """asyncwithaiohttp.request(method='GET',url=f'{self.store_api}/arguments',timeout=self.timeout)asresponse:ifresponse.status==HTTPStatus.OK:returnawaitresponse.json()@if_aliveasyncdefcreate(self,workspace_id:Union[str,'DaemonID'],payload:Dict,envs:Dict[str,str]={},)->Tuple[bool,str]:"""Create a remote Pod / Deployment :param workspace_id: id of workspace where the Pod would live in :param payload: json payload :param envs: dict of env vars to be passed :return: (True if Pod/Deployment creation succeeded) and (the identity of the spawned Pod/Deployment or, error message) """envs=([('envs',f'{k}={v}')fork,vinenvs.items()]ifenvsandisinstance(envs,Dict)else[])asyncwithaiohttp.request(method='POST',url=self.store_api,params=[('workspace_id',daemonize(workspace_id))]+envs,json=payload,timeout=self.timeout,)asresponse:response_json=awaitresponse.json()ifresponse.status==HTTPStatus.CREATED:self._logger.success(f'successfully created a {self._kind.title()}{response_json} in workspace {workspace_id}')returnTrue,response_jsonelifresponse.status==HTTPStatus.UNPROCESSABLE_ENTITY:field_msg=(f' for field {response_json["detail"][0]["loc"][1]}'if'loc'inresponse_json["detail"][0]else'')error_msg=f'validation error in the payload: {response_json["detail"][0]["msg"]}{field_msg}'self._logger.error(error_msg)returnFalse,error_msgelse:error_msg=error_msg_from(response_json)self._logger.error(f'{self._kind.title()} creation failed as: {error_msg}')returnFalse,error_msg@if_aliveasyncdefdelete(self,id:Union[str,'DaemonID'],**kwargs)->bool:"""Delete a remote Pod/Deployment :param id: the identity of the Pod/Deployment :param kwargs: keyword arguments :return: True if the deletion is successful """asyncwithaiohttp.request(method='DELETE',url=f'{self.store_api}/{daemonize(id,self._kind)}',timeout=self.timeout,)asresponse:response_json=awaitresponse.json()ifresponse.status!=HTTPStatus.OK:self._logger.error(f'deletion of {self._kind.title()}{id} failed: {error_msg_from(response_json)}')returnresponse.status==HTTPStatus.OK
[docs]classPodClient(AsyncToSyncMixin,AsyncPodClient):"""Client to create/update/delete Pods on remote JinaD"""