XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Run a job (host.stop) defined in XOCE via API

    Scheduled Pinned Locked Moved REST API
    10 Posts 4 Posters 248 Views 4 Watching
    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.
    • H Offline
      hanzzz
      last edited by hanzzz

      Dear all,
      My setup is far from advanced (single host in the pool) that is only on on demand not 24h - it is more playing than productivity. I am trying to use home assistant to control my XCP-ng 8.3 host. I would like to be able to start the host, start/stop/restart VMs on that host, shutdown the host (all VMs shutdown before). The following steps I solved:

      1. Start host (wake on lan)
      2. Control VMs (shell command: shell_command: curl -X POST -b authenticationToken={{token}} 'http://{{xoserver}}/rest/v0/vms/{{vmcode}}/actions/{{action}}')

      For the last part (shutdown host) I could not figure out a solution so far. I think there is no endpoint to stop the host or do I just miss it? That would the simplest way to go. Alternatively, I tried to setup a job with the only command "Host.stop". So an alternative approach could be to run this job from API but I could not find an endpoint for this as well...

      Actually, I am running XOCE in a Docker on a Synology NAS, so I can control the host from that and make sure that all VMs are shutdown.

      Does anyone have an idea how to realize this with API calls (via Home Assistent) or is this just not possible?

      1 Reply Last reply Reply Quote 0
      • olivierlambertO Offline
        olivierlambert Vates 🪐 Co-Founder CEO
        last edited by

        Hi,

        What do you mean? The host {{actions}} doesn't have any endpoint to stop it?

        H 1 Reply Last reply Reply Quote 0
        • H Offline
          hanzzz @olivierlambert
          last edited by

          @olivierlambert hi, I think so, or let's say I could not find the correct endpoint at least.
          To shutdown the VMs I used:
          'http://{{xoserver}}/rest/v0/vms/{{vmcode}}/actions/clean_shutdown'
          But adjusting this to:
          'http://{{xoserver}}/rest/v0/hosts/{{hostcode}}/actions/clean_shutdown'
          to stop the host did not work. Most likely I am just missing the correct action term to stop it?

          MathieuRAM 1 Reply Last reply Reply Quote 0
          • olivierlambertO Offline
            olivierlambert Vates 🪐 Co-Founder CEO
            last edited by

            Ping @lsouai-vates

            1 Reply Last reply Reply Quote 0
            • MathieuRAM Offline
              MathieuRA Vates 🪐 XO Team @hanzzz
              last edited by

              Hi.
              I confirm that no actions are currently available for hosts.

              H 1 Reply Last reply Reply Quote 1
              • olivierlambertO Offline
                olivierlambert Vates 🪐 Co-Founder CEO
                last edited by

                Nice, something to add in a near feature 🙂

                1 Reply Last reply Reply Quote 0
                • H Offline
                  hanzzz @MathieuRA
                  last edited by hanzzz

                  @MathieuRA I see, no problem! Would be nice to see something like this in the future. Just to make sure: there is also no actions to start a job via API? That would be a workaround with a job doing nothing but host.stop.
                  Thank you for your time and help!

                  lsouai-vatesL MathieuRAM 2 Replies Last reply Reply Quote 1
                  • lsouai-vatesL Offline
                    lsouai-vates Vates 🪐 XO Team @hanzzz
                    last edited by

                    @hanzzz Hello, indeed I agree that we need to add this to the hosts actions to handle by REST API.
                    Let's add this to our futures features on the REST-API 🙂

                    FYI @MathieuRA

                    1 Reply Last reply Reply Quote 2
                    • MathieuRAM Offline
                      MathieuRA Vates 🪐 XO Team @hanzzz
                      last edited by

                      @hanzzz This PR adds the ability to run a schedule. So, a temporary workaround is to create a job, create a schedule for this job, then run your schedule.

                      If you are not using XO from source, you will have to wait for version 5.106

                      1 Reply Last reply Reply Quote 1
                      • olivierlambertO Offline
                        olivierlambert Vates 🪐 Co-Founder CEO
                        last edited by

                        🍾

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