All Products
Search
Document Center

CDN

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see init_vod_client.

Preload content to cache nodes

For more information about the request and response parameters, see PreloadVodObjectCaches.

from aliyunsdkvod.request.v20170321 import PreloadVodObjectCachesRequest
def preload_object_caches(clt):
    request = PreloadVodObjectCachesRequest.PreloadVodObjectCachesRequest()
    objectPath = ['http://test.com/fd.mp4',
                  'http://test.com/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())

Refresh the cached content on nodes

For more information about the request and response parameters, see RefreshVodObjectCaches.

from aliyunsdkvod.request.v20170321 import RefreshVodObjectCachesRequest
def refresh_object_caches(clt):
    request = RefreshVodObjectCachesRequest.RefreshVodObjectCachesRequest()
    objectPath = ['http://test.com/fd.mp4',
                  'http://test.com/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())

Query the status of refresh and preload tasks

For more information about the request and response parameters, see 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())

Query the maximum number and remaining number of requests to refresh and preload content on the current day

For more information about the request and response parameters, see 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())

Obtain the network traffic monitoring data for accelerating domain names

For more information about the request and response parameters, see 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())

Obtain the network bandwidth monitoring data for accelerating domain names

For more information about the request and response parameters, see 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())

Download raw CDN access logs for a specified domain name

For more information about the request and response parameters, see 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())