|
|
@ -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,
|
|
|
|
)
|
|
|
|
)
|
|
|
|