加速域名管理
更新时间:2023-05-16
下列代码中对函数入参c即是CdnClient对象,详情参见CdnClient
查询域名是否可添加
Python
1def test_valid_domain(c):
2 """
3 test valid domain
4 """
5 response = c.valid_domain('test.example.com')
6 print(response)
新建加速域名
case1:支持自定义源站端口,指定业务类型(form),默认回源host(defaultHost)
Python
1def test_create_domain(c):
2 """
3 test_create_domain
4 """
5 origin = [
6 {'peer': 'http://1.2.3.2'}, # no port
7 {'peer': 'http://1.2.3.7:80'}, # set origin with http port
8 {'peer': 'https://1.2.3.9:443'}, # set origin with https port
9 {'peer': '1.2.3.1:8080'} # set origin with http port
10 ]
11
12 other_config = {
13 "form":"image",
14 "defaultHost":"1.2.3.4"
15 }
16
17 response = c.create_domain('test-sdk.sys-qa.com', origin, other_config)
18 print(response)
case2:创建域名时设置302跟随回源(follow302)
Python
1def test_create_domain_with_follow302(c):
2 """
3 create_domain with origin follow302 config
4 """
5
6 origin = [
7 {'peer': '1.2.3.5'}
8 ]
9 other_config = {
10 "follow302": True
11 }
12
13 response = c.create_domain('example.test.com', origin, other_config)
14 print(response)
注意:由于加速域名在所有区域中是唯一的,所以需要保证domain不与其他所有区域上的加速域名名称相同。
查看加速域名列表
Python
1def test_list_domains(c):
2 """
3 test_list_domains
4 """
5 response = c.list_domains()
6 print(response)
查看用户名下所有域名及其状态
Python
1def test_list_user_domains(c):
2 """
3 test list user domains with status,rule
4 """
5 status = 'ALL'
6 rule = None
7
8 response = c.list_user_domains(status, rule)
9 print(response)
查看域名全量配置
Python
1def test_get_domain_config(c):
2 """
3 test_get_domain_config
4 """
5 response = c.get_domain_config('test.example.com')
6 print(response)
删除加速域名
Python
1def test_delete_domain(c):
2 """
3 test_delete_domain
4 """
5 response = c.delete_domain('example.test.com')
6 print(response)