# 多层网络策略

# 创建多层网络策略

# 简介

创建多层网络策略

# URI

POST /admin-api/global/1/layer_policy

# JSON body 参数

{
    "name": "policy_1",
    "rules": [
        {
            "gateway": 3, // current gateway id
            "backup": 2, // backup upstream gateway id, not necessary
            "upstream": 1 // upstream gateway id
        },
        {
            "gateway": 4, // current gateway id
            "upstream": 3 // upstream gateway id
        }
    ]
}

上面的示例会创建一个像这样的多层网络策略:

┌────────┐       ┌───────────┐  backup
│        │<──────│ gateway-2 │<---------┐
│ Source │       └───────────┘          │
│  site  │       ┌───────────┐    ┌───────────┐    ┌───────────┐
│        │<──────│ gateway-1 │<───│ gateway-3 │<───│ gateway-4 │
└────────┘       └───────────┘    └───────────┘    └───────────┘

# 请求示例

# Shell

curl -X POST \
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://{admin-site}/admin-api/global/1/layer_policy \
  -d '{"name":"policy_1","rules":[{"gateway":3,"backup":2,"upstream":1},{"gateway":4,"upstream":3}]}'

# 响应示例

Status: 200 OK

{"status":0,"data":{"id":1}}

# 删除多层网络策略

# 简介

删除多层网络策略

# URI

DELETE /admin-api/global/1/layer_policy/{policy_id}

# 请求示例

# Shell

curl -X DELETE \
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://{admin-site}/admin-api/global/1/layer_policy/1

# 响应示例

Status: 200 OK

{"status":0}

# 更新多层网络策略

# 简介

更新多层网络策略

# URI

PUT /admin-api/global/1/layer_policy/{policy_id}

# JSON body 参数

{
    "name": "policy_2",
    "rules": [
        {
            "gateway": 3, // current gateway id
            "backup": 1, // backup upstream gateway id, not necessary
            "upstream": 2 // upstream gateway id
        }
    ]
}

# 请求示例

# Shell

curl -X PUT\
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://{admin-site}/admin-api/global/1/layer_policy/1 \
  -d '{"name":"policy_2","rules":[{"gateway":3,"backup":1,"upstream":2}]}'

# 响应示例

Status: 200 OK

{"status":0}

# 获取多层网络策略

# 简介

获取多层网络策略

# URI

GET /admin-api/global/1/layer_policy

# URI 参数

  • detail

    type: integer

    required: no

    description: Are detailed results required (default 0)

  • page

    type: integer

    required: no

    description: Results page (default 1)

  • page_size

    type: integer

    required: no

    description: Results page size (default 20)

# 请求示例

# Shell

curl \
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://{admin-site}/admin-api/global/1/layer_policy?detail=1

# 响应示例

Status: 200 OK
{
    "status": 0,
    "data": [
        {
            "rules": [
                {
                    "backup": 1,
                    "upstream": 2,
                    "gateway": 3,
                    "id": 9
                }
            ],
            "name": "policy_2",
            "id": 5,
            "_created_unix": 1621828296.5587,
            "_modified_unix": 1621828300.1128
        }
    ]
}