cloudstack: fix pep8 for loadbalancer modules (#22822)
This commit is contained in:
parent
45951a69a6
commit
e3525d8df9
2 changed files with 65 additions and 62 deletions
|
@ -222,8 +222,14 @@ state:
|
|||
sample: "Add"
|
||||
'''
|
||||
|
||||
# import cloudstack common
|
||||
from ansible.module_utils.cloudstack import *
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
)
|
||||
|
||||
|
||||
class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
||||
|
||||
|
@ -241,13 +247,11 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|||
'privateport': 'private_port',
|
||||
}
|
||||
|
||||
|
||||
def get_rule(self, **kwargs):
|
||||
rules = self.cs.listLoadBalancerRules(**kwargs)
|
||||
if rules:
|
||||
return rules['loadbalancerrule'][0]
|
||||
|
||||
|
||||
def _get_common_args(self):
|
||||
return {
|
||||
'account': self.get_account(key='name'),
|
||||
|
@ -258,7 +262,6 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|||
'name': self.module.params.get('name'),
|
||||
}
|
||||
|
||||
|
||||
def present_lb_rule(self):
|
||||
missing_params = []
|
||||
for required_params in [
|
||||
|
@ -282,17 +285,18 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|||
rule = self.ensure_tags(resource=rule, resource_type='LoadBalancer')
|
||||
return rule
|
||||
|
||||
|
||||
def _create_lb_rule(self, rule):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
args = self._get_common_args()
|
||||
args['algorithm'] = self.module.params.get('algorithm')
|
||||
args['privateport'] = self.module.params.get('private_port')
|
||||
args['publicport'] = self.module.params.get('public_port')
|
||||
args['cidrlist'] = self.module.params.get('cidr')
|
||||
args['description'] = self.module.params.get('description')
|
||||
args['protocol'] = self.module.params.get('protocol')
|
||||
args.update({
|
||||
'algorithm': self.module.params.get('algorithm'),
|
||||
'privateport': self.module.params.get('private_port'),
|
||||
'publicport': self.module.params.get('public_port'),
|
||||
'cidrlist': self.module.params.get('cidr'),
|
||||
'description': self.module.params.get('description'),
|
||||
'protocol': self.module.params.get('protocol'),
|
||||
})
|
||||
res = self.cs.createLoadBalancerRule(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
|
@ -302,12 +306,12 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|||
rule = self.poll_job(res, 'loadbalancer')
|
||||
return rule
|
||||
|
||||
|
||||
def _update_lb_rule(self, rule):
|
||||
args = {}
|
||||
args['id'] = rule['id']
|
||||
args['algorithm'] = self.module.params.get('algorithm')
|
||||
args['description'] = self.module.params.get('description')
|
||||
args = {
|
||||
'id': rule['id'],
|
||||
'algorithm': self.module.params.get('algorithm'),
|
||||
'description': self.module.params.get('description'),
|
||||
}
|
||||
if self.has_changed(args, rule):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
|
@ -320,7 +324,6 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|||
rule = self.poll_job(res, 'loadbalancer')
|
||||
return rule
|
||||
|
||||
|
||||
def absent_lb_rule(self):
|
||||
args = self._get_common_args()
|
||||
rule = self.get_rule(**args)
|
||||
|
@ -339,22 +342,22 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|||
def main():
|
||||
argument_spec = cs_argument_spec()
|
||||
argument_spec.update(dict(
|
||||
name = dict(required=True),
|
||||
description = dict(default=None),
|
||||
algorithm = dict(choices=['source', 'roundrobin', 'leastconn'], default='source'),
|
||||
private_port = dict(type='int', default=None),
|
||||
public_port = dict(type='int', default=None),
|
||||
protocol = dict(default=None),
|
||||
state = dict(choices=['present', 'absent'], default='present'),
|
||||
ip_address = dict(required=True, aliases=['public_ip']),
|
||||
cidr = dict(default=None),
|
||||
project = dict(default=None),
|
||||
open_firewall = dict(type='bool', default=False),
|
||||
tags = dict(type='list', aliases=['tag'], default=None),
|
||||
zone = dict(default=None),
|
||||
domain = dict(default=None),
|
||||
account = dict(default=None),
|
||||
poll_async = dict(type='bool', default=True),
|
||||
name=dict(required=True),
|
||||
description=dict(),
|
||||
algorithm=dict(choices=['source', 'roundrobin', 'leastconn'], default='source'),
|
||||
private_port=dict(type='int'),
|
||||
public_port=dict(type='int'),
|
||||
protocol=dict(),
|
||||
state=dict(choices=['present', 'absent'], default='present'),
|
||||
ip_address=dict(required=True, aliases=['public_ip']),
|
||||
cidr=dict(),
|
||||
project=dict(),
|
||||
open_firewall=dict(type='bool', default=False),
|
||||
tags=dict(type='list', aliases=['tag']),
|
||||
zone=dict(),
|
||||
domain=dict(),
|
||||
account=dict(),
|
||||
poll_async=dict(type='bool', default=True),
|
||||
))
|
||||
|
||||
module = AnsibleModule(
|
||||
|
@ -379,7 +382,6 @@ def main():
|
|||
|
||||
module.exit_json(**result)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -204,8 +204,14 @@ state:
|
|||
sample: "Add"
|
||||
'''
|
||||
|
||||
# import cloudstack common
|
||||
from ansible.module_utils.cloudstack import *
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
)
|
||||
|
||||
|
||||
class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
|
||||
|
||||
|
@ -223,13 +229,15 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
|
|||
'privateport': 'private_port',
|
||||
}
|
||||
|
||||
|
||||
def get_rule(self):
|
||||
args = self._get_common_args()
|
||||
args['name'] = self.module.params.get('name')
|
||||
args['zoneid'] = self.get_zone(key='id') if self.module.params.get('zone') else None
|
||||
args = self._get_common_args()
|
||||
args.update({
|
||||
'name': self.module.params.get('name'),
|
||||
'zoneid': self.get_zone(key='id') if self.module.params.get('zone') else None,
|
||||
})
|
||||
if self.module.params.get('ip_address'):
|
||||
args['publicipid'] = self.get_ip_address(key='id')
|
||||
|
||||
rules = self.cs.listLoadBalancerRules(**args)
|
||||
if rules:
|
||||
if len(rules['loadbalancerrule']) > 1:
|
||||
|
@ -237,7 +245,6 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
|
|||
return rules['loadbalancerrule'][0]
|
||||
return None
|
||||
|
||||
|
||||
def _get_common_args(self):
|
||||
return {
|
||||
'account': self.get_account(key='name'),
|
||||
|
@ -245,14 +252,12 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
|
|||
'projectid': self.get_project(key='id'),
|
||||
}
|
||||
|
||||
|
||||
def _get_members_of_rule(self, rule):
|
||||
res = self.cs.listLoadBalancerRuleInstances(id=rule['id'])
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
return res.get('loadbalancerruleinstance', [])
|
||||
|
||||
|
||||
def _ensure_members(self, operation):
|
||||
if operation not in ['add', 'remove']:
|
||||
self.module.fail_json(msg="Bad operation: %s" % operation)
|
||||
|
@ -267,7 +272,7 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
|
|||
|
||||
wanted_names = self.module.params.get('vms')
|
||||
|
||||
if operation =='add':
|
||||
if operation == 'add':
|
||||
cs_func = self.cs.assignToLoadBalancerRule
|
||||
to_change = set(wanted_names) - set(existing.keys())
|
||||
else:
|
||||
|
@ -293,8 +298,8 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
|
|||
|
||||
if to_change_ids and not self.module.check_mode:
|
||||
res = cs_func(
|
||||
id = rule['id'],
|
||||
virtualmachineids = to_change_ids,
|
||||
id=rule['id'],
|
||||
virtualmachineids=to_change_ids,
|
||||
)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
|
@ -304,15 +309,12 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
|
|||
rule = self.get_rule()
|
||||
return rule
|
||||
|
||||
|
||||
def add_members(self):
|
||||
return self._ensure_members('add')
|
||||
|
||||
|
||||
def remove_members(self):
|
||||
return self._ensure_members('remove')
|
||||
|
||||
|
||||
def get_result(self, rule):
|
||||
super(AnsibleCloudStackLBRuleMember, self).get_result(rule)
|
||||
if rule:
|
||||
|
@ -325,15 +327,15 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
|
|||
def main():
|
||||
argument_spec = cs_argument_spec()
|
||||
argument_spec.update(dict(
|
||||
name = dict(required=True),
|
||||
ip_address = dict(default=None, aliases=['public_ip']),
|
||||
vms = dict(required=True, aliases=['vm'], type='list'),
|
||||
state = dict(choices=['present', 'absent'], default='present'),
|
||||
zone = dict(default=None),
|
||||
domain = dict(default=None),
|
||||
project = dict(default=None),
|
||||
account = dict(default=None),
|
||||
poll_async = dict(type='bool', default=True),
|
||||
name=dict(required=True),
|
||||
ip_address=dict(aliases=['public_ip']),
|
||||
vms=dict(required=True, aliases=['vm'], type='list'),
|
||||
state=dict(choices=['present', 'absent'], default='present'),
|
||||
zone=dict(),
|
||||
domain=dict(),
|
||||
project=dict(),
|
||||
account=dict(),
|
||||
poll_async=dict(type='bool', default=True),
|
||||
))
|
||||
|
||||
module = AnsibleModule(
|
||||
|
@ -358,7 +360,6 @@ def main():
|
|||
|
||||
module.exit_json(**result)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue