华为云编程刷新CDN
API-explorer
user@zmti8jpmhtg9i7g-machine:~$ hcloud CDN ListDomains/v1 --cli-region=cn-north-1
{
"total": 3,
"domains": [
{
"sources": [
"domain_id": "0f5472528d354",
"origin_type": "domain",
"ip_or_domain": "源站IP 域名",
"active_standby": 1
}
],
"id": "0f5472528d354", #实际测试的时候 id与user_domain_id都能完成刷新
"user_domain_id": "12d941e5d23345", #下面的参数需要使用--cli-domain-id=user_domain_id
"domain_name": "you 域名",
...
初始化hcloud
https://cn-north-4-hdn-koocli.obs.cn-north-4.myhuaweicloud.com/cli/latest/huaweicloud-cli-linux-amd64.tar.gz
[root@os1 ~]# mkdir hcdir
[root@os1 ~]# tar xf huaweicloud-cli-linux-amd64.tar.gz -C hcdir/
[root@os1 ~]# ls hcdir/
hcloud OpenSourceSoftwareNotice.md README.md
[root@os1 /]# mv hcdir/hcloud /usr/local/bin/
[root@os1 /]# hcloud version
Current KooCLI version: 4.2.8
[root@os1 /]# hcloud --help #功能似乎很全,涵盖所有云服务
KooCLI Version 4.2.8 Copyright(C) 2020-2023 www.huaweicloud.com
Usage:
hcloud [options] <service> <operation> [--param1=paramValue1 --param2=paramValue2 ...]
Sample:
hcloud ECS NovaListServers --cli-region=xxx
Options:
--help Display help information.
--debug Print debugging information.
--dryrun Print the request message after verification, without execution.
--interactive Enter interactive mode.
--cli-region Region.
--cli-endpoint Custom request domain name.
--cli-access-key Access key ID required for the AK/SK mode. Configure it by running `hcloud configure set`.
--cli-secret-key Secret access key required for the AK/SK mode. Configure it by running `hcloud configure set`.
--cli-security-token Temporary token, which must be used with temporary AK/SK.
--cli-domain-id Account ID.
--cli-project-id Project ID.
--cli-profile Profile. If not specified, the default one is used.
--cli-mode Authentication mode [AKSK|ecsAgency].
--cli-jsonInput Enter parameters by specifying a JSON file.
--cli-connect-timeout Request connection timeout (s). Min.: 1; default: 5.
--cli-read-timeout I/O timeout (s). Min.: 1; default: 10.
--cli-retry-count Number of connection attempts. Min.: 0; max.: 5; default: 0.
--cli-output Response output format [json|table|tsv].
--cli-query JMESPath for filtering response data.
--cli-output-num Indicates whether to print the row numbers during table output.
--cli-skip-secure-verify Skip HTTPS certificate verification (not recommended) [true|false].
System commands:
configure Configuration management (adding, deleting, modifying profiles).
update Upgrade KooCLI to the latest version.
meta Download or clear metadata cache files.
version Print current version.
auto-complete Turn on or off autocomplete.
log Configure or query log parameters.
template Template management (listing and downloading templates).
obs Object Storage Service.
Available services:
AOM CSE DLI GES LTS ROMA
APIExplorer CSMS DNS GaussDB Live RabbitMQ
APIG CSS DRS GaussDBforCassandra MPC RocketMQ
AS CTS DSC GaussDBforInflux MRS SCM
Anti-DDoS CloudDeploy DWS GaussDBforMongo Meeting SFSTurbo
BMS CloudTest DataArtsStudio GaussDBforNoSQL ModelArts SIS
CBH CodeArtsBuild ECS GaussDBforRedis Moderation SMN
CBR CodeCheck EIP GaussDBforopenGauss NAT SMS
CBS CodeHub ELB HSS OCR SWR
CC DBSS EPS IAM OMS ServiceStage
CCE DC ER IMS Organizations TMS
CCM DCS EVS Image ProjectMan UGO
CDM DCSforMemcached FACS ImageSearch RAM VOD
CDN DCSforRedis FRS IoTDA RDS VPC
CES DDM FunctionGraph KMS RDSforPostgreSQL VPCEP
CFW DDS GA KPS RDSforSQLServer WAF
CPTS DLF GACS Kafka RMS
初始化hcloud
[root@os1 ~]# hcloud configure init
Initialization will delete the existing configuration information. Continue? (y/N): y
Starting initialization. 'Secret Access Key' is anonymized. To obtain the parameter, see 'https://support.huaweicloud.com/usermanual-hcli/hcli_09.html'.
Access Key ID [required]: DYQXCWJYWXWDX9MNR1RV
Secret Access Key [required]: ****
Secret Access Key (again): ****
[root@os1 /]# hcloud CDN ListDomains/v1 --cli-region=cn-north-1 --cli-domain-id="you domain id "
{
"total": 3,
"domains": [...
shell刷新
[root@os1 ~]# hcloud CDN CreateRefreshTasks --cli-region=cn-north-1 --cli-domain-id="上面的domain_id" --refresh_task.urls.1=https://www.baidu.com --refresh_task.mode=detect_modify_refresh
{
"refresh_task": "1932439732"
}
--cli-region=cn-north-1 #目前固定
--cli-domain-id="domain_id" #上面的domain_id
--refresh_task.urls.1=https://www.baidu.com #多个任务urls.1,2,3
--refresh_task.mode=detect_modify_refresh # 刷新变化的文件,默认是all
--refresh_task.type=directory # [file|directory] #加了这个反而报参数错误了
[root@os1 ~]# hcloud CDN CreateRefreshTasks --cli-region=cn-north-1 --help
python刷新
安装python3.6.5
(1)安装python依赖包
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel python-devel wget
(2)安装python
[root@os1 ~]# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
[root@os1 ~]# tar xf Python-3.6.5.tgz ;cd Python-3.6.5
[root@os1 Python-3.6.5]# ./configure --prefix=/usr/local/python3
[root@os1 Python-3.6.5]# make && make install
[root@os1 ~]# ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
[root@os1 ~]# ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
[root@os1 ~]# python3 -V
Python 3.6.5
[root@os1 ~]# pip3 install --upgrade pip #更新pip
[root@os1 ~]# pip3 install ipython #安装ipython方便调试
[root@os1 ~]# ln -s /usr/local/python3/bin/ipython /usr/local/bin/ipython
[root@os1 ~]# ipython
In [1]:
[root@os1 ~]# pip3 install huaweicloudsdkcdn
#或https://github.com/huaweicloud/huaweicloud-sdk-python-v3 #下载,python setup.py install
[root@os1 ~]# python3 refresh.py #下面
{"refresh_task": "1933248854"}
# refresh.py
# coding: utf-8
from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdkcdn.v1.region.cdn_region import CdnRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcdn.v1 import *
if __name__ == "__main__":
ak = "you ak"
sk = "you sk"
domainID="you domain id "
credentials = GlobalCredentials(ak, sk,domainID) \
client = CdnClient.new_builder() \
.with_credentials(credentials) \
.with_region(CdnRegion.value_of("cn-north-1")) \
.build()
try:
request = CreateRefreshTasksRequest()
listUrlsRefreshTask = [
"https://www.biaodu.com/2023/"
]
refreshTaskbody = RefreshTaskRequestBody(
urls=listUrlsRefreshTask
)
request.body = RefreshTaskRequest(
refresh_task=refreshTaskbody
)
response = client.create_refresh_tasks(request)
print(response)
except exceptions.ClientRequestException as e:
print(e.status_code)
print(e.request_id)
print(e.error_code)
print(e.error_msg)
华为云账号:${domain_name};
上报类型: ${clear_type};
事件名称: ${event_name};
区域名称: ${region_name};
通知类型:${event_type};
事件级别:${event_severity};
事件名称:${event_name};
发生时间:${starts_at};
事件源1:${resource_provider};
事件源: $event.metadata.resource_provider;
资源类型1: $event.metadata.resource_type;
资源类型:${resource_type};
资源标识:${resources};
可能原因:${alarm_probableCause_zh};
附加信息:${message};
修复建议:${alarm_fix_suggestion_zh};
告警信息:
${starts_at};
$event.metadata.nodeName ;
${message};