Here are some examples
Create a network
To create networks, use a POST request:
curl -k1 -u admin:testpw -X POST https://192.168.1.2/wapi/v2.11.2/network \ -d network=10.1.0.0/16
The server returns a reference of the created network:
"network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:10.1.0.0%2F16"
To create another network, send another POST request:
curl -k1 -u admin:testpw -X POST https://192.168.1.2/wapi/v2.11.2/network \ -d network=10.2.0.0/16
Read a network
To verify that both networks have been created, send a GET request:
curl -k1 -u admin:testpw -X GET https://192.168.1.2/wapi/v2.11.2/network
The server returns a list with both networks:
[ { "_ref": "network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:10.1.0.0%2F16", "network": "10.1.0.0/16", "network_view": "default" }, { "_ref": "network/ZG5zLm5ldHdvcmskMTAuMi4wLjAvMTYvMA:10.2.0.0%2F16", "network": "10.2.0.0/16", "network_view": "default" } ]
Note that the returned references could be different in your installation. The sample code uses references returned in the above example. Depending on your installation, make sure that you use the references your server returns.
Modify a network
To modify a network, send a PUT request. Send the following to modify its comment:
curl -k1 -u admin:testpw -X PUT \ https://192.168.1.2/wapi/v2.11.2/network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:\ 10.1.0.0%2F16 -d comment='Sample comment'
The server still returns the network reference. Note that this could be different from before:
"network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:10.1.0.0%2F16"
Check that the network was modified, since comment is not a field that is returned by default add _return_fields to the GET request:
curl -k1 -u admin:testpw -X GET https://192.168.1.2/wapi/v2.11.2/network \ -d _return_fields=network,network_view,comment
Note that the 10.1.0.0/16 network has been modified:
[ { "_ref": "network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:10.1.0.0%2F16", "comment": "Sample comment", "network": "10.1.0.0/16", "network_view": "default" }, { "_ref": "network/ZG5zLm5ldHdvcmskMTAuMi4wLjAvMTYvMA:10.2.0.0%2F16", "network": "10.2.0.0/16", "network_view": "default" } ]
Search for a network
To find networks with comments that contain the word sample in a case-insensitive way:
curl -k1 -u admin:testpw -X GET https://192.168.1.2/wapi/v2.11.2/network \ -d comment~:=sample
The server returns the network we just modified:
[ { "_ref": "network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:10.1.0.0%2F16", "comment": "Sample comment", "network": "10.1.0.0/16", "network_view": "default" } ]
If there is no match, the server returns an empty list:
curl -k1 -u admin:testpw -X GET https://192.168.1.2/wapi/v2.11.2/network \ -d comment~:=nomatch
The server returns the following:
[]
Delete a network
To delete a network, send a DELETE request using a reference you have retrieved by searching. For example, to delete the networks we created above, send the following:
curl -k1 -u admin:testpw -X DELETE \ https://192.168.1.2/wapi/v2.11.2/network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:\ 10.1.0.0%2F16
The server returns the reference of the object it just deleted, if the deletion was successful:
"network/ZG5zLm5ldHdvcmskMTAuMS4wLjAvMTYvMA:10.1.0.0%2F16"
To delete the other network, send the following:
curl -k1 -u admin:testpw -X DELETE \ https://192.168.1.2/wapi/v2.11.2/network/ZG5zLm5ldHdvcmskMTAuMi4wLjAvMTYvMA:\ 10.2.0.0%2F16
Note that both networks have been removed:
curl -k1 -u admin:testpw -X GET https://192.168.1.2/wapi/v2.11.2/network
The server returns the following:
[]