1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-11 04:58:16 +03:00

F #3953: Add RAW validator for KVM

- VirtualMachine
  - VMTemplate
  - Add libvirt rng files

co-authored-by: Christian González <cgonzalez@opennebula.io>
This commit is contained in:
Ruben S. Montero 2020-05-18 02:23:29 +02:00
parent a392c407f2
commit b22c569ab2
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
22 changed files with 8844 additions and 14 deletions

View File

@ -34,14 +34,18 @@ public:
~LibVirtDriver(){};
int validate_raw(const string& raw_section, string& error) const override;
private:
static const float CGROUP_BASE_CPU_SHARES;
static const float CGROUP_BASE_CPU_SHARES;
static const int CEPH_DEFAULT_PORT;
static const int CEPH_DEFAULT_PORT;
static const int GLUSTER_DEFAULT_PORT;
static const int GLUSTER_DEFAULT_PORT;
static const int ISCSI_DEFAULT_PORT;
static const int ISCSI_DEFAULT_PORT;
static const char * XML_DOMAIN_RNG_PATH;
int deployment_description(const VirtualMachine * vm, const string& fn) const override
{

View File

@ -327,6 +327,16 @@ public:
return var_location;
};
/**
* Returns the default share location. When ONE_LOCATION is defined this path
* points to $ONE_LOCATION/share, otherwise it is /usr/share/one.
* @return the log location.
*/
const string& get_share_location()
{
return share_location;
};
/**
*
*
@ -749,6 +759,7 @@ private:
var_location = "/var/lib/one/";
remotes_location = "/var/lib/one/remotes/";
vms_location = "/var/lib/one/vms/";
share_location = "/usr/share/one";
}
else
{
@ -765,6 +776,7 @@ private:
var_location = nebula_location + "var/";
remotes_location = nebula_location + "var/remotes/";
vms_location = nebula_location + "var/vms/";
share_location = nebula_location + "share/";
}
};
@ -784,6 +796,7 @@ private:
string var_location;
string remotes_location;
string vms_location;
string share_location;
string hostname;

View File

@ -283,6 +283,16 @@ public:
*/
static int validate_xml(const std::string &xml_doc);
/**
* Validates the XML doc against a RelaxNG schema
*
* @param xml_doc string containing the XML document
* @param schema_path path to RelaxNG schema file
* @return 0 if the xml validates
*/
static int validate_rng(const std::string &xml_doc,
const std::string& schema_path);
/**
* Renames the nodes given in the xpath expression
* @param xpath_expr xpath expression to find the nodes to rename

View File

@ -72,20 +72,20 @@ public:
/**
* Returns a copy of the DISK attributes of this template, the attributes
* are copied and must be freed by the calling function.
* @param a vector to store the disks.
* are copied and must be freed by the calling function.
* @param a vector to store the disks.
*/
void clone_disks(vector<VectorAttribute *>& disks)
{
vector<const VectorAttribute *> _disks;
vector<const VectorAttribute *> _disks;
obj_template->get("DISK", _disks);
obj_template->get("DISK", _disks);
for (vector<const VectorAttribute *>::const_iterator i = _disks.begin();
i != _disks.end() ; ++i)
{
disks.push_back(new VectorAttribute(*i));
}
for (vector<const VectorAttribute *>::const_iterator i = _disks.begin();
i != _disks.end() ; ++i)
{
disks.push_back(new VectorAttribute(*i));
}
}
/**

View File

@ -217,6 +217,16 @@ public:
(MadManager::get(0,_name,name));
};
/**
* Validates raw sections in the Virtual Machine Template for the
* target driver
* @param template of the virtual machine
* @param error_str error if any
*
* @return 0 on success (valid raw)
*/
int validate_raw(const Template * vmt, string& error_str);
private:
/**
* Thread id for the Virtual Machine Manager

View File

@ -71,6 +71,16 @@ public:
const VirtualMachine * vm,
const string& file_name) const = 0;
/**
* Validates de VM raws section
* @param raw_section raw section of the VM.
* @param error description on error
* @return 0 on success
*/
virtual int validate_raw(const string& raw, string& error) const
{
return 0;
}
/**
* Check if action is supported for imported VMs
* @param action

View File

@ -231,6 +231,8 @@ SHARE_DIRS="$SHARE_LOCATION/examples \
$SHARE_LOCATION/websockify/websockify \
$SHARE_LOCATION/esx-fw-vnc \
$SHARE_LOCATION/oneprovision \
$SHARE_LOCATION/schemas \
$SHARE_LOCATION/schemas/libvirt \
$SHARE_LOCATION/ssh \
$SHARE_LOCATION/start-scripts"
@ -669,6 +671,7 @@ INSTALL_FILES=(
ONE_CLI_LIB_FILES:$LIB_LOCATION/ruby/cli/one_helper
VENDOR_DIRS:$LIB_LOCATION/ruby/vendors
START_SCRIPT_SHARE_FILES:$SHARE_LOCATION/start-scripts
LIBVIRT_RNG_SHARE_MODULE_FILES:$SHARE_LOCATION/schemas/libvirt
SSH_SH_LIB_FILES:$LIB_LOCATION/sh
SSH_SH_OVERRIDE_LIB_FILES:$LIB_LOCATION/sh/override
SSH_SHARE_FILES:$SHARE_LOCATION/ssh
@ -2748,6 +2751,21 @@ DOCS_FILES="LICENSE LICENSE.addons NOTICE README.md"
VENDOR_DIRS="share/vendor/ruby/gems/packethost"
#-------------------------------------------------------------------------------
# Libvirt RelaxNG schemas
#-------------------------------------------------------------------------------
LIBVIRT_RNG_SHARE_MODULE_FILES="share/schemas/libvirt/basictypes.rng \
share/schemas/libvirt/cputypes.rng \
share/schemas/libvirt/domaincaps.rng \
share/schemas/libvirt/domaincheckpoint.rng \
share/schemas/libvirt/domaincommon.rng \
share/schemas/libvirt/domain.rng \
share/schemas/libvirt/domainsnapshot.rng \
share/schemas/libvirt/networkcommon.rng \
share/schemas/libvirt/nwfilter_params.rng \
share/schemas/libvirt/storagecommon.rng"
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# INSTALL.SH SCRIPT

View File

@ -0,0 +1,610 @@
<?xml version="1.0"?>
<!-- network-related definitions used in multiple grammars -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<!-- Our unsignedInt doesn't allow a leading "+" in its lexical form -->
<define name="unsignedInt">
<data type="unsignedInt">
<param name="pattern">[0-9]+</param>
</data>
</define>
<define name='unsignedLong'>
<data type='unsignedLong'>
<param name='pattern'>[0-9]+</param>
</data>
</define>
<define name='hexuint'>
<data type='string'>
<param name="pattern">(0x)?[0-9a-f]+</param>
</data>
</define>
<define name="positiveInteger">
<data type="positiveInteger">
<param name="pattern">[0-9]+</param>
</data>
</define>
<define name='octalMode'>
<data type="unsignedInt">
<param name='pattern'>[0-7]+</param>
</data>
</define>
<define name="uint8">
<choice>
<data type="string">
<param name="pattern">0x[0-9a-fA-F]{1,2}</param>
</data>
<data type="int">
<param name="minInclusive">0</param>
<param name="maxInclusive">255</param>
</data>
</choice>
</define>
<define name="uint16">
<choice>
<data type="string">
<param name="pattern">(0x)?[0-9a-fA-F]{1,4}</param>
</data>
<data type='int'>
<param name="minInclusive">0</param>
<param name="maxInclusive">65535</param>
</data>
</choice>
</define>
<define name="uint24">
<choice>
<data type="string">
<param name="pattern">0x[0-9a-fA-F]{1,6}</param>
</data>
<data type="int">
<param name="minInclusive">0</param>
<param name="maxInclusive">16777215</param>
</data>
</choice>
</define>
<define name="uint32">
<choice>
<data type="string">
<param name="pattern">(0x)?[0-9a-fA-F]{1,8}</param>
</data>
<data type="unsignedInt">
<param name="minInclusive">0</param>
<param name="maxInclusive">4294967295</param>
</data>
</choice>
</define>
<define name="UUID">
<choice>
<data type="string">
<param name="pattern">[a-fA-F0-9]{32}</param>
</data>
<data type="string">
<param name="pattern">[a-fA-F0-9]{8}\-([a-fA-F0-9]{4}\-){3}[a-fA-F0-9]{12}</param>
</data>
</choice>
</define>
<define name="numaDistanceValue">
<data type="unsignedInt">
<param name="minInclusive">10</param>
<param name="maxInclusive">255</param>
</data>
</define>
<define name="pciaddress">
<optional>
<attribute name="domain">
<ref name="pciDomain"/>
</attribute>
</optional>
<optional>
<attribute name="bus">
<ref name="pciBus"/>
</attribute>
</optional>
<optional>
<attribute name="slot">
<ref name="pciSlot"/>
</attribute>
</optional>
<optional>
<attribute name="function">
<ref name="pciFunc"/>
</attribute>
</optional>
<optional>
<attribute name="multifunction">
<ref name="virOnOff"/>
</attribute>
</optional>
</define>
<define name="zpciaddress">
<optional>
<element name="zpci">
<optional>
<attribute name="uid">
<ref name="uint16"/>
</attribute>
</optional>
<optional>
<attribute name="fid">
<ref name="uint32"/>
</attribute>
</optional>
</element>
</optional>
</define>
<!-- a 6 byte MAC address in ASCII-hex format, eg "12:34:56:78:9A:BC" -->
<!-- The lowest bit of the 1st byte is the "multicast" bit. a -->
<!-- uniMacAddr requires that bit to be 0, and a multiMacAddr -->
<!-- requires it to be 1. Plain macAddr will accept either. -->
<!-- Currently there is no use of multiMacAddr in libvirt, it -->
<!-- is included here for documentation/comparison purposes. -->
<define name="uniMacAddr">
<data type="string">
<param name="pattern">[a-fA-F0-9][02468aAcCeE](:[a-fA-F0-9]{2}){5}</param>
</data>
</define>
<define name="multiMacAddr">
<data type="string">
<param name="pattern">[a-fA-F0-9][13579bBdDfF](:[a-fA-F0-9]{2}){5}</param>
</data>
</define>
<define name="macAddr">
<data type="string">
<param name="pattern">[a-fA-F0-9]{2}(:[a-fA-F0-9]{2}){5}</param>
</data>
</define>
<!--====================================================================-->
<!--The duid is a unique identifier used in DHCPv6 to identity an -->
<!--interface on a device (system). The duid is often used by servers -->
<!--such as dnsmasq to assign a specific IP address (and optionally a -->
<!--name to an interface. The applicable standards are RFC3315 and -->
<!--RFC6355. These standards actually require the duid to be fixed for -->
<!--the hardward device and applicable to all network interfaces on -->
<!--that device. It is not clear that any software currently enforces -->
<!--this requirement although it could be implemented manually. -->
<!--====================================================================-->
<!--There are currently four types of duids defined: -->
<!-- type 1, duid-LLT, link-layer (MAC) plus 32 bit time when the -->
<!-- duid-LLT was created in seconds from January 1, 2000 -->
<!-- type 2, duid-EN, 32 bit "enterprise number" followed by a -->
<!-- variable length unique identifier. -->
<!-- type 3, duid-LL, link-layer (MAC) -->
<!-- type 4, duid-UUID, a 128 bit UUID (16 bytes) -->
<!--RFC3315 states that the maximum length of a duid is 128 bytes plus -->
<!--the 16 bit type field. Often, the machine type is "1" which is the -->
<!--number assigned to ethernet. -->
<define name="duidLLT">
<data type="string">
<!-- 0======| type======| 0======| machine type======| time================| link-layer============| -->
<param name="pattern">[0]{1,2}:[0]{0,1}[1]:[0]{1,2}:[0]{0,1}[a-fA-F1-9](:[a-fA-F0-9]{1,2}){4}(:[a-fA-F0-9]{1,2}){6,8}</param>
</data>
</define>
<define name="duidEN">
<data type="string">
<!-- 0======| type======| Enterprise number===| unique id ==============| -->
<param name="pattern">[0]{1,2}:[0]{0,1}[2](:[a-fA-F0-9]{1,2}){4}(:[a-fA-F0-9]{1,2}){1,124}</param>
</data>
</define>
<define name="duidLL">
<data type="string">
<!-- 0======| type======| 0======| machine type======| link-layer============| -->
<param name="pattern">[0]{1,2}:[0]{0,1}[3]:[0]{1,2}:[0]{0,1}[a-fA-F1-9](:[a-fA-F0-9]{1,2}){6,8}</param>
</data>
</define>
<define name="duidUUID">
<data type="string">
<!-- 0======| type======| UUID=================| -->
<param name="pattern">[0]{1,2}:[0]{0,1}[4](:[a-fA-F0-9]{1,2}){16}</param>
</data>
</define>
<define name="DUID">
<choice>
<ref name="duidLLT"/>
<ref name="duidEN"/>
<ref name="duidLL"/>
<ref name="duidUUID"/>
</choice>
</define>
<!--======================================================================-->
<!-- An ipv4 "dotted quad" address -->
<define name="ipv4Addr">
<data type="string">
<param name="pattern">(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9]))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9]))</param>
</data>
</define>
<!-- Based on http://blog.mes-stats.fr/2008/10/09/regex-ipv4-et-ipv6 -->
<define name="ipv6Addr">
<data type="string">
<!-- To understand this better, take apart the toplevel "|"s -->
<param name="pattern">(([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9]))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9])))|(([0-9A-Fa-f]{1,4}:){0,5}:(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9]))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9])))|(::([0-9A-Fa-f]{1,4}:){0,5}(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9]))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9])))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:)|(::)</param>
</data>
</define>
<define name="ipAddr">
<choice>
<ref name="ipv4Addr"/>
<ref name="ipv6Addr"/>
</choice>
</define>
<define name="ipv4Prefix">
<data type="unsignedInt">
<param name="maxInclusive">32</param>
</data>
</define>
<define name="ipv6Prefix">
<data type="unsignedInt">
<param name="maxInclusive">128</param>
</data>
</define>
<define name="ipPrefix">
<choice>
<ref name="ipv4Prefix"/>
<ref name="ipv6Prefix"/>
</choice>
</define>
<define name="genericName">
<data type="string">
<param name="pattern">[a-zA-Z0-9_\+\-]+</param>
</data>
</define>
<define name="dnsName">
<data type="string">
<param name="pattern">[a-zA-Z0-9\.\-]+</param>
</data>
</define>
<define name="deviceName">
<data type="string">
<param name="pattern">[a-zA-Z0-9_\.\-\\:/]+</param>
</data>
</define>
<define name="zoneName">
<data type="string">
<param name="pattern">[a-zA-Z0-9_\-]+</param>
</data>
</define>
<define name="filePath">
<data type="string">
<param name="pattern">.+</param>
</data>
</define>
<define name="dirPath">
<data type="string">
<param name="pattern">.+</param>
</data>
</define>
<define name="absFilePath">
<data type="string">
<param name="pattern">/.+</param>
</data>
</define>
<define name="absDirPath">
<data type="string">
<param name="pattern">/.*</param>
</data>
</define>
<define name='unit'>
<data type='string'>
<param name='pattern'>([bB]([yY][tT][eE][sS]?)?)|([kKmMgGtTpPeE]([iI]?[bB])?)</param>
</data>
</define>
<define name='scaledInteger'>
<optional>
<attribute name='unit'>
<ref name='unit'/>
</attribute>
</optional>
<ref name='unsignedLong'/>
</define>
<define name="pciDomain">
<ref name="uint32"/>
</define>
<define name="pciBus">
<ref name="uint8"/>
</define>
<define name="pciSlot">
<choice>
<data type="string">
<param name="pattern">(0x)?[0-1]?[0-9a-fA-F]</param>
</data>
<data type="int">
<param name="minInclusive">0</param>
<param name="maxInclusive">31</param>
</data>
</choice>
</define>
<define name="pciFunc">
<choice>
<data type="string">
<param name="pattern">(0x)?[0-7]</param>
</data>
<data type="int">
<param name="minInclusive">0</param>
<param name="maxInclusive">7</param>
</data>
</choice>
</define>
<define name='wwn'>
<data type='string'>
<param name='pattern'>(0x)?[0-9a-fA-F]{16}</param>
</data>
</define>
<define name="ccwCssidRange">
<choice>
<data type="string">
<param name="pattern">0x[0-9a-eA-E][0-9a-fA-F]?</param>
</data>
<data type="string">
<param name="pattern">0x[fF][0-9a-eA-E]?</param>
</data>
<data type="int">
<param name="minInclusive">0</param>
<param name="maxInclusive">254</param>
</data>
</choice>
</define>
<define name="ccwSsidRange">
<data type="string">
<param name="pattern">(0x)?[0-3]</param>
</data>
</define>
<define name="ccwDevnoRange">
<choice>
<data type="string">
<param name="pattern">0x[0-9a-fA-F]{1,4}</param>
</data>
<data type="int">
<param name="minInclusive">0</param>
<param name="maxInclusive">65535</param>
</data>
</choice>
</define>
<define name="cpuset">
<data type="string">
<param name="pattern">([0-9]+(-[0-9]+)?|\^[0-9]+)(,([0-9]+(-[0-9]+)?|\^[0-9]+))*</param>
</data>
</define>
<define name='volName'>
<!-- directory pools allow almost any file name as a volume name -->
<data type='string'>
<param name="pattern">[^/]+</param>
<except>
<choice>
<value>.</value>
<value>..</value>
</choice>
</except>
</data>
</define>
<define name='archnames'>
<choice>
<value>aarch64</value>
<value>alpha</value>
<value>armv6l</value>
<value>armv7l</value>
<value>cris</value>
<value>i686</value>
<value>ia64</value>
<value>lm32</value>
<value>m68k</value>
<value>microblaze</value>
<value>microblazeel</value>
<value>mips</value>
<value>mipsel</value>
<value>mips64</value>
<value>mips64el</value>
<value>openrisc</value>
<value>parisc</value>
<value>parisc64</value>
<value>ppc</value>
<value>ppc64</value>
<value>ppc64le</value>
<value>ppcemb</value>
<value>riscv32</value>
<value>riscv64</value>
<value>s390</value>
<value>s390x</value>
<value>sh4</value>
<value>sh4eb</value>
<value>sparc</value>
<value>sparc64</value>
<value>unicore32</value>
<value>x86_64</value>
<value>xtensa</value>
<value>xtensaeb</value>
</choice>
</define>
<define name="PortNumber">
<data type="int">
<param name="minInclusive">-1</param>
<param name="maxInclusive">65535</param>
</data>
</define>
<define name='sourceinfoadapter'>
<element name='adapter'>
<choice>
<group>
<!-- To keep back-compat, 'type' is not mandatory for
scsi_host adapter -->
<optional>
<attribute name='type'>
<value>scsi_host</value>
</attribute>
</optional>
<choice>
<group>
<attribute name='name'>
<text/>
</attribute>
</group>
<group>
<interleave>
<element name="parentaddr">
<optional>
<attribute name='unique_id'>
<ref name='positiveInteger'/>
</attribute>
</optional>
<element name="address">
<ref name="pciaddress"/>
</element>
</element>
</interleave>
</group>
</choice>
</group>
<group>
<attribute name='type'>
<value>fc_host</value>
</attribute>
<optional>
<attribute name='parent'>
<text/>
</attribute>
</optional>
<optional>
<attribute name='managed'>
<ref name="virYesNo"/>
</attribute>
</optional>
<optional>
<attribute name='parent_wwnn'>
<ref name='wwn'/>
</attribute>
</optional>
<optional>
<attribute name='parent_wwpn'>
<ref name='wwn'/>
</attribute>
</optional>
<optional>
<attribute name='parent_fabric_wwn'>
<ref name='wwn'/>
</attribute>
</optional>
<attribute name='wwnn'>
<ref name='wwn'/>
</attribute>
<attribute name='wwpn'>
<ref name='wwn'/>
</attribute>
</group>
</choice>
<empty/>
</element>
</define>
<define name="isaaddress">
<optional>
<attribute name="iobase">
<data type="string">
<param name="pattern">0x[a-fA-F0-9]{1,4}</param>
</data>
</attribute>
</optional>
<optional>
<attribute name="irq">
<data type="string">
<param name="pattern">0x[a-fA-F0-9]</param>
</data>
</attribute>
</optional>
</define>
<define name="link-speed-state">
<optional>
<element name="link">
<optional>
<attribute name="speed">
<ref name="unsignedInt"/>
</attribute>
</optional>
<optional>
<attribute name="state">
<choice>
<value>unknown</value>
<value>notpresent</value>
<value>down</value>
<value>lowerlayerdown</value>
<value>testing</value>
<value>dormant</value>
<value>up</value>
</choice>
</attribute>
</optional>
</element>
</optional>
</define>
<define name="virYesNo">
<choice>
<value>yes</value>
<value>no</value>
</choice>
</define>
<define name="virOnOff">
<choice>
<value>on</value>
<value>off</value>
</choice>
</define>
<define name="metadata">
<element name="metadata">
<zeroOrMore>
<ref name="customElement"/>
</zeroOrMore>
</element>
</define>
<define name="customElement">
<element>
<anyName/>
<zeroOrMore>
<choice>
<attribute>
<anyName/>
</attribute>
<text/>
<ref name="customElement"/>
</choice>
</zeroOrMore>
</element>
</define>
</grammar>

View File

@ -0,0 +1,189 @@
<?xml version="1.0"?>
<!-- CPU-related definitions used in multiple grammars -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<define name="cpuMode">
<attribute name="mode">
<choice>
<value>custom</value>
<value>host-model</value>
<value>host-passthrough</value>
</choice>
</attribute>
</define>
<define name="cpuMatch">
<attribute name="match">
<choice>
<value>minimum</value>
<value>exact</value>
<value>strict</value>
</choice>
</attribute>
</define>
<define name="cpuCheck">
<attribute name="check">
<choice>
<value>none</value>
<value>partial</value>
<value>full</value>
</choice>
</attribute>
</define>
<define name="cpuModel">
<element name="model">
<optional>
<attribute name="fallback">
<choice>
<value>allow</value>
<value>forbid</value>
</choice>
</attribute>
</optional>
<optional>
<attribute name="vendor_id">
<data type="string">
<param name='pattern'>[^,]{12}</param>
</data>
</attribute>
</optional>
<choice>
<text/>
<empty/>
</choice>
</element>
</define>
<define name="cpuVendor">
<element name="vendor">
<text/>
</element>
</define>
<define name="cpuFeature">
<element name="feature">
<attribute name="policy">
<choice>
<value>force</value>
<value>require</value>
<value>optional</value>
<value>disable</value>
<value>forbid</value>
</choice>
</attribute>
<attribute name="name">
<ref name="featureName"/>
</attribute>
<empty/>
</element>
</define>
<define name="cpuTopology">
<element name="topology">
<attribute name="sockets">
<ref name="positiveInteger"/>
</attribute>
<attribute name="cores">
<ref name="positiveInteger"/>
</attribute>
<attribute name="threads">
<ref name="positiveInteger"/>
</attribute>
</element>
</define>
<define name="cpuNuma">
<element name="numa">
<oneOrMore>
<ref name="numaCell"/>
</oneOrMore>
</element>
</define>
<define name="numaCell">
<element name="cell">
<optional>
<attribute name="id">
<ref name="unsignedInt"/>
</attribute>
</optional>
<attribute name="cpus">
<ref name="cpuset"/>
</attribute>
<attribute name="memory">
<ref name="memoryKB"/>
</attribute>
<optional>
<attribute name="unit">
<ref name="unit"/>
</attribute>
</optional>
<optional>
<attribute name="memAccess">
<choice>
<value>shared</value>
<value>private</value>
</choice>
</attribute>
</optional>
<optional>
<attribute name="discard">
<ref name="virYesNo"/>
</attribute>
</optional>
<optional>
<element name="distances">
<oneOrMore>
<ref name="numaDistance"/>
</oneOrMore>
</element>
</optional>
</element>
</define>
<define name="numaDistance">
<element name="sibling">
<attribute name="id">
<ref name="unsignedInt"/>
</attribute>
<attribute name="value">
<ref name="numaDistanceValue"/>
</attribute>
</element>
</define>
<!-- Memory as an attribute is in KiB, no way to express a unit -->
<define name="memoryKB">
<data type="unsignedLong"/>
</define>
<define name="featureName">
<data type="string">
<param name='pattern'>[a-zA-Z0-9\-_\.]+</param>
</data>
</define>
<define name="cpuCache">
<element name="cache">
<optional>
<attribute name="level">
<choice>
<value>1</value>
<value>2</value>
<value>3</value>
</choice>
</attribute>
</optional>
<attribute name="mode">
<choice>
<value>emulate</value>
<value>passthrough</value>
<value>disable</value>
</choice>
</attribute>
</element>
</define>
</grammar>

View File

@ -0,0 +1,21 @@
<?xml version="1.0"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<!-- Grammar for accepting a domain element, both as top level, and
also suitable for inclusion in domainsnapshot.rng -->
<start>
<ref name="domain"/>
</start>
<include href='domaincommon.rng'/>
<define name='storageStartupPolicy' combine='choice'>
<!-- overrides the no-op version in storagecommon.rng -->
<ref name='startupPolicy'/>
</define>
<define name='storageSourceExtra' combine='choice'>
<!-- overrides the no-op version in storagecommon.rng -->
<ref name='diskspec'/>
</define>
</grammar>

View File

@ -0,0 +1,282 @@
<?xml version="1.0"?>
<!-- A Relax NG schema for the libvirt domain capabilities XML format -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<include href='basictypes.rng'/>
<include href='cputypes.rng'/>
<start>
<ref name='domainCapabilities'/>
</start>
<define name='domainCapabilities'>
<element name='domainCapabilities'>
<interleave>
<element name='path'>
<ref name="absFilePath"/>
</element>
<element name='domain'>
<text/>
</element>
<optional>
<element name='machine'>
<text/>
</element>
</optional>
<element name='arch'>
<text/>
</element>
<optional>
<ref name='vcpu'/>
</optional>
<optional>
<ref name='iothreads'/>
</optional>
<optional>
<ref name='os'/>
</optional>
<optional>
<ref name='cpu'/>
</optional>
<optional>
<ref name='devices'/>
</optional>
<optional>
<ref name='features'/>
</optional>
</interleave>
</element>
</define>
<define name='vcpu'>
<element name='vcpu'>
<attribute name='max'>
<ref name='unsignedInt'/>
</attribute>
<empty/>
</element>
</define>
<define name='iothreads'>
<element name='iothreads'>
<ref name='supported'/>
<empty/>
</element>
</define>
<define name='loader'>
<element name='loader'>
<ref name='supported'/>
<optional>
<ref name='value'/>
</optional>
<ref name='enum'/>
</element>
</define>
<define name='os'>
<element name='os'>
<interleave>
<ref name='supported'/>
<ref name='enum'/>
<optional>
<ref name='loader'/>
</optional>
</interleave>
</element>
</define>
<define name='cpu'>
<element name='cpu'>
<ref name='cpuHost'/>
<ref name='cpuHostModel'/>
<ref name='cpuCustom'/>
</element>
</define>
<define name='cpuHost'>
<element name='mode'>
<attribute name='name'>
<value>host-passthrough</value>
</attribute>
<ref name='supported'/>
</element>
</define>
<define name='cpuHostModel'>
<element name='mode'>
<attribute name='name'>
<value>host-model</value>
</attribute>
<ref name='supported'/>
<optional>
<ref name="cpuModel"/>
<optional>
<ref name="cpuVendor"/>
</optional>
<zeroOrMore>
<ref name="cpuFeature"/>
</zeroOrMore>
</optional>
</element>
</define>
<define name='cpuCustom'>
<element name='mode'>
<attribute name='name'>
<value>custom</value>
</attribute>
<ref name='supported'/>
<zeroOrMore>
<element name='model'>
<attribute name='usable'>
<choice>
<value>yes</value>
<value>no</value>
<value>unknown</value>
</choice>
</attribute>
<text/>
</element>
</zeroOrMore>
</element>
</define>
<define name='devices'>
<element name='devices'>
<optional>
<ref name='disk'/>
</optional>
<optional>
<ref name='graphics'/>
</optional>
<optional>
<ref name='video'/>
</optional>
<optional>
<ref name='hostdev'/>
</optional>
<optional>
<ref name='rng'/>
</optional>
</element>
</define>
<define name='disk'>
<element name='disk'>
<ref name='supported'/>
<ref name='enum'/>
</element>
</define>
<define name='graphics'>
<element name='graphics'>
<ref name='supported'/>
<ref name='enum'/>
</element>
</define>
<define name='video'>
<element name='video'>
<ref name='supported'/>
<ref name='enum'/>
</element>
</define>
<define name='hostdev'>
<element name='hostdev'>
<ref name='supported'/>
<ref name='enum'/>
</element>
</define>
<define name='rng'>
<element name='rng'>
<ref name='supported'/>
<ref name='enum'/>
</element>
</define>
<define name='features'>
<element name='features'>
<optional>
<ref name='gic'/>
</optional>
<optional>
<ref name='vmcoreinfo'/>
</optional>
<optional>
<ref name='vmgenid'/>
</optional>
<optional>
<ref name='backingStoreInput'/>
</optional>
<optional>
<ref name='sev'/>
</optional>
</element>
</define>
<define name='gic'>
<element name='gic'>
<ref name='supported'/>
<ref name='enum'/>
</element>
</define>
<define name='vmcoreinfo'>
<element name='vmcoreinfo'>
<ref name='supported'/>
</element>
</define>
<define name='vmgenid'>
<element name='genid'>
<ref name='supported'/>
</element>
</define>
<define name='backingStoreInput'>
<element name='backingStoreInput'>
<ref name='supported'/>
</element>
</define>
<define name='sev'>
<element name='sev'>
<ref name='supported'/>
<optional>
<element name='cbitpos'>
<data type='unsignedInt'/>
</element>
<element name='reducedPhysBits'>
<data type='unsignedInt'/>
</element>
</optional>
</element>
</define>
<define name='value'>
<zeroOrMore>
<element name='value'>
<text/>
</element>
</zeroOrMore>
</define>
<define name='supported'>
<attribute name='supported'>
<ref name="virYesNo"/>
</attribute>
</define>
<define name='enum'>
<zeroOrMore>
<element name='enum'>
<attribute name='name'>
<text/>
</attribute>
<ref name='value'/>
</element>
</zeroOrMore>
</define>
</grammar>

View File

@ -0,0 +1,94 @@
<?xml version='1.0'?>
<!-- A Relax NG schema for the libvirt domain checkpoint properties XML format -->
<grammar xmlns='http://relaxng.org/ns/structure/1.0' datatypeLibrary='http://www.w3.org/2001/XMLSchema-datatypes'>
<start>
<ref name='domaincheckpoint'/>
</start>
<include href='domaincommon.rng'/>
<define name='domaincheckpoint'>
<element name='domaincheckpoint'>
<interleave>
<optional>
<element name='name'>
<ref name='checkpointName'/>
</element>
</optional>
<optional>
<element name='description'>
<text/>
</element>
</optional>
<optional>
<element name='creationTime'>
<ref name='unsignedLong'/>
</element>
</optional>
<optional>
<element name='disks'>
<oneOrMore>
<ref name='diskcheckpoint'/>
</oneOrMore>
</element>
</optional>
<optional>
<!-- Nested grammar ensures that any of our overrides of
storagecommon/domaincommon defines do not conflict
with any domain.rng overrides. -->
<grammar>
<include href='domain.rng'/>
</grammar>
</optional>
<optional>
<element name='parent'>
<element name='name'>
<ref name='checkpointName'/>
</element>
</element>
</optional>
</interleave>
</element>
</define>
<define name='diskcheckpoint'>
<element name='disk'>
<attribute name='name'>
<choice>
<ref name='diskTarget'/>
<ref name='absFilePath'/>
</choice>
</attribute>
<choice>
<attribute name='checkpoint'>
<value>no</value>
</attribute>
<group>
<optional>
<attribute name='checkpoint'>
<value>bitmap</value>
</attribute>
</optional>
<optional>
<attribute name='bitmap'>
<text/>
</attribute>
</optional>
<optional>
<attribute name='size'>
<ref name='unsignedLong'/>
</attribute>
</optional>
</group>
</choice>
</element>
</define>
<define name='checkpointName'>
<data type='string'>
<!-- Notably: no leading '.' and no embedded '/' or newline -->
<param name='pattern'>[a-zA-Z0-9_\-][a-zA-Z0-9_\-.]*</param>
</data>
</define>
</grammar>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,208 @@
<?xml version="1.0"?>
<!-- A Relax NG schema for the libvirt domain snapshot properties XML format -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<ref name='domainsnapshot'/>
</start>
<include href='domaincommon.rng'/>
<define name='domainsnapshot'>
<element name='domainsnapshot'>
<interleave>
<optional>
<element name='name'>
<text/>
</element>
</optional>
<optional>
<element name='description'>
<text/>
</element>
</optional>
<optional>
<element name='state'>
<ref name='state'/>
</element>
</optional>
<optional>
<element name='creationTime'>
<text/>
</element>
</optional>
<optional>
<element name='memory'>
<choice>
<attribute name='snapshot'>
<choice>
<value>no</value>
<value>internal</value>
</choice>
</attribute>
<group>
<optional>
<attribute name='snapshot'>
<value>external</value>
</attribute>
</optional>
<attribute name='file'>
<ref name='absFilePath'/>
</attribute>
</group>
</choice>
<empty/>
</element>
</optional>
<optional>
<element name='disks'>
<zeroOrMore>
<ref name='disksnapshot'/>
</zeroOrMore>
</element>
</optional>
<optional>
<element name='active'>
<choice>
<value>0</value>
<value>1</value>
</choice>
</element>
</optional>
<optional>
<choice>
<element name='domain'>
<element name='uuid'>
<ref name="UUID"/>
</element>
</element>
<!-- Nested grammar ensures that any of our overrides of
storagecommon/domaincommon defines do not conflict
with any domain.rng overrides. -->
<grammar>
<include href='domain.rng'/>
</grammar>
</choice>
</optional>
<optional>
<element name='parent'>
<element name='name'>
<text/>
</element>
</element>
</optional>
<optional>
<element name='cookie'>
<zeroOrMore>
<ref name='customElement'/>
</zeroOrMore>
</element>
</optional>
</interleave>
</element>
</define>
<define name='state'>
<choice>
<value>running</value>
<value>blocked</value>
<value>paused</value>
<value>shutdown</value>
<value>shutoff</value>
<value>crashed</value>
<value>disk-snapshot</value>
</choice>
</define>
<define name='storageSourceExtra' combine='choice'>
<!-- overrides the no-op version in storagecommon.rng -->
<ref name='disksnapshotdriver'/>
</define>
<define name='disksnapshot'>
<element name='disk'>
<attribute name='name'>
<choice>
<ref name='diskTarget'/>
<ref name='absFilePath'/>
</choice>
</attribute>
<choice>
<attribute name='snapshot'>
<value>no</value>
</attribute>
<attribute name='snapshot'>
<value>internal</value>
</attribute>
<group>
<optional>
<attribute name='snapshot'>
<value>external</value>
</attribute>
</optional>
<choice>
<group>
<optional>
<attribute name='type'>
<value>file</value>
</attribute>
</optional>
<interleave>
<optional>
<element name='source'>
<optional>
<attribute name='file'>
<ref name='absFilePath'/>
</attribute>
</optional>
<optional>
<ref name='storageStartupPolicy'/>
</optional>
<zeroOrMore>
<ref name='devSeclabel'/>
</zeroOrMore>
<empty/>
</element>
</optional>
<ref name='storageSourceExtra'/>
</interleave>
</group>
<group>
<attribute name='type'>
<value>block</value>
</attribute>
<interleave>
<optional>
<element name="source">
<attribute name="dev">
<ref name="absFilePath"/>
</attribute>
<zeroOrMore>
<ref name='devSeclabel'/>
</zeroOrMore>
<empty/>
</element>
</optional>
<ref name='storageSourceExtra'/>
</interleave>
</group>
<ref name='diskSourceNetwork'/>
</choice>
</group>
</choice>
</element>
</define>
<define name='disksnapshotdriver'>
<optional>
<element name='driver'>
<optional>
<attribute name='type'>
<ref name='storageFormatBacking'/>
</attribute>
</optional>
<empty/>
</element>
</optional>
</define>
</grammar>

View File

@ -0,0 +1,283 @@
<?xml version="1.0"?>
<!-- network-related definitions used in multiple grammars -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<define name="virtualPortProfileID">
<data type="string">
<param name="maxLength">39</param>
</data>
</define>
<define name="virtualPortProfile">
<choice>
<group>
<element name="virtualport">
<attribute name="type">
<value>802.1Qbg</value>
</attribute>
<optional>
<element name="parameters">
<optional>
<attribute name="managerid">
<ref name="uint8"/>
</attribute>
</optional>
<optional>
<attribute name="typeid">
<ref name="uint24"/>
</attribute>
</optional>
<optional>
<attribute name="typeidversion">
<ref name="uint8"/>
</attribute>
</optional>
<optional>
<attribute name="instanceid">
<ref name="UUID"/>
</attribute>
</optional>
</element>
</optional>
</element>
</group>
<group>
<element name="virtualport">
<attribute name="type">
<value>802.1Qbh</value>
</attribute>
<optional>
<element name="parameters">
<optional>
<attribute name="profileid">
<ref name="virtualPortProfileID"/>
</attribute>
</optional>
</element>
</optional>
</element>
</group>
<group>
<element name="virtualport">
<attribute name="type">
<value>openvswitch</value>
</attribute>
<optional>
<element name="parameters">
<optional>
<attribute name="profileid">
<ref name="virtualPortProfileID"/>
</attribute>
</optional>
<optional>
<attribute name="interfaceid">
<ref name="UUID"/>
</attribute>
</optional>
</element>
</optional>
</element>
</group>
<group>
<element name="virtualport">
<attribute name="type">
<value>midonet</value>
</attribute>
<element name="parameters">
<attribute name="interfaceid">
<ref name="UUID"/>
</attribute>
</element>
</element>
</group>
<group>
<!-- use this when no type attribute is present -->
<element name="virtualport">
<optional>
<element name="parameters">
<optional>
<attribute name="managerid">
<ref name="uint8"/>
</attribute>
</optional>
<optional>
<attribute name="typeid">
<ref name="uint24"/>
</attribute>
</optional>
<optional>
<attribute name="typeidversion">
<ref name="uint8"/>
</attribute>
</optional>
<optional>
<attribute name="instanceid">
<ref name="UUID"/>
</attribute>
</optional>
<optional>
<attribute name="profileid">
<ref name="virtualPortProfileID"/>
</attribute>
</optional>
<optional>
<attribute name="interfaceid">
<ref name="UUID"/>
</attribute>
</optional>
</element>
</optional>
</element>
</group>
</choice>
</define>
<define name="bandwidth">
<element name="bandwidth">
<optional>
<attribute name="classID">
<ref name="positiveInteger"/>
</attribute>
</optional>
<interleave>
<optional>
<element name="inbound">
<ref name="bandwidth-attributes"/>
<empty/>
</element>
</optional>
<optional>
<element name="outbound">
<ref name="bandwidth-attributes"/>
<empty/>
</element>
</optional>
</interleave>
</element>
</define>
<define name="bandwidth-attributes">
<optional>
<attribute name="average">
<ref name="speed"/>
</attribute>
</optional>
<optional>
<attribute name="peak">
<ref name="speed"/>
</attribute>
</optional>
<optional>
<attribute name="floor">
<ref name="speed"/>
</attribute>
</optional>
<optional>
<attribute name='burst'>
<ref name="BurstSize"/>
</attribute>
</optional>
</define>
<define name="speed">
<data type="unsignedInt">
<param name="pattern">[0-9]+</param>
<param name="minInclusive">1</param>
</data>
</define>
<define name="BurstSize">
<data type="unsignedInt">
<param name="pattern">[0-9]+</param>
<param name="minInclusive">1</param>
</data>
</define>
<define name='unsignedShort'>
<data type='integer'>
<param name="minInclusive">0</param>
<param name="maxInclusive">65535</param>
</data>
</define>
<define name='protocol'>
<data type='string'>
<param name='pattern'>(tcp)|(udp)</param>
</data>
</define>
<define name='addr-family'>
<data type='string'>
<param name="pattern">(ipv4)|(ipv6)</param>
</data>
</define>
<define name="vlan">
<element name="vlan">
<optional>
<attribute name="trunk">
<value>yes</value>
</attribute>
</optional>
<oneOrMore>
<element name="tag">
<attribute name="id">
<data type="unsignedInt">
<param name="maxInclusive">4095</param>
</data>
</attribute>
<optional>
<attribute name="nativeMode">
<choice>
<value>tagged</value>
<value>untagged</value>
</choice>
</attribute>
</optional>
<empty/>
</element>
</oneOrMore>
</element>
</define>
<define name='port'>
<data type='integer'>
<param name='minInclusive'>1</param>
<param name='maxInclusive'>65535</param>
</data>
</define>
<!-- The (static) route element specifies a network address and gateway
address to access that network. Both the network address and
the gateway address must be specified. -->
<define name='route'>
<element name="route">
<optional>
<attribute name="family"><ref name="addr-family"/></attribute>
</optional>
<attribute name="address"><ref name="ipAddr"/></attribute>
<optional>
<choice>
<attribute name="netmask"><ref name="ipv4Addr"/></attribute>
<attribute name="prefix"><ref name="ipPrefix"/></attribute>
</choice>
</optional>
<attribute name="gateway"><ref name="ipAddr"/></attribute>
<optional>
<attribute name="metric"><ref name="unsignedInt"/></attribute>
</optional>
</element>
</define>
<define name="macTableManager">
<choice>
<value>kernel</value>
<value>libvirt</value>
</choice>
</define>
<define name="mtu">
<element name="mtu">
<attribute name="size">
<ref name="unsignedShort"/>
</attribute>
</element>
</define>
</grammar>

View File

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<!-- network-related definitions used in multiple grammars -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<define name="filterref-node-attributes">
<attribute name="filter">
<data type="NCName"/>
</attribute>
<zeroOrMore>
<element name="parameter">
<attribute name="name">
<ref name="filter-param-name"/>
</attribute>
<attribute name="value">
<ref name="filter-param-value"/>
</attribute>
</element>
</zeroOrMore>
</define>
<define name="filter-param-name">
<data type="string">
<param name="pattern">[a-zA-Z0-9_]+</param>
</data>
</define>
<define name="filter-param-value">
<data type="string">
<param name="pattern">[a-zA-Z0-9_\.:]+</param>
</data>
</define>
</grammar>

View File

@ -0,0 +1,246 @@
<?xml version="1.0"?>
<!-- A Relax NG schema for common libvirt XML storage elements -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<!-- This schema is not designed for standalone use; another file
must include both this file and basictypes.rng -->
<define name="poolName">
<data type="string">
<!-- Use literal newline instead of \n for bug in libxml2 2.7.6 -->
<param name="pattern">[^/
]+</param>
</data>
</define>
<define name='encryption'>
<element name='encryption'>
<attribute name='format'>
<choice>
<value>default</value>
<value>qcow</value>
<value>luks</value>
</choice>
</attribute>
<interleave>
<ref name='secret'/>
<optional>
<element name='cipher'>
<ref name='keycipher'/>
</element>
<element name='ivgen'>
<ref name='keyivgen'/>
</element>
</optional>
</interleave>
</element>
</define>
<define name='initiatorinfo'>
<element name='initiator'>
<element name='iqn'>
<attribute name='name'>
<text/>
</attribute>
<empty/>
</element>
</element>
</define>
<define name="reconnect">
<element name="reconnect">
<attribute name="enabled">
<ref name="virYesNo"/>
</attribute>
<optional>
<attribute name="timeout">
<ref name="unsignedInt"/>
</attribute>
</optional>
</element>
</define>
<define name='unixSocketSource'>
<element name="source">
<attribute name="type">
<value>unix</value>
</attribute>
<attribute name="path">
<ref name="absFilePath"/>
</attribute>
<attribute name="mode">
<choice>
<value>server</value>
<value>client</value>
</choice>
</attribute>
<optional>
<ref name="reconnect"/>
</optional>
<empty/>
</element>
</define>
<define name='reservations'>
<element name='reservations'>
<optional>
<attribute name='managed'>
<ref name='virYesNo'/>
</attribute>
</optional>
<optional>
<ref name='unixSocketSource'/>
</optional>
</element>
</define>
<define name='secret'>
<element name='secret'>
<attribute name='type'>
<value>passphrase</value>
</attribute>
<choice>
<attribute name='uuid'>
<ref name="UUID"/>
</attribute>
<attribute name='usage'>
<text/>
</attribute>
</choice>
</element>
</define>
<define name='compat'>
<element name='compat'>
<data type='string'>
<param name='pattern'>[0-9]+\.[0-9]+</param>
</data>
</element>
</define>
<define name='fileFormatFeatures'>
<element name='features'>
<interleave>
<optional>
<element name='lazy_refcounts'>
<empty/>
</element>
</optional>
</interleave>
</element>
</define>
<!-- split the list of known storage formats into two, those where
we know how to follow backing chains, and all others -->
<define name='storageFormatBacking'>
<choice>
<value>cow</value>
<value>qcow</value>
<value>qcow2</value>
<value>qed</value>
<value>vmdk</value>
</choice>
</define>
<define name='storageFormat'>
<choice>
<value>raw</value>
<value>dir</value>
<value>bochs</value>
<value>cloop</value>
<value>dmg</value>
<value>iso</value>
<value>vpc</value>
<value>vdi</value>
<value>fat</value>
<value>vhd</value>
<value>ploop</value>
<value>luks</value>
<ref name='storageFormatBacking'/>
</choice>
</define>
<define name='storageStartupPolicy'>
<!-- Use a combine='choice' override in client files that want to
add additional attributes to a <source> sub-element
associated with a storage source -->
<notAllowed/>
</define>
<define name='storageSourceExtra'>
<!-- Use a combine='choice' override in client files that want to
add additional elements as siblings of a <source> sub-element
associated with a storage source -->
<notAllowed/>
</define>
<define name='permissions'>
<optional>
<element name='permissions'>
<interleave>
<optional>
<element name='mode'>
<ref name='octalMode'/>
</element>
</optional>
<optional>
<element name='owner'>
<choice>
<ref name='unsignedInt'/>
<value>-1</value>
</choice>
</element>
</optional>
<optional>
<element name='group'>
<choice>
<ref name='unsignedInt'/>
<value>-1</value>
</choice>
</element>
</optional>
<optional>
<element name='label'>
<text/>
</element>
</optional>
</interleave>
</element>
</optional>
</define>
<define name='keycipher'>
<attribute name='name'>
<text/>
</attribute>
<attribute name='size'>
<ref name="unsignedInt"/>
</attribute>
<optional>
<attribute name='mode'>
<text/>
</attribute>
<attribute name='hash'>
<text/>
</attribute>
</optional>
</define>
<define name='keyivgen'>
<attribute name='name'>
<text/>
</attribute>
<optional>
<attribute name='hash'>
<text/>
</attribute>
</optional>
</define>
<define name='refreshVolumeAllocation'>
<choice>
<value>default</value>
<value>capacity</value>
</choice>
</define>
</grammar>

View File

@ -739,7 +739,6 @@ int VirtualMachine::insert(SqlDB * db, string& error_str)
set<int> cluster_ids;
set<int> datastore_ids;
vector<Template *> quotas;
ostringstream oss;
// ------------------------------------------------------------------------
@ -890,6 +889,16 @@ int VirtualMachine::insert(SqlDB * db, string& error_str)
// ------------------------------------------------------------------------
parse_cpu_model(user_obj_template);
// ------------------------------------------------------------------------
// Validate RAW attribute
// ------------------------------------------------------------------------
rc = Nebula::instance().get_vmm()->validate_raw(obj_template, error_str);
if (rc != 0)
{
goto error_raw;
}
// ------------------------------------------------------------------------
// PCI Devices (Needs to be parsed before network)
// ------------------------------------------------------------------------
@ -1105,6 +1114,7 @@ error_one_vms:
error_str = "Trying to import an OpenNebula VM: 'one-*'.";
goto error_common;
error_raw:
error_os:
error_pci:
error_defaults:
@ -2872,6 +2882,14 @@ int VirtualMachine::updateconf(VirtualMachineTemplate& tmpl, string &err)
return -1;
}
// -------------------------------------------------------------------------
// Validates RAW data section
// -------------------------------------------------------------------------
if (Nebula::instance().get_vmm()->validate_raw(&tmpl, err) != 0)
{
return -1;
}
// -------------------------------------------------------------------------
// Update OS, FEATURES, INPUT, GRAPHICS, RAW, CPU_MODEL
// -------------------------------------------------------------------------
@ -3584,6 +3602,9 @@ void VirtualMachine::encrypt()
user_obj_template->encrypt(one_key);
};
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
void VirtualMachine::decrypt()
{
std::string one_key;
@ -3592,3 +3613,7 @@ void VirtualMachine::decrypt()
obj_template->decrypt(one_key);
user_obj_template->decrypt(one_key);
};
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */

View File

@ -15,6 +15,8 @@
/* ------------------------------------------------------------------------ */
#include "VMTemplate.h"
#include "Nebula.h"
#include "VirtualMachineManager.h"
#include "ScheduledAction.h"
/* ************************************************************************ */
@ -77,6 +79,16 @@ int VMTemplate::insert(SqlDB *db, string& error_str)
return rc;
}
// ------------------------------------------------------------------------
// Validate RAW attribute
// ------------------------------------------------------------------------
rc = Nebula::instance().get_vmm()->validate_raw(obj_template, error_str);
if (rc != 0)
{
return rc;
}
// ------------------------------------------------------------------------
// Insert the Template
// ------------------------------------------------------------------------
@ -182,11 +194,21 @@ int VMTemplate::parse_sched_action(string& error_str)
int VMTemplate::post_update_template(string& error)
{
vector<const VectorAttribute *> raw;
int rc = parse_sched_action(error);
if (rc == -1)
{
return rc;
}
rc = Nebula::instance().get_vmm()->validate_raw(obj_template, error);
if (rc != 0)
{
return rc;
}
return 0;
}

View File

@ -20,6 +20,8 @@
#include "HostPool.h"
#include "ClusterPool.h"
#include "VirtualNetwork.h"
#include "ObjectXML.h"
#include "Nebula.h"
#include <sstream>
#include <fstream>
@ -34,6 +36,8 @@ const int LibVirtDriver::GLUSTER_DEFAULT_PORT = 24007;
const int LibVirtDriver::ISCSI_DEFAULT_PORT = 3260;
const char * LibVirtDriver::XML_DOMAIN_RNG_PATH = "/schemas/libvirt/domain.rng";
#define set_sec_default(v, dv) if (v.empty() && !dv.empty()){v = dv;}
/**
@ -375,6 +379,30 @@ static string get_disk_bus(std::string &machine, std::string &target,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int LibVirtDriver::validate_raw(const string& raw_section, string& error) const
{
ostringstream oss;
string path = Nebula::instance().get_share_location() + XML_DOMAIN_RNG_PATH;
oss << "<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>"
<< "<name>aux</name>"
<< raw_section << "</domain>";
int rc = ObjectXML::validate_rng(oss.str(), path);
if ( rc != 0 )
{
error = "Invalid RAW section: cannot validate DATA with domain.rng schema";
return -1;
}
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int LibVirtDriver::deployment_description_kvm(
const VirtualMachine * vm,
const string& file_name) const

View File

@ -183,6 +183,36 @@ void VirtualMachineManager::user_action(const ActionRequest& ar)
/* Manager Actions */
/* ************************************************************************** */
int VirtualMachineManager::validate_raw(const Template * vmt, string& error_str)
{
const VectorAttribute * raw = vmt->get("RAW");
if (raw == nullptr)
{
return 0;
}
string value = raw->vector_value("TYPE");
one_util::tolower(value);
const VirtualMachineManagerDriver * vmd = get(value);
if ( vmd == 0 )
{
error_str = "Invalid RAW section: unsupported TYPE";
return -1;
}
value = raw->vector_value("DATA");
return vmd->validate_raw(value, error_str);
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string * VirtualMachineManager::format_message(
const string& hostname,
const string& m_hostname,

View File

@ -19,6 +19,8 @@
#include <cstring>
#include <iostream>
#include <sstream>
#include <libxml/parser.h>
#include <libxml/relaxng.h>
#include "expr_arith.h"
#include "expr_bool.h"
@ -538,3 +540,34 @@ error_yy:
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int ObjectXML::validate_rng(const std::string &xml_doc, const string& schema_path)
{
int rc;
xmlDocPtr doc = 0;
xmlRelaxNGPtr schema;
xmlRelaxNGValidCtxtPtr validctxt;
xmlRelaxNGParserCtxtPtr rngparser;
doc = xmlParseMemory (xml_doc.c_str(),xml_doc.length());
if (doc == 0)
{
return -1;
}
rngparser = xmlRelaxNGNewParserCtxt(schema_path.c_str());
schema = xmlRelaxNGParse(rngparser);
validctxt = xmlRelaxNGNewValidCtxt(schema);
rc = xmlRelaxNGValidateDoc(validctxt, doc);
xmlRelaxNGFree(schema);
xmlRelaxNGFreeValidCtxt(validctxt);
xmlRelaxNGFreeParserCtxt(rngparser);
xmlFreeDoc(doc);
return rc;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */