加速域名配置

设置回源地址

def test_set_domain_origin(self):
    """
    test_set_domain_origin
    """
    error = None
    try:
        origin = [
                    {'peer': '1.2.3.4', 'host': 'www.origin_host.com'}, #回源地址1.2.3.4,回源Host www.origin_host.com,不配置则默认使用加速域名
                    {'peer': '1.2.3.5', 'host': 'www.origin_host.com'}
                 ]
        response = self.cdn_client.set_domain_origin('opencdn3.sys-qa.com', origin)
        print response
    except BceServerError as e:
        error = e
    finally:
        self.assertIsNone(error)

设置缓存策略

def test_set_domain_cache_ttl(self):
    """
    test_set_domain_cache_ttl
    """
    error = None
    try:
        rules = []
        rules.append({'type':'suffix', 'value': '.jpg', 'ttl': 3600, 'weight': 30})    # .jpg后缀缓存一小时
        rules.append({'type':'path', 'value': '/a/b/c', 'ttl': 1800, 'weight': 15})    # /a/b/c/目录下所有文件缓存1800秒
        response = self.cdn_client.set_domain_cache_ttl('opencdn3.sys-qa.com', rules)
        print response
    except BceServerError as e:
        error = e
    finally:
        self.assertIsNone(error)

设置全url缓存

def test_set_domain_cache_full_url(self):
    """
    test_set_domain_cache_full_url
    """
    error = None
    try:
        response = self.cdn_client.set_domain_cache_full_url('opencdn3.sys-qa.com', True)
        print response
    except BceServerError as e:
        error = e
    finally:
        self.assertIsNone(error)

设置访问Referer控制

def test_set_domain_referer_acl(self):
    """
    test_set_domain_referer_acl
    """
    error = None
    try:
        blackList = ["http://a.com", "http://c.com"]
        response = self.cdn_client.set_domain_referer_acl(
                            domain = 'opencdn3.sys-qa.com',
                            blackList = blackList,
                            allowEmpty = True)
        print response
    except BceServerError as e:
        error = e
    finally:
        self.assertIsNone(error)

设置访问Ip控制

def test_set_domain_ip_acl(self):
    """
    test_set_domain_ip_acl
    """
    error = None
    try:
        blackList = ['1.1.1.2', '1.1.1.3']
        response = self.cdn_client.set_domain_ip_acl(
                            domain = 'opencdn3.sys-qa.com',
                            blackList = blackList)
        print response
    except BceServerError as e:
        error = e
    finally:
        self.assertIsNone(error)

设置访问鉴权

def test_set_request_auth(self):
    """
    test_set_request_auth
    """
    error = None
    try:
        request_auth = {
            "type": "c",
            "key1": "secretekey1",
            "key2": "secretekey2",
            "timeout": 300,
            "whiteList": ["/crossdomain.xml"],
            "signArg": "sign",
            "timeArg": "t"
        }
        self.cdn_client.set_request_auth('opencdn3.sys-qa.com', request_auth)
    except BceServerError as e:
        error = e
    finally:
        self.assertIsNone(error)

设置域名https

def test_set_domain_https(self):
    """
    test_set_domain_https
    """
    error = None
    try:
        https = {
                'enabled': True,
                'certId': 'cert-rm45x46isit4',
                }
        response = self.cdn_client.set_domain_https('opencdn3.sys-qa.com', https)
        print response
    except BceServerError as e:
        error = e
    finally:
        self.assertIsNone(error)