全部产品

点播CDN

本篇文档提供了Python SDK点播CDN模块相关功能的API调用示例。包含预热缓存、刷新缓存、查询刷新和预热状态、查询刷新预热次数限制和余量、查询流量数据、查询网络带宽、下载域名日志。

初始化客户端

使用前请先初始化客户端,请参见初始化

预热缓存

调用PreloadVodObjectCaches接口,完成预热缓存功能。

接口参数和返回字段请参见PreloadVodObjectCaches。调用示例如下:

from aliyunsdkvod.request.v20170321 import PreloadVodObjectCachesRequest
def preload_object_caches(clt):
    request = PreloadVodObjectCachesRequest.PreloadVodObjectCachesRequest()
    objectPath = ['http://192.168.0.0/16/fd.mp4',
                  'http://192.168.0.0/16/ld.mp4']
    request.set_ObjectPath("\n".join(objectPath))

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = preload_object_caches(clt)
    print(res['PreloadTaskId'])
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

刷新缓存

调用RefreshVodObjectCaches接口,完成刷新缓存功能。

接口参数和返回字段请参见RefreshVodObjectCaches。调用示例如下:

from aliyunsdkvod.request.v20170321 import RefreshVodObjectCachesRequest
def refresh_object_caches(clt):
    request = RefreshVodObjectCachesRequest.RefreshVodObjectCachesRequest()
    objectPath = ['http://192.168.0.0/16/fd.mp4',
                  'http://192.168.0.0/16/ld.mp4']
    request.set_ObjectPath("\n".join(objectPath))

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = refresh_object_caches(clt)
    print(res['RefreshTaskId'])
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

查询刷新和预热状态

调用DescribeVodRefreshTasks接口,完成查询刷新和预热状态功能。

接口参数和返回字段请参见DescribeVodRefreshTasks。调用示例如下:

from aliyunsdkvod.request.v20170321 import DescribeVodRefreshTasksRequest
def describe_refresh_task(clt):
    request = DescribeVodRefreshTasksRequest.DescribeVodRefreshTasksRequest()
    request.set_DomainName('test.com')
    request.set_ObjectType('preload')

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = describe_refresh_task(clt)
    print(res['Tasks']['Task'])
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

查询刷新预热次数限制和余量

调用DescribeVodRefreshQuota接口,完成查询刷新预热次数限制和余量功能。

接口参数和返回字段请参见DescribeVodRefreshQuota。调用示例如下:

from aliyunsdkvod.request.v20170321 import DescribeVodRefreshQuotaRequest
def describe_refresh_quota(clt):
    request = DescribeVodRefreshQuotaRequest.DescribeVodRefreshQuotaRequest()

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = describe_refresh_quota(clt)
    print(res['PreloadRemain'])
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

查询流量数据

调用DescribeVodDomainTrafficData接口,完成查询流量数据功能。

接口参数和返回字段请参见DescribeVodDomainTrafficData。调用示例如下:

from aliyunsdkvod.request.v20170321 import DescribeVodDomainTrafficDataRequest
def describe_domain_traffic_data(clt):
    request = DescribeVodDomainTrafficDataRequest.DescribeVodDomainTrafficDataRequest()
    request.set_DomainName("example.test.com")
    request.set_StartTime("2019-01-15T15:59:59Z")
    request.set_EndTime("2019-01-20T15:59:58Z")

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = describe_domain_traffic_data(clt)
    print(res['TrafficDataPerInterval']['DataModule'])
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

查询网络带宽

调用DescribeVodDomainBpsData接口,完成查询网络带宽功能。

接口参数和返回字段请参见DescribeVodDomainBpsData。调用示例如下:

from aliyunsdkvod.request.v20170321 import DescribeVodDomainBpsDataRequest
def describe_domain_bps_data(clt):
    request = DescribeVodDomainBpsDataRequest.DescribeVodDomainBpsDataRequest()
    request.set_DomainName("example.test.com")
    request.set_StartTime("2019-01-15T15:59:59Z")
    request.set_EndTime("2019-01-20T15:59:58Z")

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = describe_domain_bps_data(clt)
    print(res['BpsDataPerInterval']['DataModule'])
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

下载域名日志

调用DescribeVodDomainLog接口,完成下载域名日志功能。

接口参数和返回字段请参见DescribeVodDomainLog。调用示例如下:

from aliyunsdkvod.request.v20170321 import DescribeVodDomainLogRequest
def describe_domain_log(clt):
    request = DescribeVodDomainLogRequest.DescribeVodDomainLogRequest()
    request.set_DomainName("example.test.com")
    request.set_StartTime("2019-01-15T15:59:59Z")
    request.set_EndTime("2019-01-20T15:59:58Z")
    request.set_PageNumber(1)
    request.set_PageSize(300)

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = describe_domain_log(clt)
    logDetail = res['DomainLogDetails']['DomainLogDetail'][0]
    print("TotalLogCount: %s" % (logDetail['PageInfos']['Total']))
    print(logDetail['LogInfos']['LogInfoDetail'])
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())