OpenResty Edge™ Python SDK Manual

MethodParametersParameters typeDescriptionReturn type
Edge2Clienthost, username, password, api_tokenstringinit SDK clientobject
loginlogin to edge systembool
use_appapp_idnumberset the application you want to operatebool
new_appdomains, labelstringadd a new applicationnumber
put_appdomains, labelstringupdate applicationbool
get_appapp_idnumberget application infoarray
put_app_configlimiterdictupdate application configbool
get_app_configapp_idnumberget application configdict
del_appapp_idnumberdelete applicationbool
search_app**kwargsdictsearch applicationarray
search_http_app_by_keyword**kwargsdictsearch application by domain or namearray
search_upstream_by_ip**kwargsdictsearch upstream by IParray
search_upstream_by_name**kwargsdictsearch upstream by namearray
search_k8s_upstream_by_name**kwargsdictsearch upstream by namearray
get_all_appsget all applicationsarray
new_upstream**kwargsdictadd a new upstreamnumber
put_upstream**kwargsdictupdate upstreambool
get_upstreamup_idnumberget upstream by up_idarray
del_upstreamup_idnumberdelete upstreambool
get_all_upstreamsdetailboolget all upstreamsarray
new_k8s_upstream**kwargsdictadd a new k8s upstreamnumber
copy_upstream_to_k8s_upstreamup_id, k8s_servicesnumbercopy an upstream to an k8s_upstreamnumber
put_k8s_upstream**kwargsdictupdate k8s upstreambool
get_k8s_upstreamup_idnumberget k8s upstream by up_idarray
del_k8s_upstreamup_idnumberdelete k8s upstreambool
get_all_k8s_upstreamsdetailboolget all k8s upstreamsarray
new_rule**kwargsdictadd a new request rewrite rulenumber
put_rule**kwargsdictupdate request rewrite rulebool
get_rulerule_idnumberget request rewrite rulearray
del_rulerule_idnumberdelete request rewrite rulebool
get_all_rulesapp_idnumberget all request rewrite rulesarray
get_global_actions_used_in_appapp_idnumberget all request rewrite global action rulesarray
get_all_rules_by_app_domaindomainstringget request rewrite rules of all matched apps by domainarray
get_all_rules_by_upstream_ipIPstringget request rewrite rules of all matched apps by upstream IParray
get_all_waf_rulesapp_idnumberget all waf rulesarray
set_le_cert**kwargsdictset LE SSLnumber
put_le_cert**kwargsdictput LE SSLnumber
get_le_certcert_idnumberget LE certificate status
set_cert_key**kwargsdictset SSL key and certnumber
put_cert_key**kwargsdictupdate SSL key and certbool
get_cert_keycert_idnumberget SSL key and certarray
get_all_cert_keysget all SSL key and certsarray
del_cert_keycert_idlistdelete SSL key and certbool
new_elphase, code, **kwargsstring, string, arrayadd EL codenumber
new_releasenew releasebool
pending_changespending changesnumber
sync_statusthe sync status of releasenumber, number
use_dns_appapp_idnumberset the DNS application you want to operatebool
new_dns_app**kwargsdictadd a new DNSnumber
put_dns_app**kwargsdictupdate DNSbool
get_dns_appdns_idnumberget DNSarray
del_dns_appdns_idnumberdelete DNSbool
new_dns_record**kwargsdictadd record of DNSnumber
put_dns_record**kwargsdictupdate record of DNSbool
get_dns_recordrecord_idnumberget record of DNSarray
del_dns_recordrecord_idnumberdelete record of DNSbool
set_global_cert_key**kwargsdictset global cert and keynumber
put_global_cert_key**kwargsdictupdate global cert and keybool
get_global_cert_keycert_idnumberget global cert and keyarray
del_global_cert_keycert_idnumberdelete global cert and keybool
add_global_user**kwargsdictadd global userbool
search_global_usernamestringsearch global userarray
get_all_global_usersdetailbooleanget all global userarray
add_app_user**kwargsdictadd user of applicationnumber
put_app_user**kwargsdictupdate user of applicationbool
get_app_user**kwargsdictget user of applicationarray
del_app_user**kwargsdictdelete user of applicationarray
get_all_app_usersget all users of applicationarray
add_user_for_all_apps**kwargsdictadd user for all applicationsbool
add_all_users_for_app**kwargsdictadd all users for applicationbool
new_global_rule**kwargsdictadd a new global rewrite rulenumber
put_global_rule**kwargsdictupdate global rewrite rulebool
get_global_rulerule_idnumberget global rewrite rulearray
get_global_action_by_namenamestringget global action id by namenumber
get_all_global_rulesget all global rewrite rulesarray
del_global_rulerule_idnumberdelete global rewrite rulebool
new_global_var**kwargsdictadd a new global varnumber
put_global_var**kwargsdictupdate global varbool
get_global_varvar_idnumberget global vararray
get_all_global_varsget all global varsarray
del_global_varvar_idnumberdelete global varbool
get_global_ngx_configget global nginx configuresarray
set_global_ngx_configoptsdictset global nginx configuresbool
get_global_misc_configget global misc configuresarray
set_global_misc_configoptsdictset global misc configuresbool
get_request_id_statusget status of global request idbool
enable_request_idenable global request idbool
disable_request_iddisable global request idbool
new_global_waf_rule**kwargsdictadd a new global waf rulenumber
put_global_waf_rule**kwargsdictupdate global waf rulebool
get_global_waf_rulerule_idnumberget global waf rule by idarray
del_global_waf_rulerule_idnumberdelete global waf rule by idbool
get_all_global_waf_rulesdetailboolreturn all global waf rule sets with name and id, and including built-in rule setsarray
new_global_action**kwargsdictadd a new global custom actionnumber
put_global_action**kwargsdictupdate global custom actionbool
get_global_actionaction_idnumberget global custom actionarray
del_global_actionaction_idnumberdelete global custom actionbool
count_global_actionsGet the number of Global Actionsbool
get_all_global_actionsget all global actionsbool
new_user_var**kwargsdictadd a new user varnumber
put_user_var**kwargsdictupdate user varbool
get_user_varvar_idnumberget user vararray
del_user_varvar_idnumberdelete user varbool
node_sync_statussync status of all nodesdict
upload_static_file**kwargsdictupload global static filenumber
get_static_filefile_idnumberget global static filearray
del_static_filefile_idnumberdelete global static filebool
new_waf_whitelist**kwargsdictadd a new whitelist rulenumber
put_waf_whitelist**kwargsdictupdate waf whitelist rulebool
get_waf_whitelistwhitelist_idnumberget waf whitelist by idarray
del_waf_whitelistwhitelist_idnumberdelete waf whitelist rule by idbool
get_all_waf_whitelistsdetailboolreturn all whitelist rulesarray
new_ip_listadd application IP listbool
put_ip_listidnumberchange the specified IP listbool or number
del_ip_listidnumberdelete the specified IP listbool
get_ip_listidnumberget the specified IP listdict
get_healthcheck_statusnode_idnumberreturn health check statusarray
new_cluster_groupnamedictadd a new cluster groupnumber
put_cluster_group**kwargsdictupdate cluster groupbool
get_cluster_groupgroup_idnumberget cluster groupdict
get_all_cluster_groupsget all cluster groupsarray
del_cluster_groupgroup_idnumberdelete cluster groupbool
put_proxy_rule**kwargsdictupdate proxy rulebool
decode_request_idrequest_idstringget info from request_iddict
search_waf_logrequest_idstringsearch waf log by request iddict or None
add_api_tokenname, expirestring, numberadd api tokendict
get_api_tokenid, limitnumber, numberget api tokendict
del_api_tokenidnumberdelete api tokenbool
get_all_gateway_tagget all gateway tagarray
get_all_gatewayget all gatewayarray
get_app_metricsidnumberget HTTP request status metrics and network metricsarray
new_app_dymetricsadd application dynamic metricsbool
put_app_dymetricsidnumberchange the specified application dynamic metricsbool or number
del_app_dymetricsidnumberdelete the specified application dynamic metricsbool
get_app_dymetricsidnumberget the specified application dynamic metricsdict
get_all_app_dymetricsget all application dynamic metricsarray
get_app_dymetrics_dataget application dynamic metrics dataarray
new_global_dymetricsadd global dynamic metricsbool
put_global_dymetricsidnumberchange the specified global dynamic metricsbool or number
del_global_dymetricsidnumberdelete the specified global dynamic metricsbool
get_global_dymetricsidnumberget the specified global dynamic metricsdict
get_all_global_dymetricsget all global dynamic metricsarray
get_global_dymetrics_dataget all global dynamic metrics dataarray
new_global_ip_listadd global IP listbool
put_global_ip_listidnumberchange the specified IP listbool or number
del_global_ip_listidnumberdelete the specified IP listbool
get_global_ip_listidnumberget the specified IP listdict
node_monitorget CPU and memory load metrics for gateway nodesarray
get_versionObtain the versions of Admin, Admin DB, Log Server, Log Server DB, and WAF.dict
new_global_k8sadd a new global k8s cluster configurationnumber
put_global_k8supdate global k8s cluster configurationbool
get_global_k8sget global k8s cluster configurationdict
get_k8s_services_detailget k8s service detail infodict
get_all_global_k8sget all global k8sarray
del_global_k8sdel global k8sbool
new_global_upstream**kwargsdictadd a new global upstreamnumber
put_global_upstream**kwargsdictupdate global upstreambool
get_global_upstreamup_idnumberget global upstream by up_idarray
del_global_upstreamup_idnumberdelete global upstreambool
get_all_global_upstreamsdetailboolget all global upstreamsarray
new_global_k8s_upstream**kwargsdictadd a new global k8s upstreamnumber
put_global_k8s_upstream**kwargsdictupdate global k8s upstreambool
get_global_k8s_upstreamup_idnumberget global k8s upstream by up_idarray
del_global_k8s_upstreamup_idnumberdelete global k8s upstreambool
get_all_global_k8s_upstreamsdetailboolget all global k8s upstreamsarray
get_all_nodesget all gateway nodesarray
get_nodenode_id, gateway_idnumber, numberget node by node iddict
get_node_by_hardware_idhardware_idstringget node by hardware id of nodedict
put_nodenode_id, gateway_id, **kwargsnumber, number, dictupdate nodebool
del_nodenode_id, gateway_idnumber, numberdelete nodebool
lmdb_backuptrigger a backup of LMDB.bool
get_global_cert_referencedidnumberget a list of applications that reference the specified global certificatelist
get_all_partition_lua_modulepartition_idnumberget all Lua modules for the specified partition.list
get_partition_lua_modulepartition_id, module_idnumber, numberget the specified Lua module for the specified partitiondict
new_partition_lua_modulepartition_id, name, codenumber, string, stringadds a Lua module to the specified partitiondict
put_partition_lua_modulepartition_id, module_id, name, codenumber, number, string, stringedit the specified Lua module for the specified partitiondict
del_partition_lua_modulepartition_id, module_idnumber, numberremoves the specified Lua module for the specified partitiondict
conv_crl_to_lua_modulecrl_filesarrayconvert CRL to Lua Modulestring
get_all_candidate_nodeget all candidate nodesarray
approve_candidate_nodegateway_id, hardware_idnumber, stringapprove the node to join the gateway clusterbool

Edge2Client

client = Edge2Client(host, username, password, api_token=None)

Description of parameters:

Key nameTypeRequiredDescription
hoststringyesaddress of edge admin, including host and port
usernamestringyesusername of edge-admin
passwordstringyespassword of edge-admin
api_tokenstringnoapi 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 nameTypeRequiredDescription
domainslistyesdomains of application
labelstringyesname of application
cluster_groupslistnocluster 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 nameTypeRequiredDescription
app_idnumberyesid of application
domainslistyesdomains of application
labelstringyesname of application
cluster_groupslistnocluster group ids of application
offlineboolnothe 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 nameTypeRequiredDescription
app_idnumberyesid of application
limiterdictyesconfig of application
enable_websocketboolnoenable 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 nameTypeRequiredDescription
app_domainstringyessearch app by the domain
pagenumbernopage number of results, default value is ‘1’
pagesizenumbernopage 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 nameTypeRequiredDescription
keywordstringyessearch app by the domain or name
pagenumbernopage number of results, default value is ‘1’
pagesizenumbernopage 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 nameTypeRequiredDescription
ipstringyessearch upstream by IP
pagenumbernopage number of results, default value is ‘1’
pagesizenumbernopage 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 nameTypeRequiredDescription
ipstringyessearch upstream by ip
pagenumbernopage number of results, default value is ‘1’
pagesizenumbernopage 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 nameTypeRequiredDescription
namestringyessearch upstream by name
pagenumbernopage number of results, default value is ‘1’
pagesizenumbernopage 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 nameTypeRequiredDescription
namestringyessearch upstream by name
pagenumbernopage number of results, default value is ‘1’
pagesizenumbernopage 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 nameTypeRequiredDescription
namespacestringnosearch upstream by namespace
servicestringnosearch upstream by service
portnumbernosearch upstream by port
pagenumbernopage number of results, default value is ‘1’
pagesizenumbernopage size of results, default value is ‘20’
type_listlistnosearch 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 nameTypeRequiredDescription
pagenumbernopage number of results, default value is ‘1’
pagesizenumbernopage size of results, default value is ‘20’
start_timenumbernostart time
end_timenumbernoend 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 nameTypeRequiredDescription
detailboolnodefault 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 nameTypeRequiredDescription
namestringyesname of upstream
serverslistyesupstreams
sslboolnoset protocol to HTTPS, default is false(HTTP)
health_checkerdictnodetail configure of health checker, default is none

servers

Description of array servers in **kwargs:

Key nameTypeRequiredDescription
domainstringnodomain of upstream
ipstringnoIP of upstream. Choose one from domain and ip
portstringyesport of upstream
weightnumbernoweight 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 nameTypeRequiredDescription
namestringyesname of upstream
serverslistyesupstreams
sslboolnoset protocol to HTTPS, default is false(HTTP)
health_checkerdictnodetail configure of health checker, default is none

servers

Description of array servers in **kwargs:

Key nameTypeRequiredDescription
domainstringnodomain of upstream
ipstringnoIP of upstream. Choose one from domain and ip
portstringyesport of upstream
weightnumbernoweight 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 nameTypeRequiredDescription
namestringyesname of upstream
k8s_serviceslistyesupstreams is k8s services
sslboolnoset protocol to HTTPS, default is false(HTTP)
health_checkerdictnodetail configure of health checker, default is none

k8s_services

Description of array k8s_services in **kwargs:

Key nameTypeRequiredDescription
k8snumberyesk8s cluster id
k8s_namespacestringyesk8s namespace
k8s_servicestringyesk8s service
k8s_service_portnumberyesk8s 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 nameTypeRequiredDescription
up_idnumberyesorigin upstream id
k8s_serviceslistyesk8s services
rulesarraynothe 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 nameTypeRequiredDescription
k8snumberyesk8s cluster id
k8s_namespacestringyesk8s namespace
k8s_servicestringyesk8s service
k8s_service_portnumberyesk8s 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 nameTypeRequiredDescription
namestringyesname of upstream
k8s_serviceslistyesupstreams is k8s services
sslboolnoset protocol to HTTPS, default is false(HTTP)
health_checkerdictnodetail configure of health checker, default is none

servers

Description of array servers in **kwargs:

Key nameTypeRequiredDescription
domainstringnodomain of upstream
ipstringnoIP of upstream. Choose one from domain and ip
portstringyesport of upstream
weightnumbernoweight 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 nameTypeRequiredDescription
conditionlistnoconditions of rule
conseqdict or listnoactions of rule
waflistnorules of waf
proxylistnorules of proxy
cachelistnorules of cache
contentlistnorules of content
topnumberno1: always top rule, -1: always bottom rule
ordernumbernorule order, lower priority than top parameter
lastbooleannoskip any subsequent page rules when this rule matches

condition

Description of array condition in **kwargs:

Key nameTypeRequiredDescription
varstring or arrayyesname of edgelang builtin predicate function if type is string, name and args of function if type is array
opstringnooperator, default is eq
valstringeither val or valsstring or array
valslisteither val or valsarray of val

conseq

Description of conseq in **kwargs:

Key nameTypeRequiredDescription
edgelang builtin action functionstringyesone of edgelang builtin action functions
args of edgelang builtin action functionlistyesargs 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 nameTypeRequiredDescription
rule_setslistnothe set of user defined rules in global waf, default is empty array
robotsboolnowhether to enable this type of detection, default is False
genericboolnowhether to enable this type of detection, default is False
injectboolnowhether to enable this type of detection, default is False
trojansboolnowhether to enable this type of detection, default is False
xssboolnowhether to enable this type of detection, default is False
actionstringyesone of log, 403 Forbidden, edge-captcha, redirect
thresholdstringyesone of high, medium or low
clearancenumbernoclearance time of edge captcha challenge, default is 60 secs
redirect_urlstringnoredirect 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 nameTypeRequiredDescription
upstreamslistyesupstreams
backup_upstreamslistyesbackup upstreams
upstream_el_codestryesusing Edgelang to set upstream
timeoutnumbernotimeout of proxy, default is 3 seconds
connect_timeoutnumbernoconnect timeout of proxy, default is the same as timeout
read_timeoutnumbernoread timeout of proxy, default is the same as timeout
send_timeoutnumbernosend timeout of proxy, default is the same as timeout
retriesnumbernoretries time, default is 1
retry_conditionlistnoconditions 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_algorithmstringnoalgorithm of balancing policy, default is roundrobin, and you can set to hash and chash.
balancer_varslistnovariables of balancing policy. If you set to balancer_algorithm to hash or chash, then you must set balancer_vars too.
multi_tiernumbernomulti-tier policy ID.

upstreams

Description of array upstreams and backup_upstreams in **kwargs:

Key nameTypeRequiredDescription
upstreamnumberyesid of upstream
global_upstreamnumberyesid of global upstream
k8s_upstreamnumberyesid of k8s upstream
global_k8s_upstreamnumberyesid of global k8s upstream
weightnumbernoweight 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 nameTypeRequiredDescription
cache_keylistyescache keys
default_ttlslistnoCaching by Default, the default value is None
browser_ttlnumbernoBrowser Cache, the default value is None
browser_ttl_unitstringnoBrowser Cache Unit, only valid after browser_ttl is set, the default value is ‘min’
enable_globalbooleannoCache Across Domains, the default value is False
enforce_cachebooleannoAlways Cache, the default value is False
cluster_hashbooleannoGateway Cluster Level Cache Sharing, the default value is False
disable_convert_headbooleannoConvert 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 nameTypeRequiredDescription
faviconnumberyesfile id
gidnumbernoarray 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 nameTypeRequiredDescription
conditionlistnoconditions of rule
conseqdict or listnoactions of rule
waflistnorules of waf
proxylistnorules of proxy
cachelistnorules of cache
contentlistnorules of content
topnumberno1: always top rule, -1: always bottom rule
ordernumbernorule order, lower priority than top parameter
lastbooleannoskip any subsequent page rules when this rule matches

condition

Description of array condition in **kwargs:

Key nameTypeRequiredDescription
varstring or arrayyesname of edgelang builtin predicate function if type is string, name and args of function if type is array
opstringnooperator, default is eq
valstringeither val or valsvalue
valslisteither val or valsarray of val

conseq

Description of array conseq in **kwargs:

Key nameTypeRequiredDescription
edgelang builtin action functionstringyesone of edgelang builtin action functions
args of edgelang builtin action functionlistyesargs 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 nameTypeRequiredDescription
app_idnumbernoid 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()

get_global_actions_used_in_app

rules = get_global_actions_used_in_app(app_id)

Key nameTypeRequiredDescription
app_idnumbernoid 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 nameTypeRequiredDescription
domainstringyesdomain 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 nameTypeRequiredDescription
ipstringyesIP 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 nameTypeRequiredDescription
app_idnumbernoid 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 nameTypeRequiredDescription
domainsstring arrayyesdomains
gidlistnoarray of user group id

put_le_cert

cert_id = put_le_cert(**kwargs)

Description of array **kwargs:

Key nameTypeRequiredDescription
cert_idnumberyesid of cert
domainsstring arrayyesdomains
gidlistnoarray of user group id
resignbooleannowhether to re-sign the certificate

get_le_cert

data = get_le_cert(cert_id)

Description of return value data:

Key nameTypeDescription
statusstringcertificate status: valid / pending / invalid
expdatenumberthe expiration date (in unix timestamp)
next_updatenumberthe next update date (in unix timestamp)

set_cert_key

cert_id = set_cert_key(**kwargs)

Description of array **kwargs:

Key nameTypeRequiredDescription
keystringyescontent of private key
certstringnocontent of server cert
ca_chainstringnocontent of CA chain
global_cert_idnumbernoid of global cert
gidlistnoarray 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 nameTypeRequiredDescription
cert_idnumberyesid of cert
keystringyescontent of private key
certstringnocontent of server cert
ca_chainstringnocontent of CA chain
global_cert_idnumbernoid of global cert
gidlistnoarray 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 nameTypeRequiredDescription
cert_idnumberyesid 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 nameTypeRequiredDescription
cert_idnumberyesid 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 nameTypeRequiredDescription
phasestringyesphase
codestringyesedgelang code
postboolyesput 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 nameTypeRequiredDescription
zonestringyesdomain of DNS
authoritylistyesserver names of DNS
soa_emailstringnosoa 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 nameTypeRequiredDescription
dns_idnumberyesid of DNS
zonestringyesdomain of DNS
authoritylistyesserver names of DNS
soa_emailstringnosoa 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 nameTypeRequiredDescription
sub_domainstringyessub domain
linenumbernodefault is 0, see Client Geo Location for detail
cidrstringnocidr
record_typestringyestype of record, one of [A, TXT, MX, CNAME, CAA]
textstringnorequired if record_type is TXT or CAA
ipstringnorequired if response is IP
gatewaynumbernorequired if response is gateway cluster
domainstringnorequired if response is domain
prioritynumbernorequired 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 nameTypeRequiredDescription
record_idnumberyesrecord id of DNS
sub_domainstringyessub domain
linenumbernodefault is 0, see Client Geo Location for detail
cidrstringnocidr
record_typestringyestype of record, one of [A, TXT, MX, CNAME, CAA]
textstringnorequired if record_type is TXT or CAA
ipstringnorequired if response is IP
domainstringnorequired if response is domain
prioritynumbernorequired 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 nameTypeRequiredDescription
keystringyescontent of private key
certstringnocontent of server cert
ca_chainstringnocontent 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 nameTypeRequiredDescription
cert_idnumberyesid of cert
keystringyescontent of private key
certstringnocontent of server cert
ca_chainstringnocontent 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 nameTypeRequiredDescription
cert_idnumberyesid 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 nameTypeRequiredDescription
cert_idnumberyesid 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 nameTypeRequiredDescription
namestringyesname of global user
pwdstringyespassword of global user
gidarrayyesgroup 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 nameTypeRequiredDescription
namestringyesname 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 nameTypeRequiredDescription
namestringyesname of user
readboolnowhether has read permission, default is True
writeboolnowhether has write permission, default is True
releaseboolnowhether has release permission, default is False
dns_readboolnowhether has read DNS permission, default is False
dns_writeboolnowhether 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 nameTypeRequiredDescription
idlistyesid of user
namestringyesname of user
readboolnowhether has read permission, default is True
writeboolnowhether has write permission, default is True
releaseboolnowhether has release permission, default is False
dns_readboolnowhether has read DNS permission, default is False
dns_writeboolnowhether 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 nameTypeRequiredDescription
idlistnoid of user
namestringnoname of app
app_idnumbernoid of app, default is the current id of app
user_idnumbernoid 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 nameTypeRequiredDescription
idlistnoid of user
namestringnoname of app
app_idnumbernoid of app, default is the current id of app
user_idnumbernoid 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 nameTypeRequiredDescription
app_idnumbernoid 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 nameTypeRequiredDescription
namestringnoname of global user
readboolnowhether has read permission, default is True
writeboolnowhether has write permission, default is True
releaseboolnowhether has release permission, default is False
dns_readboolnowhether has read DNS permission, default is False
dns_writeboolnowhether 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 nameTypeRequiredDescription
app_idnumbernoid of app, default is the current app
readboolnowhether has read permission, default is True
writeboolnowhether has write permission, default is True
releaseboolnowhether has release permission, default is False
dns_readboolnowhether has read DNS permission, default is False
dns_writeboolnowhether 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 nameTypeRequiredDescription
conditionlistnoconditions of rule
conseqdict or listnoactions of rule
gidlistnoarray of user group id

condition

Description of array condition in **kwargs:

Key nameTypeRequiredDescription
varstring or arrayyesname of edgelang builtin predicate function if type is string, name and args of function if type is array
opstringnooperator, default is eq
valstringeither val or valsvalue
valslisteither val or valsarray of val

conseq

Description of array conseq in **kwargs:

Key nameTypeRequiredDescription
edgelang builtin action functionstringyesone of edgelang builtin action functions
args of edgelang builtin action functionlistyesargs 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 nameTypeRequiredDescription
rule_idnumberyesid of rule
conditionlistnoconditions of rule
conseqdict or listnoactions of rule
gidlistnoarray of user group id

condition

Description of array condition in **kwargs:

Key nameTypeRequiredDescription
varstring or arrayyesname of edgelang builtin predicate function if type is string, name and args of function if type is array
opstringnooperator, default is eq
valstringeither val or valsvalue
valslisteither val or valsarray of val

conseq

Description of array conseq in **kwargs:

Key nameTypeRequiredDescription
edgelang builtin action functionstringyesone of edgelang builtin action functions
args of edgelang builtin action functionlistyesargs 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 nameTypeRequiredDescription
namestringyesname of var
var_typestringyestype of var
defaultstringyesdefault 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 nameTypeRequiredDescription
var_idnumberyesid of var
namestringyesname of var
var_typestringyestype of var
defaultstringyesdefault 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 nameTypeRequiredDescription
namestringyesname of rule
codestringyesEL 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 nameTypeRequiredDescription
rule_idnumberyesid of rule
namestringyesname of rule
codestringyesEL 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 nameTypeRequiredDescription
detailboolnodefault 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 nameTypeRequiredDescription
namestringyesname of action
conditionlistnoconditions of global custom action
conseqdict or listnoactions of global custom action
[gid]listnoarray of user group id

condition

Description of array condition in **kwargs:

Key nameTypeRequiredDescription
varstring or arrayyesname of edgelang builtin predicate function if type is string, name and args of function if type is array
opstringnooperator, default is eq
valstringeither val or valsvalue
valslisteither val or valsarray of val

conseq

Description of array conseq in **kwargs:

Key nameTypeRequiredDescription
edgelang builtin action functionstringyesone of edgelang builtin action functions
args of edgelang builtin action functionlistyesargs 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 nameTypeRequiredDescription
action_idnumberyesid of action
namestringnoname of action
conditionlistnoconditions of global custom action
conseqdict or listnoactions of global custom action
[gid]listnoarray of user group id

condition

Description of array condition in **kwargs:

Key nameTypeRequiredDescription
varstring or arrayyesname of edgelang builtin predicate function if type is string, name and args of function if type is array
opstringnooperator, default is eq
valstringeither val or valsvalue
valslisteither val or valsarray of val

conseq

Description of array conseq in **kwargs:

Key nameTypeRequiredDescription
edgelang builtin action functionstringyesone of edgelang builtin action functions
args of edgelang builtin action functionlistyesargs 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 nameTypeRequiredDescription
namestringyesname of var
var_typestringyestype of var
defaultstringyesdefault 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 nameTypeRequiredDescription
var_idnumberyesid of var
namestringyesname of var
var_typestringyestype of var
defaultstringyesdefault 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 nameTypeRequiredDescription
contentstringyescontent of static file
labelstringyeslabel of static file
file_typestringnodefault is ‘html’
gidlistnoarray 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 nameTypeRequiredDescription
conditionlistnoconditions of rule
rule_setslistyeslist of waf rule id

condition

Description of array condition in **kwargs:

Key nameTypeRequiredDescription
varstring or arrayyesname of edgelang builtin predicate function if type is string, name and args of function if type is array
opstringnooperator, default is eq
valstringeither val or valsvalue
valslisteither val or valsarray 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 nameTypeRequiredDescription
whitelist_idnumberyesid of whitelist
conditionlistnoconditions of rule
rule_setslistyeslist 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 nameTypeRequiredDescription
namestringyesname of the application IP list
typestringnotype of IP address, ‘ipv4’ or ‘ipv6’(coming soon)
itemsarraynolist of IP address

items

Description of array items:

Key nameTypeRequiredDescription
ipstringyesIP 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 nameTypeRequiredDescription
rule_idnumberyesid of the application IP list
namestringyesname of the application IP list
typestringnotype of IP address, ‘ipv4’ or ‘ipv6’(coming soon)
itemsarraynolist of IP address

items

Description of array items:

Key nameTypeRequiredDescription
ipstringyesIP 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 nameTypeRequiredDescription
rule_idnumberyesid 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 nameTypeRequiredDescription
rule_idnumberyesid 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 nameTypeRequiredDescription
group_namestringyesname 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 nameTypeRequiredDescription
group_idnumberyesid of group
group_namestringyesname 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 nameTypeRequiredDescription
rule_idnumberyesid of rule
proxylistyesrules 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 nameTypeRequiredDescription
namestringnoapi token name
expirenumbernoapi 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 nameTypeRequiredDescription
idnumbernoapi token id
limitnumbernolimit 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 nameTypeRequiredDescription
idnumbernoapi 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 nameTypeRequiredDescription
namestringyesgateway cluster name
partition_idnumberyesgateway partition id
tagarraynotags 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 nameTypeRequiredDescription
gateway_idstringyesgateway 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 nameTypeRequiredDescription
idnumberyesid of application
start_timenumbernostart of unix timestamp
end_timenumbernoend 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 nameTypeRequiredDescription
app_idnumberyesapplication id
namestringyesname of dymetrics
notestringnonote for dymetrics
intervalnumbernostatistical interval
sqlstringyesSQL 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 nameTypeRequiredDescription
app_idnumberyesapplication id
idnumberyesid of dymetrics
namestringyesname of dymetrics
notestringnonote for dymetrics
intervalnumbernostatistical 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 nameTypeRequiredDescription
app_idnumberyesapplication id
idnumberyesid 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 nameTypeRequiredDescription
app_idnumberyesapplication id
idnumberyesid 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 nameTypeRequiredDescription
app_idnumberyesapplication 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 nameTypeRequiredDescription
app_idnumberyesapplication id
idnumberyesid of application
chart_typestringnoid of application, default ’line’
start_timenumbernostart of unix timestamp
end_timenumbernoend of unix timestamp
node_idnumbernoid 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 nameTypeRequiredDescription
namestringyesname of dymetrics
notestringnonote for dymetrics
intervalnumbernostatistical interval
sqlstringyesSQL 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 nameTypeRequiredDescription
idnumberyesid of dymetrics
namestringyesname of dymetrics
notestringnonote for dymetrics
intervalnumbernostatistical 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 nameTypeRequiredDescription
idnumberyesid 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 nameTypeRequiredDescription
idnumberyesid 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 nameTypeRequiredDescription
idnumberyesid of application
chart_typestringnoid of application, default ’line’
start_timenumbernostart of unix timestamp
end_timenumbernoend of unix timestamp
node_idnumbernoid 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 nameTypeRequiredDescription
namestringyesname of the global IP list
typestringnotype of IP address, ‘ipv4’ or ‘ipv6’(coming soon)
itemsarraynolist of IP address

items

Description of array items:

Key nameTypeRequiredDescription
ipstringyesIP 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 nameTypeRequiredDescription
rule_idnumberyesid of the global IP list
namestringyesname of the global IP list
typestringnotype of IP address, ‘ipv4’ or ‘ipv6’(coming soon)
itemsarraynolist of IP address

items

Description of array items:

Key nameTypeRequiredDescription
ipstringyesIP 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 nameTypeRequiredDescription
rule_idnumberyesid 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 nameTypeRequiredDescription
rule_idnumberyesid 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 nameTypeRequiredDescription
node_idnumberyesid of gateway node
start_timenumbernostart of unix timestamp
end_timenumbernoend of unix timestamp
stepnumbernostatistical 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 nameTypeRequiredDescription
namestringyesname of k8s cluster
hoststringnoIP of k8s cluster
domainnumbernodomain of k8s cluster, one of IP and domain must be specified
portnumberyesport of k8s cluster
connect_timeoutnumbernok8s connect timeout, default 5 seconds
read_timeoutnumbernok8s read timeout, default 5 seconds
ssl_verifyboolnossl verify enable
tokenstringyesapi 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 nameTypeRequiredDescription
k8s_idstringyesk8s id
namestringnoname of k8s cluster
hoststringnohost of k8s cluster
domainnumbernodomain of k8s cluster, one of IP and domain must be specified
portnumbernoport of k8s cluster
connect_timeoutnumbernok8s connect timeout
read_timeoutnumbernok8s read timeout
ssl_verifyboolnossl verify enable
tokenstringnoapi 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 nameTypeRequiredDescription
k8s_idstringyesk8s 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 nameTypeRequiredDescription
k8s_idstringyesk8s 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 nameTypeRequiredDescription
namestringyesname of global upstream
serverslistyesupstreams
sslboolnoset protocol to HTTPS, default is false(HTTP)
health_checkerdictnodetail configure of health checker, default is none

servers

Description of array servers in **kwargs:

Key nameTypeRequiredDescription
domainstringnodomain of upstream
ipstringnoIP of upstream. Choose one from domain and ip
portstringyesport of upstream
weightnumbernoweight 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 nameTypeRequiredDescription
namestringyesname of upstream
serverslistyesupstreams
sslboolnoset protocol to HTTPS, default is false(HTTP)
health_checkerdictnodetail configure of health checker, default is none

servers

Description of array servers in **kwargs:

Key nameTypeRequiredDescription
domainstringnodomain of upstream
ipstringnoIP of upstream. Choose one from domain and ip
portstringyesport of upstream
weightnumbernoweight 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 nameTypeRequiredDescription
namestringyesname of upstream
k8s_serviceslistyesupstreams is k8s services
sslboolnoset protocol to HTTPS, default is false(HTTP)
health_checkerdictnodetail configure of health checker, default is none

k8s_services

Description of array k8s_services in **kwargs:

Key nameTypeRequiredDescription
k8snumberyesk8s cluster id
k8s_namespacestringyesk8s namespace
k8s_servicestringyesk8s service
k8s_service_portnumberyesk8s 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 nameTypeRequiredDescription
namestringyesname of upstream
k8s_serviceslistyesupstreams is k8s services
sslboolnoset protocol to HTTPS, default is false(HTTP)
health_checkerdictnodetail configure of health checker, default is none

servers

Description of array servers in **kwargs:

Key nameTypeRequiredDescription
domainstringnodomain of upstream
ipstringnoIP of upstream. Choose one from domain and ip
portstringyesport of upstream
weightnumbernoweight 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 nameTypeRequiredDescription
node_idnumberyesnode id
gateway_idnumbernogateway 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_hardware_id

node = client.get_node_by_hardware_id(hardware_id)

Get node info by hardware id of node.

Description of args:

Key nameTypeRequiredDescription
hardware_idstringyeshardware id of 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_hardware_id("3e20ff1b92ca06e03b2ab0d877687662")

put_node

node = client.put_node(node_id, gateway_id=None, **kwargs)

Update node info.

Description of args:

Key nameTypeRequiredDescription
node_idnumberyesnode id
gateway_idnumbernogateway cluster id. When not specified, the corresponding node will be found by traversing
namestringnonode name
is_grayboolnoset/unset gray node
statusnumberno0: disable DNS,enable cluster cache, 1: enable DNS,enable cluster cache, 2: disable DNS,disable cluster cache
external_ipstringnoexternal IP
external_ipv6stringnoexternal IPv6
internal_ipstringnointernal 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 nameTypeRequiredDescription
node_idnumberyesnode id
gateway_idnumbernogateway 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 nameTypeRequiredDescription
idnumberyesglobal 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 nameTypeRequiredDescription
partition_idnumberyespartition 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 nameTypeRequiredDescription
partition_idnumberyespartition ID
module_idnumberyesmodule 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 nameTypeRequiredDescription
partition_idnumberyespartition ID
namestringyesname of module
codestringyescode 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 nameTypeRequiredDescription
partition_idnumberyespartition ID
module_idnumberyesmodule ID
namestringnoname of module
codestringnocode 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 nameTypeRequiredDescription
partition_idnumberyespartition ID
module_idnumberyesmodule 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 nameTypeRequiredDescription
crl_filesarrayyesCRL files

Example

import sys

from edge2client import Edge2Client

client = Edge2Client('https://your-admin-addr', 'edge-admin', 'openresty@Admin2020')

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, hardware_id)

Approve the node specified by hardware_id to join the gateway cluster specified by gateway_id.

Description of args:

Key nameTypeRequiredDescription
gateway_idnumberyesgateway cluster id
hardware_idstringyeshardware id of node
internal_ipstringnointernal IPv4 address of node
external_ipstringnoexternal IPv4 address of node
namestringnoThe name of the node, the hostname is used by default
external_ipv6stringnoexternal IPv6 address of node
statusstringnonode 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.

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, nodes.get('hardware_id'))
        break