Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roles: hosted_engine_setup: Replace xml community module #438

Merged
merged 5 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- hosted_engine_setup - Replace xml community module (https://github.com/oVirt/ovirt-ansible-collection/pull/438).
31 changes: 31 additions & 0 deletions plugins/filter/get_ovf_disk_size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"Module to create filter to find ovf disk size from xml"
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.errors import AnsibleFilterError

import xml.etree.ElementTree as ET


def get_ovf_disk_size(data):
try:
root = ET.fromstring(data)
for child in root:
for element in child:
if element.tag == "Disk":
return element.attrib.get(
"{http://schemas.dmtf.org/ovf/envelope/1/}size"
)
except Exception as e:
raise AnsibleFilterError(
"Error in get_ovf_disk_size filter plugin:\n%s" % e
)


class FilterModule(object):
"""OVF disk size filter"""

def filters(self):
return {
"get_ovf_disk_size": get_ovf_disk_size
}
19 changes: 7 additions & 12 deletions roles/hosted_engine_setup/tasks/create_storage_domain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,16 @@
patterns: ^.*.(?<!meta).ovf$
use_regex: true
register: app_ovf
- name: Parse OVF
xml:
path: "{{ app_ovf.files[0].path }}"
xpath: /ovf:Envelope/Section/Disk
namespaces:
ovf: http://schemas.dmtf.org/ovf/envelope/1/
rasd: http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData
vssd: http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData
xsi: http://www.w3.org/2001/XMLSchema-instance
content: attribute
register: disk_size_xml
- name: Get ovf data
set_fact:
ovf_data: "{{ lookup('file', app_ovf.files[0].path) }}"
- name: Get disk size from ovf data
set_fact:
disk_size: "{{ ovf_data | @NAMESPACE@.@NAME@.get_ovf_disk_size }}"
- name: Get required size
set_fact:
required_size: >-
{{ disk_size_xml.matches[0].Disk['{http://schemas.dmtf.org/ovf/envelope/1/}size']|int * 1024 * 1024 * 1024 +
{{ disk_size|int * 1024 * 1024 * 1024 +
storage_domain_details.ovirt_storage_domains[0].critical_space_action_blocker|int *
1024 * 1024 * 1024 + 5 * 1024 * 1024 * 1024 }}
# +5G: 2xOVF_STORE, lockspace, metadata, configuration
Expand Down