From ec441cd4bca4dda2c405b781540b06b4df50a8e4 Mon Sep 17 00:00:00 2001 From: Ondra Machacek Date: Fri, 26 Oct 2018 14:51:39 +0200 Subject: [PATCH] ovirt_host_pm: Fix to powermanagement module (#47659) This PR is fixing following issues: 1) Don't try to check password. 2) Check options. 3) Order wasn't adding at the end, as doc says. Signed-off-by: Ondra Machacek --- .../modules/cloud/ovirt/ovirt_host_pm.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_host_pm.py b/lib/ansible/modules/cloud/ovirt/ovirt_host_pm.py index 6f9fae08967..cbea3201a7f 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_host_pm.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_host_pm.py @@ -144,7 +144,13 @@ class HostModule(BaseModule): class HostPmModule(BaseModule): + def pre_create(self, entity): + # Save the entity, so we know if Agent already existed + self.entity = entity + def build_entity(self): + last = next((s for s in sorted([a.order for a in self._service.list()])), 0) + order = self.param('order') if self.param('order') is not None else self.entity.order if self.entity else last + 1 return otypes.Agent( address=self._module.params['address'], encrypt_options=self._module.params['encrypt_options'], @@ -158,14 +164,23 @@ class HostPmModule(BaseModule): port=self._module.params['port'], type=self._module.params['type'], username=self._module.params['username'], - order=self._module.params.get('order', 100), + order=order, ) def update_check(self, entity): + def check_options(): + if self.param('options'): + current = [] + if entity.options: + current = [(opt.name, str(opt.value)) for opt in entity.options] + passed = [(k, str(v)) for k, v in self.param('options').items()] + return sorted(current) == sorted(passed) + return True + return ( + check_options() and equal(self._module.params.get('address'), entity.address) and equal(self._module.params.get('encrypt_options'), entity.encrypt_options) and - equal(self._module.params.get('password'), entity.password) and equal(self._module.params.get('username'), entity.username) and equal(self._module.params.get('port'), entity.port) and equal(self._module.params.get('type'), entity.type) and