Пример #1
0
 def POST(self):
     '''handle POST calls'''
     headers = cherrypy.request.headers
     cmd = dict()
     try:
         cmd.update(headers)
     except KeyError, exp:
         raise cherrypy.HTTPError(400)
Пример #2
0
 def DELETE(self):
     '''handle DELETE calls'''
     # parse the input
     headers = cherrypy.request.headers
     cmd = dict()
     try:
         cmd.update(headers)
     except KeyError, exp:
         raise cherrypy.HTTPError(400)
Пример #3
0
    def _postCommandAndWait(self, name, cmdObject, args=None):
        '''
        Post a command to the server and then post a get to
        get the results.  This will set the wait parameter
        in the get to ensure we wait untill the get returns
        '''
        if (args is None):
            args = {}

        cmd = {}
        cmd['name'] = name
        cmd['object'] = cmdObject
        cmd.update(args)

        url = '%s/api/v1/cblr/session/%d/command' % (self.url, self.session)

        # post the command
        cmdobj = self._doPost(url, cmd)

        try:
            # reset our keepalive - we just did a command
            self.keepaliveSec = 0

            # now wait for the reply
            url += '/%d' % cmdobj['id']

            ret = self._doGet(url, params={'wait':'true'})

        except KeyboardInterrupt:
            # we got a keyboard interupt.  Try to cancel
            # the pending command
            cancel = {'id' : cmdobj['id'], 'status' : 'cancel'}
            self._doPut(url, data_dict=cancel)

            print "Command Canceled"
            raise CliCommandCanceled("Command canceled")

        err = ret.get('result_code', 0)
        if (err != 0):
            raise CmdSensorWindowsError(err)

        return ret
Пример #4
0
    def _postCommandAndWait(self, name, cmdObject, args=None):
        '''
        Post a command to the server and then post a get to
        get the results.  This will set the wait parameter
        in the get to ensure we wait untill the get returns
        '''
        if (args is None):
            args = {}

        cmd = {}
        cmd['name'] = name
        cmd['object'] = cmdObject
        cmd.update(args)

        url = '%s/api/v1/cblr/session/%d/command' % (self.url, self.session)

        # post the command
        cmdobj = self._doPost(url, cmd)

        try:
            # reset our keepalive - we just did a command
            self.keepaliveSec = 0

            # now wait for the reply
            url += '/%d' % cmdobj['id']

            ret = self._doGet(url, params={'wait':'true'})

        except KeyboardInterrupt:
            # we got a keyboard interupt.  Try to cancel
            # the pending command
            cancel = {'id' : cmdobj['id'], 'status' : 'cancel'}
            self._doPut(url, data_dict=cancel)

            print "Command Canceled"
            raise CliCommandCanceled("Command canceled")

        err = ret.get('result_code', 0)
        if (err != 0):
            raise CmdSensorWindowsError(err)

        return ret