Browse Source

Merge pull request #73 from alexandruavadanii/aarch64-salt-control

libvirt xml: pass loader, virt machine, cpu mode
pull/74/head
Petr Michalec 6 years ago
parent
commit
1f125682bf
No account linked to committer's email address
4 changed files with 61 additions and 1 deletions
  1. +7
    -0
      README.rst
  2. +39
    -1
      _modules/virtng.py
  3. +9
    -0
      salt/control/virt.sls
  4. +6
    -0
      tests/pillar/control_virt_custom.sls

+ 7
- 0
README.rst View File

@@ -481,6 +481,13 @@ Control VM provisioning:
rate:
period: '1800'
bytes: '1500'
# Custom per-node loader definition (e.g. for AArch64 UEFI)
loader:
readonly: yes
type: pflash
path: /usr/share/AAVMF/AAVMF_CODE.fd
machine: virt-2.11 # Custom per-node virt machine type
cpu_mode: host-passthrough
mac:
nic01: AC:DE:48:AA:AA:AA
nic02: AC:DE:48:AA:AA:BB

+ 39
- 1
_modules/virtng.py View File

@@ -531,6 +531,9 @@ def init(name,
disk='default',
saltenv='base',
rng=None,
loader=None,
machine=None,
cpu_mode=None,
**kwargs):
'''
Initialize a new vm
@@ -699,6 +702,37 @@ def init(name,
xml_doc.getElementsByTagName("domain")[0].getElementsByTagName("devices")[0].appendChild(iso_xml)
xml = xml_doc.toxml()

# TODO: Remove this code and refactor module, when salt-common would have updated libvirt_domain.jinja template
if cpu_mode:
xml_doc = minidom.parseString(xml)
cpu_xml = xml_doc.createElement("cpu")
cpu_xml.setAttribute('mode', cpu_mode)
xml_doc.getElementsByTagName("domain")[0].appendChild(cpu_xml)
xml = xml_doc.toxml()

# TODO: Remove this code and refactor module, when salt-common would have updated libvirt_domain.jinja template
if machine:
xml_doc = minidom.parseString(xml)
os_xml = xml_doc.getElementsByTagName("domain")[0].getElementsByTagName("os")[0]
os_xml.getElementsByTagName("type")[0].setAttribute('machine', machine)
xml = xml_doc.toxml()

# TODO: Remove this code and refactor module, when salt-common would have updated libvirt_domain.jinja template
if loader and 'path' not in loader:
log.info('`path` is a required property of `loader`, and cannot be found. Skipping loader configuration')
loader = None
elif loader:
xml_doc = minidom.parseString(xml)
loader_xml = xml_doc.createElement("loader")
for key, val in loader.items():
if key == 'path':
continue
loader_xml.setAttribute(key, val)
loader_path_xml = xml_doc.createTextNode(loader['path'])
loader_xml.appendChild(loader_path_xml)
xml_doc.getElementsByTagName("domain")[0].getElementsByTagName("os")[0].appendChild(loader_xml)
xml = xml_doc.toxml()

# TODO: Remove this code and refactor module, when salt-common would have updated libvirt_domain.jinja template
for _nic in nicp:
if _nic['virtualport']:
@@ -1602,7 +1636,11 @@ def undefine(vm_):
salt '*' virtng.undefine <vm name>
'''
dom = _get_dom(vm_)
return dom.undefine() == 0
if getattr(libvirt, 'VIR_DOMAIN_UNDEFINE_NVRAM', False):
# This one is only in 1.2.8+
return dom.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_NVRAM) == 0
else:
return dom.undefine() == 0


def purge(vm_, dirs=False):

+ 9
- 0
salt/control/virt.sls View File

@@ -61,6 +61,15 @@ salt_control_virt_{{ cluster_name }}_{{ node_name }}:
{%- elif rng is defined %}
- rng: {{ rng }}
{%- endif %}
{%- if node.loader is defined %}
- loader: {{ node.loader }}
{%- endif %}
{%- if node.machine is defined %}
- machine: {{ node.machine }}
{%- endif %}
{%- if node.cpu_mode is defined %}
- cpu_mode: {{ node.cpu_mode }}
{%- endif %}
- kwargs:
{%- if cloud_init is defined %}
cloud_init: {{ cloud_init }}

+ 6
- 0
tests/pillar/control_virt_custom.sls View File

@@ -96,11 +96,17 @@ salt:
image: ubuntu.qcow
size: medium
img_dest: /var/lib/libvirt/ssdimages
machine: virt-2.11
cpu_mode: host-passthrough
ubuntu2:
provider: node02.domain.com
image: bubuntu.qcomw
size: small
img_dest: /var/lib/libvirt/hddimages
loader:
readonly: yes
type: pflash
path: /usr/share/AAVMF/AAVMF_CODE.fd
ubuntu3:
provider: node03.domain.com
image: meowbuntu.qcom2

Loading…
Cancel
Save