• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Create host by API (curl)

    Scheduled Pinned Locked Moved
    FOG Problems
    2
    11
    1.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mnsk
      last edited by

      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?

      Tom ElliottT 2 Replies Last reply Reply Quote 0
      • Tom ElliottT
        Tom Elliott @mnsk
        last edited by

        @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:

        https://news.fogproject.org/simplified-api-documentation/

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

        M 1 Reply Last reply Reply Quote 0
        • Tom ElliottT
          Tom Elliott @mnsk
          last edited by

          @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
          

          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

          Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

          Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

          M 1 Reply Last reply Reply Quote 0
          • M
            mnsk @Tom Elliott
            last edited by

            @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.

            1 Reply Last reply Reply Quote 0
            • M
              mnsk @Tom Elliott
              last edited by mnsk

              @tom-elliott

              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
              
              1 Reply Last reply Reply Quote 0
              • M
                mnsk
                last edited by

                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

                Tom ElliottT 1 Reply Last reply Reply Quote 0
                • Tom ElliottT
                  Tom Elliott @mnsk
                  last edited by

                  @mnsk If the mac address already exists, and the host exists, then I would search the GUI for the mac address.

                  Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                  Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                  Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                  M 1 Reply Last reply Reply Quote 0
                  • M
                    mnsk @Tom Elliott
                    last edited by

                    @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)

                    Tom ElliottT 1 Reply Last reply Reply Quote 0
                    • Tom ElliottT
                      Tom Elliott @mnsk
                      last edited by

                      @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).

                      Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                      Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                      Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                      M 1 Reply Last reply Reply Quote 0
                      • M
                        mnsk @Tom Elliott
                        last edited by

                        @tom-elliott, thanks for your support ! Greate product !

                        1 Reply Last reply Reply Quote 0
                        • M
                          mnsk
                          last edited by

                          @Tom-Elliott can you get me curl command or minimal list json params to create image in fog ?
                          Thanks

                          1 Reply Last reply Reply Quote 0
                          • 1 / 1
                          • First post
                            Last post

                          197

                          Online

                          12.1k

                          Users

                          17.3k

                          Topics

                          155.3k

                          Posts
                          Copyright © 2012-2024 FOG Project