From ecbed163004e77ec4213db9489f0b586e456d2f1 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Mon, 27 Apr 2015 20:20:37 +0200 Subject: [PATCH] cloudstack: cs_securitygroup_rule: minor cleanup, DRY --- .../cloud/cloudstack/cs_securitygroup_rule.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py index e602281583b..cd05440c4b1 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py @@ -228,18 +228,21 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack): and cidr == rule['cidr'] + def get_end_port(self): + if self.module.params.get('end_port'): + return self.module.params.get('end_port') + return self.module.params.get('start_port') + + def _get_rule(self, rules): user_security_group_name = self.module.params.get('user_security_group') cidr = self.module.params.get('cidr') protocol = self.module.params.get('protocol') start_port = self.module.params.get('start_port') - end_port = self.module.params.get('end_port') + end_port = self.get_end_port() icmp_code = self.module.params.get('icmp_code') icmp_type = self.module.params.get('icmp_type') - if not end_port: - end_port = start_port - if protocol in ['tcp', 'udp'] and not (start_port and end_port): self.module.fail_json(msg="no start_port or end_port set for protocol '%s'" % protocol) @@ -294,15 +297,12 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack): args['protocol'] = self.module.params.get('protocol') args['startport'] = self.module.params.get('start_port') - args['endport'] = self.module.params.get('end_port') + args['endport'] = self.get_end_port() args['icmptype'] = self.module.params.get('icmp_type') args['icmpcode'] = self.module.params.get('icmp_code') args['projectid'] = self.get_project_id() args['securitygroupid'] = security_group['id'] - if not args['endport']: - args['endport'] = args['startport'] - rule = None res = None sg_type = self.module.params.get('type')