|
|
@ -222,8 +222,14 @@ state:
|
|
|
|
sample: "Add"
|
|
|
|
sample: "Add"
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
# import cloudstack common
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils.cloudstack import *
|
|
|
|
from ansible.module_utils.cloudstack import (
|
|
|
|
|
|
|
|
AnsibleCloudStack,
|
|
|
|
|
|
|
|
CloudStackException,
|
|
|
|
|
|
|
|
cs_argument_spec,
|
|
|
|
|
|
|
|
cs_required_together,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|
|
|
class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|
|
|
|
|
|
|
|
|
|
@ -241,13 +247,11 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|
|
|
'privateport': 'private_port',
|
|
|
|
'privateport': 'private_port',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_rule(self, **kwargs):
|
|
|
|
def get_rule(self, **kwargs):
|
|
|
|
rules = self.cs.listLoadBalancerRules(**kwargs)
|
|
|
|
rules = self.cs.listLoadBalancerRules(**kwargs)
|
|
|
|
if rules:
|
|
|
|
if rules:
|
|
|
|
return rules['loadbalancerrule'][0]
|
|
|
|
return rules['loadbalancerrule'][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_common_args(self):
|
|
|
|
def _get_common_args(self):
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
'account': self.get_account(key='name'),
|
|
|
|
'account': self.get_account(key='name'),
|
|
|
@ -258,7 +262,6 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|
|
|
'name': self.module.params.get('name'),
|
|
|
|
'name': self.module.params.get('name'),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def present_lb_rule(self):
|
|
|
|
def present_lb_rule(self):
|
|
|
|
missing_params = []
|
|
|
|
missing_params = []
|
|
|
|
for required_params in [
|
|
|
|
for required_params in [
|
|
|
@ -282,17 +285,18 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|
|
|
rule = self.ensure_tags(resource=rule, resource_type='LoadBalancer')
|
|
|
|
rule = self.ensure_tags(resource=rule, resource_type='LoadBalancer')
|
|
|
|
return rule
|
|
|
|
return rule
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _create_lb_rule(self, rule):
|
|
|
|
def _create_lb_rule(self, rule):
|
|
|
|
self.result['changed'] = True
|
|
|
|
self.result['changed'] = True
|
|
|
|
if not self.module.check_mode:
|
|
|
|
if not self.module.check_mode:
|
|
|
|
args = self._get_common_args()
|
|
|
|
args = self._get_common_args()
|
|
|
|
args['algorithm'] = self.module.params.get('algorithm')
|
|
|
|
args.update({
|
|
|
|
args['privateport'] = self.module.params.get('private_port')
|
|
|
|
'algorithm': self.module.params.get('algorithm'),
|
|
|
|
args['publicport'] = self.module.params.get('public_port')
|
|
|
|
'privateport': self.module.params.get('private_port'),
|
|
|
|
args['cidrlist'] = self.module.params.get('cidr')
|
|
|
|
'publicport': self.module.params.get('public_port'),
|
|
|
|
args['description'] = self.module.params.get('description')
|
|
|
|
'cidrlist': self.module.params.get('cidr'),
|
|
|
|
args['protocol'] = self.module.params.get('protocol')
|
|
|
|
'description': self.module.params.get('description'),
|
|
|
|
|
|
|
|
'protocol': self.module.params.get('protocol'),
|
|
|
|
|
|
|
|
})
|
|
|
|
res = self.cs.createLoadBalancerRule(**args)
|
|
|
|
res = self.cs.createLoadBalancerRule(**args)
|
|
|
|
if 'errortext' in res:
|
|
|
|
if 'errortext' in res:
|
|
|
|
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
|
|
|
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
|
|
@ -302,12 +306,12 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|
|
|
rule = self.poll_job(res, 'loadbalancer')
|
|
|
|
rule = self.poll_job(res, 'loadbalancer')
|
|
|
|
return rule
|
|
|
|
return rule
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _update_lb_rule(self, rule):
|
|
|
|
def _update_lb_rule(self, rule):
|
|
|
|
args = {}
|
|
|
|
args = {
|
|
|
|
args['id'] = rule['id']
|
|
|
|
'id': rule['id'],
|
|
|
|
args['algorithm'] = self.module.params.get('algorithm')
|
|
|
|
'algorithm': self.module.params.get('algorithm'),
|
|
|
|
args['description'] = self.module.params.get('description')
|
|
|
|
'description': self.module.params.get('description'),
|
|
|
|
|
|
|
|
}
|
|
|
|
if self.has_changed(args, rule):
|
|
|
|
if self.has_changed(args, rule):
|
|
|
|
self.result['changed'] = True
|
|
|
|
self.result['changed'] = True
|
|
|
|
if not self.module.check_mode:
|
|
|
|
if not self.module.check_mode:
|
|
|
@ -320,7 +324,6 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|
|
|
rule = self.poll_job(res, 'loadbalancer')
|
|
|
|
rule = self.poll_job(res, 'loadbalancer')
|
|
|
|
return rule
|
|
|
|
return rule
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def absent_lb_rule(self):
|
|
|
|
def absent_lb_rule(self):
|
|
|
|
args = self._get_common_args()
|
|
|
|
args = self._get_common_args()
|
|
|
|
rule = self.get_rule(**args)
|
|
|
|
rule = self.get_rule(**args)
|
|
|
@ -339,22 +342,22 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
argument_spec = cs_argument_spec()
|
|
|
|
argument_spec = cs_argument_spec()
|
|
|
|
argument_spec.update(dict(
|
|
|
|
argument_spec.update(dict(
|
|
|
|
name = dict(required=True),
|
|
|
|
name=dict(required=True),
|
|
|
|
description = dict(default=None),
|
|
|
|
description=dict(),
|
|
|
|
algorithm = dict(choices=['source', 'roundrobin', 'leastconn'], default='source'),
|
|
|
|
algorithm=dict(choices=['source', 'roundrobin', 'leastconn'], default='source'),
|
|
|
|
private_port = dict(type='int', default=None),
|
|
|
|
private_port=dict(type='int'),
|
|
|
|
public_port = dict(type='int', default=None),
|
|
|
|
public_port=dict(type='int'),
|
|
|
|
protocol = dict(default=None),
|
|
|
|
protocol=dict(),
|
|
|
|
state = dict(choices=['present', 'absent'], default='present'),
|
|
|
|
state=dict(choices=['present', 'absent'], default='present'),
|
|
|
|
ip_address = dict(required=True, aliases=['public_ip']),
|
|
|
|
ip_address=dict(required=True, aliases=['public_ip']),
|
|
|
|
cidr = dict(default=None),
|
|
|
|
cidr=dict(),
|
|
|
|
project = dict(default=None),
|
|
|
|
project=dict(),
|
|
|
|
open_firewall = dict(type='bool', default=False),
|
|
|
|
open_firewall=dict(type='bool', default=False),
|
|
|
|
tags = dict(type='list', aliases=['tag'], default=None),
|
|
|
|
tags=dict(type='list', aliases=['tag']),
|
|
|
|
zone = dict(default=None),
|
|
|
|
zone=dict(),
|
|
|
|
domain = dict(default=None),
|
|
|
|
domain=dict(),
|
|
|
|
account = dict(default=None),
|
|
|
|
account=dict(),
|
|
|
|
poll_async = dict(type='bool', default=True),
|
|
|
|
poll_async=dict(type='bool', default=True),
|
|
|
|
))
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
@ -379,7 +382,6 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
module.exit_json(**result)
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
|
|
|
|
|
|
|
# import module snippets
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import *
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
main()
|
|
|
|