通过阿里云SDK实现阿里云CDN目录刷新功能

#!/usr/bin/env python
#coding:utf-8
#devops
__author__ = '张祺'

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcdn.request.v20180510.RefreshObjectCachesRequest import RefreshObjectCachesRequest


class PushCdn(object):
    
    def __init__(self,acessid,secert,domain):
        
        self.__acessid = acessid
        self.__secert = secert
        self.__domain = domain
        self.acessdir = "Directory"
        self.china = "cn-beijing"
        
    
    def Flush_Dir(self):
        try:
            client = AcsClient(self.__acessid,self.__secert,self.china)
            request = RefreshObjectCachesRequest()
            request.set_accept_format("json")
            request.set_ObjectPath(self.__domain)
            request.set_ObjectType(self.acessdir)
            responce = client.do_action_with_exception(request)
            print(responce)
        except Exception:
            print("请求错误,请查看用户认证信息是否正确")

  

posted @ 2019-06-26 14:30  张祺  阅读(801)  评论(0)    收藏  举报