xcat2 / xcat-inventory

An inventory tool for xcat cluster
8 stars 16 forks source link

Add network/route API #196

Closed cxhong closed 5 years ago

cxhong commented 5 years ago

This for https://github.ibm.com/xcat2/task_management/issues/141

Route Resource 1) Get all the routes defined in the route table

]# curl -X GET "http://10.6.31.1:5000/api/v2/inventory/routes" -H  "accept: application/json"
[
    {
        "meta": {
            "name": "20net"
        },
        "spec": {
            "mask": "255.0.0.0",
            "gateway": "0.0.0.0",
            "ifname": "eth1",
            "net": "20.0.0.0"
        }
    },
    {
        "meta": {
            "name": "21net"
        },
        "spec": {
            "mask": "255.255.0.0",
            "gateway": "1.0.0.0",
            "ifname": "eth3",
            "net": "21.0.0.0"
        }
    }
]

2) delete 21net from route table

# curl -X DELETE "http://10.6.31.1:5000/api/v2/inventory/routes/21net" -H  "accept: application/json"
null
# tabdump routes
#routename,net,mask,gateway,ifname,comments,disable
"20net","20.0.0.0","255.0.0.0","0.0.0.0","eth1",,

3) POST 21net to route table

# curl -X POST "http://10.6.31.1:5000/api/v2/inventory/routes" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"meta\": {    \"name\": \"21net\"  },  \"spec\": {    \"mask\": \"255.255.0.0\",    \"gateway\": \"1.0.0.0\",    \"ifname\": \"eth3\",    \"net\": \"21.0.0.0\"  }}"
]# tabdump routes
#routename,net,mask,gateway,ifname,comments,disable
"20net","20.0.0.0","255.0.0.0","0.0.0.0","eth1",,
"21net","21.0.0.0","255.255.0.0","1.0.0.0","eth3",,

4) Patch 21net, modify net

# curl -X PATCH "http://10.6.31.1:5000/api/v2/inventory/routes/21net" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"modify\": {    \"net\": \"23.0.0.0\"    }}"
# tabdump routes
#routename,net,mask,gateway,ifname,comments,disable
"20net","20.0.0.0","255.0.0.0","0.0.0.0","eth1",,
"21net","23.0.0.0","255.255.0.0","1.0.0.0","eth3",,

5) PUT (replace) 21net

# curl -X PUT "http://10.6.31.1:5000/api/v2/inventory/routes/21net" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"meta\": {    \"name\": \"21net\"  },  \"spec\": {    \"mask\": \"255.255.0.0\",    \"gateway\": \"1.0.0.0\",    \"ifname\": \"eth3\",    \"net\": \"21.2.0.0\"  }}"
]# tabdump routes
#routename,net,mask,gateway,ifname,comments,disable
"20net","20.0.0.0","255.0.0.0","0.0.0.0","eth1",,
"21net","21.2.0.0","255.255.0.0","1.0.0.0","eth3",,

Network Resource 1) Get all the networks define in the network table

# curl -X GET "http://10.6.31.1:5000/api/v2/inventory/subnets" -H  "accept: application/json" | grep name | grep -v mgtifname
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2069  100  2069    0     0  53271      0 --:--:-- --:--:-- --:--:-- 54447
            "name": "172_21_0_0-255_255_0_0"
            "name": "30_5_0_0-255_255_0_0"
            "name": "40_5_0_0-255_255_0_0"
            "name": "10_0_0_0-255_0_0_0"
            "name": "172_20_0_0-255_255_0_0"