Exemplo n.º 1
0
 def defParser(cls, response):
     '''
     Default parser
     - It 
     [in]
     response: A HTTP response 
     '''
     resultJSON = json.load(response)
     Logger.DbgLog('Parse fetcher response status: %s' % resultJSON['status'])
     return resultJSON['result']
Exemplo n.º 2
0
def test(db):
    udrdata1 = db.createCacheData('FBUDR1')
    udrdata1.setLastFetchTS(time.time())
    Logger.DbgLog('Fetched TS: {0}'.format(udrdata1.getLastFetchTS()))

    ret = udrdata1.clearData()
    assert (ret)
    ret = udrdata1.setData([('u001', '"pid1", "pid2"'),
                            ('u002', '"pid3", "pid4"')])
    assert (ret)
    ret = udrdata1.getData()
    assert (len(ret) > 0)
    print ret
Exemplo n.º 3
0
    def feed(self):
        data = self.__cache.getData()
        if (len(data) == 0): return True

        token = UDRFeeder.__createToken(self.__authKey, self.__group_cid)

        feedData = {
            'udrId': self.__cache.getName(),
            'group': self.__group,
            'cid': self.__cid,
            'authId': self.__authId,
            'authToken': token[0],
            'timestamp': token[1],
            'list': [],
        }

        for d in data:
            feedData['list'].append({'key': d[0], 'value': d[1]})

        urlParseResult = urlparse.urlparse(self.__ERUDRFeedAPI)

        conn = None
        if (urlParseResult.scheme == 'https'):
            conn = httplib.HTTPSConnection(urlParseResult.netloc)
        else:
            conn = httplib.HTTPConnection(urlParseResult.netloc)

        feedDataJSON = json.dumps(feedData)

        conn.request('POST', urlParseResult.path, feedDataJSON,
                     {'Content-Type': 'application/json'})

        res = conn.getresponse()

        ret = False
        if (res.status == 200):
            result = res.read()
            if (result == 'success'):
                Logger.DbgLog('API server processed completely.')
                self.__cache.clearData()
                ret = True
            else:
                Logger.ErrorLog('Response from ER API server: %s' % result)
        else:
            Logger.ErrorLog('Response status: %d' % res.status)

        return ret