华为云 缓存过期 python 脚本

华为云 缓存过期 python 脚本

下载GitHub源码安装方式,如下:

将代码下载到您项目合适的位置,以pythonsdk作为您选择的位置举例,执行下面的命令完成源码下载和安装:

git clone https://github.com/huaweicloud/huaweicloud-sdk-python pythonsdk

cd pythonsdk

pip install -r requirements.txt

python setup.py install

 

 

[root@jenkins tools]# cat refreshTask.py 
# -*- coding:utf-8 -*-

import os
from openstack import connection

os.environ.setdefault('OS_CDN_ENDPOINT_OVERRIDE',
                      'https://cdn.myhuaweicloud.com/v1.0/')  # CDN API url,example:https://cdn.myhuaweicloud.com/v1.0/

# AKSK Auth
projectId = "0539e8c1e700260a2fbec0160d871c9c"  # Project ID of cn-north-1
cloud = "myhuaweicloud"  # cdn use: cloud = "myhuaweicloud.com"
region = "cn-north-1"  # example: region = "cn-north-1"
AK = "xxxxxxx"
SK = "xxxxx"

conn = connection.Connection(
    project_id=projectId,
    cloud=cloud,
    region=region,
    ak=AK,
    sk=SK)


# token Auth
# username = "xxxxxxxxxxx"  # IAM User Name
# password = "xxxxxxxxxxx"  # IAM User Password
# projectId = "xxxxxxxxxxx"  # Project ID of cn-north-1
# userDomainId = "xxxxxxxxxxx"  # Account ID
# auth_url = "xxxxxxxxxxx"  # IAM auth url,example: https://iam.myhuaweicloud.com/v3
#
# conn = connection.Connection(
#     auth_url=auth_url,
#     user_domain_id=userDomainId,
#     project_id=projectId,
#     username=username,
#     password=password
# )

# new version API
# part 3: Refreshing and Preheating
# Creating a Cache Refreshing Task
def refresh_create(_refresh_task):
    print("refresh files or dirs:")
    task = conn.cdn.create_refresh_task(**_refresh_task)
    print(task)


if __name__ == "__main__":
    # new version API
    # part 3: Refreshing and Preheating
    # Creating a Cache Refreshing Task
#    refresh_file_task = {
#        "type": "file",
#        "urls": ["xxxxxxxxxxx",
#                 "xxxxxxxxxxx"]
#    }
    refresh_dir_task = {
        "type": "directory",
        "urls": ["https://static.xxxxx.com/home/",
                 "https://static.xxxxx.com/learn/"]
    }
#    refresh_create(refresh_file_task)
    refresh_create(refresh_dir_task)

 

posted @ 2020-08-12 11:23  fengjian1585  阅读(197)  评论(0编辑  收藏  举报