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
# -*- coding: utf-8 -*-
#
# (c) 2015, Darren Worrall <darren@iweb.co.uk>
# (c) 2015, René Moser <mail@renemoser.net>
#
# 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/>.
# Copyright (c) 2015, Darren Worrall <darren@iweb.co.uk>
# 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)
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'],
@ -67,20 +53,25 @@ options:
description:
- Name of the zone in which the rule should be located.
- 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
'''
EXAMPLES = '''
# Add VMs to an existing load balancer
- local_action:
- name: Add VMs to an existing load balancer
local_action:
module: cs_loadbalancer_rule_member
name: balance_http
vms:
- web01
- web02
# Remove a VM from an existing load balancer
- local_action:
- name: Remove a VM from an existing load balancer
local_action:
module: cs_loadbalancer_rule_member
name: balance_http
vms:
@ -259,10 +250,10 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
wanted_names = self.module.params.get('vms')
if operation == 'add':
cs_func = self.cs.assignToLoadBalancerRule
cs_func = 'assignToLoadBalancerRule'
to_change = set(wanted_names) - set(existing.keys())
else:
cs_func = self.cs.removeFromLoadBalancerRule
cs_func = 'removeFromLoadBalancerRule'
to_change = set(wanted_names) & set(existing.keys())
if not to_change:
@ -284,7 +275,8 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
self.result['changed'] = True
if to_change_ids and not self.module.check_mode:
res = cs_func(
res = self.query_api(
cs_func,
id=rule['id'],
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 E324
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_acl_rule.py E324
lib/ansible/modules/cloud/cloudstack/cs_network_acl_rule.py E326