cs_loadbalancer_rule_member: fix error handling (#46012)

* make use of query_api
* fix sanity
This commit is contained in:
René Moser 2018-09-22 13:40:40 +02:00 committed by GitHub
parent c123b4e7ef
commit 83ec418470
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 27 deletions

View file

@ -1,23 +1,9 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# (c) 2015, Darren Worrall <darren@iweb.co.uk> # Copyright (c) 2015, Darren Worrall <darren@iweb.co.uk>
# (c) 2015, René Moser <mail@renemoser.net> # Copyright (c) 2015, René Moser <mail@renemoser.net>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'], 'status': ['stableinterface'],
@ -67,20 +53,25 @@ options:
description: description:
- Name of the zone in which the rule should be located. - Name of the zone in which the rule should be located.
- If not set, default zone is used. - If not set, default zone is used.
poll_async:
description:
- Poll async jobs until job has finished.
type: bool
default: yes
extends_documentation_fragment: cloudstack extends_documentation_fragment: cloudstack
''' '''
EXAMPLES = ''' EXAMPLES = '''
# Add VMs to an existing load balancer - name: Add VMs to an existing load balancer
- local_action: local_action:
module: cs_loadbalancer_rule_member module: cs_loadbalancer_rule_member
name: balance_http name: balance_http
vms: vms:
- web01 - web01
- web02 - web02
# Remove a VM from an existing load balancer - name: Remove a VM from an existing load balancer
- local_action: local_action:
module: cs_loadbalancer_rule_member module: cs_loadbalancer_rule_member
name: balance_http name: balance_http
vms: vms:
@ -259,10 +250,10 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
wanted_names = self.module.params.get('vms') wanted_names = self.module.params.get('vms')
if operation == 'add': if operation == 'add':
cs_func = self.cs.assignToLoadBalancerRule cs_func = 'assignToLoadBalancerRule'
to_change = set(wanted_names) - set(existing.keys()) to_change = set(wanted_names) - set(existing.keys())
else: else:
cs_func = self.cs.removeFromLoadBalancerRule cs_func = 'removeFromLoadBalancerRule'
to_change = set(wanted_names) & set(existing.keys()) to_change = set(wanted_names) & set(existing.keys())
if not to_change: if not to_change:
@ -284,7 +275,8 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
self.result['changed'] = True self.result['changed'] = True
if to_change_ids and not self.module.check_mode: if to_change_ids and not self.module.check_mode:
res = cs_func( res = self.query_api(
cs_func,
id=rule['id'], id=rule['id'],
virtualmachineids=to_change_ids, virtualmachineids=to_change_ids,
) )

View file

@ -154,9 +154,6 @@ lib/ansible/modules/cloud/cloudstack/cs_iso.py E325
lib/ansible/modules/cloud/cloudstack/cs_loadbalancer_rule.py E322 lib/ansible/modules/cloud/cloudstack/cs_loadbalancer_rule.py E322
lib/ansible/modules/cloud/cloudstack/cs_loadbalancer_rule.py E324 lib/ansible/modules/cloud/cloudstack/cs_loadbalancer_rule.py E324
lib/ansible/modules/cloud/cloudstack/cs_loadbalancer_rule.py E325 lib/ansible/modules/cloud/cloudstack/cs_loadbalancer_rule.py E325
lib/ansible/modules/cloud/cloudstack/cs_loadbalancer_rule_member.py E322
lib/ansible/modules/cloud/cloudstack/cs_loadbalancer_rule_member.py E324
lib/ansible/modules/cloud/cloudstack/cs_loadbalancer_rule_member.py E325
lib/ansible/modules/cloud/cloudstack/cs_network.py E324 lib/ansible/modules/cloud/cloudstack/cs_network.py E324
lib/ansible/modules/cloud/cloudstack/cs_network_acl_rule.py E324 lib/ansible/modules/cloud/cloudstack/cs_network_acl_rule.py E324
lib/ansible/modules/cloud/cloudstack/cs_network_acl_rule.py E326 lib/ansible/modules/cloud/cloudstack/cs_network_acl_rule.py E326