(self, request, pk=None)
Operate Node

        Do some operation on node, start/stop/restart
Operate Node
Operate Node
def operate(self, request, pk=None):
        """
        Operate Node

        Do some operation on node, start/stop/restart
        """
        try:
            serializer = NodeOperationSerializer(data=request.data)
            if serializer.is_valid(raise_exception=True):
                action = serializer.validated_data.get("action")

                if action == "start":
                    try:
                        infos = self._agent_params(pk)

                        agent = AgentHandler(infos)
                        cid = agent.create(infos)
                        if cid:
                            Node.objects.filter(id=pk).update(cid=cid)
                            response = NodeCIDSerializer(data={"id": cid})
                            if response.is_valid(raise_exception=True):
                                return Response(
                                    ok(response.validated_data), status=status.HTTP_201_CREATED
                                )
                        else:
                            raise ResourceNotFound
                    except Exception as e:
                        raise e
                    if infos.get("status") == "running" or infos.get("status") == "deleting" or infos.get("status") == "deploying":
                        raise ResourceInUse
                    elif infos.get("status") == "":

                        pass
                    elif infos.get("status") == "stopped" or infos.get("status") == "deleted":
                        pass
                    elif infos.get("status") == "error":
                        pass
                    else:
                        pass

                elif action == "stop":
                    #todo
                    pass
                elif action == "restart":
                    # todo
                    pass
                else:
                    # todo
                    pass
        except Exception as e:
            return Response(
                err(e.args), status=status.HTTP_400_BAD_REQUEST
            )
def operate ( self , request , pk = None ) : try : serializer = NodeOperationSerializer ( data = request . data ) if serializer . is_valid ( raise_exception = True ) : action = serializer . validated_data . get ( "action" ) if action == "start" : try : infos = self . _agent_params ( pk ) agent = AgentHandler ( infos ) cid = agent . create ( infos ) if cid : Node . objects . filter ( id = pk ) . update ( cid = cid ) response = NodeCIDSerializer ( data = { "id" : cid } ) if response . is_valid ( raise_exception = True ) : return Response ( ok ( response . validated_data ) , status = status . HTTP_201_CREATED ) else : raise ResourceNotFound except Exception as e : raise e if infos . get ( "status" ) == "running" or infos . get ( "status" ) == "deleting" or infos . get ( "status" ) == "deploying" : raise ResourceInUse elif infos . get ( "status" ) == "" : pass elif infos . get ( "status" ) == "stopped" or infos . get ( "status" ) == "deleted" : pass elif infos . get ( "status" ) == "error" : pass else : pass elif action == "stop" : #todo pass elif action == "restart" : # todo pass else : # todo pass except Exception as e : return Response ( err ( e . args ) , status = status . HTTP_400_BAD_REQUEST )