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

    XO Rest API

    Scheduled Pinned Locked Moved REST API
    28 Posts 5 Posters 1.1k Views 5 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.
    • I Offline
      irtaza9 @julien-f
      last edited by

      @julien-f I'm hitting the api in postman and this is the response i'm getting from the endpoint. My Pool is active and the template also is available. Can you please help me to solve this issue. Thank you.

      af08d031-7919-4164-b652-ffe272ac0e50-image.png

      DanpD 1 Reply Last reply Reply Quote 0
      • I Offline
        irtaza9
        last edited by

        Also this is the task output in XO.

        1ab20195-cf59-4d9d-a67d-a6e85b17f6a0-image.png

        1 Reply Last reply Reply Quote 0
        • I Offline
          irtaza9
          last edited by

          This is the JSON-RPC send request and it's is using the same template which I'm using in above postman api call. If I pass all the params of JSON-RPC in
          pools/_/actions/create_vm does it support all the payload? Actually I want to create the VM programmatically.

          fa9e92a8-b6a4-4661-b2ec-a10702004628-image.png

          1 Reply Last reply Reply Quote 0
          • DanpD Offline
            Danp Pro Support Team @irtaza9
            last edited by Danp

            @irtaza9 Have you tried it with the body formatted like this?

            {
            	"boot": true,
            	"memory": 2147483648,
            	"name_label": "testingVM" ,
            	"template": "f6745939-cc54-fa9c-5169-6f14ba830a6a" ,
            	"auto_poweron": true
            }
            
            I 1 Reply Last reply Reply Quote 0
            • I Offline
              irtaza9 @Danp
              last edited by

              @Danp for now I'm hitting cli for testing. This is the response im getting rn. The error is saying that the template doesn't exists in the pool, right? Also shared json-object is not giving the right response in postman.

              a4e2124c-216e-4d43-978d-dd28e1d7c93d-image.png

              65396814-2782-4a89-b290-9719e7e85cd8-image.png

              "result": {
                "message": "no object with UUID or opaque ref: 'f6745939-cc54-fa9c-5169-6f14ba830a6a'",
                "name": "Error",
                "stack": "Error: no object with UUID or opaque ref: 'f6745939-cc54-fa9c-5169-6f14ba830a6a'\n    at Xapi.apply (file:///opt/xen-orchestra/packages/xen-api/index.mjs:726:11)\n    at Xapi.getObject (file:///opt/xen-orchestra/packages/xo-server/src/xapi/index.mjs:98:26)\n    at Xapi.apply (file:///opt/xen-orchestra/packages/xo-server/src/xapi/mixins/vm.mjs:63:27)\n    at Xapi.createVm (/opt/xen-orchestra/node_modules/golike-defer/src/index.js:85:19)\n    at apply (file:///opt/xen-orchestra/packages/xo-server/src/xo-mixins/rest-api.mjs:715:38)\n    at fn (/opt/xen-orchestra/node_modules/golike-defer/src/index.js:85:19)\n    at file:///opt/xen-orchestra/packages/xo-server/src/xo-mixins/rest-api.mjs:1339:38\n    at AsyncLocalStorage.run (node:internal/async_local_storage/async_hooks:91:14)\n    at Task.runInside (/opt/xen-orchestra/@vates/task/index.js:172:41)\n    at Task.run (/opt/xen-orchestra/@vates/task/index.js:156:31)\n    at file:///opt/xen-orchestra/packages/xo-server/src/xo-mixins/rest-api.mjs:1339:28\n    at Layer.handle [as handle_request] (/opt/xen-orchestra/node_modules/express/lib/router/layer.js:95:5)\n    at next (/opt/xen-orchestra/node_modules/express/lib/router/route.js:149:13)\n    at /opt/xen-orchestra/node_modules/body-parser/lib/read.js:137:5\n    at AsyncResource.runInAsyncScope (node:async_hooks:211:14)\n    at invokeCallback (/opt/xen-orchestra/node_modules/raw-body/index.js:238:16)\n    at done (/opt/xen-orchestra/node_modules/raw-body/index.js:227:7)\n    at IncomingMessage.onEnd (/opt/xen-orchestra/node_modules/raw-body/index.js:287:7)\n    at IncomingMessage.emit (node:events:518:28)\n    at IncomingMessage.patchedEmit [as emit] (/opt/xen-orchestra/@xen-orchestra/log/configure.js:52:17)\n    at endReadableNT (node:internal/streams/readable:1698:12)\n    at processTicksAndRejections (node:internal/process/task_queues:90:21)"
              }
              
              DanpD 1 Reply Last reply Reply Quote 0
              • DanpD Offline
                Danp Pro Support Team @irtaza9
                last edited by

                @irtaza9 I assume that you are running XO from the sources. Is your VM up-to-date with the latest sources?

                Are you sure a template with that UUID exists for the target pool? What does the following command return?

                xo-cli --list-objects type=VM-template uuid=f6745939-cc54-fa9c-5169-6f14ba830a6a

                I 3 Replies Last reply Reply Quote 0
                • I Offline
                  irtaza9 @Danp
                  last edited by

                  @Danp said in XO Rest API:

                  xo-cli --list-objects type=VM-template uuid=f6745939-cc54-fa9c-5169-6f14ba830a6a

                  Reply

                  C:\Users\PC>xo-cli --list-objects type=VM-template uuid=f6745939-cc54-fa9c-5169-6f14ba830a6a
                  `--list-objects` is deprecated and will be removed in the future, use `list-objects` subcommand instead
                  
                  [
                  {
                    "type": "VM-template",
                    "addresses": {},
                    "auto_poweron": false,
                    "bios_strings": {
                      "bios-vendor": "Xen",
                      "bios-version": "",
                      "system-manufacturer": "Xen",
                      "system-product-name": "HVM domU",
                      "system-version": "",
                      "system-serial-number": "",
                      "baseboard-manufacturer": "",
                      "baseboard-product-name": "",
                      "baseboard-version": "",
                      "baseboard-serial-number": "",
                      "baseboard-asset-tag": "",
                      "baseboard-location-in-chassis": "",
                      "enclosure-asset-tag": "",
                      "hp-rombios": "",
                      "oem-1": "Xen",
                      "oem-2": "MS_VM_CERT/SHA1/bdbeb6e0a816d43fa6d3fe8aaef04c2bad9d3e3d"
                    },
                    "blockedOperations": {},
                    "boot": {
                      "order": "cdn"
                    },
                    "CPUs": {
                      "max": 2,
                      "number": 2
                    },
                    "current_operations": {},
                    "expNestedHvm": false,
                    "viridian": true,
                    "high_availability": "",
                    "isFirmwareSupported": true,
                    "memory": {
                      "dynamic": [
                        2147483648,
                        2147483648
                      ],
                      "static": [
                        2147483648,
                        2147483648
                      ],
                      "size": 2147483648
                    },
                    "installTime": null,
                    "name_description": "Ubuntu Linux (64-bit)",
                    "name_label": "ubuntu22image",
                    "needsVtpm": false,
                    "other": {
                      "import_task": "OpaqueRef:a36b7087-b9a2-4e31-96c6-a0e95a0b280f",
                      "mac_seed": "09d66866-7e77-af81-7432-3d5b48caa0d0",
                      "vgpu_pci": "",
                      "base_template_name": "Other install media",
                      "install-methods": "cdrom"
                    },
                    "os_version": {},
                    "power_state": "Halted",
                    "hasVendorDevice": false,
                    "snapshots": [],
                    "startDelay": 0,
                    "startTime": null,
                    "secureBoot": false,
                    "tags": [],
                    "VIFs": [],
                    "VTPMs": [],
                    "virtualizationMode": "hvm",
                    "$container": "d1aa29fb-9fed-e39b-0f88-fc4ebbd42d3f",
                    "$VBDs": [
                      "11bb8f2c-6cd0-e55a-9ff1-6d9b14689237"
                    ],
                    "VGPUs": [],
                    "$VGPUs": [],
                    "xenStoreData": {
                      "vm-data/mmio-hole-size": "268435456",
                      "vm-data": ""
                    },
                    "vga": "cirrus",
                    "videoram": 4,
                    "isDefaultTemplate": false,
                    "template_info": {
                      "disks": [],
                      "install_methods": [
                        "cdrom"
                      ]
                    },
                    "cpuWeight": 256,
                    "id": "f6745939-cc54-fa9c-5169-6f14ba830a6a",
                    "uuid": "f6745939-cc54-fa9c-5169-6f14ba830a6a",
                    "$pool": "d1aa29fb-9fed-e39b-0f88-fc4ebbd42d3f",
                    "$poolId": "d1aa29fb-9fed-e39b-0f88-fc4ebbd42d3f",
                    "_xapiRef": "OpaqueRef:ce5af387-410c-4e10-8eaf-46315b980ed2"
                  }
                  ]
                  
                  1 Reply Last reply Reply Quote 0
                  • I Offline
                    irtaza9 @Danp
                    last edited by

                    @Danp template info via rest-api

                    a227dc22-db3a-41b3-bc5b-9fa766784905-image.png

                    1 Reply Last reply Reply Quote 0
                    • I Offline
                      irtaza9 @Danp
                      last edited by

                      @Danp said in XO Rest API:

                      Is your VM up-to-date with the latest sources?

                      8892b31b-6087-4951-af2d-a4f8b4a2d0bd-image.png

                      Yes I configured the XO from sources and it's not up to date. Should I update my XO and will it fix the issue or not?

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

                        I strongly suggest to read this part of the doc: https://docs.xen-orchestra.com/community

                        And especially with this big yellow warning: https://docs.xen-orchestra.com/community#report-a-bug

                        I 1 Reply Last reply Reply Quote 0
                        • I Offline
                          irtaza9 @olivierlambert
                          last edited by

                          @olivierlambert Thank you for your time. I've a paid subscription but I am using XO from sources. I've opened a ticket from the help desk 😢

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

                            Great 🙂 For the version from the sources, it doesn't matter that you have paid support or not: you must use it with latest commits as possible 🙂 For XOA, then it's up to the support to answer you 🙂

                            I 1 Reply Last reply Reply Quote 0
                            • I Offline
                              irtaza9 @olivierlambert
                              last edited by

                              @olivierlambert omg 😵 I'll upgrade the XO. My question is still same, why the rest-api is not responding properly when I hit it from postman and the same api is responding with error when using xo-cli 😊

                              1 Reply Last reply Reply Quote 0
                              • D Offline
                                df-cgdm
                                last edited by

                                It looks like that's not possible to specify the CPU ??! with the /rest/v0/pools/{{pool_id}}/actions/create_vm

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

                                  What do you mean by "specify the CPU"?

                                  D 1 Reply Last reply Reply Quote 0
                                  • D Offline
                                    df-cgdm @olivierlambert
                                    last edited by

                                    @olivierlambert I'm not able to specify the number of vCPU for the VM

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

                                      Are you fully up to date? Also pinging @julien-f about this.

                                      D 1 Reply Last reply Reply Quote 0
                                      • D Offline
                                        df-cgdm @olivierlambert
                                        last edited by

                                        @olivierlambert yes I think so.

                                        XOA.jpg

                                        Here is the result of /rest/v0/pools/_/actions/create_vm (there is no cpu parameter)

                                        {
                                          "params": {
                                            "affinity": {
                                              "type": "string",
                                              "optional": true
                                            },
                                            "auto_poweron": {
                                              "type": "boolean",
                                              "optional": true
                                            },
                                            "boot": {
                                              "type": "boolean",
                                              "default": false
                                            },
                                            "clone": {
                                              "type": "boolean",
                                              "default": true
                                            },
                                            "cloud_config": {
                                              "type": "string",
                                              "optional": true
                                            },
                                            "destroy_cloud_config_vdi": {
                                              "type": "boolean",
                                              "default": false
                                            },
                                            "install": {
                                              "type": "object",
                                              "optional": true,
                                              "properties": {
                                                "method": {
                                                  "enum": [
                                                    "cdrom",
                                                    "network"
                                                  ]
                                                },
                                                "repository": {
                                                  "type": "string"
                                                }
                                              }
                                            },
                                            "memory": {
                                              "type": "integer",
                                              "optional": true
                                            },
                                            "name_description": {
                                              "type": "string",
                                              "minLength": 0,
                                              "optional": true
                                            },
                                            "name_label": {
                                              "type": "string"
                                            },
                                            "network_config": {
                                              "type": "string",
                                              "optional": true
                                            },
                                            "template": {
                                              "type": "string"
                                            },
                                            "vdis": {
                                              "type": "array",
                                              "default": [],
                                              "items": {
                                                "type": "object",
                                                "properties": {
                                                  "destroy": {
                                                    "type": "boolean",
                                                    "optional": true
                                                  },
                                                  "userdevice": {
                                                    "type": "string",
                                                    "optional": true
                                                  },
                                                  "size": {
                                                    "type": "number",
                                                    "optional": true
                                                  },
                                                  "sr": {
                                                    "type": "string",
                                                    "optional": true
                                                  },
                                                  "name_description": {
                                                    "type": "string",
                                                    "optional": true
                                                  },
                                                  "name_label": {
                                                    "type": "string",
                                                    "optional": true
                                                  }
                                                },
                                                "if": {
                                                  "not": {
                                                    "required": [
                                                      "userdevice"
                                                    ]
                                                  }
                                                },
                                                "then": {
                                                  "required": [
                                                    "size",
                                                    "name_label"
                                                  ],
                                                  "not": {
                                                    "required": [
                                                      "destroy"
                                                    ]
                                                  }
                                                }
                                              }
                                            },
                                            "vifs": {
                                              "default": [],
                                              "type": "array",
                                              "items": {
                                                "type": "object",
                                                "properties": {
                                                  "destroy": {
                                                    "type": "boolean",
                                                    "optional": true
                                                  },
                                                  "device": {
                                                    "type": "string",
                                                    "optional": true
                                                  },
                                                  "ipv4_allowed": {
                                                    "type": "array",
                                                    "items": {
                                                      "type": "string"
                                                    },
                                                    "optional": true
                                                  },
                                                  "ipv6_allowed": {
                                                    "type": "array",
                                                    "items": {
                                                      "type": "string"
                                                    },
                                                    "optional": true
                                                  },
                                                  "mac": {
                                                    "type": "string",
                                                    "optional": true
                                                  },
                                                  "network": {
                                                    "type": "string",
                                                    "optional": true
                                                  }
                                                }
                                              }
                                            }
                                          }
                                        }
                                        
                                        DanpD 1 Reply Last reply Reply Quote 0
                                        • DanpD Offline
                                          Danp Pro Support Team @df-cgdm
                                          last edited by

                                          @df-cgdm You are correct. That feature isn't currently available via the REST APIs as previously mentioned by Julien earlier in this thread.

                                          I 1 Reply Last reply Reply Quote 1
                                          • I Offline
                                            irtaza9 @Danp
                                            last edited by

                                            @Danp For now I'm going with JSON-RPC for only VM creation and for listings I'm using rest-apis. When XO6 will release I'll change the endpoint with rest endpoint. @olivierlambert any expected release date for XO6?

                                            julien-fJ 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post