コード例 #1
0
ファイル: purgeApi.py プロジェクト: JerryDog/cdn
def purgeQueryXmlToPurgeList(ret):
    ''' 缓存查询 xml结果解析成 Purge对象的列表'''
    
    global X_CNC_REQUEST_ID
    requestId = ret.getheader(X_CNC_REQUEST_ID)
   
    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    purgeListNode = util.getChildNode(doc, 'purge-list')
    purgeList = []
    purgeDataList = util.getChildNodeList(purgeListNode, 'purge-request')
    for purgeNode in purgeDataList:
        purgeId = util.getChildNodeText(purgeNode, 'purge-id')
        requestDateStr = util.getChildNodeText(purgeNode, 'request-date')
        requestDate = util.parseRFC1123Time(requestDateStr)
        itemNodeList = util.getChildNodeList(purgeNode, 'item')
        purgeItems = []
        for itemNode in itemNodeList:
            path = util.getChildNodeText(itemNode, "path")
            status = util.getChildNodeText(itemNode, "status")
            rate = util.getChildNodeText(itemNode, "rate")
            isDir = util.getChildNodeText(itemNode, "isdir")
            purgeItem = PurgeItem(path, status, rate, isDir)
            purgeItems.append(purgeItem)
        purge = Purge(purgeId, requestDate, purgeItems)
        purgeList.append(purge)
    return PurgeQueryResult(ret.status, 'OK', xCncRequestId = requestId, purgeList = purgeList);
コード例 #2
0
def purgeQueryXmlToPurgeList(ret):
    ''' 缓存查询 xml结果解析成 Purge对象的列表'''

    global X_CNC_REQUEST_ID
    requestId = ret.getheader(X_CNC_REQUEST_ID)

    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    purgeListNode = util.getChildNode(doc, 'purge-list')
    purgeList = []
    purgeDataList = util.getChildNodeList(purgeListNode, 'purge-request')
    for purgeNode in purgeDataList:
        purgeId = util.getChildNodeText(purgeNode, 'purge-id')
        requestDateStr = util.getChildNodeText(purgeNode, 'request-date')
        #        requestDate = util.parseRFC1123Time(requestDateStr)
        itemNodeList = util.getChildNodeList(purgeNode, 'item')
        purgeItems = []
        for itemNode in itemNodeList:
            path = util.getChildNodeText(itemNode, "path")
            status = util.getChildNodeText(itemNode, "status")
            rate = util.getChildNodeText(itemNode, "rate")
            isDir = util.getChildNodeText(itemNode, "isdir")
            purgeItem = PurgeItem(path, status, rate, isDir)
            purgeItems.append(purgeItem)
        purge = Purge(purgeId, requestDateStr, purgeItems)
        purgeList.append(purge)
    return PurgeQueryResult(ret.status,
                            'OK',
                            xCncRequestId=requestId,
                            purgeList=purgeList)
コード例 #3
0
ファイル: reportApi.py プロジェクト: yianjiajia/my_all_codes
def xmlToLogList(ret):
    ''' 返回xml 转换成 带Log对象列表的LogProcessResult对象 '''
    global X_CNC_REQUEST_ID
    requestId = ret.getheader(X_CNC_REQUEST_ID)

    isoFormat = "%Y-%m-%d-%H%M"

    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    logListNode = util.getChildNode(doc, 'logs')
    logList = []
    logDataList = util.getChildNodeList(logListNode, 'log')
    for logNode in logDataList:
        dateFromStr = util.getChildNodeText(logNode, 'datefrom')
        dateToStr = util.getChildNodeText(logNode, 'dateto')
        url = util.getChildNodeText(logNode, 'log-url')
        fileSize = util.getChildNodeText(logNode, 'file-size')

        dateFrom = datetime.datetime.strptime(dateFromStr, isoFormat)
        dateTo = datetime.datetime.strptime(dateToStr, isoFormat)

        log = Log(dateFrom, dateTo, url, fileSize)
        logList.append(log)
    return LogProcessResult(ret.status,
                            'OK',
                            xCncRequestId=requestId,
                            logs=logList)
コード例 #4
0
ファイル: reportApi.py プロジェクト: yianjiajia/my_all_codes
def xmlToFlowPointList(ret, reportType):
    ''' 返回xml 转换成 带 FlowPoint对象列表的FlowProcessResult对象'''
    global X_CNC_REQUEST_ID, X_CNC_LOCATION
    requestId = ret.getheader(X_CNC_REQUEST_ID)

    isoFormat = getDateFormat(reportType)

    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    flowPointListNode = util.getChildNode(doc, 'flow-report')
    flowSummary = util.getChildNodeText(flowPointListNode, 'flow-summary')
    flowPointList = []
    flowDataList = util.getChildNodeList(flowPointListNode, 'flow-data')
    for flowNode in flowDataList:
        pointStr = util.getChildNodeText(flowNode, 'timestamp')
        gaga = re.sub('24:00:00', '00:00:00', pointStr)
        point = datetime.datetime.strptime(gaga, isoFormat)
        flow = util.getChildNodeText(flowNode, 'flow')
        flowPoint = FlowPoint(point, flow)
        flowPointList.append(flowPoint)
    return FlowProcessResult(ret.status,
                             'OK',
                             xCncRequestId=requestId,
                             flowPoints=flowPointList,
                             flowSummary=flowSummary)
コード例 #5
0
ファイル: reportApi.py プロジェクト: JerryDog/cdn
def xmlToLogList(ret):
    ''' 返回xml 转换成 带Log对象列表的LogProcessResult对象 '''
    global X_CNC_REQUEST_ID
    requestId = ret.getheader(X_CNC_REQUEST_ID)
   
    isoFormat = "%Y-%m-%d-%H%M"
    
    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    logListNode = util.getChildNode(doc, 'logs')
    logList = []
    logDataList = util.getChildNodeList(logListNode, 'log')
    for logNode in logDataList:
        dateFromStr = util.getChildNodeText(logNode, 'datefrom')
        dateToStr = util.getChildNodeText(logNode, 'dateto')
        url = util.getChildNodeText(logNode, 'log-url')
        fileSize = util.getChildNodeText(logNode, 'file-size')
        
        dateFrom = datetime.datetime.strptime(dateFromStr, isoFormat)
        dateTo = datetime.datetime.strptime(dateToStr, isoFormat)
        
        log = Log(dateFrom, dateTo, url, fileSize)
        logList.append(log)
    return LogProcessResult(ret.status, 'OK', xCncRequestId = requestId, logs = logList);
コード例 #6
0
ファイル: domainApi.py プロジェクト: yianjiajia/my_all_codes
def parseVisitControlRulesList(nodeList):
    vistControlRulesList = []
    for node in nodeList:
        pathPattern = util.getChildNodeText(node, 'path-pattern')
        allowNullReffer = util.getChildNodeText(node, 'allownullreferer')
        validReferRootNode = util.getChildNode(node, "valid-referers")
        validRNode = util.getChildNodeList(validReferRootNode, 'referer')
        validRefers = []
        for ref in validRNode:
            validRefers.append(util.getChildNodeText(ref, "referer"))
        
        invalidReferRootNode = util.getChildNode(node, "invalid-referers")
        invalidRNode = util.getChildNodeList(invalidReferRootNode, 'referer')
        invalidRefers = []
        for ref in invalidRNode:
            invalidRefers.append(util.getChildNodeText(ref, "referer"))
        
        forbiddenIps = splitStr(util.getChildNodeText(node, 'forbidden-ips'))
        
        visitControlRule = VisitControlRule(pathPattern, allowNullReffer, validRefers, invalidRefers, forbiddenIps)
        vistControlRulesList.append(visitControlRule)
        
    return vistControlRulesList
コード例 #7
0
ファイル: domainApi.py プロジェクト: JerryDog/cdn
def parseVisitControlRulesList(nodeList):
    vistControlRulesList = []
    for node in nodeList:
        pathPattern = util.getChildNodeText(node, 'path-pattern')
        allowNullReffer = util.getChildNodeText(node, 'allownullreferer')
        validReferRootNode = util.getChildNode(node, "valid-referers")
        validRNode = util.getChildNodeList(validReferRootNode, 'referer')
        validRefers = []
        for ref in validRNode:
            validRefers.append(util.getChildNodeText(ref, "referer"))
        
        invalidReferRootNode = util.getChildNode(node, "invalid-referers")
        invalidRNode = util.getChildNodeList(invalidReferRootNode, 'referer')
        invalidRefers = []
        for ref in invalidRNode:
            invalidRefers.append(util.getChildNodeText(ref, "referer"))
        
        forbiddenIps = splitStr(util.getChildNodeText(node, 'forbidden-ips'))
        
        visitControlRule = VisitControlRule(pathPattern, allowNullReffer, validRefers, invalidRefers, forbiddenIps)
        vistControlRulesList.append(visitControlRule)
        
    return vistControlRulesList
コード例 #8
0
ファイル: reportApi.py プロジェクト: JerryDog/cdn
def xmlToHitPointList(ret, reportType):
    ''' 返回xml 转换成 带 HitPoint对象列表的HitProcessResult对象 '''
    global X_CNC_REQUEST_ID, X_CNC_LOCATION
    requestId = ret.getheader(X_CNC_REQUEST_ID)
    
    isoFormat = getDateFormat(reportType)
   
    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    hitPointListNode = util.getChildNode(doc, 'hit-report')
    hitPointList = []
    hitDataList = util.getChildNodeList(hitPointListNode, 'hit-data')
    for hitNode in hitDataList:
        pointStr = util.getChildNodeText(hitNode, 'timestamp')
        point = datetime.datetime.strptime(pointStr, isoFormat)
        hit = util.getChildNodeText(hitNode, 'hit')
        hitPoint = HitPoint(point, hit)
        hitPointList.append(hitPoint)
    return HitProcessResult(ret.status, 'OK', xCncRequestId = requestId, hitPoints = hitPointList)
コード例 #9
0
ファイル: reportApi.py プロジェクト: JerryDog/cdn
def xmlToFlowPointList(ret, reportType):
    ''' 返回xml 转换成 带 FlowPoint对象列表的FlowProcessResult对象'''
    global X_CNC_REQUEST_ID, X_CNC_LOCATION
    requestId = ret.getheader(X_CNC_REQUEST_ID)
   
    isoFormat = getDateFormat(reportType)
   
    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    flowPointListNode = util.getChildNode(doc, 'flow-report')
    flowSummary = util.getChildNodeText(flowPointListNode, 'flow-summary')
    flowPointList = []
    flowDataList = util.getChildNodeList(flowPointListNode, 'flow-data')
    for flowNode in flowDataList:
        pointStr = util.getChildNodeText(flowNode, 'timestamp')
        point = datetime.datetime.strptime(pointStr, isoFormat)
        flow = util.getChildNodeText(flowNode, 'flow')
        flowPoint = FlowPoint(point, flow)
        flowPointList.append(flowPoint)
    return FlowProcessResult(ret.status, 'OK', xCncRequestId = requestId, flowPoints = flowPointList, flowSummary = flowSummary);
コード例 #10
0
ファイル: reportApi.py プロジェクト: yianjiajia/my_all_codes
def xmlToHitPointList(ret, reportType):
    ''' 返回xml 转换成 带 HitPoint对象列表的HitProcessResult对象 '''
    global X_CNC_REQUEST_ID, X_CNC_LOCATION
    requestId = ret.getheader(X_CNC_REQUEST_ID)

    isoFormat = getDateFormat(reportType)

    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    hitPointListNode = util.getChildNode(doc, 'hit-report')
    hitPointList = []
    hitDataList = util.getChildNodeList(hitPointListNode, 'hit-data')
    for hitNode in hitDataList:
        pointStr = util.getChildNodeText(hitNode, 'timestamp')
        gaga = re.sub('24:00:00', '00:00:00', pointStr)
        point = datetime.datetime.strptime(gaga, isoFormat)
        hit = util.getChildNodeText(hitNode, 'hit')
        hitPoint = HitPoint(point, hit)
        hitPointList.append(hitPoint)
    return HitProcessResult(ret.status,
                            'OK',
                            xCncRequestId=requestId,
                            hitPoints=hitPointList)
コード例 #11
0
ファイル: domainApi.py プロジェクト: yianjiajia/my_all_codes
def xmlToDomainList(ret):
    ''' 返回xml 转换成 带 Domain对象列表的ProcessResult对象, 在查询用户下所有频道时候使用'''
    global X_CNC_REQUEST_ID, X_CNC_LOCATION
    requestId = ret.getheader(X_CNC_REQUEST_ID)
    
    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    domainListNode = util.getChildNode(doc, 'domain-list')
    domainList = []
    domainSummaryList = util.getChildNodeList(domainListNode, 'domain-summary')
    for domainNode in domainSummaryList:
        domainId = util.getChildNodeText(domainNode, 'domain-id')
        cname = util.getChildNodeText(domainNode, 'cname')
        domainName = util.getChildNodeText(domainNode, 'domain-name')
        status = util.getChildNodeText(domainNode, 'status')
        serviceType = util.getChildNodeText(domainNode, "service-type")
        enabled = util.getChildNodeText(domainNode, 'enabled') == 'true'
        cdnServiceStatus = util.getChildNodeText(domainNode, 'cdn-service-status') == 'true'
        domainSummary = DomainSummary(domainId, domainName, cname,
                  status, enabled,
                  serviceType, cdnServiceStatus)
        domainList.append(domainSummary)
    return ProcessResult(0, 'OK', xCncRequestId = requestId, domainSummarys = domainList);
コード例 #12
0
ファイル: domainApi.py プロジェクト: JerryDog/cdn
def xmlToDomainList(ret):
    ''' 返回xml 转换成 带 Domain对象列表的ProcessResult对象, 在查询用户下所有频道时候使用'''
    global X_CNC_REQUEST_ID, X_CNC_LOCATION
    requestId = ret.getheader(X_CNC_REQUEST_ID)
    
    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    domainListNode = util.getChildNode(doc, 'domain-list')
    domainList = []
    domainSummaryList = util.getChildNodeList(domainListNode, 'domain-summary')
    for domainNode in domainSummaryList:
        domainId = util.getChildNodeText(domainNode, 'domain-id')
        cname = util.getChildNodeText(domainNode, 'cname')
        domainName = util.getChildNodeText(domainNode, 'domain-name')
        status = util.getChildNodeText(domainNode, 'status')
        serviceType = util.getChildNodeText(domainNode, "service-type")
        enabled = util.getChildNodeText(domainNode, 'enabled') == 'true'
        cdnServiceStatus = util.getChildNodeText(domainNode, 'cdn-service-status') == 'true'
        domainSummary = DomainSummary(domainId, domainName, cname,
                  status, enabled,
                  serviceType, cdnServiceStatus)
        domainList.append(domainSummary)
    return ProcessResult(0, 'OK', xCncRequestId = requestId, domainSummarys = domainList);
コード例 #13
0
ファイル: domainApi.py プロジェクト: yianjiajia/my_all_codes
def xmlToDomain(ret):
    ''' 返回xml 转换成 带 Domain对象的ProcessResult对象, 在查询频道信息的时候使用'''
    
    global X_CNC_REQUEST_ID, X_CNC_LOCATION, logger
    requestId = ret.getheader(X_CNC_REQUEST_ID)
    
    xmlString = ret.read().decode("utf-8")
    logger.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    
    domainNode = util.getChildNode(doc, 'domain')
    domainName = util.getChildNodeText(domainNode, 'domain-name')
    domainId = util.getChildNodeText(domainNode, 'domain-id')
    serviceType = util.getChildNodeText(domainNode, 'service-type')
    comment = util.getChildNodeText(domainNode, 'comment')
    serviceAreas = util.getChildNodeText(domainNode, 'service-areas')
    enabled = util.getChildNodeText(domainNode, 'enabled')
    cname = util.getChildNodeText(domainNode, 'cname')
    status = util.getChildNodeText(domainNode, 'status')
    
    domain = Domain(domainName = domainName, 
                    serviceType = serviceType, 
                    domainId = domainId,
                    comment = comment, 
                    serviceAreas = serviceAreas,
                    enabled = enabled, 
                    cname = cname,
                    status = status)
    
    originConfigNode = util.getChildNode(domainNode, 'origin-config')
    if originConfigNode is not None:
        originIpsStr = util.getChildNodeText(originConfigNode, 'origin-ips')
        originIps = splitStr(originIpsStr)
        originDomainName = util.getChildNodeText(originConfigNode, 'origin-domain-name')
        advOriginConfigListRootNode = util.getChildNode(originConfigNode, 'adv-origin-configs')
        if advOriginConfigListRootNode is not None:
            advOriginConfigListNode = util.getChildNodeList(advOriginConfigListRootNode, 'adv-origin-config')
            advOriginConfigs = []
            if advOriginConfigListNode is not None:
                advOriginConfigs = parseAdvOriginConfigList(advOriginConfigListNode)
                originConfig = OriginConfig(originIps, originDomainName, advOriginConfigs)
                domain.originConfig = originConfig   
        else:
            originConfig = OriginConfig(originIps, originDomainName)
            domain.originConfig = originConfig   
    
    queryStringSettingListRootNode = util.getChildNode(domainNode, 'query-string-settings')
    if queryStringSettingListRootNode is not None:
        queryStringSettingListNode = util.getChildNodeList(queryStringSettingListRootNode, 'query-string-setting')
        if queryStringSettingListNode is not None:
            queryStringSettingList = parseQueryStringSettingListNode(queryStringSettingListNode)
            domain.queryStringSettings = queryStringSettingList
    
    cacheBehaviorListRootNode = util.getChildNode(domainNode, 'cache-behaviors')
    if cacheBehaviorListRootNode is not None:
        cacheBehaviorListNode = util.getChildNodeList(cacheBehaviorListRootNode, 'cache-behavior')
        if cacheBehaviorListNode is not None:
            cacheBehaviorList = parseCacheBehaviorList(cacheBehaviorListNode)
            domain.cacheBehaviors = cacheBehaviorList
    
    visitControlRulesListRootNode = util.getChildNode(domainNode, 'visit-control-rules')
    if visitControlRulesListRootNode is not None:
        visitControlRulesListNode = util.getChildNodeList(visitControlRulesListRootNode, 'visit-control-rule')
        if visitControlRulesListNode is not None:
            visitControlRulesList = parseVisitControlRulesList(visitControlRulesListNode)
            domain.visitControlRules = visitControlRulesList
        
    return ProcessResult(0, 'OK', xCncRequestId = requestId, domain = domain);
コード例 #14
0
ファイル: domainApi.py プロジェクト: JerryDog/cdn
def xmlToDomain(ret):
    ''' 返回xml 转换成 带 Domain对象的ProcessResult对象, 在查询频道信息的时候使用'''
    
    global X_CNC_REQUEST_ID, X_CNC_LOCATION, logger
    requestId = ret.getheader(X_CNC_REQUEST_ID)
    
    xmlString = ret.read().decode("utf-8")
    logger.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    
    domainNode = util.getChildNode(doc, 'domain')
    domainName = util.getChildNodeText(domainNode, 'domain-name')
    domainId = util.getChildNodeText(domainNode, 'domain-id')
    serviceType = util.getChildNodeText(domainNode, 'service-type')
    comment = util.getChildNodeText(domainNode, 'comment')
    serviceAreas = util.getChildNodeText(domainNode, 'service-areas')
    enabled = util.getChildNodeText(domainNode, 'enabled')
    cname = util.getChildNodeText(domainNode, 'cname')
    status = util.getChildNodeText(domainNode, 'status')
    
    domain = Domain(domainName = domainName, 
                    serviceType = serviceType, 
                    domainId = domainId,
                    comment = comment, 
                    serviceAreas = serviceAreas,
                    enabled = enabled, 
                    cname = cname,
                    status = status)
    
    originConfigNode = util.getChildNode(domainNode, 'origin-config')
    if originConfigNode is not None:
        originIpsStr = util.getChildNodeText(originConfigNode, 'origin-ips')
        originIps = splitStr(originIpsStr)
        originDomainName = util.getChildNodeText(originConfigNode, 'origin-domain-name')
        advOriginConfigListRootNode = util.getChildNode(originConfigNode, 'adv-origin-configs')
        if advOriginConfigListRootNode is not None:
            advOriginConfigListNode = util.getChildNodeList(advOriginConfigListRootNode, 'adv-origin-config')
            advOriginConfigs = []
            if advOriginConfigListNode is not None:
                advOriginConfigs = parseAdvOriginConfigList(advOriginConfigListNode)
                originConfig = OriginConfig(originIps, originDomainName, advOriginConfigs)
                domain.originConfig = originConfig   
        else:
            originConfig = OriginConfig(originIps, originDomainName)
            domain.originConfig = originConfig   
    
    queryStringSettingListRootNode = util.getChildNode(domainNode, 'query-string-settings')
    if queryStringSettingListRootNode is not None:
        queryStringSettingListNode = util.getChildNodeList(queryStringSettingListRootNode, 'query-string-setting')
        if queryStringSettingListNode is not None:
            queryStringSettingList = parseQueryStringSettingListNode(queryStringSettingListNode)
            domain.queryStringSettings = queryStringSettingList
    
    cacheBehaviorListRootNode = util.getChildNode(domainNode, 'cache-behaviors')
    if cacheBehaviorListRootNode is not None:
        cacheBehaviorListNode = util.getChildNodeList(cacheBehaviorListRootNode, 'cache-behavior')
        if cacheBehaviorListNode is not None:
            cacheBehaviorList = parseCacheBehaviorList(cacheBehaviorListNode)
            domain.cacheBehaviors = cacheBehaviorList
    
    visitControlRulesListRootNode = util.getChildNode(domainNode, 'visit-control-rules')
    if visitControlRulesListRootNode is not None:
        visitControlRulesListNode = util.getChildNodeList(visitControlRulesListRootNode, 'visit-control-rule')
        if visitControlRulesListNode is not None:
            visitControlRulesList = parseVisitControlRulesList(visitControlRulesListNode)
            domain.visitControlRules = visitControlRulesList
        
    return ProcessResult(0, 'OK', xCncRequestId = requestId, domain = domain);