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

    How to expand a VM disk using xo-cli?

    Scheduled Pinned Locked Moved REST API
    7 Posts 2 Posters 139 Views 2 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.
    • E Offline
      eeldivad
      last edited by

      I'm trying to expand a VM disk using xo-cli or some automated method with a script. Anyone done this before and have an example?

      E 1 Reply Last reply Reply Quote 0
      • E Offline
        eeldivad @eeldivad
        last edited by eeldivad

        I figured out how to expand a VDI disk if I can get the id of the disk. But how do I get a list of disks attached to a VM if I have the name label of a vm? This is what I would run to get object details of the vm but I was hoping it would show a list of VDI ids attached to this VM but it doesn't.

        xo-cli list-objects name_label=vmtest1

        G 1 Reply Last reply Reply Quote 1
        • G Offline
          Gurve @eeldivad
          last edited by

          @eeldivad I think i can "help" somewhat. the "new" and probably more supported in the future way as I see it is doing stuff through xen orchestra Rest api (not everything is possible there yet however)

          http://[yourXO]/rest/v0/vms

          this endpoint is pretty "fire" as the kids say

          as per the README of the rest-api here

          you can add fields to the result, so adding "name_label" like so:

          http://[yourXO]/rest/v0/vms?fields=name_label

          http://[yourXO]/rest/v0/vms?fields=name_label&filter=[namelabelSearch]

          we can then search this output for the VM UUID we want (if you didn't just filter the api query)
          in my example i want "9a5730fa-77bc-1730-4583-c383cbc5c1f1"

          I then call:

          http://[yourXO]/rest/v0/vms/9a5730fa-77bc-1730-4583-c383cbc5c1f1/vdis

          which again is a list of endpoints like this:

          /rest/v0/vdis/cd59c164-b382-4a5c-8449-e668d31696da

          the last part after "vdis" is the disk UUID, you could then call that endpoint to get the VDI size, usage etc.

          Hope this was somewhat helpful 😄

          I did not see a easy way to get this from xo-cli but I figured you can probably get the UUID's from REST and then the "rest" on xo-cli

          E 2 Replies Last reply Reply Quote 1
          • E Offline
            eeldivad @Gurve
            last edited by

            @Gurve I was trying it your way and then I noticed something in the doc where we can use xo-cli to call any REST method. So from your example we can do the following in xo-cli

            get all VMs
            xo-cli rest get vms

            get single vm with id. this includes the VDI disks IDs I needed
            xo-cli rest get vms/d55b0683-2fb9-7b06-6fa5-be6f2065e4b5

            get vdis for a vm by vm id
            xo-cli rest get vms/d55b0683-2fb9-7b06-6fa5-be6f2065e4b5/vdis

            get VDI details with vdi ID
            xo-cli rest get vdis/50436f36-5d5b-4048-9834-2cad0b869f66

            Thank you so much!! you solved my problem

            1 Reply Last reply Reply Quote 1
            • E Offline
              eeldivad @Gurve
              last edited by eeldivad

              @Gurve Even though I figured out how to do it all in xo-cli now, I haven't figured out how to build the filter search in the querystring using the API method you mentioned above. Could you give me a couple examples for my curiosity as I may need it in the future.
              &filter=[namelabelSearch]

              G 1 Reply Last reply Reply Quote 1
              • G Offline
                Gurve @eeldivad
                last edited by

                @eeldivad Cool that you can call the rest api's through there! 😄

                I mess about in the web browser, seems to use the cookie that XO web ui uses (ie. logging in to web ui also makes you able to call api in web browser)

                my bad for not including a example, namelabel was supposed to hint at displayname of VM

                http://[yourXO]/rest/v0/vms?fields=name_label&filter=app

                this returns all vm's with "app" in their name_label (displayname)

                according to this documentation
                filter should be compatible with the search bar in XO, so you can make your query there by selecting pools etc. in GUI and it just seems to work (tested just now 😮 )

                http://[yourXO]/rest/v0/vms?fields=name_label&filter=power_state:running+tags:/^ansiblegrp_linuxbaseline$/

                I created the above query in GUI and just tested "+" between and it seems to work. This returns running vms that are also tagged with "ansiblegrp_linuxbaseline" which i use for my ansible inventory (xen orchestra has a pretty nifty inventory plugin) 🙂

                E 1 Reply Last reply Reply Quote 0
                • E Offline
                  eeldivad @Gurve
                  last edited by

                  @Gurve Oh wow that's neat! It works! very cool we can use the same query search from the GUI.
                  Thank you.

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