python3刷新aliyuncdn

DevOps Aliyun Python评论254字数 1135阅读3分47秒阅读模式

脚本

[root@us-common]# cat refresh-CDN.py 
#刷新阿里云CDN

#!/usr/bin/env python3
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
import sys

client = AcsClient('LT323AI4GKd23','eweewkL231sdwF')
def refresh(type, url):                                                #默认File(url刷新),Directory目录刷新(但是目录刷新必须以/结尾)
  request = RefreshObjectCachesRequest()
  request.set_accept_format('json')
  request.set_ObjectPath(url)
  request.set_ObjectType(type)
  response = client.do_action_with_exception(request)
  print(str(response, encoding='utf-8'))

if __name__ == '__main__':
  refresh(sys.argv[1], sys.argv[2])

安装依赖

devops@DevopsdeMacBook-Pro ~ % pip3 install aliyun-python-sdk-core
devops@DevopsdeMacBook-Pro ~ % pip3 install aliyun-python-sdk-ecs
root@DevopsdeMacBook-Pro ~ # pip3 install aliyun-python-sdk-core-v3
root@DevopsdeMacBook-Pro ~ # pip3 install aliyun-python-sdk-cdn

刷新cdn

root@DevopsdeMacBook-Pro ~ #  python3 refresh-CDN.py Directory https://cdn.centoscn.vip/download/android/  
{"RequestId":"19Adda8D8707F","RefreshTaskId":"14637dfdf070867"}

查看cdn刷新状态

python3刷新aliyuncdnCDN

 

继续阅读
DevOps
  • 本文由 发表于 2022年6月6日 13:35:37
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
评论  0  访客  0

发表评论