Просмотр исходного кода

Add VM inventory CSV endpoint to api-ref docs

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu 1 месяц назад
Родитель
Сommit
c3cb2c1ff2

+ 3 - 0
coriolis/api-refs/api_samples/endpoint/endpoint-inventory-resp.csv

@@ -0,0 +1,3 @@
+vm_id,vm_name,firmware,num_cpu,memory_mb,nested_virtualization,dynamic_memory_enabled,secure_boot,os_type,guest_id,disks,nics,hostname,parent_vapp,host,power_state
+4cb7e5e1-d3c4-4b0a-8742-f2b1b3d9a1c2,web-server-01,efi,4,8192,False,True,False,linux,ubuntu64Guest,150GB,Network adapter 1|00:50:56:aa:bb:cc|VM Network|10.0.0.10,web-server-01,,esxi-host-01.example.com,poweredOn
+9fa23b11-7e2a-4c10-a3f8-0d1e2f3c4a5b,db-server-01,bios,8,16384,False,False,False,windows,windows9Server64Guest,300GB,Network adapter 1|00:50:56:aa:cc:dd|VM Network|10.0.0.20,db-server-01,db-vapp,esxi-host-02.example.com,poweredOn

+ 58 - 0
coriolis/api-refs/source/endpoint.inc

@@ -325,6 +325,64 @@ Response
   .. literalinclude:: ../api_samples/endpoint/endpoint-instance-show-resp.json
      :language: javascript
 
+Get Endpoint VM Inventory
+=========================
+
+.. rest_method:: GET /endpoints/{endpoint_id}/inventory
+
+Exports the full VM inventory of an endpoint in CSV format.
+
+**Preconditions**
+
+The endpoint must exist and the provider must support inventory export.
+
+Normal response codes: 200
+
+Error response codes: unauthorized(401), forbidden(403),
+itemNotFound(404)
+
+Request
+-------
+
+.. rest_parameters:: parameters.yaml
+
+   - endpoint_id : endpoint_id_path
+   - env : inventory_source_env
+
+Response
+--------
+
+The response body is a UTF-8 encoded CSV file with various columns returned.
+Each provider may return more specific fields (i.e. parentVapp when using VMWare).
+The example below shows the values returned by the VMWare provider.
+
+- **vm_id** – Unique identifier (UUID) of the VM.
+- **vm_name** – Display name of the VM.
+- **guest_id** – Raw VMware guest OS identifier (e.g. ``ubuntu64Guest``).
+- **firmware** – Firmware type (``bios`` or ``efi``).
+- **num_cpu** – Number of vCPUs.
+- **memory_mb** – Memory in megabytes.
+- **nested_virtualization** – Whether nested virtualisation is enabled.
+- **dynamic_memory_enabled** – Whether dynamic memory is enabled.
+- **secure_boot** – Whether EFI Secure Boot is enabled.
+- **os_type** – Coriolis-normalised OS type (e.g. ``linux``, ``windows``).
+- **disks** – Total provisioned disk size for the VM (e.g. ``150GB``).
+- **nics** – Semicolon-separated list of NIC entries, each formatted as
+  ``label|mac[|network[|ip1,ip2,...]]``.
+- **hostname** – Guest hostname as reported by VMware Tools (empty if tools
+  are not running).
+- **parent_vapp** – Name of the parent vApp, if any.
+- **host** – ESXi host the VM is currently running on.
+- **power_state** – Current power state (e.g. ``poweredOn``, ``poweredOff``).
+
+The response is returned with ``Content-Type: text/csv`` and a
+``Content-Disposition: attachment`` header suggesting a filename of the form
+``vm_inventory_{endpoint_id}.csv``.
+
+**Example VM Inventory CSV Response**
+
+.. literalinclude:: ../api_samples/endpoint/endpoint-inventory-resp.csv
+
 Get Endpoint Destination Options
 ================================
 

+ 7 - 0
coriolis/api-refs/source/parameters.yaml

@@ -96,6 +96,13 @@ instance_refresh:
   required: false
   type: boolean
   default: false
+inventory_source_env:
+  description: |
+    Optional base64-encoded JSON object containing source environment options
+    for the inventory export When omitted, the provider's defaults are used.
+  in: query
+  required: false
+  type: string
 show_deleted:
   description: |
     Whether to include deleted resources in the response.

+ 10 - 2
coriolis/providers/base.py

@@ -1400,8 +1400,16 @@ class BaseEndpointInventoryExportProvider(
             self, ctxt, connection_info, source_environment):
         """Export the full VM inventory as a CSV-formatted string.
 
-        Returns a standards-compliant CSV string with a header row and one
-        row per VM, sorted deterministically by VM ID.
+        :param ctxt: Coriolis request context
+        :param connection_info: endpoint connection parameters
+        :param source_environment: provider-specific source environment
+                                   parameters
+
+        :returns: a standards-compliant CSV string with a header row and one
+                  row per VM, sorted deterministically by VM ID. Each row
+                  contains fields such as VM ID, VM name, guest OS, firmware
+                  type, number of CPUs, memory (MB), total disk size (GB),
+                  disk details, and network interface details.
         """
         raise NotImplementedError()