xcat2 / xcat-inventory

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

Inventory api implementation #207

Closed robin2008 closed 5 years ago

robin2008 commented 5 years ago

Leverage node inventory API to implement the RESTful API

nodes inventory API

PATH METHOD Description Parameters
/system/nodes?type=inventory GET get node inventory type=inventory
/system/nodes? POST create node with inventory
/system/nodes/{node} GET get specify node inventory
/system/nodes/{node} DELETE delete specify node
/system/nodes/{node} PUT replace the specify node with new inventory data
robin2008 commented 5 years ago

1, Get all node inventory (No group, obj_type=node)

curl -X GET "http://10.6.27.1:5000/api/v2/system/nodes?type=inventory" -H  "accept: application/json" -H  "Authorization: token <my token>"

[
  {
    "meta": {
      "name": "mid05tor12cn02"
    },
    "spec": {
      "obj_type": "node",
      "engines": {
        "netboot_engine": {
          "engine_info": {
            "chain": "runcmd",
            "osimage": "rhels7.5-ppc64le-netboot-compute"
          },
          "engine_type": "grub2"
        },
        "hardware_mgt_engine": {
          "engine_info": {
            "bmc": "10.11.139.2",
            "bmctaggedvlan": "11"
          },
          "engine_type": "openbmc"
        },
        "console_engine": {
          "engine_info": {
            "consoleenabled": "1"
          },
          "engine_type": "openbmc"
        }
      },
      "device_info": {
        "arch": "ppc64le"
      },
      "obj_info": {
        "groups": "all,compute,cn_regex"
      },
      "role": "compute",
      "device_type": "server",
      "network_info": {
        "connections": {
          "switch": "mid05tor12",
          "switchport": "2"
        },
        "primarynic": {
          "ip": "192.168.139.2",
          "mac": [
            "11:11:11:11:11:11"
          ]
        }
      }
    }
  },
 ...
]
robin2008 commented 5 years ago

2, create a node, and get the node

curl -X POST "http://10.6.27.1:5000/api/v2/system/nodes" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{    \"meta\": {        \"name\": \"abcd123\"    },    \"spec\": {        \"obj_type\": \"node\",        \"role\": \"compute\",        \"device_type\": \"server\",        \"obj_info\": {        \"groups\": \"fake\"}    }}"
null

curl -X GET "http://10.6.27.1:5000/api/v2/system/nodes/abcd123"
{
    "meta": {
        "name": "abcd123"
    },
    "spec": {
        "obj_type": "node",
        "obj_info": {
            "groups": "fake"
        },
        "role": "compute",
        "device_type": "server"
    }
}
robin2008 commented 5 years ago

3, replace it with all information

curl -X PUT "http://10.6.27.1:5000/api/v2/system/nodes/abcd123" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{    \"meta\": {        \"name\": \"abcd123\"    },    \"spec\": {        \"obj_type\": \"node\",        \"obj_info\": {            \"groups\": \"fake,all,compute\"        },      \"engines\": {        \"netboot_engine\": {          \"engine_info\": {            \"chain\": \"runcmd\",            \"osimage\": \"rhels7.5-ppc64le-netboot-compute\"          },          \"engine_type\": \"grub2\"        }      },        \"role\": \"compute\",        \"device_type\": \"server\"    }}"
null

curl -X GET "http://10.6.27.1:5000/api/v2/system/nodes/abcd123"
{
    "meta": {
        "name": "abcd123"
    },
    "spec": {
        "obj_type": "node",
        "engines": {
            "netboot_engine": {
                "engine_info": {
                    "chain": "runcmd",
                    "osimage": "rhels7.5-ppc64le-netboot-compute"
                },
                "engine_type": "grub2"
            }
        },
        "obj_info": {
            "groups": "fake,all,compute"
        },
        "role": "compute",
        "device_type": "server"
    }
}
robin2008 commented 5 years ago

4, patch node (only support using lsdef attribute name)

curl -X PATCH "http://10.6.27.1:5000/api/v2/system/nodes/abcd123" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"modify\": {\"provmethod\":\"fake-osimage\"}}"

lsdef abcd123
Object name: abcd123
    chain=runcmd
    groups=fake,all,compute
    netboot=grub2
    nichostnamesuffixes.ib0=ib
    nicnetworks.ib0=ipoib
    nictypes.ib0=Infiniband
    postbootscripts=otherpkgs
    postscripts=syslog,remoteshell,syncfiles
    provmethod=fake-osimage   <===========
robin2008 commented 5 years ago

5, delete the node

curl -X DELETE "http://10.6.27.1:5000/api/v2/system/nodes/abcd123" -H  "accept: application/json"
null
lsdef abcd123
Error: [briggs01]: Could not find an object named 'abcd123' of type 'node'.
No object definitions have been found

curl -X DELETE "http://10.6.27.1:5000/api/v2/system/nodes/abcd123" -H  "accept: application/json"
{
    "message": "Could not find an object named 'abcd123' of type 'node'."
}
robin2008 commented 5 years ago

The CI failure is caused by installing xcatd (xcat-dep is updated today)