[Feature] libvirt xml: pass rng to vm
[Fix] Doc
Issue: - It is not possible to pass [R]andom [N]umber [G]enerator
device to libvirt guest xml in order to control entropy.
- Doc has no information on how to provision vms using salt
Solution: - Pass rng parameters via kwargs from node: pillar
Attach rng xml object to generated xml.
- Provide with an example
Prod-Related: PROD-19214
Customer-Found
Change-Id: Iea111f2d927edf46f06bb7ccfad06d37b752fba9
diff --git a/_modules/virtng.py b/_modules/virtng.py
index 304a6bb..e664f68 100644
--- a/_modules/virtng.py
+++ b/_modules/virtng.py
@@ -550,6 +550,7 @@
start=True, # pylint: disable=redefined-outer-name
disk='default',
saltenv='base',
+ rng={},
**kwargs):
'''
Initialize a new vm
@@ -667,6 +668,28 @@
.format(hypervisor))
xml = _gen_xml(name, cpu, mem, diskp, nicp, hypervisor, **kwargs)
+
+ # TODO: Remove this code and refactor module, when salt-common would have updated libvirt_domain.jinja template
+ if rng:
+ rng_model = rng.get('model', 'random')
+ rng_backend = rng.get('backend', '/dev/urandom')
+ xml_doc = minidom.parseString(xml)
+ rng_xml = xml_doc.createElement("rng")
+ rng_xml.setAttribute("model", "virtio")
+ backend = xml_doc.createElement("backend")
+ backend.setAttribute("model", rng_model)
+ backend.appendChild(xml_doc.createTextNode(rng_backend))
+ rng_xml.appendChild(backend)
+ if 'rate' in rng:
+ rng_rate_period = rng['rate'].get('period', '2000')
+ rng_rate_bytes = rng['rate'].get('bytes', '1234')
+ rate = xml_doc.createElement("rate")
+ rate.setAttribute("period", rng_rate_period)
+ rate.setAttribute("bytes", rng_rate_bytes)
+ rng_xml.appendChild(rate)
+ xml_doc.getElementsByTagName("domain")[0].getElementsByTagName("devices")[0].appendChild(rng_xml)
+ xml = xml_doc.toxml()
+
define_xml_str(xml)
if start: