From 9f41d7834656352529dd3827bd00ab88d218853e Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Wed, 13 May 2015 23:26:27 +0200 Subject: [PATCH 1/7] cloudstack: avoid logging of secrets --- cloud/cloudstack/cs_account.py | 2 +- cloud/cloudstack/cs_affinitygroup.py | 2 +- cloud/cloudstack/cs_firewall.py | 2 +- cloud/cloudstack/cs_instance.py | 2 +- cloud/cloudstack/cs_instancegroup.py | 2 +- cloud/cloudstack/cs_iso.py | 2 +- cloud/cloudstack/cs_portforward.py | 2 +- cloud/cloudstack/cs_securitygroup.py | 2 +- cloud/cloudstack/cs_securitygroup_rule.py | 2 +- cloud/cloudstack/cs_sshkeypair.py | 2 +- cloud/cloudstack/cs_vmsnapshot.py | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cloud/cloudstack/cs_account.py b/cloud/cloudstack/cs_account.py index ccb29e1015f..dd47a3f93d3 100644 --- a/cloud/cloudstack/cs_account.py +++ b/cloud/cloudstack/cs_account.py @@ -366,7 +366,7 @@ def main(): timezone = dict(default=None), poll_async = dict(choices=BOOLEANS, default=True), api_key = dict(default=None), - api_secret = dict(default=None), + api_secret = dict(default=None, no_log=True), api_url = dict(default=None), api_http_method = dict(default='get'), ), diff --git a/cloud/cloudstack/cs_affinitygroup.py b/cloud/cloudstack/cs_affinitygroup.py index 1a11fb537db..617a50ee010 100644 --- a/cloud/cloudstack/cs_affinitygroup.py +++ b/cloud/cloudstack/cs_affinitygroup.py @@ -201,7 +201,7 @@ def main(): state = dict(choices=['present', 'absent'], default='present'), poll_async = dict(choices=BOOLEANS, default=True), api_key = dict(default=None), - api_secret = dict(default=None), + api_secret = dict(default=None, no_log=True), api_url = dict(default=None), api_http_method = dict(default='get'), ), diff --git a/cloud/cloudstack/cs_firewall.py b/cloud/cloudstack/cs_firewall.py index 5c96d606e68..de38233a12f 100644 --- a/cloud/cloudstack/cs_firewall.py +++ b/cloud/cloudstack/cs_firewall.py @@ -303,7 +303,7 @@ def main(): account = dict(default=None), project = dict(default=None), api_key = dict(default=None), - api_secret = dict(default=None), + api_secret = dict(default=None, no_log=True), api_url = dict(default=None), api_http_method = dict(default='get'), ), diff --git a/cloud/cloudstack/cs_instance.py b/cloud/cloudstack/cs_instance.py index 82d33725250..1d7e2492216 100644 --- a/cloud/cloudstack/cs_instance.py +++ b/cloud/cloudstack/cs_instance.py @@ -785,7 +785,7 @@ def main(): tags = dict(type='list', aliases=[ 'tag' ], default=None), poll_async = dict(choices=BOOLEANS, default=True), api_key = dict(default=None), - api_secret = dict(default=None), + api_secret = dict(default=None, no_log=True), api_url = dict(default=None), api_http_method = dict(default='get'), ), diff --git a/cloud/cloudstack/cs_instancegroup.py b/cloud/cloudstack/cs_instancegroup.py index 71aa4bfa38b..d74648d2313 100644 --- a/cloud/cloudstack/cs_instancegroup.py +++ b/cloud/cloudstack/cs_instancegroup.py @@ -197,7 +197,7 @@ def main(): account = dict(default=None), project = dict(default=None), api_key = dict(default=None), - api_secret = dict(default=None), + api_secret = dict(default=None, no_log=True), api_url = dict(default=None), api_http_method = dict(default='get'), ), diff --git a/cloud/cloudstack/cs_iso.py b/cloud/cloudstack/cs_iso.py index 1bdb2ee75cc..9dcd46ea539 100644 --- a/cloud/cloudstack/cs_iso.py +++ b/cloud/cloudstack/cs_iso.py @@ -293,7 +293,7 @@ def main(): is_dynamically_scalable = dict(choices=BOOLEANS, default=False), state = dict(choices=['present', 'absent'], default='present'), api_key = dict(default=None), - api_secret = dict(default=None), + api_secret = dict(default=None, no_log=True), api_url = dict(default=None), api_http_method = dict(default='get'), ), diff --git a/cloud/cloudstack/cs_portforward.py b/cloud/cloudstack/cs_portforward.py index 74519fccb28..dd5ecb12bda 100644 --- a/cloud/cloudstack/cs_portforward.py +++ b/cloud/cloudstack/cs_portforward.py @@ -402,7 +402,7 @@ def main(): project = dict(default=None), poll_async = dict(choices=BOOLEANS, default=True), api_key = dict(default=None), - api_secret = dict(default=None), + api_secret = dict(default=None, no_log=True), api_url = dict(default=None), api_http_method = dict(default='get'), ), diff --git a/cloud/cloudstack/cs_securitygroup.py b/cloud/cloudstack/cs_securitygroup.py index 88908e559e5..2964a918f1f 100644 --- a/cloud/cloudstack/cs_securitygroup.py +++ b/cloud/cloudstack/cs_securitygroup.py @@ -167,7 +167,7 @@ def main(): state = dict(choices=['present', 'absent'], default='present'), project = dict(default=None), api_key = dict(default=None), - api_secret = dict(default=None), + api_secret = dict(default=None, no_log=True), api_url = dict(default=None), api_http_method = dict(default='get'), ), diff --git a/cloud/cloudstack/cs_securitygroup_rule.py b/cloud/cloudstack/cs_securitygroup_rule.py index 100a92df4ef..76ddf7207fc 100644 --- a/cloud/cloudstack/cs_securitygroup_rule.py +++ b/cloud/cloudstack/cs_securitygroup_rule.py @@ -401,7 +401,7 @@ def main(): project = dict(default=None), poll_async = dict(choices=BOOLEANS, default=True), api_key = dict(default=None), - api_secret = dict(default=None), + api_secret = dict(default=None, no_log=True), api_url = dict(default=None), api_http_method = dict(default='get'), ), diff --git a/cloud/cloudstack/cs_sshkeypair.py b/cloud/cloudstack/cs_sshkeypair.py index f24faee41d6..1e3233dd76e 100644 --- a/cloud/cloudstack/cs_sshkeypair.py +++ b/cloud/cloudstack/cs_sshkeypair.py @@ -219,7 +219,7 @@ def main(): project = dict(default=None), state = dict(choices=['present', 'absent'], default='present'), api_key = dict(default=None), - api_secret = dict(default=None), + api_secret = dict(default=None, no_log=True), api_url = dict(default=None), api_http_method = dict(default='get'), ), diff --git a/cloud/cloudstack/cs_vmsnapshot.py b/cloud/cloudstack/cs_vmsnapshot.py index fc11790579f..1321d35da82 100644 --- a/cloud/cloudstack/cs_vmsnapshot.py +++ b/cloud/cloudstack/cs_vmsnapshot.py @@ -292,7 +292,7 @@ def main(): project = dict(default=None), poll_async = dict(choices=BOOLEANS, default=True), api_key = dict(default=None), - api_secret = dict(default=None), + api_secret = dict(default=None, no_log=True), api_url = dict(default=None), api_http_method = dict(default='get'), ), From 63e9014e16d3fead0eeb899b8936141d277ca89a Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Wed, 13 May 2015 23:51:23 +0200 Subject: [PATCH 2/7] cloudstack: cs_affinitygroup: add domain and account support --- cloud/cloudstack/cs_affinitygroup.py | 42 +++++++++++++++++++++------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/cloud/cloudstack/cs_affinitygroup.py b/cloud/cloudstack/cs_affinitygroup.py index 617a50ee010..119e875c5bb 100644 --- a/cloud/cloudstack/cs_affinitygroup.py +++ b/cloud/cloudstack/cs_affinitygroup.py @@ -47,6 +47,16 @@ options: required: false default: 'present' choices: [ 'present', 'absent' ] + domain: + description: + - Domain the affinity group is related to. + required: false + default: null + account: + description: + - Account the affinity group is related to. + required: false + default: null poll_async: description: - Poll async jobs until job has finished. @@ -112,12 +122,16 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack): def get_affinity_group(self): if not self.affinity_group: - affinity_group_name = self.module.params.get('name') + affinity_group = self.module.params.get('name') - affinity_groups = self.cs.listAffinityGroups() + args = {} + args['account'] = self.get_account('name') + args['domainid'] = self.get_domain('id') + + affinity_groups = self.cs.listAffinityGroups(**args) if affinity_groups: for a in affinity_groups['affinitygroup']: - if a['name'] == affinity_group_name: + if affinity_group in [ a['name'], a['id'] ]: self.affinity_group = a break return self.affinity_group @@ -142,10 +156,12 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack): if not affinity_group: self.result['changed'] = True - args = {} - args['name'] = self.module.params.get('name') - args['type'] = self.get_affinity_type() + args = {} + args['name'] = self.module.params.get('name') + args['type'] = self.get_affinity_type() args['description'] = self.module.params.get('description') + args['account'] = self.get_account('name') + args['domainid'] = self.get_domain('id') if not self.module.check_mode: res = self.cs.createAffinityGroup(**args) @@ -156,7 +172,6 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if res and poll_async: affinity_group = self._poll_job(res, 'affinitygroup') - return affinity_group @@ -165,8 +180,10 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack): if affinity_group: self.result['changed'] = True - args = {} - args['name'] = self.module.params.get('name') + args = {} + args['name'] = self.module.params.get('name') + args['account'] = self.get_account('name') + args['domainid'] = self.get_domain('id') if not self.module.check_mode: res = self.cs.deleteAffinityGroup(**args) @@ -177,7 +194,6 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack): poll_async = self.module.params.get('poll_async') if res and poll_async: res = self._poll_job(res, 'affinitygroup') - return affinity_group @@ -189,6 +205,10 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack): self.result['description'] = affinity_group['description'] if 'type' in affinity_group: self.result['affinity_type'] = affinity_group['type'] + if 'domain' in affinity_group: + self.result['domain'] = affinity_group['domain'] + if 'account' in affinity_group: + self.result['account'] = affinity_group['account'] return self.result @@ -199,6 +219,8 @@ def main(): affinty_type = dict(default=None), description = dict(default=None), state = dict(choices=['present', 'absent'], default='present'), + domain = dict(default=None), + account = dict(default=None), poll_async = dict(choices=BOOLEANS, default=True), api_key = dict(default=None), api_secret = dict(default=None, no_log=True), From 7705d1bb503c20a57522bb47939b4f1b71ff5b15 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Thu, 14 May 2015 00:03:17 +0200 Subject: [PATCH 3/7] cloudstack: remove self.result, is defined in super class from utils --- cloud/cloudstack/cs_account.py | 1 - cloud/cloudstack/cs_affinitygroup.py | 4 ---- cloud/cloudstack/cs_firewall.py | 4 ---- cloud/cloudstack/cs_instance.py | 1 - cloud/cloudstack/cs_instancegroup.py | 1 - cloud/cloudstack/cs_iso.py | 4 ---- cloud/cloudstack/cs_portforward.py | 2 -- cloud/cloudstack/cs_securitygroup.py | 4 ---- cloud/cloudstack/cs_securitygroup_rule.py | 3 --- cloud/cloudstack/cs_sshkeypair.py | 4 ---- cloud/cloudstack/cs_vmsnapshot.py | 4 ---- 11 files changed, 32 deletions(-) diff --git a/cloud/cloudstack/cs_account.py b/cloud/cloudstack/cs_account.py index dd47a3f93d3..313c786dee3 100644 --- a/cloud/cloudstack/cs_account.py +++ b/cloud/cloudstack/cs_account.py @@ -97,7 +97,6 @@ extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' ---- # create an account in domain 'CUSTOMERS' local_action: module: cs_account diff --git a/cloud/cloudstack/cs_affinitygroup.py b/cloud/cloudstack/cs_affinitygroup.py index 119e875c5bb..e4460b93695 100644 --- a/cloud/cloudstack/cs_affinitygroup.py +++ b/cloud/cloudstack/cs_affinitygroup.py @@ -66,7 +66,6 @@ extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' ---- # Create a affinity group - local_action: module: cs_affinitygroup @@ -114,9 +113,6 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack): def __init__(self, module): AnsibleCloudStack.__init__(self, module) - self.result = { - 'changed': False, - } self.affinity_group = None diff --git a/cloud/cloudstack/cs_firewall.py b/cloud/cloudstack/cs_firewall.py index de38233a12f..012005432fc 100644 --- a/cloud/cloudstack/cs_firewall.py +++ b/cloud/cloudstack/cs_firewall.py @@ -88,7 +88,6 @@ extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' ---- # Allow inbound port 80/tcp from 1.2.3.4 to 4.3.2.1 - local_action: module: cs_firewall @@ -171,9 +170,6 @@ class AnsibleCloudStackFirewall(AnsibleCloudStack): def __init__(self, module): AnsibleCloudStack.__init__(self, module) - self.result = { - 'changed': False, - } self.firewall_rule = None diff --git a/cloud/cloudstack/cs_instance.py b/cloud/cloudstack/cs_instance.py index 1d7e2492216..0b2c9d4c935 100644 --- a/cloud/cloudstack/cs_instance.py +++ b/cloud/cloudstack/cs_instance.py @@ -164,7 +164,6 @@ extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' ---- # Create a instance on CloudStack from an ISO # NOTE: Names of offerings and ISOs depending on the CloudStack configuration. - local_action: diff --git a/cloud/cloudstack/cs_instancegroup.py b/cloud/cloudstack/cs_instancegroup.py index d74648d2313..dc216733c63 100644 --- a/cloud/cloudstack/cs_instancegroup.py +++ b/cloud/cloudstack/cs_instancegroup.py @@ -56,7 +56,6 @@ extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' ---- # Create an instance group - local_action: module: cs_instancegroup diff --git a/cloud/cloudstack/cs_iso.py b/cloud/cloudstack/cs_iso.py index 9dcd46ea539..fe92a6baca2 100644 --- a/cloud/cloudstack/cs_iso.py +++ b/cloud/cloudstack/cs_iso.py @@ -99,7 +99,6 @@ extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' ---- # Register an ISO if ISO name does not already exist. - local_action: module: cs_iso @@ -185,9 +184,6 @@ class AnsibleCloudStackIso(AnsibleCloudStack): def __init__(self, module): AnsibleCloudStack.__init__(self, module) - self.result = { - 'changed': False, - } self.iso = None def register_iso(self): diff --git a/cloud/cloudstack/cs_portforward.py b/cloud/cloudstack/cs_portforward.py index dd5ecb12bda..127979e3d79 100644 --- a/cloud/cloudstack/cs_portforward.py +++ b/cloud/cloudstack/cs_portforward.py @@ -106,7 +106,6 @@ extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' ---- # 1.2.3.4:80 -> web01:8080 - local_action: module: cs_portforward @@ -144,7 +143,6 @@ EXAMPLES = ''' public_port: 22 private_port: 22 state: absent - ''' RETURN = ''' diff --git a/cloud/cloudstack/cs_securitygroup.py b/cloud/cloudstack/cs_securitygroup.py index 2964a918f1f..35d8851bdef 100644 --- a/cloud/cloudstack/cs_securitygroup.py +++ b/cloud/cloudstack/cs_securitygroup.py @@ -51,7 +51,6 @@ extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' ---- # Create a security group - local_action: module: cs_securitygroup @@ -94,9 +93,6 @@ class AnsibleCloudStackSecurityGroup(AnsibleCloudStack): def __init__(self, module): AnsibleCloudStack.__init__(self, module) - self.result = { - 'changed': False, - } self.security_group = None diff --git a/cloud/cloudstack/cs_securitygroup_rule.py b/cloud/cloudstack/cs_securitygroup_rule.py index 76ddf7207fc..c294e062007 100644 --- a/cloud/cloudstack/cs_securitygroup_rule.py +++ b/cloud/cloudstack/cs_securitygroup_rule.py @@ -194,9 +194,6 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack): def __init__(self, module): AnsibleCloudStack.__init__(self, module) - self.result = { - 'changed': False, - } def _tcp_udp_match(self, rule, protocol, start_port, end_port): diff --git a/cloud/cloudstack/cs_sshkeypair.py b/cloud/cloudstack/cs_sshkeypair.py index 1e3233dd76e..995e0b5b81a 100644 --- a/cloud/cloudstack/cs_sshkeypair.py +++ b/cloud/cloudstack/cs_sshkeypair.py @@ -63,7 +63,6 @@ extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' ---- # create a new private / public key pair: - local_action: cs_sshkeypair name=linus@example.com register: key @@ -114,9 +113,6 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack): def __init__(self, module): AnsibleCloudStack.__init__(self, module) - self.result = { - 'changed': False, - } self.ssh_key = None diff --git a/cloud/cloudstack/cs_vmsnapshot.py b/cloud/cloudstack/cs_vmsnapshot.py index 1321d35da82..d5d84bd8ea7 100644 --- a/cloud/cloudstack/cs_vmsnapshot.py +++ b/cloud/cloudstack/cs_vmsnapshot.py @@ -81,7 +81,6 @@ extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' ---- # Create a VM snapshot of disk and memory before an upgrade - local_action: module: cs_vmsnapshot @@ -175,9 +174,6 @@ class AnsibleCloudStackVmSnapshot(AnsibleCloudStack): def __init__(self, module): AnsibleCloudStack.__init__(self, module) - self.result = { - 'changed': False, - } def get_snapshot(self): From 2b7a40a46a01a52ffcf78803c7030d01cdf350d5 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Thu, 14 May 2015 00:18:10 +0200 Subject: [PATCH 4/7] cloudstack: replace old _id() with new generic style from utils --- cloud/cloudstack/cs_instance.py | 2 +- cloud/cloudstack/cs_iso.py | 14 +++++++------- cloud/cloudstack/cs_securitygroup.py | 6 +++--- cloud/cloudstack/cs_securitygroup_rule.py | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cloud/cloudstack/cs_instance.py b/cloud/cloudstack/cs_instance.py index 0b2c9d4c935..d8db6b683c8 100644 --- a/cloud/cloudstack/cs_instance.py +++ b/cloud/cloudstack/cs_instance.py @@ -536,7 +536,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack): args_instance_update['group'] = self.module.params.get('group') args_instance_update['displayname'] = self.get_display_name() args_instance_update['userdata'] = self.get_user_data() - args_instance_update['ostypeid'] = self.get_os_type_id() + args_instance_update['ostypeid'] = self.get_os_type('id') args_ssh_key = {} args_ssh_key['id'] = instance['id'] diff --git a/cloud/cloudstack/cs_iso.py b/cloud/cloudstack/cs_iso.py index fe92a6baca2..b0048c75f45 100644 --- a/cloud/cloudstack/cs_iso.py +++ b/cloud/cloudstack/cs_iso.py @@ -190,11 +190,11 @@ class AnsibleCloudStackIso(AnsibleCloudStack): iso = self.get_iso() if not iso: args = {} - args['zoneid'] = self.get_zone_id() - args['projectid'] = self.get_project_id() + args['zoneid'] = self.get_zone('id') + args['projectid'] = self.get_project('id') args['bootable'] = self.module.params.get('bootable') - args['ostypeid'] = self.get_os_type_id() + args['ostypeid'] = self.get_os_type('id') if args['bootable'] and not args['ostypeid']: self.module.fail_json(msg="OS type 'os_type' is requried if 'bootable=true'.") @@ -221,8 +221,8 @@ class AnsibleCloudStackIso(AnsibleCloudStack): args = {} args['isready'] = self.module.params.get('is_ready') args['isofilter'] = self.module.params.get('iso_filter') - args['projectid'] = self.get_project_id() - args['zoneid'] = self.get_zone_id() + args['projectid'] = self.get_project('id') + args['zoneid'] = self.get_zone('id') # if checksum is set, we only look on that. checksum = self.module.params.get('checksum') @@ -247,8 +247,8 @@ class AnsibleCloudStackIso(AnsibleCloudStack): self.result['changed'] = True args = {} args['id'] = iso['id'] - args['projectid'] = self.get_project_id() - args['zoneid'] = self.get_zone_id() + args['projectid'] = self.get_project('id') + args['zoneid'] = self.get_zone('id') if not self.module.check_mode: res = self.cs.deleteIso(**args) return iso diff --git a/cloud/cloudstack/cs_securitygroup.py b/cloud/cloudstack/cs_securitygroup.py index 35d8851bdef..ec5f8d59ad4 100644 --- a/cloud/cloudstack/cs_securitygroup.py +++ b/cloud/cloudstack/cs_securitygroup.py @@ -100,7 +100,7 @@ class AnsibleCloudStackSecurityGroup(AnsibleCloudStack): if not self.security_group: sg_name = self.module.params.get('name') args = {} - args['projectid'] = self.get_project_id() + args['projectid'] = self.get_project('id') sgs = self.cs.listSecurityGroups(**args) if sgs: for s in sgs['securitygroup']: @@ -117,7 +117,7 @@ class AnsibleCloudStackSecurityGroup(AnsibleCloudStack): args = {} args['name'] = self.module.params.get('name') - args['projectid'] = self.get_project_id() + args['projectid'] = self.get_project('id') args['description'] = self.module.params.get('description') if not self.module.check_mode: @@ -136,7 +136,7 @@ class AnsibleCloudStackSecurityGroup(AnsibleCloudStack): args = {} args['name'] = self.module.params.get('name') - args['projectid'] = self.get_project_id() + args['projectid'] = self.get_project('id') if not self.module.check_mode: res = self.cs.deleteSecurityGroup(**args) diff --git a/cloud/cloudstack/cs_securitygroup_rule.py b/cloud/cloudstack/cs_securitygroup_rule.py index c294e062007..cc21ac9022e 100644 --- a/cloud/cloudstack/cs_securitygroup_rule.py +++ b/cloud/cloudstack/cs_securitygroup_rule.py @@ -268,7 +268,7 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack): security_group_name = self.module.params.get('security_group') args = {} args['securitygroupname'] = security_group_name - args['projectid'] = self.get_project_id() + args['projectid'] = self.get_project('id') sgs = self.cs.listSecurityGroups(**args) if not sgs or 'securitygroup' not in sgs: self.module.fail_json(msg="security group '%s' not found" % security_group_name) @@ -298,7 +298,7 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack): 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['projectid'] = self.get_project('id') args['securitygroupid'] = security_group['id'] rule = None From 0f884ead4088933d2a28940e2fd7b0e7b4926fbb Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Sat, 16 May 2015 11:45:48 +0200 Subject: [PATCH 5/7] cloudstack: add catch all exceptions and show a user friendly message Also see GH-493. --- cloud/cloudstack/cs_account.py | 3 +++ cloud/cloudstack/cs_affinitygroup.py | 3 +++ cloud/cloudstack/cs_firewall.py | 3 +++ cloud/cloudstack/cs_instance.py | 3 +++ cloud/cloudstack/cs_instancegroup.py | 3 +++ cloud/cloudstack/cs_iso.py | 3 +++ cloud/cloudstack/cs_portforward.py | 3 +++ cloud/cloudstack/cs_securitygroup.py | 3 +++ cloud/cloudstack/cs_securitygroup_rule.py | 3 +++ cloud/cloudstack/cs_sshkeypair.py | 3 +++ cloud/cloudstack/cs_vmsnapshot.py | 3 +++ 11 files changed, 33 insertions(+) diff --git a/cloud/cloudstack/cs_account.py b/cloud/cloudstack/cs_account.py index 313c786dee3..399dfa090cc 100644 --- a/cloud/cloudstack/cs_account.py +++ b/cloud/cloudstack/cs_account.py @@ -400,6 +400,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) + except Exception, e: + module.fail_json(msg='Exception: %s' % str(e)) + module.exit_json(**result) # import module snippets diff --git a/cloud/cloudstack/cs_affinitygroup.py b/cloud/cloudstack/cs_affinitygroup.py index e4460b93695..2a8de46fe41 100644 --- a/cloud/cloudstack/cs_affinitygroup.py +++ b/cloud/cloudstack/cs_affinitygroup.py @@ -243,6 +243,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) + except Exception, e: + module.fail_json(msg='Exception: %s' % str(e)) + module.exit_json(**result) # import module snippets diff --git a/cloud/cloudstack/cs_firewall.py b/cloud/cloudstack/cs_firewall.py index 012005432fc..8a63710cf4a 100644 --- a/cloud/cloudstack/cs_firewall.py +++ b/cloud/cloudstack/cs_firewall.py @@ -327,6 +327,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) + except Exception, e: + module.fail_json(msg='Exception: %s' % str(e)) + module.exit_json(**result) # import module snippets diff --git a/cloud/cloudstack/cs_instance.py b/cloud/cloudstack/cs_instance.py index d8db6b683c8..1f5cc6ca393 100644 --- a/cloud/cloudstack/cs_instance.py +++ b/cloud/cloudstack/cs_instance.py @@ -825,6 +825,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) + except Exception, e: + module.fail_json(msg='Exception: %s' % str(e)) + module.exit_json(**result) # import module snippets diff --git a/cloud/cloudstack/cs_instancegroup.py b/cloud/cloudstack/cs_instancegroup.py index dc216733c63..d62004cc94f 100644 --- a/cloud/cloudstack/cs_instancegroup.py +++ b/cloud/cloudstack/cs_instancegroup.py @@ -220,6 +220,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) + except Exception, e: + module.fail_json(msg='Exception: %s' % str(e)) + module.exit_json(**result) # import module snippets diff --git a/cloud/cloudstack/cs_iso.py b/cloud/cloudstack/cs_iso.py index b0048c75f45..43367530855 100644 --- a/cloud/cloudstack/cs_iso.py +++ b/cloud/cloudstack/cs_iso.py @@ -313,6 +313,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) + except Exception, e: + module.fail_json(msg='Exception: %s' % str(e)) + module.exit_json(**result) # import module snippets diff --git a/cloud/cloudstack/cs_portforward.py b/cloud/cloudstack/cs_portforward.py index 127979e3d79..aa0401355cd 100644 --- a/cloud/cloudstack/cs_portforward.py +++ b/cloud/cloudstack/cs_portforward.py @@ -423,6 +423,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) + except Exception, e: + module.fail_json(msg='Exception: %s' % str(e)) + module.exit_json(**result) # import module snippets diff --git a/cloud/cloudstack/cs_securitygroup.py b/cloud/cloudstack/cs_securitygroup.py index ec5f8d59ad4..73a54fef795 100644 --- a/cloud/cloudstack/cs_securitygroup.py +++ b/cloud/cloudstack/cs_securitygroup.py @@ -187,6 +187,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) + except Exception, e: + module.fail_json(msg='Exception: %s' % str(e)) + module.exit_json(**result) # import module snippets diff --git a/cloud/cloudstack/cs_securitygroup_rule.py b/cloud/cloudstack/cs_securitygroup_rule.py index cc21ac9022e..ef48b3896ce 100644 --- a/cloud/cloudstack/cs_securitygroup_rule.py +++ b/cloud/cloudstack/cs_securitygroup_rule.py @@ -428,6 +428,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) + except Exception, e: + module.fail_json(msg='Exception: %s' % str(e)) + module.exit_json(**result) # import module snippets diff --git a/cloud/cloudstack/cs_sshkeypair.py b/cloud/cloudstack/cs_sshkeypair.py index 995e0b5b81a..0d2e2c822f1 100644 --- a/cloud/cloudstack/cs_sshkeypair.py +++ b/cloud/cloudstack/cs_sshkeypair.py @@ -245,6 +245,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) + except Exception, e: + module.fail_json(msg='Exception: %s' % str(e)) + module.exit_json(**result) # import module snippets diff --git a/cloud/cloudstack/cs_vmsnapshot.py b/cloud/cloudstack/cs_vmsnapshot.py index d5d84bd8ea7..b71901a317f 100644 --- a/cloud/cloudstack/cs_vmsnapshot.py +++ b/cloud/cloudstack/cs_vmsnapshot.py @@ -314,6 +314,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) + except Exception, e: + module.fail_json(msg='Exception: %s' % str(e)) + module.exit_json(**result) # import module snippets From de1f642efdb9907931240054432c2f34c91a9b5a Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Sat, 16 May 2015 12:45:55 +0200 Subject: [PATCH 6/7] cloudstack: cs_iso: add account and domain --- cloud/cloudstack/cs_iso.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/cloud/cloudstack/cs_iso.py b/cloud/cloudstack/cs_iso.py index 43367530855..0b86b7424e7 100644 --- a/cloud/cloudstack/cs_iso.py +++ b/cloud/cloudstack/cs_iso.py @@ -73,6 +73,16 @@ options: - Register the ISO to be bootable. Only used if C(state) is present. required: false default: true + domain: + description: + - Domain the ISO is related to. + required: false + default: null + account: + description: + - Account the ISO is related to. + required: false + default: null project: description: - Name of the project the ISO to be registered in. @@ -168,6 +178,21 @@ created: returned: success type: string sample: 2015-03-29T14:57:06+0200 +domain: + description: Domain the ISO is related to. + returned: success + type: string + sample: example domain +account: + description: Account the ISO is related to. + returned: success + type: string + sample: example account +project: + description: Project the ISO is related to. + returned: success + type: string + sample: example project ''' try: @@ -191,8 +216,9 @@ class AnsibleCloudStackIso(AnsibleCloudStack): if not iso: args = {} args['zoneid'] = self.get_zone('id') + args['domainid'] = self.get_domain('id') + args['account'] = self.get_account('name') args['projectid'] = self.get_project('id') - args['bootable'] = self.module.params.get('bootable') args['ostypeid'] = self.get_os_type('id') if args['bootable'] and not args['ostypeid']: @@ -221,6 +247,8 @@ class AnsibleCloudStackIso(AnsibleCloudStack): args = {} args['isready'] = self.module.params.get('is_ready') args['isofilter'] = self.module.params.get('iso_filter') + args['domainid'] = self.get_domain('id') + args['account'] = self.get_account('name') args['projectid'] = self.get_project('id') args['zoneid'] = self.get_zone('id') @@ -270,6 +298,12 @@ class AnsibleCloudStackIso(AnsibleCloudStack): self.result['is_ready'] = iso['isready'] if 'created' in iso: self.result['created'] = iso['created'] + if 'project' in iso: + self.result['project'] = iso['project'] + if 'domain' in iso: + self.result['domain'] = iso['domain'] + if 'account' in iso: + self.result['account'] = iso['account'] return self.result @@ -281,6 +315,8 @@ def main(): os_type = dict(default=None), zone = dict(default=None), iso_filter = dict(default='self', choices=[ 'featured', 'self', 'selfexecutable','sharedexecutable','executable', 'community' ]), + domain = dict(default=None), + account = dict(default=None), project = dict(default=None), checksum = dict(default=None), is_ready = dict(choices=BOOLEANS, default=False), From 46cb5627dc47ae681dbf3c6997d452e29f38f793 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Sat, 16 May 2015 13:04:14 +0200 Subject: [PATCH 7/7] cloudstack: cs_iso code style and cleanup --- cloud/cloudstack/cs_iso.py | 56 ++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/cloud/cloudstack/cs_iso.py b/cloud/cloudstack/cs_iso.py index 0b86b7424e7..749acdf594a 100644 --- a/cloud/cloudstack/cs_iso.py +++ b/cloud/cloudstack/cs_iso.py @@ -214,13 +214,21 @@ class AnsibleCloudStackIso(AnsibleCloudStack): def register_iso(self): iso = self.get_iso() if not iso: - args = {} - args['zoneid'] = self.get_zone('id') - args['domainid'] = self.get_domain('id') - args['account'] = self.get_account('name') - args['projectid'] = self.get_project('id') - args['bootable'] = self.module.params.get('bootable') - args['ostypeid'] = self.get_os_type('id') + + args = {} + args['zoneid'] = self.get_zone('id') + args['domainid'] = self.get_domain('id') + args['account'] = self.get_account('name') + args['projectid'] = self.get_project('id') + args['bootable'] = self.module.params.get('bootable') + args['ostypeid'] = self.get_os_type('id') + args['name'] = self.module.params.get('name') + args['displaytext'] = self.module.params.get('name') + args['checksum'] = self.module.params.get('checksum') + args['isdynamicallyscalable'] = self.module.params.get('is_dynamically_scalable') + args['isfeatured'] = self.module.params.get('is_featured') + args['ispublic'] = self.module.params.get('is_public') + if args['bootable'] and not args['ostypeid']: self.module.fail_json(msg="OS type 'os_type' is requried if 'bootable=true'.") @@ -228,13 +236,6 @@ class AnsibleCloudStackIso(AnsibleCloudStack): if not args['url']: self.module.fail_json(msg="URL is requried.") - args['name'] = self.module.params.get('name') - args['displaytext'] = self.module.params.get('name') - args['checksum'] = self.module.params.get('checksum') - args['isdynamicallyscalable'] = self.module.params.get('is_dynamically_scalable') - args['isfeatured'] = self.module.params.get('is_featured') - args['ispublic'] = self.module.params.get('is_public') - self.result['changed'] = True if not self.module.check_mode: res = self.cs.registerIso(**args) @@ -244,13 +245,14 @@ class AnsibleCloudStackIso(AnsibleCloudStack): def get_iso(self): if not self.iso: - args = {} - args['isready'] = self.module.params.get('is_ready') - args['isofilter'] = self.module.params.get('iso_filter') - args['domainid'] = self.get_domain('id') - args['account'] = self.get_account('name') - args['projectid'] = self.get_project('id') - args['zoneid'] = self.get_zone('id') + + args = {} + args['isready'] = self.module.params.get('is_ready') + args['isofilter'] = self.module.params.get('iso_filter') + args['domainid'] = self.get_domain('id') + args['account'] = self.get_account('name') + args['projectid'] = self.get_project('id') + args['zoneid'] = self.get_zone('id') # if checksum is set, we only look on that. checksum = self.module.params.get('checksum') @@ -273,10 +275,12 @@ class AnsibleCloudStackIso(AnsibleCloudStack): iso = self.get_iso() if iso: self.result['changed'] = True - args = {} - args['id'] = iso['id'] - args['projectid'] = self.get_project('id') - args['zoneid'] = self.get_zone('id') + + args = {} + args['id'] = iso['id'] + args['projectid'] = self.get_project('id') + args['zoneid'] = self.get_zone('id') + if not self.module.check_mode: res = self.cs.deleteIso(**args) return iso @@ -310,7 +314,7 @@ class AnsibleCloudStackIso(AnsibleCloudStack): def main(): module = AnsibleModule( argument_spec = dict( - name = dict(required=True, default=None), + name = dict(required=True), url = dict(default=None), os_type = dict(default=None), zone = dict(default=None),