Exemple #1
0
 def execute(self, cmd, *args, **kwargs):
     payload = pack({'cmd': cmd, 'args': args, 'kwargs': kwargs})
     resp = requests.post(self._service_uri, data=payload)
     if resp.status_code != 200:
         raise HTTPError(resp.status_code, resp.content)
     result = unpack(resp.content)
     if result.get('rc', 0):
         raise ServiceException(result.get('err_msg', 'Unknown exception'))
     return result.get('data', {})
Exemple #2
0
 def execute(self, cmd, *args, **kwargs):
     payload = pack({
         'cmd': cmd,
         'args': args,
         'kwargs': kwargs
         })
     resp = requests.post(self._service_uri, data=payload)
     if resp.status_code != 200:
         raise HTTPError(resp.status_code, resp.content)
     result = unpack(resp.content)
     if result.get('rc', 0):
         raise ServiceException(result.get('err_msg', 'Unknown exception'))
     return result.get('data', {})
Exemple #3
0
 def view(self):
     payload = unpack(request.data)
     method = getattr(self._service_obj, payload['cmd'], None)
     if not method:
         return error(ErrorCode.MethodNotFound,
                      "Cannot find command {}".format(payload['cmd']))
     try:
         data = method(*payload['args'], **payload['kwargs'])
         return pack({'rc': 0, 'data': data})
     except Exception, e:
         logging.exception("Error in executing command %s", payload['cmd'])
         return pack({
             'rc': getattr(e, 'code', ErrorCode.UnknownError),
             'err_msg': e.message
         })
Exemple #4
0
 def view(self):
     payload = unpack(request.data)
     method = getattr(self._service_obj, payload['cmd'], None)
     if not method:
         return error(ErrorCode.MethodNotFound,
                      "Cannot find command {}".format(payload['cmd']))
     try:
         data = method(*payload['args'], **payload['kwargs'])
         return pack({
             'rc': 0,
             'data': data})
     except Exception, e:
         logging.exception("Error in executing command %s", payload['cmd'])
         return pack({
             'rc': getattr(e, 'code', ErrorCode.UnknownError),
             'err_msg': e.message
             })