소스 검색

[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
pull/73/head
Dzmitry Stremkouski 6 년 전
부모
커밋
7ee2340ea8
4개의 변경된 파일73개의 추가작업 그리고 0개의 파일을 삭제
  1. +41
    -0
      README.rst
  2. +23
    -0
      _modules/virtng.py
  3. +3
    -0
      salt/control/virt.sls
  4. +6
    -0
      tests/pillar/control_virt_custom.sls

+ 41
- 0
README.rst 파일 보기

@@ -340,6 +340,47 @@ Event to trigger the key removal

salt-call event.send 'salt/key/remove'

Control VM provisioning

.. code-block:: yaml

virt:
disk:
three_disks:
- system:
size: 4096
image: ubuntu.qcow
- repository_snapshot:
size: 8192
image: snapshot.qcow
- cinder-volume:
size: 2048

salt:
control:
enabled: true
virt_enabled: true
size:
medium_three_disks:
cpu: 2
ram: 4
disk_profile: three_disks
cluster:
mycluster:
domain: neco.virt.domain.com
engine: virt
node:
ubuntu1:
provider: node01.domain.com
image: ubuntu.qcow
size: medium
img_dest: /var/lib/libvirt/ssdimages
rng:
backend: /dev/urandom
model: random
rate:
period: '1800'
bytes: '1500'

Jinja options
-------------

+ 23
- 0
_modules/virtng.py 파일 보기

@@ -550,6 +550,7 @@ def init(name,
start=True, # pylint: disable=redefined-outer-name
disk='default',
saltenv='base',
rng={},
**kwargs):
'''
Initialize a new vm
@@ -667,6 +668,28 @@ def init(name,
.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:

+ 3
- 0
salt/control/virt.sls 파일 보기

@@ -41,6 +41,9 @@ salt_control_virt_{{ cluster_name }}_{{ node_name }}:
- start: True
- disk: {{ size.disk_profile }}
- nic: {{ size.net_profile }}
{%- if node.rng is defined %}
- rng: {{ node.rng }}
{%- endif %}
- kwargs:
seed: True
serial_type: pty

+ 6
- 0
tests/pillar/control_virt_custom.sls 파일 보기

@@ -53,3 +53,9 @@ salt:
provider: node03.domain.com
image: meowbuntu.qcom2
size: medium_three_disks
rng:
backend: /dev/urandom
model: random
rate:
period: '1800'
bytes: '1500'

Loading…
취소
저장