From 5430497151ccc29e2c452a12aec483a134c4ff9a Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Wed, 6 Jan 2016 23:49:45 +0100 Subject: [PATCH] cloudstack: fixes and improvements cs_instance: fix case insensitivity cs_instance: remove duplicate code block cs_securitygroup_rule: fix KeyError on older ACS --- .../modules/extras/cloud/cloudstack/cs_instance.py | 8 +------- .../extras/cloud/cloudstack/cs_securitygroup_rule.py | 6 ++++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py index 2242a41283..4ad9b06c6d 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py @@ -500,7 +500,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): instances = self.cs.listVirtualMachines(**args) if instances: for v in instances['virtualmachine']: - if instance_name in [ v['name'], v['displayname'], v['id'] ]: + if instance_name.lower() in [ v['name'].lower(), v['displayname'].lower(), v['id'] ]: self.instance = v break return self.instance @@ -668,12 +668,6 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): if self.module.params.get('ssh_key'): args_ssh_key['keypair'] = self.module.params.get('ssh_key') - # SSH key data - args_ssh_key = {} - args_ssh_key['id'] = instance['id'] - args_ssh_key['projectid'] = self.get_project(key='id') - if self.module.params.get('ssh_key'): - args_ssh_key['keypair'] = self.module.params.get('ssh_key') if self._has_changed(args_service_offering, instance) or \ self._has_changed(args_instance_update, instance) or \ 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 aea9754af9..782d7870df 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py @@ -308,14 +308,16 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack): res = None sg_type = self.module.params.get('type') if sg_type == 'ingress': - rule = self._get_rule(security_group['ingressrule']) + if 'ingressrule' in security_group: + rule = self._get_rule(security_group['ingressrule']) if not rule: self.result['changed'] = True if not self.module.check_mode: res = self.cs.authorizeSecurityGroupIngress(**args) elif sg_type == 'egress': - rule = self._get_rule(security_group['egressrule']) + if 'egressrule' in security_group: + rule = self._get_rule(security_group['egressrule']) if not rule: self.result['changed'] = True if not self.module.check_mode: