OpenResty Edge™ Python SDK Manual
Method | Parameters | Parameters type | Description | Return type |
---|---|---|---|---|
Edge2Client | host, username, password, api_token | string | init SDK client | object |
login | login to edge system | bool | ||
use_app | app_id | number | set the application you want to operate | bool |
new_app | domains, label | string | add a new application | number |
put_app | domains, label | string | update application | bool |
get_app | app_id | number | get application info | array |
put_app_config | limiter | dict | update application config | bool |
get_app_config | app_id | number | get application config | dict |
del_app | app_id | number | delete application | bool |
search_app | **kwargs | dict | search application | array |
search_http_app_by_keyword | **kwargs | dict | search application by domain or name | array |
search_upstream_by_ip | **kwargs | dict | search upstream by IP | array |
search_upstream_by_name | **kwargs | dict | search upstream by name | array |
search_k8s_upstream_by_name | **kwargs | dict | search upstream by name | array |
get_all_apps | get all applications | array | ||
new_upstream | **kwargs | dict | add a new upstream | number |
put_upstream | **kwargs | dict | update upstream | bool |
get_upstream | up_id | number | get upstream by up_id | array |
del_upstream | up_id | number | delete upstream | bool |
get_all_upstreams | detail | bool | get all upstreams | array |
new_k8s_upstream | **kwargs | dict | add a new k8s upstream | number |
copy_upstream_to_k8s_upstream | up_id, k8s_services | number | copy an upstream to an k8s_upstream | number |
put_k8s_upstream | **kwargs | dict | update k8s upstream | bool |
get_k8s_upstream | up_id | number | get k8s upstream by up_id | array |
del_k8s_upstream | up_id | number | delete k8s upstream | bool |
get_all_k8s_upstreams | detail | bool | get all k8s upstreams | array |
new_rule | **kwargs | dict | add a new request rewrite rule | number |
put_rule | **kwargs | dict | update request rewrite rule | bool |
get_rule | rule_id | number | get request rewrite rule | array |
del_rule | rule_id | number | delete request rewrite rule | bool |
get_all_rules | app_id | number | get all request rewrite rules | array |
reorder_rules | orders | dict | adjust the order of page rules | bool |
get_global_actions_used_in_app | app_id | number | get all request rewrite global action rules | array |
get_all_rules_by_app_domain | domain | string | get request rewrite rules of all matched apps by domain | array |
get_all_rules_by_upstream_ip | IP | string | get request rewrite rules of all matched apps by upstream IP | array |
get_all_waf_rules | app_id | number | get all waf rules | array |
set_le_cert | **kwargs | dict | set LE SSL | number |
put_le_cert | **kwargs | dict | put LE SSL | number |
get_le_cert | cert_id | number | get LE certificate status | |
set_cert_key | **kwargs | dict | set SSL key and cert | number |
put_cert_key | **kwargs | dict | update SSL key and cert | bool |
get_cert_key | cert_id | number | get SSL key and cert | array |
get_all_cert_keys | get all SSL key and certs | array | ||
del_cert_key | cert_id | list | delete SSL key and cert | bool |
new_el | phase, code, **kwargs | string, string, array | add EL code | number |
new_release | new release | bool | ||
pending_changes | pending changes | number | ||
sync_status | the sync status of release | number, number | ||
use_dns_app | app_id | number | set the DNS application you want to operate | bool |
new_dns_app | **kwargs | dict | add a new DNS | number |
put_dns_app | **kwargs | dict | update DNS | bool |
get_dns_app | dns_id | number | get DNS | array |
del_dns_app | dns_id | number | delete DNS | bool |
new_dns_record | **kwargs | dict | add record of DNS | number |
put_dns_record | **kwargs | dict | update record of DNS | bool |
get_dns_record | record_id | number | get record of DNS | array |
del_dns_record | record_id | number | delete record of DNS | bool |
set_global_cert_key | **kwargs | dict | set global cert and key | number |
put_global_cert_key | **kwargs | dict | update global cert and key | bool |
get_global_cert_key | cert_id | number | get global cert and key | array |
del_global_cert_key | cert_id | number | delete global cert and key | bool |
add_global_user | **kwargs | dict | add global user | bool |
search_global_user | name | string | search global user | array |
get_all_global_users | detail | boolean | get all global user | array |
add_app_user | **kwargs | dict | add user of application | number |
put_app_user | **kwargs | dict | update user of application | bool |
get_app_user | **kwargs | dict | get user of application | array |
del_app_user | **kwargs | dict | delete user of application | array |
get_all_app_users | get all users of application | array | ||
add_user_for_all_apps | **kwargs | dict | add user for all applications | bool |
add_all_users_for_app | **kwargs | dict | add all users for application | bool |
new_global_rule | **kwargs | dict | add a new global rewrite rule | number |
put_global_rule | **kwargs | dict | update global rewrite rule | bool |
get_global_rule | rule_id | number | get global rewrite rule | array |
get_global_action_by_name | name | string | get global action id by name | number |
get_all_global_rules | get all global rewrite rules | array | ||
del_global_rule | rule_id | number | delete global rewrite rule | bool |
new_global_var | **kwargs | dict | add a new global var | number |
put_global_var | **kwargs | dict | update global var | bool |
get_global_var | var_id | number | get global var | array |
get_all_global_vars | get all global vars | array | ||
del_global_var | var_id | number | delete global var | bool |
get_global_ngx_config | get global nginx configures | array | ||
set_global_ngx_config | opts | dict | set global nginx configures | bool |
get_global_misc_config | get global misc configures | array | ||
set_global_misc_config | opts | dict | set global misc configures | bool |
get_request_id_status | get status of global request id | bool | ||
enable_request_id | enable global request id | bool | ||
disable_request_id | disable global request id | bool | ||
new_global_waf_rule | **kwargs | dict | add a new global waf rule | number |
put_global_waf_rule | **kwargs | dict | update global waf rule | bool |
get_global_waf_rule | rule_id | number | get global waf rule by id | array |
del_global_waf_rule | rule_id | number | delete global waf rule by id | bool |
get_all_global_waf_rules | detail | bool | return all global waf rule sets with name and id, and including built-in rule sets | array |
new_global_action | **kwargs | dict | add a new global custom action | number |
put_global_action | **kwargs | dict | update global custom action | bool |
get_global_action | action_id | number | get global custom action | array |
del_global_action | action_id | number | delete global custom action | bool |
count_global_actions | Get the number of Global Actions | bool | ||
get_all_global_actions | get all global actions | bool | ||
new_user_var | **kwargs | dict | add a new user var | number |
put_user_var | **kwargs | dict | update user var | bool |
get_user_var | var_id | number | get user var | array |
del_user_var | var_id | number | delete user var | bool |
node_sync_status | sync status of all nodes | dict | ||
upload_static_file | **kwargs | dict | upload global static file | number |
get_static_file | file_id | number | get global static file | array |
del_static_file | file_id | number | delete global static file | bool |
new_waf_whitelist | **kwargs | dict | add a new whitelist rule | number |
put_waf_whitelist | **kwargs | dict | update waf whitelist rule | bool |
get_waf_whitelist | whitelist_id | number | get waf whitelist by id | array |
del_waf_whitelist | whitelist_id | number | delete waf whitelist rule by id | bool |
get_all_waf_whitelists | detail | bool | return all whitelist rules | array |
new_ip_list | add application IP list | bool | ||
put_ip_list | id | number | change the specified IP list | bool or number |
del_ip_list | id | number | delete the specified IP list | bool |
get_ip_list | id | number | get the specified IP list | dict |
get_healthcheck_status | node_id | number | return health check status | array |
new_cluster_group | name | dict | add a new cluster group | number |
put_cluster_group | **kwargs | dict | update cluster group | bool |
get_cluster_group | group_id | number | get cluster group | dict |
get_all_cluster_groups | get all cluster groups | array | ||
del_cluster_group | group_id | number | delete cluster group | bool |
put_proxy_rule | **kwargs | dict | update proxy rule | bool |
decode_request_id | request_id | string | get info from request_id | dict |
search_waf_log | request_id | string | search waf log by request id | dict or None |
add_api_token | name, expire | string, number | add api token | dict |
get_api_token | id, limit | number, number | get api token | dict |
del_api_token | id | number | delete api token | bool |
get_all_gateway_tag | get all gateway tag | array | ||
get_all_gateway | get all gateway | array | ||
get_app_metrics | id | number | get HTTP request status metrics and network metrics | array |
new_app_dymetrics | add application dynamic metrics | bool | ||
put_app_dymetrics | id | number | change the specified application dynamic metrics | bool or number |
del_app_dymetrics | id | number | delete the specified application dynamic metrics | bool |
get_app_dymetrics | id | number | get the specified application dynamic metrics | dict |
get_all_app_dymetrics | get all application dynamic metrics | array | ||
get_app_dymetrics_data | get application dynamic metrics data | array | ||
new_global_dymetrics | add global dynamic metrics | bool | ||
put_global_dymetrics | id | number | change the specified global dynamic metrics | bool or number |
del_global_dymetrics | id | number | delete the specified global dynamic metrics | bool |
get_global_dymetrics | id | number | get the specified global dynamic metrics | dict |
get_all_global_dymetrics | get all global dynamic metrics | array | ||
get_global_dymetrics_data | get all global dynamic metrics data | array | ||
new_global_ip_list | add global IP list | bool | ||
put_global_ip_list | id | number | change the specified IP list | bool or number |
del_global_ip_list | id | number | delete the specified IP list | bool |
get_global_ip_list | id | number | get the specified IP list | dict |
node_monitor | get CPU and memory load metrics for gateway nodes | array | ||
get_version | Obtain the versions of Admin, Admin DB, Log Server, Log Server DB, and WAF. | dict | ||
new_global_k8s | add a new global k8s cluster configuration | number | ||
put_global_k8s | update global k8s cluster configuration | bool | ||
get_global_k8s | get global k8s cluster configuration | dict | ||
get_k8s_services_detail | get k8s service detail info | dict | ||
get_all_global_k8s | get all global k8s | array | ||
del_global_k8s | del global k8s | bool | ||
new_global_upstream | **kwargs | dict | add a new global upstream | number |
put_global_upstream | **kwargs | dict | update global upstream | bool |
get_global_upstream | up_id | number | get global upstream by up_id | array |
del_global_upstream | up_id | number | delete global upstream | bool |
get_all_global_upstreams | detail | bool | get all global upstreams | array |
new_global_k8s_upstream | **kwargs | dict | add a new global k8s upstream | number |
put_global_k8s_upstream | **kwargs | dict | update global k8s upstream | bool |
get_global_k8s_upstream | up_id | number | get global k8s upstream by up_id | array |
del_global_k8s_upstream | up_id | number | delete global k8s upstream | bool |
get_all_global_k8s_upstreams | detail | bool | get all global k8s upstreams | array |
get_all_nodes | get all gateway nodes | array | ||
get_node | node_id, gateway_id | number, number | get node by node id | dict |
get_node_by_mac_address | mac_address | string | get node by MAC address of node | dict |
put_node | node_id, gateway_id, **kwargs | number, number, dict | update node | bool |
del_node | node_id, gateway_id | number, number | delete node | bool |
lmdb_backup | trigger a backup of LMDB. | bool | ||
get_global_cert_referenced | id | number | get a list of applications that reference the specified global certificate | list |
get_all_partition_lua_module | partition_id | number | get all Lua modules for the specified partition. | list |
get_partition_lua_module | partition_id, module_id | number, number | get the specified Lua module for the specified partition | dict |
new_partition_lua_module | partition_id, name, code | number, string, string | adds a Lua module to the specified partition | dict |
put_partition_lua_module | partition_id, module_id, name, code | number, number, string, string | edit the specified Lua module for the specified partition | dict |
del_partition_lua_module | partition_id, module_id | number, number | removes the specified Lua module for the specified partition | dict |
conv_crl_to_lua_module | crl_files | array | convert CRL to Lua Module | string |
get_all_candidate_node | get all candidate nodes | array | ||
approve_candidate_node | gateway_id, mac_address | number, string | approve the node to join the gateway cluster | bool |
Edge2Client
client = Edge2Client(host, username, password, api_token=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
host | string | yes | address of edge admin, including host and port |
username | string | yes | username of edge-admin |
password | string | yes | password of edge-admin |
api_token | string | no | api access token of edge-admin |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
# or
client = Edge2Client('http://127.0.0.1:8080', None, None, 'api_token')
login
ok = login()
Returns True
if login success else False
.
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
ok = client.login()
use_app
ok = use_app(app_id)
Returns True
if success else False
.
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
client.use_app(10)
new_app
app_id = new_app(domains, label)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
domains | list | yes | domains of application |
label | string | yes | name of application |
cluster_groups | list | no | cluster group ids of application |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com', cluster_groups = [1])
put_app
ok = put_app(domains, label)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
app_id | number | yes | id of application |
domains | list | yes | domains of application |
label | string | yes | name of application |
cluster_groups | list | no | cluster group ids of application |
offline | bool | no | the offline status of application |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
ok = client.put_app(app_id, domains = ['*.foo.com'], label = 'foo.com')
get_app
data = get_app()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
data = client.get_app()
put_app_config
ok = put_app_config(limiter)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
app_id | number | yes | id of application |
limiter | dict | yes | config of application |
enable_websocket | bool | no | enable websocket |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
ok = client.put_app_config(app_id, {'max_uri_args': 120, 'check_post_args_type': False}, True)
get_app_config
data = get_app_config(app_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
data = client.get_app_config(app_id)
del_app
ok = del_app(app_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
ok = client.del_app(app_id)
search_app
data = search_app(app_domain)
Key name | Type | Required | Description |
---|---|---|---|
app_domain | string | yes | search app by the domain |
page | number | no | page number of results, default value is ‘1’ |
pagesize | number | no | page size of results, default value is ‘20’ |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
data = client.search_app(app_domain = 'orig.foo.com')
search_http_app_by_keyword
data = search_http_app_by_keyword(keyword, page, pagesize)
Key name | Type | Required | Description |
---|---|---|---|
keyword | string | yes | search app by the domain or name |
page | number | no | page number of results, default value is ‘1’ |
pagesize | number | no | page size of results, default value is ‘20’ |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
data = client.search_http_app_by_keyword('orig.foo.com')
data = client.search_http_app_by_keyword('orig.foo.com', 1, 50)
data = client.search_http_app_by_keyword('origin')
search_upstream_by_ip
data = search_upstream_by_ip(ip, page, pagesize)
Key name | Type | Required | Description |
---|---|---|---|
ip | string | yes | search upstream by IP |
page | number | no | page number of results, default value is ‘1’ |
pagesize | number | no | page size of results, default value is ‘20’ |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.search_upstream_by_ip('1.1.1.1')
search_k8s_upstream_by_ip
data = search_k8s_upstream_by_ip(ip, page, pagesize)
Key name | Type | Required | Description |
---|---|---|---|
ip | string | yes | search upstream by ip |
page | number | no | page number of results, default value is ‘1’ |
pagesize | number | no | page size of results, default value is ‘20’ |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.search_k8s_upstream_by_ip('1.1.1.1')
search_upstream_by_name
data = search_upstream_by_name(name, page, pagesize)
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | search upstream by name |
page | number | no | page number of results, default value is ‘1’ |
pagesize | number | no | page size of results, default value is ‘20’ |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.search_upstream_by_name('test')
search_k8s_upstream_by_name
data = search_k8s_upstream_by_name(name, page, pagesize)
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | search upstream by name |
page | number | no | page number of results, default value is ‘1’ |
pagesize | number | no | page size of results, default value is ‘20’ |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.search_k8s_upstream_by_name('test')
search_k8s_upstream
data = search_k8s_upstream(namespace, service, port, page, pagesize, type_list=['k8s_http', 'k8s_global']):
Key name | Type | Required | Description |
---|---|---|---|
namespace | string | no | search upstream by namespace |
service | string | no | search upstream by service |
port | number | no | search upstream by port |
page | number | no | page number of results, default value is ‘1’ |
pagesize | number | no | page size of results, default value is ‘20’ |
type_list | list | no | search type list, k8s_http, k8s_global, the default is search all |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.search_k8s_upstream(port = 80, service = "test-hello", namespace = "default")
search_k8s_upstream_history
data = search_k8s_upstream_history( page, pagesize, start_time, end_time):
Key name | Type | Required | Description |
---|---|---|---|
page | number | no | page number of results, default value is ‘1’ |
pagesize | number | no | page size of results, default value is ‘20’ |
start_time | number | no | start time |
end_time | number | no | end time |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.search_k8s_upstream_history(1, 10)
get_all_apps
data = get_all_apps(detail)
Key name | Type | Required | Description |
---|---|---|---|
detail | bool | no | default is False , only return app ids; returns app’s detail if True |
the return data
will be list
if detail
is False
, and will be dict
if detail
is True
.
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
apps = client.get_all_apps()
apps = client.get_all_apps(detail = True)
new_upstream
app_id = new_upstream(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of upstream |
servers | list | yes | upstreams |
ssl | bool | no | set protocol to HTTPS, default is false(HTTP) |
health_checker | dict | no | detail configure of health checker, default is none |
servers
Description of array servers
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
domain | string | no | domain of upstream |
ip | string | no | IP of upstream. Choose one from domain and ip |
port | string | yes | port of upstream |
weight | number | no | weight of upstream, default is 1 |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
up_id = client.new_upstream(name = 'origin-upstream',
servers = [
{'ip': '172.22.31.1', 'port': 80},
{'ip': '172.22.31.2', 'port': 80, 'weight': 2}
])
put_upstream
ok = put_upstream(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of upstream |
servers | list | yes | upstreams |
ssl | bool | no | set protocol to HTTPS, default is false(HTTP) |
health_checker | dict | no | detail configure of health checker, default is none |
servers
Description of array servers
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
domain | string | no | domain of upstream |
ip | string | no | IP of upstream. Choose one from domain and ip |
port | string | yes | port of upstream |
weight | number | no | weight of upstream, default is 1 |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
up_id = client.new_upstream(name = 'origin-upstream',
servers = [
{'domain': 'a.com', 'port': 80},
{'ip': '172.22.31.2', 'port': 80, 'weight': 2}
])
ok = client.put_upstream(up_id, name = 'origin-upstream',
servers = [
{'domain': 'test.com', 'port': 8080},
{'ip': '172.22.31.2', 'port': 8080, 'weight': 1}
],
health_checker = {
'type': 'http',
'http_req_uri': '/status',
'http_req_host': 'test.com',
'interval': 3,
'interval_unit': 'sec',
'timeout': 1,
'fall': 3,
'rise': 2,
'valid_statuses': [200, 302],
'report_interval': 3,
'report_interval_unit': 'min'
})
get_upstream
data = get_upstream(up_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
up_id = client.new_upstream(name = 'origin-upstream',
servers = [
{'ip': '172.22.31.1', 'port': 80},
{'ip': '172.22.31.2', 'port': 80, 'weight': 2}
])
data = client.get_upstream(up_id)
del-upstream
ok = del_upstream(up_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
up_id = client.new_upstream(name = 'origin-upstream',
servers = [
{'ip': '172.22.31.1', 'port': 80},
{'ip': '172.22.31.2', 'port': 80, 'weight': 2}
])
ok = client.del_upstream(up_id)
get_all_upstreams
upstreams = client.get_all_upstreams()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
up_id = client.new_upstream(name = 'origin-upstream',
servers = [
{'ip': '172.22.31.1', 'port': 80},
{'ip': '172.22.31.2', 'port': 80, 'weight': 2}
])
upstreams = client.get_all_upstreams(up_id)
new_k8s_upstream
k8s_up_id = new_k8s_upstream(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of upstream |
k8s_services | list | yes | upstreams is k8s services |
ssl | bool | no | set protocol to HTTPS, default is false(HTTP) |
health_checker | dict | no | detail configure of health checker, default is none |
k8s_services
Description of array k8s_services
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
k8s | number | yes | k8s cluster id |
k8s_namespace | string | yes | k8s namespace |
k8s_service | string | yes | k8s service |
k8s_service_port | number | yes | k8s service port |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
k8s_up_id = client.new_k8s_upstream(name = 'k8s-upstream',
k8s_services = [
{
'k8s' : 1,
'k8s_namespace' : 'default',
'k8s_service' : 'foo',
'k8s_service_port' : 80,
}
])
copy_upstream_to_k8s_upstream
k8s_up_id = copy_upstream_to_k8s_upstream(up_id, k8s_services, rules)
Key name | Type | Required | Description |
---|---|---|---|
up_id | number | yes | origin upstream id |
k8s_services | list | yes | k8s services |
rules | array | no | the rules will be traversed and the original upstream is used in rules will be migrated to k8s upstream. |
k8s_services
Description of array k8s_services
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
k8s | number | yes | k8s cluster id |
k8s_namespace | string | yes | k8s namespace |
k8s_service | string | yes | k8s service |
k8s_service_port | number | yes | k8s service port |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
up_id = client.new_upstream(name = 'origin-upstream',
servers = [
{'ip': '172.22.31.1', 'port': 80},
{'ip': '172.22.31.2', 'port': 80, 'weight': 2}
])
k8s_up_id = client.copy_upstream_to_k8s_upstream(up_id,
k8s_services = [
{
'k8s' : 1,
'k8s_namespace' : 'default',
'k8s_service' : 'foo',
'k8s_service_port' : 80,
}
])
Example2
client.use_app(app_id)
rules = client.get_all_rules()
k8s_up_id = client.copy_upstream_to_k8s_upstream(up_id = up_id,
k8s_services = [
{
'k8s' : 1,
'k8s_namespace' : 'default',
'k8s_service' : 'foo',
'k8s_service_port' : 80,
}
],
rules = rules)
put_k8s_upstream
ok = put_k8s_upstream(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of upstream |
k8s_services | list | yes | upstreams is k8s services |
ssl | bool | no | set protocol to HTTPS, default is false(HTTP) |
health_checker | dict | no | detail configure of health checker, default is none |
servers
Description of array servers
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
domain | string | no | domain of upstream |
ip | string | no | IP of upstream. Choose one from domain and ip |
port | string | yes | port of upstream |
weight | number | no | weight of upstream, default is 1 |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
ok = client.put_k8s_upstream(up_id, name = 'origin-upstream',
k8s_services = [
{
'k8s' : 1,
'k8s_namespace' : 'default',
'k8s_service' : 'foo',
'k8s_service_port' : 80,
}
],
health_checker = {
'type': 'http',
'http_req_uri': '/status',
'http_req_host': 'test.com',
'interval': 3,
'interval_unit': 'sec',
'timeout': 1,
'fall': 3,
'rise': 2,
'valid_statuses': [200, 302],
'report_interval': 3,
'report_interval_unit': 'min'
})
get_k8s_upstream
data = get_k8s_upstream(up_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
data = client.get_k8s_upstream(up_id)
del-k8s-upstream
ok = del_k8s_upstream(up_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
ok = client.del_k8s_upstream(up_id)
get_all_k8s_upstreams
upstreams = client.get_all_k8s_upstreams()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
upstreams = client.get_all_k8s_upstreams(app_id)
new_rule
rule_id = new_rule(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
condition | list | no | conditions of rule |
conseq | dict or list | no | actions of rule |
waf | list | no | rules of waf |
proxy | list | no | rules of proxy |
cache | list | no | rules of cache |
content | list | no | rules of content |
top | number | no | 1: always top rule, -1: always bottom rule |
order | number | no | rule order, lower priority than top parameter |
last | boolean | no | skip any subsequent page rules when this rule matches |
reorder | boolean | no | whether to rebuild the value of order, default is False |
condition
Description of array condition
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
var | string or array | yes | name of edgelang builtin predicate function if type is string , name and args of function if type is array |
op | string | no | operator, default is eq |
val | string | either val or vals | string or array |
vals | list | either val or vals | array of val |
conseq
Description of conseq
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
edgelang builtin action function | string | yes | one of edgelang builtin action functions |
args of edgelang builtin action function | list | yes | args of edgelang builtin action function |
conseq
can be a dict or a list, below is an example of dict.
Example 1
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [
{
'var': 'host',
'val': 'con.' + APEX
},
{
'var': ['req-header', 'Referer'],
'vals': [
'foo.com',
['foo\d+', 'rx'],
['foo*', 'wc']
]
}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302},
'user-code': {'el': 'true => say(\"hello\");'}
}
rule_id = client.new_rule(condition = condition, conseq = conseq)
The dict
is not guaranteed to be in order, and cannot set the same action repeatedly.
So it is recommended to use the usage of the following list
instead of dict
:
Example 2
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [
{'var': 'host', 'val': 'con.' + APEX},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = [
{'set-proxy-header': {
'header': 'Foo',
'value': 'default',
}},
{'set-proxy-header': {
'header': 'Host',
'value': "orig",
}},
{'print': {
'msg': 'hello'
}}
]
rule_id = client.new_rule(condition = condition, conseq = conseq)
waf
Description of array waf
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
rule_sets | list | no | the set of user defined rules in global waf, default is empty array |
robots | bool | no | whether to enable this type of detection, default is False |
generic | bool | no | whether to enable this type of detection, default is False |
inject | bool | no | whether to enable this type of detection, default is False |
trojans | bool | no | whether to enable this type of detection, default is False |
xss | bool | no | whether to enable this type of detection, default is False |
action | string | yes | one of log , 403 Forbidden , edge-captcha , redirect |
threshold | string | yes | one of high , medium or low |
clearance | number | no | clearance time of edge captcha challenge, default is 60 secs |
redirect_url | string | no | redirect url when action is redirect |
Example of waf rule
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
user_defined_waf_rule_id = client.new_global_waf_rule(name = 'foo', code = "uri-arg('foo') => waf-mark-risk(level: 'definite', msg: 'found foo');")
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [{'var': 'uri', 'op': 'prefix', 'val': '/foo'}]
waf_rule = {'rule_sets': [user_defined_waf_rule_id], 'robots': True, 'generic': True, 'inject': True, 'action': '403 Forbidden', 'threshold': 'low'}
rule_id = client.new_rule(condition = condition, waf = waf_rule)
proxy
Description of array proxy
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
upstreams | list | yes | upstreams |
backup_upstreams | list | yes | backup upstreams |
upstream_el_code | str | yes | using Edgelang to set upstream |
timeout | number | no | timeout of proxy, default is 3 seconds |
connect_timeout | number | no | connect timeout of proxy, default is the same as timeout |
read_timeout | number | no | read timeout of proxy, default is the same as timeout |
send_timeout | number | no | send timeout of proxy, default is the same as timeout |
retries | number | no | retries time, default is 1 |
retry_condition | list | no | conditions of retry, default is [“error”, “timeout”, “invalid_header”, “http_500”, “http_502”, “http_504”]. And “http_503”, “http_403”, “http_404”, “http_429” and “non_valueempotent”(means even when method is POST, LOCK, PATCH) are also optional. |
balancer_algorithm | string | no | algorithm of balancing policy, default is roundrobin , and you can set to hash and chash . |
balancer_vars | list | no | variables of balancing policy. If you set to balancer_algorithm to hash or chash , then you must set balancer_vars too. |
multi_tier | number | no | multi-tier policy ID. |
upstreams
Description of array upstreams
and backup_upstreams
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
upstream | number | yes | id of upstream |
global_upstream | number | yes | id of global upstream |
k8s_upstream | number | yes | id of k8s upstream |
global_k8s_upstream | number | yes | id of global k8s upstream |
weight | number | no | weight of upstream, default is 1 |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
up_id = client.new_upstream(name = 'origin-upstream',
servers = [
{'ip': '172.22.31.1', 'port': 80},
{'ip': '172.22.31.2', 'port': 80, 'weight': 2}
])
k8s_up_id = client.new_k8s_upstream(
name='k8s-upstream',
k8s_services = [
{
'k8s' : k8s_id,
'k8s_namespace' : 'default',
'k8s_service' : 'test-hello',
'k8s_service_port' : 80,
}
])
ok = client.put_upstream(up_id, name = 'origin-upstream',
servers = [
{'ip': '172.22.31.1', 'port': 8080},
{'ip': '172.22.31.2', 'port': 8080, 'weight': 1}
])
backup_up_id = client.new_upstream(name = 'backup-upstream',
servers = [
{'ip': '172.22.31.3', 'port': 80},
{'ip': '172.22.31.4', 'port': 80, 'weight': 3}
])
proxy_rule = {
'upstreams': [{'upstream': up_id, 'weight': 2}],
'backup_upstreams': [{'upstream': backup_up_id}],
'upstream_el_code': '',
'retries': 2,
"retry_condition": ["invalid_header", "http_500"],
"balancer_algorithm": "hash",
"balancer_vars": [
{"name":"uri"},
{
"name":"uri-arg",
"args":"foo"
}
]
}
rule_id = client.new_rule(proxy = proxy_rule)
k8s_proxy_rule = {
'upstreams': [{'k8s_upstream': up_id, 'weight': 2}],
'upstream_el_code': '',
'retries': 2,
"retry_condition": ["invalid_header", "http_500"],
"balancer_algorithm": "hash",
"balancer_vars": [
{"name":"uri"},
{
"name":"uri-arg",
"args":"foo"
}
]
}
k8s_rule_id = client.new_rule(proxy = k8s_proxy_rule)
cache
Description of array cache
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
cache_key | list | yes | cache keys |
default_ttls | list | no | Caching by Default, the default value is None |
browser_ttl | number | no | Browser Cache, the default value is None |
browser_ttl_unit | string | no | Browser Cache Unit, only valid after browser_ttl is set, the default value is ‘min’ |
enable_global | boolean | no | Cache Across Domains, the default value is False |
enforce_cache | boolean | no | Always Cache, the default value is False |
cluster_hash | boolean | no | Gateway Cluster Level Cache Sharing, the default value is False |
disable_convert_head | boolean | no | Convert request method HEAD to GET, the default value is True |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [{'var': 'client-country', 'op': 'eq', 'val': 'CN'}]
# cache_key = ['uri', 'query-string', 'client-city']
# or
cache_key = [
{'name': 'uri'},
{'name':'query-string'},
{'name': 'client-city', 'args': 'first-x-forwarded-addr'}
]
default_ttls = [
{
'ttl_unit': "min", 'status': 200, 'ttl': 1
}, {
'ttl_unit': "min", 'status': 301, 'ttl': 1
}
]
cache_rule = {'cache_key': cache_key, 'default_ttls': default_ttls}
rule_id = client.new_rule(condition = condition, cache = cache_rule)
content
Description of array content
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
favicon | number | yes | file id |
gid | number | no | array of user group id |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [{'var': 'uri', 'op': 'eq', 'val': '/favicon.ico'}]
file_id = client.upload_favicon(name = 'test', favicon_content = 'content', gid=[1])
rule_id = client.new_rule(condition = condition, content = {'favicon': file_id})
put_rule
ok = put_rule(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
condition | list | no | conditions of rule |
conseq | dict or list | no | actions of rule |
waf | list | no | rules of waf |
proxy | list | no | rules of proxy |
cache | list | no | rules of cache |
content | list | no | rules of content |
top | number | no | 1: always top rule, -1: always bottom rule |
order | number | no | rule order, lower priority than top parameter |
last | boolean | no | skip any subsequent page rules when this rule matches |
condition
Description of array condition
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
var | string or array | yes | name of edgelang builtin predicate function if type is string , name and args of function if type is array |
op | string | no | operator, default is eq |
val | string | either val or vals | value |
vals | list | either val or vals | array of val |
conseq
Description of array conseq
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
edgelang builtin action function | string | yes | one of edgelang builtin action functions |
args of edgelang builtin action function | list | yes | args of edgelang builtin action function |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [
{'var': 'host', 'val': 'con.' + APEX},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302}
}
rule_id = client.new_rule(condition = condition, conseq = conseq)
conseq['redirect']['url'] = '/cn/2018/'
ok = client.put_rule(rule_id = rule_id, condition = condition, conseq = conseq)
get_rule
ok = get_rule(rule_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [
{'var': 'host', 'val': 'con.' + APEX},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302}
}
rule_id = client.new_rule(condition = condition, conseq = conseq)
data = client.get_rule(rule_id)
del_rule
ok = del_rule(rule_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [
{'var': 'host', 'val': 'con.' + APEX},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302}
}
rule_id = client.new_rule(condition = condition, conseq = conseq)
conseq['redirect']['url'] = '/cn/2018/'
ok = client.del_rule(rule_id)
get_all_rules
rules = get_all_rules(app_id)
Key name | Type | Required | Description |
---|---|---|---|
app_id | number | no | id of app, default is the current id of app |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [{'var': 'client-country', 'op': 'eq', 'val': 'CN'}]
cache_key = ['uri', 'query-string', 'client-city']
cache_rule = {'cache_key': cache_key}
rule_id = client.new_rule(condition = condition, cache = cache_rule, top = 1)
condition = [
{'var': 'host', 'val': 'con.foo.com'},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302}
}
rule_id = client.new_rule(condition = condition, conseq = conseq, last = True)
data = client.get_all_rules()
reorder_rules
ok = reorder_rules(orders)
Key name | Type | Required | Description |
---|---|---|---|
orders | number | no | the new rule order, key indicates the rule ID, value indicates the rule order |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
# swap the order of rule IDs 2 and 3
new_orders = {
1: 1,
2: 3,
3: 2,
}
data = client.reorder_rules(new_orders)
get_global_actions_used_in_app
rules = get_global_actions_used_in_app(app_id)
Key name | Type | Required | Description |
---|---|---|---|
app_id | number | no | id of app, default is the current id of app |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [
{'var': 'host', 'val': 'con.' + APEX},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302}
}
name = "test-actions"
client.new_global_rule(condition=condition, conseq=conseq, name=name)
rule_ids = client.get_global_actions_used_in_app(app_id)
get_all_rules_by_app_domain
rules = get_all_rules_by_app_domain(domain)
Key name | Type | Required | Description |
---|---|---|---|
domain | string | yes | domain name of app |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [{'var': 'client-country', 'op': 'eq', 'val': 'CN'}]
cache_key = ['uri', 'query-string', 'client-city']
cache_rule = {'cache_key': cache_key}
rule_id = client.new_rule(condition = condition, cache = cache_rule, top = 1)
condition = [
{'var': 'host', 'val': 'foo.com'},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302}
}
rule_id = client.new_rule(condition = condition, conseq = conseq, last = True)
data = client.get_all_rules_by_app_domain('orig.foo.com')
get_all_rules_by_upstream_ip
rules = get_all_rules_by_upstream_ip(domain)
Key name | Type | Required | Description |
---|---|---|---|
ip | string | yes | IP of upstream |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
upstream_ip = '172.22.31.2'
up_id = client.new_upstream(name = 'origin-upstream',
servers = [
{'domain': 'test.com', 'port': 80},
{'ip': upstream_ip, 'port': 80, 'weight': 2}
])
proxy_rule = {
'upstreams': [{'upstream': up_id, 'weight': 2}],
'retries': 2,
"retry_condition": ["invalid_header", "http_500"],
"balancer_algorithm": "hash",
"balancer_vars": [
{"name": "uri"},
{
"name": "uri-arg",
"args": "foo"
}
]
}
rule_id = client.new_rule(proxy = proxy_rule, top = 1)
data = client.get_all_rules_by_upstream_ip(upstream_ip)
for app_id, rules in data.items():
print(app_id)
get_all_waf_rules
rules = get_all_waf_rules(app_id)
Key name | Type | Required | Description |
---|---|---|---|
app_id | number | no | id of app, default is the current id of app |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [{'var': 'client-country', 'op': 'eq', 'val': 'JP'}]
waf_rule = {'robots': False, 'generic': True, 'inject': True, 'action': '403 Forbidden', 'threshold': 'high'}
rule_id = client.new_rule(condition = condition, waf = waf_rule, last = True)
data = client.get_all_waf_rules()
set_le_cert
cert_id = set_le_cert(**kwargs)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
domains | string array | yes | domains |
gid | list | no | array of user group id |
put_le_cert
cert_id = put_le_cert(**kwargs)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
cert_id | number | yes | id of cert |
domains | string array | yes | domains |
gid | list | no | array of user group id |
resign | boolean | no | whether to re-sign the certificate |
get_le_cert
data = get_le_cert(cert_id)
Description of return value data
:
Key name | Type | Description |
---|---|---|
status | string | certificate status: valid / pending / invalid |
expdate | number | the expiration date (in unix timestamp) |
next_update | number | the next update date (in unix timestamp) |
set_cert_key
cert_id = set_cert_key(**kwargs)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
key | string | yes | content of private key |
cert | string | no | content of server cert |
ca_chain | string | no | content of CA chain |
global_cert_id | number | no | id of global cert |
gid | list | no | array of user group id |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
key_file = os.path.join('tests', 'key.pem')
cert_file = os.path.join('tests', 'cert.pem')
with open(key_file) as f:
key = f.read()
with open(cert_file) as f:
cert = f.read()
cert_id = client.set_cert_key(key = key, cert = cert)
put_cert_key
cert_id = put_cert_key(**kwargs)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
cert_id | number | yes | id of cert |
key | string | yes | content of private key |
cert | string | no | content of server cert |
ca_chain | string | no | content of CA chain |
global_cert_id | number | no | id of global cert |
gid | list | no | array of user group id |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
key_file = os.path.join('tests', 'key.pem')
cert_file = os.path.join('tests', 'cert.pem')
with open(key_file) as f:
key = f.read()
with open(cert_file) as f:
cert = f.read()
cert_id = client.set_cert_key(key = key, cert = cert)
new_key_file = os.path.join('tests', 'new_key.pem')
new_cert_file = os.path.join('tests', 'new_cert.pem')
with open(new_key_file) as f:
new_key = f.read()
with open(new_cert_file) as f:
new_cert = f.read()
ok = client.put_cert_key(cert_id = cert_id, key = new_key, cert = new_cert)
get_cert_key
cert_id = get_cert_key(cert_id)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
cert_id | number | yes | id of cert |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
key_file = os.path.join('tests', 'key.pem')
cert_file = os.path.join('tests', 'cert.pem')
with open(key_file) as f:
key = f.read()
with open(cert_file) as f:
cert = f.read()
cert_id = client.set_cert_key(key = key, cert = cert)
data = client.get_cert_key(cert_id)
get_all_cert_keys
cert_id = get_all_cert_keys()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
key_file = os.path.join('tests', 'key.pem')
cert_file = os.path.join('tests', 'cert.pem')
with open(key_file) as f:
key = f.read()
with open(cert_file) as f:
cert = f.read()
cert_id = client.set_cert_key(key = key, cert = cert)
data = client.get_all_cert_keys()
del_cert_key
ok = del_cert_key(cert_id)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
cert_id | number | yes | id of cert |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
key_file = os.path.join('tests', 'key.pem')
cert_file = os.path.join('tests', 'cert.pem')
with open(key_file) as f:
key = f.read()
with open(cert_file) as f:
cert = f.read()
cert_id = client.set_cert_key(key = key, cert = cert)
ok = client.del_cert_key(cert_id)
new_el
ok = new_el(**kwargs)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
phase | string | yes | phase |
code | string | yes | edgelang code |
post | bool | yes | put EL code to then end of phase if set to True , else put to the front of phase |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
code = "true => print('hello, world');"
ok = client.new_el(phase = 'req-rewrite', code = code, pre = True)
new_release
ok = new_release()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
code = "true => print('hello, world');"
ok = client.new_el(phase = 'req-rewrite', code = code, pre = True)
ok = client.new_release()
pending_changes
changes = pending_changes()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
code = "true => print('hello, world');"
ok = client.new_el(phase = 'req-rewrite', code = code, pre = True)
changes = client.pending_changes()
sync_status
total, synced = sync_status()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
code = "true => print('hello, world');"
ok = client.new_el(phase = 'req-rewrite', code = code, pre = True)
ok = client.new_release()
total, synced = client.sync_status()
if total == synced:
print('the new release has been synced to all nodes')
use_dns_app
ok = use_dns_app(dns_id)
Returns True
if success else False
.
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
client.use_dns_app(10)
new_dns_app
dns_id = new_dns_app(**kwargs)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
zone | string | yes | domain of DNS |
authority | list | yes | server names of DNS |
soa_email | string | no | soa email of DNS |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
authority = [
{'domain': 'ns1.foo.com', 'ttl': '2 hour'},
{'domain': 'ns2.foo.com', 'ttl': '1 day'}
]
soa_email = 'admin@foo.com'
dns_id = client.new_dns_app(authority = authority, soa_email = soa_email, zone = 'foo.com')
put_dns_app
ok = put_dns_app(**kwargs)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
dns_id | number | yes | id of DNS |
zone | string | yes | domain of DNS |
authority | list | yes | server names of DNS |
soa_email | string | no | soa email of DNS |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
authority = [
{'domain': 'ns1.foo.com', 'ttl': '2 hour'},
{'domain': 'ns2.foo.com', 'ttl': '1 day'}
]
soa_email = 'admin@foo.com'
dns_id = client.new_dns_app(authority = authority, soa_email = soa_email, zone = 'foo.com')
authority = [
{'domain': 'ns1.foo.com', 'ttl': '4 hour'},
{'domain': 'ns2.foo.com', 'ttl': '1 day'}
]
ok = client.put_dns_app(authority = authority, soa_email = soa_email, zone = 'foo.com')
get_dns_app
data = get_dns_app(dns_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
authority = [
{'domain': 'ns1.foo.com', 'ttl': '2 hour'},
{'domain': 'ns2.foo.com', 'ttl': '1 day'}
]
soa_email = 'admin@foo.com'
dns_id = client.new_dns_app(authority = authority, soa_email = soa_email, zone = 'foo.com')
dat = client.get_dns_app(dns_id)
del_dns_app
ok = del_dns_app(dns_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
authority = [
{'domain': 'ns1.foo.com', 'ttl': '2 hour'},
{'domain': 'ns2.foo.com', 'ttl': '1 day'}
]
soa_email = 'admin@foo.com'
dns_id = client.new_dns_app(authority = authority, soa_email = soa_email, zone = 'foo.com')
dat = client.del_dns_app(dns_id)
new_dns_record
record_id = new_dns_record(**kwargs)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
sub_domain | string | yes | sub domain |
line | number | no | default is 0, see Client Geo Location for detail |
cidr | string | no | cidr |
record_type | string | yes | type of record, one of [A, TXT, MX, CNAME, CAA] |
text | string | no | required if record_type is TXT or CAA |
ip | string | no | required if response is IP |
gateway | number | no | required if response is gateway cluster |
domain | string | no | required if response is domain |
priority | number | no | required if record_type is MX |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
authority = [
{'domain': 'ns1.foo.com', 'ttl': '2 hour'},
{'domain': 'ns2.foo.com', 'ttl': '1 day'}
]
soa_email = 'admin@foo.com'
dns_id = client.new_dns_app(authority = authority, soa_email = soa_email, zone = 'foo.com')
record_id = client.new_dns_record(
sub_domain = 'bar', record_type = 'TXT', text = 'text string')
client.new_dns_record(
sub_domain='bar', record_type='A', ip='127.0.0.1')
client.new_dns_record(
sub_domain='bar', record_type='CNAME', domain='test.com')
client.new_dns_record(
sub_domain='bar', record_type='MX', domain='test.com', priority=3)
put_dns_record
ok = put_dns_record(**kwargs)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
record_id | number | yes | record id of DNS |
sub_domain | string | yes | sub domain |
line | number | no | default is 0, see Client Geo Location for detail |
cidr | string | no | cidr |
record_type | string | yes | type of record, one of [A, TXT, MX, CNAME, CAA] |
text | string | no | required if record_type is TXT or CAA |
ip | string | no | required if response is IP |
domain | string | no | required if response is domain |
priority | number | no | required if record_type is MX |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
authority = [
{'domain': 'ns1.foo.com', 'ttl': '2 hour'},
{'domain': 'ns2.foo.com', 'ttl': '1 day'}
]
soa_email = 'admin@foo.com'
dns_id = client.new_dns_app(authority = authority, soa_email = soa_email, zone = 'foo.com')
record_id = client.new_dns_record(sub_domain = 'bar', record_type = 'TXT', text = 'text string')
ok = client.put_dns_record(record_id = record_id, sub_domain = 'a.bar', record_type = 'TXT', text = 'text string')
get_dns_record
data = get_dns_record(record_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
authority = [
{'domain': 'ns1.foo.com', 'ttl': '2 hour'},
{'domain': 'ns2.foo.com', 'ttl': '1 day'}
]
soa_email = 'admin@foo.com'
dns_id = client.new_dns_app(authority = authority, soa_email = soa_email, zone = 'foo.com')
record_id = client.new_dns_record(sub_domain = 'bar', record_type = 'TXT', text = 'text string')
data = client.get_dns_record(record_id)
del_dns_record
ok = del_dns_record(record_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
authority = [
{'domain': 'ns1.foo.com', 'ttl': '2 hour'},
{'domain': 'ns2.foo.com', 'ttl': '1 day'}
]
soa_email = 'admin@foo.com'
dns_id = client.new_dns_app(authority = authority, soa_email = soa_email, zone = 'foo.com')
record_id = client.new_dns_record(sub_domain = 'bar', record_type = 'TXT', text = 'text string')
ok = client.del_dns_record(record_id)
set_global_cert_key
cert_id = set_global_cert_key(**kwargs)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
key | string | yes | content of private key |
cert | string | no | content of server cert |
ca_chain | string | no | content of CA chain |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
key_file = os.path.join('tests', 'key.pem')
cert_file = os.path.join('tests', 'cert.pem')
with open(key_file) as f:
key = f.read()
with open(cert_file) as f:
cert = f.read()
cert_id = client.set_global_cert_key(key = key, cert = cert)
put_global_cert_key
cert_id = put_global_cert_key(**kwargs)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
cert_id | number | yes | id of cert |
key | string | yes | content of private key |
cert | string | no | content of server cert |
ca_chain | string | no | content of CA chain |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
key_file = os.path.join('tests', 'key.pem')
cert_file = os.path.join('tests', 'cert.pem')
with open(key_file) as f:
key = f.read()
with open(cert_file) as f:
cert = f.read()
cert_id = client.set_global_cert_key(key = key, cert = cert)
new_key_file = os.path.join('tests', 'new_key.pem')
new_cert_file = os.path.join('tests', 'new_cert.pem')
with open(new_key_file) as f:
new_key = f.read()
with open(new_cert_file) as f:
new_cert = f.read()
ok = client.put_global_cert_key(cert_id = cert_id, key = new_key, cert = new_cert)
get_global_cert_key
cert_id = get_global_cert_key(cert_id)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
cert_id | number | yes | id of cert |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
key_file = os.path.join('tests', 'key.pem')
cert_file = os.path.join('tests', 'cert.pem')
with open(key_file) as f:
key = f.read()
with open(cert_file) as f:
cert = f.read()
cert_id = client.set_global_cert_key(key = key, cert = cert)
data = client.get_global_cert_key(cert_id)
del_global_cert_key
ok = del_global_cert_key(cert_id)
Description of array **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
cert_id | number | yes | id of cert |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
key_file = os.path.join('tests', 'key.pem')
cert_file = os.path.join('tests', 'cert.pem')
with open(key_file) as f:
key = f.read()
with open(cert_file) as f:
cert = f.read()
cert_id = client.set_global_cert_key(key = key, cert = cert)
ok = client.del_global_cert_key(cert_id)
add_global_user
app_id = add_global_user(name, pwd, gid)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of global user |
pwd | string | yes | password of global user |
gid | array | yes | group id array, like [1] |
Example
import random
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
write = ''.join([random.choice(string.ascii_letters) for n in range(10)])
pwd = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(12)])
ok = client.add_global_user(name = write, pwd = pwd, gid = [1])
search_global_user
ok = search_global_user(name)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of global user |
Example
import random
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
write = ''.join([random.choice(string.ascii_letters) for n in range(10)])
pwd = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(12)])
ok = client.add_global_user(name = write, pwd = pwd, can_create_app = True, role = 'user')
data = client.search_global_user(write)
user_id = data.get('id')
get_all_global_users
data = get_all_global_users(detail)
Example
import random
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
write = ''.join([random.choice(string.ascii_letters) for n in range(10)])
pwd = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(12)])
ok = client.add_global_user(name = write, pwd = pwd, can_create_app = True, role = 'user')
data = client.get_all_global_users()
data = client.get_all_global_users(True)
add_app_user
app_id = add_app_user(name, read, write, release)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of user |
read | bool | no | whether has read permission, default is True |
write | bool | no | whether has write permission, default is True |
release | bool | no | whether has release permission, default is False |
dns_read | bool | no | whether has read DNS permission, default is False |
dns_write | bool | no | whether has write DNS permission, default is False |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
id = client.add_app_user(name = 'only_reader', write = False, release = False)
put_app_user
app_id = put_app_user(id, name, read, write, release)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
id | list | yes | id of user |
name | string | yes | name of user |
read | bool | no | whether has read permission, default is True |
write | bool | no | whether has write permission, default is True |
release | bool | no | whether has release permission, default is False |
dns_read | bool | no | whether has read DNS permission, default is False |
dns_write | bool | no | whether has write DNS permission, default is False |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
id = client.add_app_user(name = 'only_reader', write = False, release = False)
ok = client.put_app_user(id = id, name = 'master', write = True, release = True)
get_app_user
data = get_app_user(id, name, app_id, user_id)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
id | list | no | id of user |
name | string | no | name of app |
app_id | number | no | id of app, default is the current id of app |
user_id | number | no | id of global user |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
id = client.add_app_user(name = 'only_reader', write = False, release = False)
data = client.get_app_user(name = 'only_reader')
del_app_user
data = del_app_user(id, name, app_id, user_id)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
id | list | no | id of user |
name | string | no | name of app |
app_id | number | no | id of app, default is the current id of app |
user_id | number | no | id of global user |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
id = client.add_app_user(name = 'only_reader', write = False, release = False)
ok = client.del_app_user(name = 'only_reader')
get_all_app_users
data = get_all_app_users(app_id)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
app_id | number | no | id of app, default is the current id of app |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
id = client.add_app_user(name = 'only_reader', write = False, release = False)
data = client.get_all_app_users()
add_user_for_all_apps
ok = add_user_for_all_apps(name, read, write, release)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
name | string | no | name of global user |
read | bool | no | whether has read permission, default is True |
write | bool | no | whether has write permission, default is True |
release | bool | no | whether has release permission, default is False |
dns_read | bool | no | whether has read DNS permission, default is False |
dns_write | bool | no | whether has write DNS permission, default is False |
Example
import random
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
write = ''.join([random.choice(string.ascii_letters) for n in range(10)])
pwd = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(12)])
ok = client.add_global_user(name = write, pwd = pwd, can_create_app = True, role = 'user')
data = client.add_user_for_all_apps(name = write)
add-all-users-for-app
ok = add_all_users_for_app(app_id, read, write, release)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
app_id | number | no | id of app, default is the current app |
read | bool | no | whether has read permission, default is True |
write | bool | no | whether has write permission, default is True |
release | bool | no | whether has release permission, default is False |
dns_read | bool | no | whether has read DNS permission, default is False |
dns_write | bool | no | whether has write DNS permission, default is False |
Example
import random
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
write = ''.join([random.choice(string.ascii_letters) for n in range(10)])
pwd = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(12)])
ok = client.add_global_user(name = write, pwd = pwd, can_create_app = True, role = 'user')
data = client.add_all_users_for_app(release = True)
new_global_rule
rule_id = new_global_rule(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
condition | list | no | conditions of rule |
conseq | dict or list | no | actions of rule |
gid | list | no | array of user group id |
condition
Description of array condition
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
var | string or array | yes | name of edgelang builtin predicate function if type is string , name and args of function if type is array |
op | string | no | operator, default is eq |
val | string | either val or vals | value |
vals | list | either val or vals | array of val |
conseq
Description of array conseq
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
edgelang builtin action function | string | yes | one of edgelang builtin action functions |
args of edgelang builtin action function | list | yes | args of edgelang builtin action function |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
condition = [
{'var': 'host', 'val': 'con.' + APEX},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302}
}
rule_id = client.new_global_rule(condition = condition, conseq = conseq, gid=[1])
put_global_rule
ok = put_global_rule(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
rule_id | number | yes | id of rule |
condition | list | no | conditions of rule |
conseq | dict or list | no | actions of rule |
gid | list | no | array of user group id |
condition
Description of array condition
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
var | string or array | yes | name of edgelang builtin predicate function if type is string , name and args of function if type is array |
op | string | no | operator, default is eq |
val | string | either val or vals | value |
vals | list | either val or vals | array of val |
conseq
Description of array conseq
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
edgelang builtin action function | string | yes | one of edgelang builtin action functions |
args of edgelang builtin action function | list | yes | args of edgelang builtin action function |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
condition = [
{'var': 'host', 'val': 'con.' + APEX},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302}
}
rule_id = client.new_global_rule(condition = condition, conseq = conseq)
conseq['redirect']['url'] = '/cn/2018/'
ok = client.put_global_rule(rule_id = rule_id, condition = condition, conseq = conseq)
get_global_rule
ok = get_global_rule(rule_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
condition = [
{'var': 'host', 'val': 'con.' + APEX},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302}
}
rule_id = client.new_global_rule(condition = condition, conseq = conseq)
data = client.get_global_rule(rule_id)
get_global_action_by_name
rule_id = get_global_action_by_name(name)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
condition = [
{'var': 'host', 'val': 'con.' + APEX},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302}
}
name = "test-actions"
client.new_global_rule(condition=condition, conseq=conseq, name=name)
rule_id = client.get_global_action_by_name('test-actions')
get_all_global_rules
ok = get_all_global_rules()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
condition = [
{'var': 'host', 'val': 'con.' + APEX},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302}
}
rule_id = client.new_global_rule(condition = condition, conseq = conseq)
data = client.get_all_global_rules()
del_global_rule
ok = del_global_rule(rule_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
condition = [
{'var': 'host', 'val': 'con.' + APEX},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302}
}
rule_id = client.new_global_rule(condition = condition, conseq = conseq)
conseq['redirect']['url'] = '/cn/2018/'
ok = client.del_global_rule(rule_id)
new_global_var
var_id = new_global_var(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of var |
var_type | string | yes | type of var |
default | string | yes | default value |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
var_id = client.new_global_var(name = 'is-whitelist', var_type = 'string', default = 'no')
put_global_var
ok = put_global_var(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
var_id | number | yes | id of var |
name | string | yes | name of var |
var_type | string | yes | type of var |
default | string | yes | default value |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
var_id = client.new_global_var(name = 'is-whitelist', var_type = 'string', default = 'no')
ok = client.put_global_var(var_id = var_id, name = 'is-whitelist', var_type = 'string', default = 'yes')
get_global_var
data = get_global_var(var_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
var_id = client.new_global_var(name = 'is-whitelist', var_type = 'string', default = 'no')
data = client.get_global_var(var_id)
get_all_global_vars
data = get_all_global_vars()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
var_id = client.new_global_var(name = 'is-whitelist', var_type = 'string', default = 'no')
data = client.get_all_global_vars()
del_global_var
ok = del_global_var(var_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
var_id = client.new_global_var(name = 'is-whitelist', var_type = 'string', default = 'no')
ok = client.del_global_var(var_id)
get_global_ngx_config
data = get_global_ngx_config()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_global_ngx_config()
set_global_ngx_config
data = set_global_ngx_config(opts)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
opts = {'keepalive_timeout': 10, 'enable_open_file_cache': False}
ok = client.set_global_ngx_config(opts)
get_global_misc_config
data = get_global_misc_config()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_global_misc_config()
set_global_misc_config
data = set_global_misc_config(opts)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
opts = {'enabled_req_id': True}
ok = client.set_global_misc_config(opts)
get_request_id_status
status = get_request_id_status()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
status = client.get_request_id_status()
enable_request_id
ok = enable_request_id()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
ok = client.enable_request_id()
disable_request_id
ok = disable_request_id()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
ok = client.disable_request_id()
new_global_waf_rule
rule_id = new_global_waf_rule(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of rule |
code | string | yes | EL code of rule |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
waf_rule_id = client.new_global_waf_rule(name = 'foo', code = "uri-arg('foo') => waf-mark-risk(level: 'definite', msg: 'found foo');")
put_global_waf_rule
ok = put_global_waf_rule(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
rule_id | number | yes | id of rule |
name | string | yes | name of rule |
code | string | yes | EL code of rule |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
waf_rule_id = client.new_global_waf_rule(name = 'foo', code = "uri-arg('foo') => waf-mark-risk(level: 'definite', msg: 'found foo');")
ok = client.put_global_waf_rule(rule_id = waf_rule_id, name = 'bar', code = "uri-arg('bar') => waf-mark-risk(level: 'definite', msg: 'found bar');")
get_global_waf_rule
data = get_global_waf_rule(rule_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
waf_rule_id = client.new_global_waf_rule(name = 'foo', code = "uri-arg('foo') => waf-mark-risk(level: 'definite', msg: 'found foo');")
data = client.get_global_waf_rule(waf_rule_id)
del_global_waf_rule
ok = del_global_waf_rule(rule_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
waf_rule_id = client.new_global_waf_rule(name = 'foo', code = "uri-arg('foo') => waf-mark-risk(level: 'definite', msg: 'found foo');")
ok = client.del_global_waf_rule(waf_rule_id)
get_all_global_waf_rules
data = get_all_global_waf_rules(detail = False)
Key name | Type | Required | Description |
---|---|---|---|
detail | bool | no | default is False , not returns the code of rules. |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
waf_rule_id = client.new_global_waf_rule(name = 'foo', code = "uri-arg('foo') => waf-mark-risk(level: 'definite', msg: 'found foo');")
data = client.get_all_global_waf_rules()
new_global_action
rule_id = new_global_action(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of action |
condition | list | no | conditions of global custom action |
conseq | dict or list | no | actions of global custom action |
[gid] | list | no | array of user group id |
condition
Description of array condition
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
var | string or array | yes | name of edgelang builtin predicate function if type is string , name and args of function if type is array |
op | string | no | operator, default is eq |
val | string | either val or vals | value |
vals | list | either val or vals | array of val |
conseq
Description of array conseq
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
edgelang builtin action function | string | yes | one of edgelang builtin action functions |
args of edgelang builtin action function | list | yes | args of edgelang builtin action function |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
name = 'test'
condition = [
{'var': 'req-method', 'vals': ['GET', 'POST', 'HEAD']}
]
conseq = [
{
'exit': {'code': 403}
}
]
action_id = client.new_global_action(name = name, condition = condition, conseq = conseq, gid=[1])
put_global_action
ok = put_global_action(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
action_id | number | yes | id of action |
name | string | no | name of action |
condition | list | no | conditions of global custom action |
conseq | dict or list | no | actions of global custom action |
[gid] | list | no | array of user group id |
condition
Description of array condition
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
var | string or array | yes | name of edgelang builtin predicate function if type is string , name and args of function if type is array |
op | string | no | operator, default is eq |
val | string | either val or vals | value |
vals | list | either val or vals | array of val |
conseq
Description of array conseq
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
edgelang builtin action function | string | yes | one of edgelang builtin action functions |
args of edgelang builtin action function | list | yes | args of edgelang builtin action function |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
name = 'test'
condition = [
{'var': 'req-method', 'vals': ['GET', 'POST', 'HEAD']}
]
conseq = [
{
'exit': {'code': 403}
}
]
action_id = client.new_global_action(name = name, condition = condition, conseq = conseq)
conseq = [
{
'exit': {'code': 404}
}
]
ok = client.put_global_action(name = name, action_id = action_id, condition = condition, conseq = conseq, gid=[1])
get_global_action
ok = get_global_action(action_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
name = 'test'
condition = [
{'var': 'req-method', 'vals': ['GET', 'POST', 'HEAD']}
]
conseq = [
{
'exit': {'code': 403}
}
]
action_id = client.new_global_action(name = name, condition = condition, conseq = conseq)
data = client.get_global_action(action_id)
del_global_action
ok = del_global_action(action_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
name = 'test'
condition = [
{'var': 'req-method', 'vals': ['GET', 'POST', 'HEAD']}
]
conseq = [
{
'exit': {'code': 403}
}
]
action_id = client.new_global_action(name = name, condition = condition, conseq = conseq)
ok = client.del_global_action(action_id)
count_global_actions
count = count_global_actions()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
ok = client.count_global_actions()
get_all_global_actions
data = get_all_global_actions()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_all_global_actions()
new_user_var
var_id = new_user_var(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of var |
var_type | string | yes | type of var |
default | string | yes | default value |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
var_id = client.new_user_var(name = 'is-whitelist', var_type = 'string', default = 'no')
put_user_var
ok = put_user_var(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
var_id | number | yes | id of var |
name | string | yes | name of var |
var_type | string | yes | type of var |
default | string | yes | default value |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
var_id = client.new_user_var(name = 'is-whitelist', var_type = 'string', default = 'no')
ok = client.put_user_var(var_id = var_id, name = 'is-whitelist', var_type = 'string', default = 'yes')
get_user_var
data = get_user_var(var_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
var_id = client.new_user_var(name = 'is-whitelist', var_type = 'string', default = 'no')
data = client.get_user_var(var_id)
del_user_var
ok = del_user_var(var_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
var_id = client.new_user_var(name = 'is-whitelist', var_type = 'string', default = 'no')
ok = client.del_user_var(var_id)
**node_sync_status
**
data = node_sync_status()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.node_sync_status()
for node_id, delay in data.items():
if delay > 0:
print('WARNING: node id {}: releases behind {}'.format(str(node_id), str(delay)))
upload_static_file
file_id = upload_static_file(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
content | string | yes | content of static file |
label | string | yes | label of static file |
file_type | string | no | default is ‘html’ |
gid | list | no | array of user group id |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
file_id = client.upload_static_file(content = 'test_content', label = '500.html', gid=[1])
get_static_file
data = get_static_file(file_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
file_id = client.upload_static_file(content = 'test_content', label = '500.html')
data = client.get_static_file(file_id)
del_static_file
ok = del_static_file(file_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
file_id = client.upload_static_file(content = 'test_content', label = '500.html')
ok = client.del_static_file(file_id)
new_waf_whitelist
rule_id = new_waf_whitelist(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
condition | list | no | conditions of rule |
rule_sets | list | yes | list of waf rule id |
condition
Description of array condition
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
var | string or array | yes | name of edgelang builtin predicate function if type is string , name and args of function if type is array |
op | string | no | operator, default is eq |
val | string | either val or vals | value |
vals | list | either val or vals | array of val |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [
{'var': 'host', 'val': 'con.foo.com'},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
id = client.new_waf_whitelist(condition = condition, rule_sets = [1, 2])
put_waf_whitelist
ok = put_waf_whitelist(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
whitelist_id | number | yes | id of whitelist |
condition | list | no | conditions of rule |
rule_sets | list | yes | list of waf rule id |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [
{'var': 'host', 'val': 'con.foo.com'},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
id = client.new_waf_whitelist(condition = condition, rule_sets = [1, 2])
ok = client.put_waf_whitelist(whitelist_id = id, condition = condition, rule_sets = [1])
get_waf_whitelist
data = get_waf_whitelist(whitelist_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [
{'var': 'host', 'val': 'con.foo.com'},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
id = client.new_waf_whitelist(condition = condition, rule_sets = [1, 2])
data = client.get_waf_whitelist(id)
del_waf_whitelist
ok = del_waf_whitelist(whitelist_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [
{'var': 'host', 'val': 'con.foo.com'},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
id = client.new_waf_whitelist(condition = condition, rule_sets = [1, 2])
ok = client.del_waf_whitelist(id)
get_all_waf_whitelists
data = get_all_waf_whitelists()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [
{'var': 'host', 'val': 'con.foo.com'},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
id = client.new_waf_whitelist(condition = condition, rule_sets = [1, 2])
data = client.get_all_waf_whitelists()
get_healthcheck_status
data = get_healthcheck_status(node_id, page=1, page_size=1000)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.node_sync_status()
for node_id, node_info in data.items():
node_id = int(node_id)
data = client.get_healthcheck_status(node_id, 1, 1000)
new_ip_list
data = new_ip_list(name=None, type='ipv4', items=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of the application IP list |
type | string | no | type of IP address, ‘ipv4’ or ‘ipv6’(coming soon) |
items | array | no | list of IP address |
items
Description of array items
:
Key name | Type | Required | Description |
---|---|---|---|
ip | string | yes | IP Address |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
ok = client.new_ip_list(name = 'ip-list-1',
type = 'ipv4',
items = [
{'ip': '127.0.0.0/24'},
{'ip': '192.168.1.0/24'}
])
put_ip_list
data = put_ip_list(rule_id=None, name=None, type='ipv4', items=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
rule_id | number | yes | id of the application IP list |
name | string | yes | name of the application IP list |
type | string | no | type of IP address, ‘ipv4’ or ‘ipv6’(coming soon) |
items | array | no | list of IP address |
items
Description of array items
:
Key name | Type | Required | Description |
---|---|---|---|
ip | string | yes | IP Address |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
ok = client.put_ip_list(rule_id = 1, items = [ {'ip': '127.0.0.2'} ])
del_ip_list
data = del_ip_list(rule_id=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
rule_id | number | yes | id of the application IP list |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
ok = client.del_ip_list(rule_id=1)
get_ip_list
data = get_ip_list(rule_id=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
rule_id | number | yes | id of the application IP list |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_ip_list(rule_id=1)
new_cluster_group
group_id = new_cluster_group(group_name)
Key name | Type | Required | Description |
---|---|---|---|
group_name | string | yes | name of cluster group |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
group_id = client.new_cluster_group('foo')
put_cluster_group
ok = put_cluster_group(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
group_id | number | yes | id of group |
group_name | string | yes | name of group |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
group_id = client.new_cluster_group(group_name = 'foo')
ok = client.put_cluster_group(group_id = group_id, group_name = 'bar')
get_cluster_group
data = get_cluster_group(group_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
group_id = client.new_cluster_group(group_name = 'foo')
data = client.get_cluster_group(group_id)
get_all_cluster_groups
data = get_all_cluster_groups()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
group_id = client.new_cluster_group(group_name = 'foo')
data = client.get_all_cluster_groups()
del_cluster_group
ok = del_cluster_group(group_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
group_id = client.new_cluster_group(group_name = 'foo')
ok = client.del_cluster_group(group_id)
put_proxy_rule
ok = put_proxy_rule(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
rule_id | number | yes | id of rule |
proxy | list | yes | rules of proxy |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
app_id = client.new_app(domains = ['orig.foo.com'], label = 'origin site for foo.com')
condition = [
{'var': 'host', 'val': 'con.' + APEX},
{'var': ['req-header', 'Referer'], 'vals': [['foo\d+', 'rx'], 'foo.com']}
]
conseq = {
'enable-websocket': {},
'redirect': {'url': '/cn/2017/', 'code': 302}
}
rule_id = client.new_rule(condition = condition, conseq = conseq)
proxy_rule = {
'upstreams': [{'upstream': up_id, 'weight': 2}],
'backup_upstreams': [{'upstream': backup_up_id}],
'retries': -1,
"retry_condition": ["invalid_header", "http_500"],
"balancer_algorithm": "hash",
"balancer_vars": [
{"name":"uri"},
{
"name":"uri-arg",
"args":"foo"
}
]
}
ok = client.put_proxy_rule(rule_id = rule_id, proxy = proxy_rule)
decode_request_id
data = decode_request_id(request_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.decode_request_id('00000a00000c0826c9803222')
# {u'timestamp': 1531859760, u'node_id': 20, u'app_id': 3, u'is_stream': False, u'sequence': 12834}
print(data)
search_waf_log
data = search_waf_log(request_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
request_id = "0000008000042c421ea80011"
data = client.search_waf_log(request_id)
add_api_token
data = add_api_token(name=None, expire=0)
Key name | Type | Required | Description |
---|---|---|---|
name | string | no | api token name |
expire | number | no | api token expiration time |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.add_api_token("name", 0)
get_api_token
data = get_api_token(id=None, limit=20)
Key name | Type | Required | Description |
---|---|---|---|
id | number | no | api token id |
limit | number | no | limit on the number of returns |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_api_token(id)
# or
data = client.get_api_token(None, 100)
del_api_token
data = del_api_token(id)
Key name | Type | Required | Description |
---|---|---|---|
id | number | no | api token id |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.del_api_token(id)
get_all_gateway_tag
tags = get_all_gateway_tag()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
tags = client.get_all_gateway_tag()
for i, tag in enumerate(tags):
print(i, tag)
get_all_gateway
gateways = get_all_gateway()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
gateways = client.get_all_gateway()
for i, gateway in enumerate(gateways):
print(i, gateway)
add_gateway
id = add_gateway(name, partition_id, tag=None)
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | gateway cluster name |
partition_id | number | yes | gateway partition id |
tag | array | no | tags of gateway cluster |
Description of return value:
type: number
1
Example
default_partition_id = 1
id = client.add_gateway("my-cluster", default_partition_id)
del_gateway
ok = del_gateway(gateway_id)
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
gateway_id | string | yes | gateway cluster id |
Description of return value:
type: number
true
Example
gateway_id = 1
ok = client.del_gateway(gateway_id)
get_app_metrics
metrics = get_app_metrics(id, start_time=None, end_time=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
id | number | yes | id of application |
start_time | number | no | start of unix timestamp |
end_time | number | no | end of unix timestamp |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
metrics = client.get_app_metrics()
for i, mt in enumerate(metrics):
print(i, mt)
new_app_dymetrics
id = new_app_dymetrics(app_id=None, name=None, note=None, interval=60, sql=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
app_id | number | yes | application id |
name | string | yes | name of dymetrics |
note | string | no | note for dymetrics |
interval | number | no | statistical interval |
sql | string | yes | SQL statements for generating metrics |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
sql = 'select status, count(*) from reqs group by status'
dymetrics_id = client.new_app_dymetrics(app_id=1, name='test', sql=sql)
put_app_dymetrics
ok = put_app_dymetrics(app_id=None, id=None, name=None, note=None, interval=60)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
app_id | number | yes | application id |
id | number | yes | id of dymetrics |
name | string | yes | name of dymetrics |
note | string | no | note for dymetrics |
interval | number | no | statistical interval |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
sql = 'select status, count(*) from reqs group by status'
ok = client.put_app_dymetrics(app_id=app_id, id=dymetrics_id, name='test')
del_app_dymetrics
ok = del_app_dymetrics(id)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
app_id | number | yes | application id |
id | number | yes | id of dymetrics |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
ok = client.del_app_dymetrics(app_id, dymetrics_id)
get_app_dymetrics
data = get_app_dymetrics(id)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
app_id | number | yes | application id |
id | number | yes | id of dymetrics |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_app_dymetrics(app_id, dymetrics_id)
get_all_app_dymetrics
data = get_all_app_dymetrics(app_id)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
app_id | number | yes | application id |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_all_app_dymetrics(app_id)
get_app_dymetrics_data
data = get_app_dymetrics_data(app_id, id, chart_type='line', start_time=None, end_time=None, node_id=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
app_id | number | yes | application id |
id | number | yes | id of application |
chart_type | string | no | id of application, default ’line’ |
start_time | number | no | start of unix timestamp |
end_time | number | no | end of unix timestamp |
node_id | number | no | id of gateway node |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_app_dymetrics_data(app_id, dymetrics_id)
new_global_dymetrics
id = new_global_dymetrics(name=None, note=None, interval=60, sql=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of dymetrics |
note | string | no | note for dymetrics |
interval | number | no | statistical interval |
sql | string | yes | SQL statements for generating metrics |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
sql = 'select status, count(*) from reqs group by status'
dymetrics_id = client.new_global_dymetrics(name='test', sql=sql)
put_global_dymetrics
ok = put_global_dymetrics(id=None, name=None, note=None, interval=60)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
id | number | yes | id of dymetrics |
name | string | yes | name of dymetrics |
note | string | no | note for dymetrics |
interval | number | no | statistical interval |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
sql = 'select status, count(*) from reqs group by status'
ok = client.put_global_dymetrics(id=dymetrics_id, name='test')
del_global_dymetrics
ok = del_global_dymetrics(id)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
id | number | yes | id of dymetrics |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
ok = client.del_global_dymetrics(dymetrics_id)
get_global_dymetrics
data = get_global_dymetrics(id)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
id | number | yes | id of dymetrics |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_global_dymetrics(dymetrics_id)
get_all_global_dymetrics
data = get_all_global_dymetrics()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_all_global_dymetrics()
get_global_dymetrics_data
data = get_global_dymetrics_data(id, chart_type='line', start_time=None, end_time=None, node_id=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
id | number | yes | id of application |
chart_type | string | no | id of application, default ’line’ |
start_time | number | no | start of unix timestamp |
end_time | number | no | end of unix timestamp |
node_id | number | no | id of gateway node |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_global_dymetrics_data(dymetrics_id)
new_global_ip_list
data = new_global_ip_list(name=None, type='ipv4', items=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of the global IP list |
type | string | no | type of IP address, ‘ipv4’ or ‘ipv6’(coming soon) |
items | array | no | list of IP address |
items
Description of array items
:
Key name | Type | Required | Description |
---|---|---|---|
ip | string | yes | IP Address |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
ok = client.new_global_ip_list(name = 'ip-list-1',
type = 'ipv4',
items = [
{'ip': '127.0.0.0/24'},
{'ip': '192.168.1.0/24'}
])
put_global_ip_list
data = put_global_ip_list(rule_id=None, name=None, type='ipv4', items=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
rule_id | number | yes | id of the global IP list |
name | string | yes | name of the global IP list |
type | string | no | type of IP address, ‘ipv4’ or ‘ipv6’(coming soon) |
items | array | no | list of IP address |
items
Description of array items
:
Key name | Type | Required | Description |
---|---|---|---|
ip | string | yes | IP Address |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
ok = client.put_global_ip_list(rule_id = 1, items = [ {'ip': '127.0.0.2'} ])
del_global_ip_list
data = del_global_ip_list(rule_id=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
rule_id | number | yes | id of the global IP list |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
ok = client.del_global_ip_list(rule_id=1)
get_global_ip_list
data = get_global_ip_list(rule_id=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
rule_id | number | yes | id of the global IP list |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_global_ip_list(rule_id=1)
node_monitor
data = node_monitor(node_id, start_time=None, end_time=None, step=60)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
node_id | number | yes | id of gateway node |
start_time | number | no | start of unix timestamp |
end_time | number | no | end of unix timestamp |
step | number | no | statistical interval |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
node_id = 1
data = client.node_monitor(node_id)
get_version
data = get_version()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_version()
new_global_k8s
k8s_id = new_global_k8s(name=None, host=None, port=None, ssl_verify=True, token=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of k8s cluster |
host | string | no | IP of k8s cluster |
domain | number | no | domain of k8s cluster, one of IP and domain must be specified |
port | number | yes | port of k8s cluster |
connect_timeout | number | no | k8s connect timeout, default 5 seconds |
read_timeout | number | no | k8s read timeout, default 5 seconds |
ssl_verify | bool | no | ssl verify enable |
token | string | yes | api token of k8s cluster |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
k8s_id = client.new_global_k8s(name = "k8s", host = "192.168.1.1", port = 443, token = "xxxxx")
put_global_k8s
ok = put_global_k8s(k8s_id=None, name=None, host=None, port=None, ssl_verify=True, token=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
k8s_id | string | yes | k8s id |
name | string | no | name of k8s cluster |
host | string | no | host of k8s cluster |
domain | number | no | domain of k8s cluster, one of IP and domain must be specified |
port | number | no | port of k8s cluster |
connect_timeout | number | no | k8s connect timeout |
read_timeout | number | no | k8s read timeout |
ssl_verify | bool | no | ssl verify enable |
token | string | no | api token of k8s cluster |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
ok = client.put_global_k8s(k8s_id = 1, name = "k8s", host = "192.168.1.1", port = 443, token = "xxxxx")
get_global_k8s
data = get_global_k8s(k8s_id=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
k8s_id | string | yes | k8s id |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_global_k8s(k8s_id = 1)
get_k8s_service_detail
data = get_k8s_service_detail(k8s_id=None)
Description of parameters:
Key name | Type | Required | Description |
---|---|---|---|
k8s_id | string | yes | k8s id |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_k8s_service_detail(k8s_id = 1)
get_all_global_k8s
data = get_all_global_k8s()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_all_global_k8s()
del_global_k8s
ok = del_global_k8s(k8s_id = None)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
ok = client.del_global_k8s(k8s_id = 1)
new_global_upstream
up_id = new_global_upstream(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of global upstream |
servers | list | yes | upstreams |
ssl | bool | no | set protocol to HTTPS, default is false(HTTP) |
health_checker | dict | no | detail configure of health checker, default is none |
servers
Description of array servers
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
domain | string | no | domain of upstream |
ip | string | no | IP of upstream. Choose one from domain and ip |
port | string | yes | port of upstream |
weight | number | no | weight of upstream, default is 1 |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
up_id = client.new_global_upstream(name = 'origin-upstream',
servers = [
{'ip': '172.22.31.1', 'port': 80},
{'ip': '172.22.31.2', 'port': 80, 'weight': 2}
])
put_global_upstream
ok = put_global_upstream(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of upstream |
servers | list | yes | upstreams |
ssl | bool | no | set protocol to HTTPS, default is false(HTTP) |
health_checker | dict | no | detail configure of health checker, default is none |
servers
Description of array servers
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
domain | string | no | domain of upstream |
ip | string | no | IP of upstream. Choose one from domain and ip |
port | string | yes | port of upstream |
weight | number | no | weight of upstream, default is 1 |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
up_id = client.new_global_upstream(name = 'origin-upstream',
servers = [
{'domain': 'a.com', 'port': 80},
{'ip': '172.22.31.2', 'port': 80, 'weight': 2}
])
ok = client.put_global_upstream(up_id, name = 'origin-upstream',
servers = [
{'domain': 'test.com', 'port': 8080},
{'ip': '172.22.31.2', 'port': 8080, 'weight': 1}
],
health_checker = {
'type': 'http',
'http_req_uri': '/status',
'http_req_host': 'test.com',
'interval': 3,
'interval_unit': 'sec',
'timeout': 1,
'fall': 3,
'rise': 2,
'valid_statuses': [200, 302],
'report_interval': 3,
'report_interval_unit': 'min'
})
get_global_upstream
data = get_global_upstream(up_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
up_id = client.new_global_upstream(name = 'origin-upstream',
servers = [
{'ip': '172.22.31.1', 'port': 80},
{'ip': '172.22.31.2', 'port': 80, 'weight': 2}
])
data = client.get_global_upstream(up_id)
del-global-upstream
ok = del_global_upstream(up_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
up_id = client.new_global_upstream(name = 'origin-upstream',
servers = [
{'ip': '172.22.31.1', 'port': 80},
{'ip': '172.22.31.2', 'port': 80, 'weight': 2}
])
ok = client.del_global_upstream(up_id)
get_all_global_upstreams
upstreams = client.get_all_global_upstreams()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
up_id = client.new_global_upstream(name = 'origin-upstream',
servers = [
{'ip': '172.22.31.1', 'port': 80},
{'ip': '172.22.31.2', 'port': 80, 'weight': 2}
])
upstreams = client.get_all_global_upstreams(up_id)
new_global_k8s_upstream
k8s_up_id = new_global_k8s_upstream(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of upstream |
k8s_services | list | yes | upstreams is k8s services |
ssl | bool | no | set protocol to HTTPS, default is false(HTTP) |
health_checker | dict | no | detail configure of health checker, default is none |
k8s_services
Description of array k8s_services
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
k8s | number | yes | k8s cluster id |
k8s_namespace | string | yes | k8s namespace |
k8s_service | string | yes | k8s service |
k8s_service_port | number | yes | k8s service port |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
k8s_up_id = client.new_global_k8s_upstream(name = 'k8s-upstream',
k8s_services = [
{
'k8s' : 1,
'k8s_namespace' : 'default',
'k8s_service' : 'foo',
'k8s_service_port' : 80,
}
])
put_global_k8s_upstream
ok = put_global_k8s_upstream(**kwargs)
Description of dict **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
name | string | yes | name of upstream |
k8s_services | list | yes | upstreams is k8s services |
ssl | bool | no | set protocol to HTTPS, default is false(HTTP) |
health_checker | dict | no | detail configure of health checker, default is none |
servers
Description of array servers
in **kwargs
:
Key name | Type | Required | Description |
---|---|---|---|
domain | string | no | domain of upstream |
ip | string | no | IP of upstream. Choose one from domain and ip |
port | string | yes | port of upstream |
weight | number | no | weight of upstream, default is 1 |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
ok = client.put_global_k8s_upstream(up_id, name = 'origin-upstream',
k8s_services = [
{
'k8s' : 1,
'k8s_namespace' : 'default',
'k8s_service' : 'foo',
'k8s_service_port' : 80,
}
],
health_checker = {
'type': 'http',
'http_req_uri': '/status',
'http_req_host': 'test.com',
'interval': 3,
'interval_unit': 'sec',
'timeout': 1,
'fall': 3,
'rise': 2,
'valid_statuses': [200, 302],
'report_interval': 3,
'report_interval_unit': 'min'
})
get_global_k8s_upstream
data = get_global_k8s_upstream(up_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
data = client.get_global_k8s_upstream(up_id)
del-global-k8s-upstream
ok = del_global_k8s_upstream(up_id)
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
ok = client.del_global_k8s_upstream(up_id)
get_all_global_k8s_upstreams
upstreams = client.get_all_global_k8s_upstreams()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
upstreams = client.get_all_global_k8s_upstreams(app_id)
get_all_nodes
nodes = client.get_all_nodes()
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
nodes = client.get_all_nodes()
get_node
node = client.get_node(node_id, gateway_id=None)
Get node info by node id.
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
node_id | number | yes | node id |
gateway_id | number | no | gateway cluster id. When not specified, the corresponding node will be found by traversing |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
node = client.get_node(1)
node = client.get_node(1, gateway_id=1)
get_node_by_mac_address
node = client.get_node_by_mac_address(mac_address)
Get node info by hardware id of node.
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
mac_address | string | yes | one of the MAC addresses of the node |
Description of return value:
type: dict
{
"mac_address": "46:b1:5f:1d:fa:ea",
"serial": "2655388572",
"is_limited": false,
"config": {
"enable_qat": false
},
"name": "test-edge-node-75c5bf6969-65tgg\n",
"id": 11,
"external_ip": "172.20.0.2",
"sync_status_utime": 0,
"online_status": true,
"internal_ip": "10.244.0.6",
"hardware_id": "a11abe66fe25be7941bda81c3f358344",
"is_healthy": true,
"status": 1,
"gateway_id": 14
}
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
node = client.get_node_by_mac_address("e2:d1:d9:e0:c4:6e")
put_node
node = client.put_node(node_id, gateway_id=None, **kwargs)
Update node info.
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
node_id | number | yes | node id |
gateway_id | number | no | gateway cluster id. When not specified, the corresponding node will be found by traversing |
name | string | no | node name |
is_gray | bool | no | set/unset gray node |
status | number | no | 0: disable DNS,enable cluster cache, 1: enable DNS,enable cluster cache, 2: disable DNS,disable cluster cache |
external_ip | string | no | external IP |
external_ipv6 | string | no | external IPv6 |
internal_ip | string | no | internal IP |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
node_id=1
gateway_id=1
ok = client.put_node(node_id, \
gateway_id=gateway_id, name='test', \
is_gray=False, status=1, external_ip='127.0.0.1', \
external_ipv6='::1', internal_ip='127.0.0.1')
del_node
node = client.del_node(node_id, gateway_id=None)
Delete gateway node.
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
node_id | number | yes | node id |
gateway_id | number | no | gateway cluster id. When not specified, the corresponding node will be found by traversing |
Description of return value:
type: bool
true
Example
node_id=1
gateway_id=1
ok = client.del_node(node_id, gateway_id)
lmdb_backup
result = client.lmdb_backup()
Trigger LMDB backup, success returns True
, failure returns dict
of the failed Node, key is Node ID, value is the reason for failure.
The backup status can be obtained using the node_sync_status
interface, where the backup_time
of the node is greater than the lmdb_backup() call time, and the node is considered to be successfully backed up.
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
result = client.lmdb_backup()
get_global_cert_referenced
result = get_global_cert_referenced(id)
Get a list of applications using the specified global certificate.
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
id | number | yes | global cert ID |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
global_cert_id = 1
result = client.get_global_cert_referenced(global_cert_id)
get_all_partition_lua_module
result = get_all_partition_lua_module(partition_id)
Get all Lua modules for the specified partition.
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
partition_id | number | yes | partition ID |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
partition_id = 1
result = client.get_all_partition_lua_module(partition_id)
get_partition_lua_module
result = get_partition_lua_module(partition_id, module_id)
Get the specified Lua module for the specified partition.
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
partition_id | number | yes | partition ID |
module_id | number | yes | module ID |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
partition_id = 1
module_id = 1
result = client.get_partition_lua_module(partition_id, module_id)
new_partition_lua_module
result = new_partition_lua_module(partition_id, name, code)
Adds a Lua module to the specified partition.
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
partition_id | number | yes | partition ID |
name | string | yes | name of module |
code | string | yes | code of module |
Description of return value:
Type: dict
{'id': 412}
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
partition_id = 1
name = "example"
code = """
local _M = {}
return _M
"""
result = client.new_partition_lua_module(partition_id, name, code)
put_partition_lua_module
result = put_partition_lua_module(partition_id, module_id, name, code)
Edit the specified Lua module for the specified partition.
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
partition_id | number | yes | partition ID |
module_id | number | yes | module ID |
name | string | no | name of module |
code | string | no | code of module |
Description of return value:
Type: bool
true
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
partition_id = 1
module_id = 1
name = "example"
code = """
local _M = {}
return _M
"""
result = client.put_partition_lua_module(partition_id, module_id, name, code)
del_partition_lua_module
result = del_partition_lua_module(partition_id, module_id)
Removes the specified Lua module for the specified partition.
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
partition_id | number | yes | partition ID |
module_id | number | yes | module ID |
Example
from edge2client import Edge2Client
client = Edge2Client('http://127.0.0.1:8080', 'username', 'password')
client.login()
partition_id = 1
module_id = 1
result = client.del_partition_lua_module(partition_id, module_id)
conv_crl_to_lua_module
result = conv_crl_to_lua_module(crl_files)
Convert CRL files into a Lua module.
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
crl_files | array | yes | CRL files |
Example
import sys
from edge2client import Edge2Client
client = Edge2Client('https://your-admin-addr', 'your-admin-user', 'your-admin-password')
crl_files = ["~/test.crl"]
code = client. conv_crl_to_lua_module(crl_files)
client.login()
partition_id = 1
name = "crl_test.com"
# for the first time, we need to create the module first
result = client.new_partition_lua_module(partition_id, name, code)
mod_id = result["id"]
# for the second time, we need to update the module with mod_id from the first creation
result = client.put_partition_lua_module(partition_id, mod_id, name, code)
print(result)
get_all_candidate_node
nodes = get_all_candidate_node()
Get all candidate nodes. In the next step, these nodes can be approved to join the specified cluster through the approve_candidate_node API.
Description of return value:
Type: bool
[
{
"priv_hash": "0ab3a37cfea7d044c93a46712053a081",
"external_ipv6": "",
"external_ip": "172.20.0.2",
"hostname": "test-edge-node-75c5bf6969-65tgg\n",
"client_city": "/",
"internal_ip": "10.244.0.3",
"os": "Linux\n3.10.0-1127.19.1.el7.x86_64\n",
"hardware_id": "3e20ff1b92ca06e03b2ab0d877687662",
"mac_address": "9e:18:28:f5:1b:d5",
"csr": "..."
}
]
Example
nodes = client.get_all_candidate_node()
print(nodes)
approve_candidate_node
ok = approve_candidate_node(gateway_id, mac_address, internal_ip=None, external_ip=None, name=None, external_ipv6=None, status=1)
Approves nodes with MAC addresses containing mac_address to join the gateway cluster specified by gateway_id.
Description of args:
Key name | Type | Required | Description |
---|---|---|---|
gateway_id | number | yes | gateway cluster id |
mac_address | string | yes | one of the MAC addresses of the node |
internal_ip | string | no | internal IPv4 address of node |
external_ip | string | no | external IPv4 address of node |
name | string | no | The name of the node, the hostname is used by default |
external_ipv6 | string | no | external IPv6 address of node |
status | string | no | node status, 0: disabled, 1: enabled, 2: offline (disable DNS and disable cluster cache hash |
Description of return value:
Type: bool
true
Example
Approve node with hostname new-edge-node to join gateway cluster with ID 1.
def first_address(addrs):
return addrs.split(' ')[0]
gateway_id=1
nodes = client.get_all_candidate_node()
for i, node in enumerate(nodes):
if nodes.get('hostname') == "new-edge-node":
ok = client.approve_candidate_node(gateway_id, first_address(nodes.get('mac_address')))
break