多層網路策略

建立多層網路策略

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

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
        }
    ]
}

更新多層網路策略

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

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}