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);