Create host by API (curl)
-
Hello, try to create host by curl.
curl --max-time 30 -H "fog-api-token: $FOG_API_TOKEN" -H "fog-user-token: $FOG_USER_API_TOKEN" -H "Content-Type: application/json" -X POST -d '{"name":"testing", "macs":"2c:94:64:01:70:f4", "imagename":"astra-1.6-gui-leg-basic-conf", "imageID":3}' http://$FOG_SERVER/fog/host/create
Where my mistake? Where i can read full API DOC with body request and depency?
-
@mnsk I’m going to make few assumptions here:
$FOG_SERVER is a variable that’s already preset with the FOG Server’s item?
$FOG_API_TOKEN is a variable that’s got the api token as taken from the fog server gui?
$FOG_USER_API_TOKEN is a variable that’s got the api token as taken from the fog server gui under the user?What’s the error you’re seeing?
I’d remove imagename as this is not needed to be defined for the host to be created. This will be set based on the “imageID” value (3 in your case)
All you should need is the hostname and primary mac address:
-
@mnsk Also the “macs” is an array. So you should have:
curl --max-time 30 \ -H "fog-api-token: $FOG_API_TOKEN" \ -H "fog-user-token: $FOG_USER_API_TOKEN" \ -H "Content-Type: application/json" \ -X POST \ -d {"name":"testing", "macs":["2c:94:64:01:70:f4"], "imageID": 3}\ http://$FOG_SERVER/fog/host/create
-
@tom-elliott
STDOUT and STDERR empty, all variable export in bash script.
After randomly change (json body) in curl command, host add in mysql base but dont visable in web-interface.
Can you get right json body with requirement params, to add host. -
kaisinav@kubuntu-vm:~/fog_auto$ curl --max-time 30 \ -H "fog-api-token: $FOG_API_TOKEN" \ -H "fog-user-token: $FOG_USER_API_TOKEN" \ -H "Content-Type: application/json" \ -X POST \ -d {"name":"testing", "macs":["2c:94:64:01:70:f4"], "imageID": 3}\ http://$FOG_SERVER/fog/host/create curl: (3) bad range in URL position 7: macs:[2c:94:64:01:70:f4],
Hmm, something going wrong
with double quotes
kaisinav@kubuntu-vm:~/fog_auto$ curl --max-time 30 -H "fog-api-token: $FOG_API_TOKEN" -H "fog-user-token: $FOG_USER_API_TOKEN" -H "Content-Type: application/json" -X POST -d "{"name":"testing", "macs":["2c:94:64:01:70:f4"]}" http://$FOG_SERVER/fog/host/create { "error": "Required database field is empty"
with single quotes, empty respones
curl --max-time 30 -H "fog-api-token: $FOG_API_TOKEN" -H "fog-user-token: $FOG_USER_API_TOKEN" -H "Content-Type: application/json" -X POST -d '{"name":"testing", "macs":["2c:94:64:01:70:f4"]}' http://$FOG_SERVER/fog/host/create
-
Yep, I found problem.
For example I use mac address, it already will be add to fog system.
Details i found in /var/log/apache2/error.log[Sun Jul 25 17:09:10.163987 2021] [proxy_fcgi:error] [pid 17738] [client 192.168.100.59:44634] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Exception: MAC address is already in use by another host: ship2-arm2-m121 in /var/www/fog/lib/fog/host.class.php:1696\nStack trace:\n#0 /var/www/fog/lib/router/route.class.php(928): Host->addPriMAC(Object(MACAddress))\n#1 /var/www/fog/lib/router/route.class.php(342): Route::create(Object(Host), 'POST')\n#2 /var/www/fog/lib/router/route.class.php(222): Route::runMatches()\n#3 /var/www/fog/api/index.php(23): Route->__construct()\n#4 {main}\n thrown in /var/www/fog/lib/fog/host.class.php on line 1696'
Some error message from web-server can be usefull, what u think ? @Tom-Elliott
-
@mnsk If the mac address already exists, and the host exists, then I would search the GUI for the mac address.
-
@tom-elliott when i change mac address curl can create host, but before i cant get any error about used mac, if json retern this error i can resolved problem)
-
@mnsk We don’t know what will error when. So if you see “empty response” the process is usually to view the error logs which will lead you in the direction the same way.
I have added some try/catches to the api information but this is in working-1.6 which I still think is not ready for prime time (though it is still functional in most areas).
-
@tom-elliott, thanks for your support ! Greate product !
-
@Tom-Elliott can you get me curl command or minimal list json params to create image in fog ?
Thanks