add custom_compatibility_version (#40813)

* add custom_compatibility_version

* use implemented methods get minor and major
pull/44174/head
Martin Nečas 6 years ago committed by ansibot
parent df581eb749
commit 9d5ce3d335

@ -31,6 +31,7 @@ try:
from enum import Enum # enum is a ovirtsdk4 requirement from enum import Enum # enum is a ovirtsdk4 requirement
import ovirtsdk4 as sdk import ovirtsdk4 as sdk
import ovirtsdk4.version as sdk_version import ovirtsdk4.version as sdk_version
import ovirtsdk4.types as otypes
HAS_SDK = LooseVersion(sdk_version.VERSION) >= LooseVersion('4.2.4') HAS_SDK = LooseVersion(sdk_version.VERSION) >= LooseVersion('4.2.4')
except ImportError: except ImportError:
HAS_SDK = False HAS_SDK = False
@ -786,3 +787,17 @@ class BaseModule(object):
entity = search_by_attributes(self._service, list_params=list_params, name=self._module.params['name']) entity = search_by_attributes(self._service, list_params=list_params, name=self._module.params['name'])
return entity return entity
def _get_major(self, full_version):
if full_version is None:
return None
if isinstance(full_version, otypes.Version):
return int(full_version.major)
return int(full_version.split('.')[0])
def _get_minor(self, full_version):
if full_version is None:
return None
if isinstance(full_version, otypes.Version):
return int(full_version.minor)
return int(full_version.split('.')[1])

@ -270,6 +270,13 @@ options:
- Name of the storage domain this virtual machine lease reside on. - Name of the storage domain this virtual machine lease reside on.
- NOTE - Supported since oVirt 4.1. - NOTE - Supported since oVirt 4.1.
version_added: "2.4" version_added: "2.4"
custom_compatibility_version:
description:
- "Enables a virtual machine to be customized to its own compatibility version. If
`C(custom_compatibility_version)` is set, it overrides the cluster's compatibility version
for this particular virtual machine."
version_added: "2.7"
delete_protected: delete_protected:
description: description:
- If I(yes) Virtual Machine will be set as delete protected. - If I(yes) Virtual Machine will be set as delete protected.
@ -1069,6 +1076,10 @@ class VmsModule(BaseModule):
self.param('instance_type'), self.param('instance_type'),
), ),
) if self.param('instance_type') else None, ) if self.param('instance_type') else None,
custom_compatibility_version=otypes.Version(
major=self._get_major(self.param('custom_compatibility_version')),
minor=self._get_minor(self.param('custom_compatibility_version')),
) if self.param('custom_compatibility_version') else None,
description=self.param('description'), description=self.param('description'),
comment=self.param('comment'), comment=self.param('comment'),
time_zone=otypes.TimeZone( time_zone=otypes.TimeZone(
@ -1156,6 +1167,8 @@ class VmsModule(BaseModule):
equal(self.param('io_threads'), entity.io.threads) and equal(self.param('io_threads'), entity.io.threads) and
equal(self.param('ballooning_enabled'), entity.memory_policy.ballooning) and equal(self.param('ballooning_enabled'), entity.memory_policy.ballooning) and
equal(self.param('serial_console'), entity.console.enabled) and equal(self.param('serial_console'), entity.console.enabled) and
equal(self._get_minor(self.param('custom_compatibility_version')), self._get_minor(entity.custom_compatibility_version)) and
equal(self._get_major(self.param('custom_compatibility_version')), self._get_major(entity.custom_compatibility_version)) and
equal(self.param('usb_support'), entity.usb.enabled) and equal(self.param('usb_support'), entity.usb.enabled) and
equal(self.param('sso'), True if entity.sso.methods else False) and equal(self.param('sso'), True if entity.sso.methods else False) and
equal(self.param('quota_id'), getattr(entity.quota, 'id', None)) and equal(self.param('quota_id'), getattr(entity.quota, 'id', None)) and
@ -1592,7 +1605,6 @@ class VmsModule(BaseModule):
def _get_role_mappings(module): def _get_role_mappings(module):
roleMappings = list() roleMappings = list()
for roleMapping in module.params['role_mappings']: for roleMapping in module.params['role_mappings']:
roleMappings.append( roleMappings.append(
otypes.RegistrationRoleMapping( otypes.RegistrationRoleMapping(
@ -1895,6 +1907,7 @@ def main():
kvm=dict(type='dict'), kvm=dict(type='dict'),
cpu_mode=dict(type='str'), cpu_mode=dict(type='str'),
placement_policy=dict(type='str'), placement_policy=dict(type='str'),
custom_compatibility_version=dict(type='str'),
cpu_pinning=dict(type='list'), cpu_pinning=dict(type='list'),
soundcard_enabled=dict(type='bool', default=None), soundcard_enabled=dict(type='bool', default=None),
smartcard_enabled=dict(type='bool', default=None), smartcard_enabled=dict(type='bool', default=None),

Loading…
Cancel
Save