From a36277c0028b3e784b8946353ea684df38a7c1cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexe=C3=AF=20KADIR?= Date: Tue, 20 Feb 2024 23:06:02 +0100 Subject: [PATCH] Started implementing XML generation for libvirt --- src/xml.c | 29 +++++++++++++++++++++++++++++ src/xml.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/xml.c create mode 100644 src/xml.h diff --git a/src/xml.c b/src/xml.c new file mode 100644 index 0000000..730db67 --- /dev/null +++ b/src/xml.c @@ -0,0 +1,29 @@ +#include "xml.h" + +result_t generate_iso_xml(char** _xml, char* iso_path, int index) { + // Initialize the output parameters + *_xml = NULL; + + if (index > 25) + return failure("Too many ISO images"); + + // Generate the XML + return foramt(_xml, "" + " " + " " + " " + " " + "", + iso_path, 'a' + index); +} + +result_t generate_vnc_xml(char** _xml, int vnc_port, char* password) { + // Initialize the output parameters + *_xml = NULL; + + // Generate the XML + if (vnc_port == -1) + return format(_xml, ""); + else + return format(_xml, "", vnc_port, password); +} diff --git a/src/xml.h b/src/xml.h new file mode 100644 index 0000000..7aa0b35 --- /dev/null +++ b/src/xml.h @@ -0,0 +1,35 @@ +#pragma once + +#include "utils.h" + +/// @brief Generate the libvirt XML used to start a container with the given parameters. +/// @param _xml The string pointer to store the resulting XML in. The caller is responsible for freeing the string. +/// @param container The container to generate the XML for. +/// @param cpu The number of CPUs to allocate to the container. +/// @param memory The amount of memory to allocate to the container, in bytes. +/// @param pci A null-terminated array of PCI devices to pass through to the container. +/// @param iso_path A null-terminated array of ISO image paths to attach to the container. +/// @param vnc_port The VNC port to use for the container. If -1, no VNC server will be started. +/// @param vnc_password The password to use for the VNC server. This parameter is ignored if VNC is not enabled. +/// @return The result of the operation. +result_t generate_container_xml(char** _xml, char* container, int cpu, uint64_t memory, char** pci, char** iso_path, int vnc_port, char* vnc_password); + +/// @brief Generate the libvirt XML used to attach an ISO image to a container. +/// @param _xml The string pointer to store the resulting XML in. +/// @param iso_path The path to the ISO image to attach. +/// @param index The index of the ISO image within the container. Must be positive, unique, and less than 26. +/// @return The result of the operation. +result_t generate_iso_xml(char** _xml, char* iso_path, int index); + +/// @brief Generate the libvirt XML used to start a VNC server for a container. +/// @param _xml The string pointer to store the resulting XML in. +/// @param vnc_port The VNC port to use for the container. +/// @param password The password to use for the VNC server. This parameter is ignored if VNC is not enabled. +/// @return The result of the operation. +result_t generate_vnc_xml(char** _xml, int vnc_port, char* password); + +/// @brief Generate the libvirt XML used to pass through a PCI device to a container. +/// @param _xml The string pointer to store the resulting XML in. +/// @param pci The PCI device to generate the XML for. +/// @return The result of the operation. +result_t generate_pci_xml(char** _xml, char* pci);