diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 343545d4..0f839681 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -13,17 +13,17 @@ jobs: defaults: run: working-directory: ansible_collections/ngine_io/cloudstack - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: fail-fast: false matrix: python-version: - - 3.8 + - "3.10" group: - 1 - 2 ansible-branch: - - devel + - stable-2.14 container-version: - 1.4.0 - 1.2.0 diff --git a/.github/workflows/sanity.yml b/.github/workflows/sanity.yml index 6917d981..fd22a6d8 100644 --- a/.github/workflows/sanity.yml +++ b/.github/workflows/sanity.yml @@ -1,8 +1,13 @@ name: Sanity on: + push: + branches: + - master schedule: - cron: "5 12 * * 2" pull_request: + workflow_call: + workflow_dispatch: jobs: sanity: @@ -11,13 +16,14 @@ jobs: run: working-directory: ansible_collections/ngine_io/cloudstack strategy: + fail-fast: false matrix: ansible: - stable-2.12 - - stable-2.11 - - stable-2.10 + - stable-2.13 + - stable-2.14 - devel - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: Check out code uses: actions/checkout@v3 @@ -27,7 +33,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.x" + python-version: "3.10" - name: Install ansible-base (${{ matrix.ansible }}) run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check diff --git a/plugins/modules/cs_account.py b/plugins/modules/cs_account.py index 694f62d7..9c6f1d53 100644 --- a/plugins/modules/cs_account.py +++ b/plugins/modules/cs_account.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -190,11 +191,9 @@ # import cloudstack common from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackAccount(AnsibleCloudStack): @@ -385,12 +384,12 @@ def absent_account(self): self.poll_job(res, 'account') return account - def get_result(self, account): - super(AnsibleCloudStackAccount, self).get_result(account) - if account: - if 'accounttype' in account: + def get_result(self, resource): + super(AnsibleCloudStackAccount, self).get_result(resource) + if resource: + if 'accounttype' in resource: for key, value in self.account_types.items(): - if value == account['accounttype']: + if value == resource['accounttype']: self.result['account_type'] = key break return self.result diff --git a/plugins/modules/cs_configuration.py b/plugins/modules/cs_configuration.py index 0b2ea75b..da83dce2 100644 --- a/plugins/modules/cs_configuration.py +++ b/plugins/modules/cs_configuration.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -134,11 +135,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackConfiguration(AnsibleCloudStack): @@ -232,8 +231,8 @@ def present_configuration(self): configuration = res['configuration'] return configuration - def get_result(self, configuration): - self.result = super(AnsibleCloudStackConfiguration, self).get_result(configuration) + def get_result(self, resource): + self.result = super(AnsibleCloudStackConfiguration, self).get_result(resource) if self.account: self.result['account'] = self.account['name'] self.result['domain'] = self.domain['path'] diff --git a/plugins/modules/cs_disk_offering.py b/plugins/modules/cs_disk_offering.py index b9bd4570..a94f5ff0 100644 --- a/plugins/modules/cs_disk_offering.py +++ b/plugins/modules/cs_disk_offering.py @@ -5,7 +5,8 @@ # Copyright (c) 2017, René Moser # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) +from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -215,11 +216,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together, -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackDiskOffering(AnsibleCloudStack): @@ -319,12 +318,12 @@ def _update_offering(self, disk_offering): disk_offering = res['diskoffering'] return disk_offering - def get_result(self, disk_offering): - super(AnsibleCloudStackDiskOffering, self).get_result(disk_offering) - if disk_offering: + def get_result(self, resource): + super(AnsibleCloudStackDiskOffering, self).get_result(resource) + if resource: # Prevent confusion, the api returns a tags key for storage tags. - if 'tags' in disk_offering: - self.result['storage_tags'] = disk_offering['tags'].split(',') or [disk_offering['tags']] + if 'tags' in resource: + self.result['storage_tags'] = resource['tags'].split(',') or [resource['tags']] if 'tags' in self.result: del self.result['tags'] diff --git a/plugins/modules/cs_firewall.py b/plugins/modules/cs_firewall.py index fda792a6..9aca3c13 100644 --- a/plugins/modules/cs_firewall.py +++ b/plugins/modules/cs_firewall.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -211,11 +212,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackFirewall(AnsibleCloudStack): @@ -376,14 +375,14 @@ def remove_firewall_rule(self): self.poll_job(res, 'firewallrule') return firewall_rule - def get_result(self, firewall_rule): - super(AnsibleCloudStackFirewall, self).get_result(firewall_rule) - if firewall_rule: + def get_result(self, resource): + super(AnsibleCloudStackFirewall, self).get_result(resource) + if resource: self.result['type'] = self.module.params.get('type') if self.result['type'] == 'egress': self.result['network'] = self.get_network(key='displaytext') - if 'cidrlist' in firewall_rule: - self.result['cidrs'] = firewall_rule['cidrlist'].split(',') or [firewall_rule['cidrlist']] + if 'cidrlist' in resource: + self.result['cidrs'] = resource['cidrlist'].split(',') or [resource['cidrlist']] return self.result diff --git a/plugins/modules/cs_host.py b/plugins/modules/cs_host.py index faf365b5..d2f7c446 100644 --- a/plugins/modules/cs_host.py +++ b/plugins/modules/cs_host.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -322,14 +323,13 @@ sample: zone01 ''' -from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together, -) import time +from ansible.module_utils.basic import AnsibleModule + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) + class AnsibleCloudStackHost(AnsibleCloudStack): @@ -560,11 +560,11 @@ def _poll_for_maintenance(self): return host self.fail_json(msg="Polling for maintenance timed out") - def get_result(self, host): - super(AnsibleCloudStackHost, self).get_result(host) - if host: - self.result['allocation_state'] = host['resourcestate'].lower() - self.result['host_tags'] = host['hosttags'].split(',') if host.get('hosttags') else [] + def get_result(self, resource): + super(AnsibleCloudStackHost, self).get_result(resource) + if resource: + self.result['allocation_state'] = resource['resourcestate'].lower() + self.result['host_tags'] = resource['hosttags'].split(',') if resource.get('hosttags') else [] return self.result diff --git a/plugins/modules/cs_instance.py b/plugins/modules/cs_instance.py index fa20356d..8a56e2e3 100644 --- a/plugins/modules/cs_instance.py +++ b/plugins/modules/cs_instance.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -72,7 +73,6 @@ description: - Name of the filter used to search for the template or iso. - Used for params I(iso) or I(template) on I(state=present). - - The filter C(all) was added in 2.6. type: str default: executable choices: [ all, featured, self, selfexecutable, sharedexecutable, executable, community ] @@ -120,8 +120,8 @@ type: int root_disk_size: description: - - Root disk size in GByte required if deploying instance with KVM hypervisor and want resize the root disk size at startup - (need CloudStack >= 4.4, cloud-initramfs-growroot installed and enabled in the template) + - "Root disk size in GByte required if deploying instance with KVM hypervisor and want resize the root disk size at startup + (needs CloudStack >= 4.4, cloud-initramfs-growroot installed and enabled in the template)." type: int security_groups: description: @@ -141,7 +141,7 @@ - Only considered when I(state=started) or instance is running. - Requires root admin privileges. type: str - pod: + pod: description: - Pod on which an instance should be deployed or started on. - Only considered when I(state=started) or instance is running. @@ -425,13 +425,12 @@ ''' import base64 -from ansible.module_utils.basic import AnsibleModule + from ansible.module_utils._text import to_bytes, to_text -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together -) +from ansible.module_utils.basic import AnsibleModule + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackInstance(AnsibleCloudStack): @@ -1039,22 +1038,22 @@ def restore_instance(self): instance = self.poll_job(res, 'virtualmachine') return instance - def get_result(self, instance): - super(AnsibleCloudStackInstance, self).get_result(instance) - if instance: - self.result['user_data'] = self._get_instance_user_data(instance) - if 'securitygroup' in instance: + def get_result(self, resource): + super(AnsibleCloudStackInstance, self).get_result(resource) + if resource: + self.result['user_data'] = self._get_instance_user_data(resource) + if 'securitygroup' in resource: security_groups = [] - for securitygroup in instance['securitygroup']: + for securitygroup in resource['securitygroup']: security_groups.append(securitygroup['name']) self.result['security_groups'] = security_groups - if 'affinitygroup' in instance: + if 'affinitygroup' in resource: affinity_groups = [] - for affinitygroup in instance['affinitygroup']: + for affinitygroup in resource['affinitygroup']: affinity_groups.append(affinitygroup['name']) self.result['affinity_groups'] = affinity_groups - if 'nic' in instance: - for nic in instance['nic']: + if 'nic' in resource: + for nic in resource['nic']: if nic['isdefault']: if 'ipaddress' in nic: self.result['default_ip'] = nic['ipaddress'] diff --git a/plugins/modules/cs_instance_info.py b/plugins/modules/cs_instance_info.py index 0427e8bf..ff5946cf 100644 --- a/plugins/modules/cs_instance_info.py +++ b/plugins/modules/cs_instance_info.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -268,6 +269,7 @@ ''' from ansible.module_utils.basic import AnsibleModule + from ..module_utils.cloudstack import AnsibleCloudStack, cs_argument_spec @@ -349,25 +351,25 @@ def run(self): 'instances': [self.update_result(resource) for resource in instances] } - def update_result(self, instance, result=None): - result = super(AnsibleCloudStackInstanceInfo, self).update_result(instance, result) - if instance: - if 'securitygroup' in instance: + def update_result(self, resource, result=None): + result = super(AnsibleCloudStackInstanceInfo, self).update_result(resource, result) + if resource: + if 'securitygroup' in resource: security_groups = [] - for securitygroup in instance['securitygroup']: + for securitygroup in resource['securitygroup']: security_groups.append(securitygroup['name']) result['security_groups'] = security_groups - if 'affinitygroup' in instance: + if 'affinitygroup' in resource: affinity_groups = [] - for affinitygroup in instance['affinitygroup']: + for affinitygroup in resource['affinitygroup']: affinity_groups.append(affinitygroup['name']) result['affinity_groups'] = affinity_groups - if 'nic' in instance: - for nic in instance['nic']: + if 'nic' in resource: + for nic in resource['nic']: if nic['isdefault'] and 'ipaddress' in nic: result['default_ip'] = nic['ipaddress'] - result['nic'] = instance['nic'] - volumes = self.get_volumes(instance) + result['nic'] = resource['nic'] + volumes = self.get_volumes(instance=resource) if volumes: result['volumes'] = volumes return result diff --git a/plugins/modules/cs_instance_nic.py b/plugins/modules/cs_instance_nic.py index 428264ef..87bdbf1d 100644 --- a/plugins/modules/cs_instance_nic.py +++ b/plugins/modules/cs_instance_nic.py @@ -6,6 +6,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -143,11 +144,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackInstanceNic(AnsibleCloudStack): @@ -241,10 +240,10 @@ def absent_nic(self): return self.remove_nic(nic) return nic - def get_result(self, nic): - super(AnsibleCloudStackInstanceNic, self).get_result(nic) - if nic and not self.module.params.get('network'): - self.module.params['network'] = nic.get('networkid') + def get_result(self, resource): + super(AnsibleCloudStackInstanceNic, self).get_result(resource) + if resource and not self.module.params.get('network'): + self.module.params['network'] = resource.get('networkid') self.result['network'] = self.get_network(key='name') self.result['vm'] = self.get_vm(key='name') return self.result diff --git a/plugins/modules/cs_instance_nic_secondaryip.py b/plugins/modules/cs_instance_nic_secondaryip.py index 004b1921..94d13f06 100644 --- a/plugins/modules/cs_instance_nic_secondaryip.py +++ b/plugins/modules/cs_instance_nic_secondaryip.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -147,11 +148,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackInstanceNicSecondaryIp(AnsibleCloudStack): @@ -220,10 +219,10 @@ def absent_nic_ip(self): self.poll_job(res, 'nicsecondaryip') return nic - def get_result(self, nic): - super(AnsibleCloudStackInstanceNicSecondaryIp, self).get_result(nic) - if nic and not self.module.params.get('network'): - self.module.params['network'] = nic.get('networkid') + def get_result(self, resource): + super(AnsibleCloudStackInstanceNicSecondaryIp, self).get_result(resource) + if resource and not self.module.params.get('network'): + self.module.params['network'] = resource.get('networkid') self.result['network'] = self.get_network(key='name') self.result['vm'] = self.get_vm(key='name') self.result['vm_guest_ip'] = self.vm_guest_ip diff --git a/plugins/modules/cs_iso.py b/plugins/modules/cs_iso.py index e48561ad..eb242451 100644 --- a/plugins/modules/cs_iso.py +++ b/plugins/modules/cs_iso.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -237,11 +238,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackIso(AnsibleCloudStack): @@ -381,8 +380,8 @@ def absent_iso(self): self.poll_job(res, 'iso') return iso - def get_result(self, iso): - super(AnsibleCloudStackIso, self).get_result(iso) + def get_result(self, resource): + super(AnsibleCloudStackIso, self).get_result(resource) # Workaround API does not return cross_zones=true if self.module.params.get('cross_zones'): self.result['cross_zones'] = True diff --git a/plugins/modules/cs_loadbalancer_rule_member.py b/plugins/modules/cs_loadbalancer_rule_member.py index 9399cc4a..963dabea 100644 --- a/plugins/modules/cs_loadbalancer_rule_member.py +++ b/plugins/modules/cs_loadbalancer_rule_member.py @@ -6,6 +6,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -192,11 +193,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together, -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackLBRuleMember(AnsibleCloudStack): @@ -300,11 +299,11 @@ def add_members(self): def remove_members(self): return self._ensure_members('remove') - def get_result(self, rule): - super(AnsibleCloudStackLBRuleMember, self).get_result(rule) - if rule: + def get_result(self, resource): + super(AnsibleCloudStackLBRuleMember, self).get_result(resource) + if resource: self.result['vms'] = [] - for vm in self._get_members_of_rule(rule=rule): + for vm in self._get_members_of_rule(rule=resource): self.result['vms'].append(vm['name']) return self.result diff --git a/plugins/modules/cs_network.py b/plugins/modules/cs_network.py index 8e3284a9..b3831165 100644 --- a/plugins/modules/cs_network.py +++ b/plugins/modules/cs_network.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -359,11 +360,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together, -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackNetwork(AnsibleCloudStack): @@ -439,7 +438,7 @@ def _get_args(self): } return args - def get_network(self, refresh=False): + def query_network(self, refresh=False): if not self.network or refresh: network = self.module.params.get('name') args = { @@ -463,7 +462,7 @@ def present_network(self): if self.module.params.get('acl') is not None and self.module.params.get('vpc') is None: self.module.fail_json(msg="Missing required params: vpc") - network = self.get_network() + network = self.query_network() if not network: network = self.create_network(network) else: @@ -498,7 +497,7 @@ def update_network(self, network): network = self.query_api('replaceNetworkACLList', **args) if self.module.params.get('poll_async'): self.poll_job(network, 'networkacllist') - network = self.get_network(refresh=True) + network = self.query_network(refresh=True) return network def create_network(self, network): @@ -533,7 +532,7 @@ def create_network(self, network): return network def restart_network(self): - network = self.get_network() + network = self.query_network() if not network: self.module.fail_json(msg="No network named '%s' found." % self.module.params('name')) @@ -556,7 +555,7 @@ def restart_network(self): return network def absent_network(self): - network = self.get_network() + network = self.query_network() if network: self.result['changed'] = True @@ -572,10 +571,10 @@ def absent_network(self): self.poll_job(res, 'network') return network - def get_result(self, network): - super(AnsibleCloudStackNetwork, self).get_result(network) - if network: - self.result['acl'] = self.get_network_acl(key='name', acl_id=network.get('aclid')) + def get_result(self, resource): + super(AnsibleCloudStackNetwork, self).get_result(resource) + if resource: + self.result['acl'] = self.get_network_acl(key='name', acl_id=resource.get('aclid')) return self.result diff --git a/plugins/modules/cs_network_acl_rule.py b/plugins/modules/cs_network_acl_rule.py index badb7307..bc2a6ac2 100644 --- a/plugins/modules/cs_network_acl_rule.py +++ b/plugins/modules/cs_network_acl_rule.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -261,11 +262,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackNetworkAclRule(AnsibleCloudStack): @@ -391,13 +390,13 @@ def _update_network_acl_rule(self, network_acl_rule): return network_acl_rule - def get_result(self, network_acl_rule): - super(AnsibleCloudStackNetworkAclRule, self).get_result(network_acl_rule) - if network_acl_rule: - if 'cidrlist' in network_acl_rule: - self.result['cidrs'] = network_acl_rule['cidrlist'].split(',') or [network_acl_rule['cidrlist']] - if network_acl_rule['protocol'] not in ['tcp', 'udp', 'icmp', 'all']: - self.result['protocol_number'] = int(network_acl_rule['protocol']) + def get_result(self, resource): + super(AnsibleCloudStackNetworkAclRule, self).get_result(resource) + if resource: + if 'cidrlist' in resource: + self.result['cidrs'] = resource['cidrlist'].split(',') or [resource['cidrlist']] + if resource['protocol'] not in ['tcp', 'udp', 'icmp', 'all']: + self.result['protocol_number'] = int(resource['protocol']) self.result['protocol'] = 'by_number' self.result['action_policy'] = self.result['action_policy'].lower() self.result['traffic_type'] = self.result['traffic_type'].lower() diff --git a/plugins/modules/cs_network_offering.py b/plugins/modules/cs_network_offering.py index be1876bf..3ba5dcdc 100644 --- a/plugins/modules/cs_network_offering.py +++ b/plugins/modules/cs_network_offering.py @@ -6,6 +6,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -258,11 +259,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together, -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackNetworkOffering(AnsibleCloudStack): @@ -411,19 +410,19 @@ def update_network_offering(self, network_offering): return network_offering - def get_result(self, network_offering): - super(AnsibleCloudStackNetworkOffering, self).get_result(network_offering) - if network_offering: - self.result['egress_default_policy'] = 'allow' if network_offering.get('egressdefaultpolicy') else 'deny' + def get_result(self, resource): + super(AnsibleCloudStackNetworkOffering, self).get_result(resource) + if resource: + self.result['egress_default_policy'] = 'allow' if resource.get('egressdefaultpolicy') else 'deny' # Return a list of comma separated network offering tags - tags = network_offering.get('tags') + tags = resource.get('tags') self.result['tags'] = tags.split(',') if tags else [] - zone_id = network_offering.get('zoneid') + zone_id = resource.get('zoneid') self.result['zones'] = zone_id.split(',') if zone_id else [] - domain_id = network_offering.get('domainid') + domain_id = resource.get('domainid') self.result['domains'] = zone_id.split(',') if domain_id else [] return self.result diff --git a/plugins/modules/cs_pod.py b/plugins/modules/cs_pod.py index b74c2ae1..b755b8d1 100644 --- a/plugins/modules/cs_pod.py +++ b/plugins/modules/cs_pod.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -133,11 +134,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackPod(AnsibleCloudStack): @@ -248,9 +247,9 @@ def _transform_ip_list(self, resource): resource[key] = resource[key][0] return resource - def get_result(self, pod): - pod = self._transform_ip_list(pod) - super(AnsibleCloudStackPod, self).get_result(pod) + def get_result(self, resource): + resource = self._transform_ip_list(resource) + super(AnsibleCloudStackPod, self).get_result(resource) return self.result diff --git a/plugins/modules/cs_portforward.py b/plugins/modules/cs_portforward.py index ea281830..e9a2c886 100644 --- a/plugins/modules/cs_portforward.py +++ b/plugins/modules/cs_portforward.py @@ -353,12 +353,12 @@ def absent_portforwarding_rule(self): self.poll_job(res, 'portforwardingrule') return portforwarding_rule - def get_result(self, portforwarding_rule): - super(AnsibleCloudStackPortforwarding, self).get_result(portforwarding_rule) - if portforwarding_rule: + def get_result(self, resource): + super(AnsibleCloudStackPortforwarding, self).get_result(resource) + if resource: for search_key, return_key in self.returns_to_int.items(): - if search_key in portforwarding_rule: - self.result[return_key] = int(portforwarding_rule[search_key]) + if search_key in resource: + self.result[return_key] = int(resource[search_key]) return self.result diff --git a/plugins/modules/cs_resourcelimit.py b/plugins/modules/cs_resourcelimit.py index fdca3bdd..3ab96491 100644 --- a/plugins/modules/cs_resourcelimit.py +++ b/plugins/modules/cs_resourcelimit.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -104,12 +105,9 @@ # import cloudstack common from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_required_together, - cs_argument_spec -) +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) RESOURCE_TYPES = { 'instance': 0, @@ -170,8 +168,8 @@ def update_resource_limit(self): resource_limit = res['resourcelimit'] return resource_limit - def get_result(self, resource_limit): - self.result = super(AnsibleCloudStackResourceLimit, self).get_result(resource_limit) + def get_result(self, resource): + self.result = super(AnsibleCloudStackResourceLimit, self).get_result(resource) self.result['resource_type'] = self.module.params.get('resource_type') return self.result diff --git a/plugins/modules/cs_securitygroup_rule.py b/plugins/modules/cs_securitygroup_rule.py index 2bd269e8..12270456 100644 --- a/plugins/modules/cs_securitygroup_rule.py +++ b/plugins/modules/cs_securitygroup_rule.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -163,7 +164,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import AnsibleCloudStack, cs_argument_spec, cs_required_together + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack): @@ -323,8 +326,8 @@ def remove_rule(self): res = self.poll_job(res, 'securitygroup') return rule - def get_result(self, security_group_rule): - super(AnsibleCloudStackSecurityGroupRule, self).get_result(security_group_rule) + def get_result(self, resource): + super(AnsibleCloudStackSecurityGroupRule, self).get_result(resource) self.result['type'] = self.module.params.get('type') self.result['security_group'] = self.module.params.get('security_group') return self.result diff --git a/plugins/modules/cs_service_offering.py b/plugins/modules/cs_service_offering.py index 8d17d521..21e7023b 100644 --- a/plugins/modules/cs_service_offering.py +++ b/plugins/modules/cs_service_offering.py @@ -4,7 +4,8 @@ # Copyright (c) 2017, René Moser # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) +from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -377,11 +378,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together, -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackServiceOffering(AnsibleCloudStack): @@ -504,15 +503,15 @@ def _update_offering(self, service_offering): service_offering = res['serviceoffering'] return service_offering - def get_result(self, service_offering): - super(AnsibleCloudStackServiceOffering, self).get_result(service_offering) - if service_offering: - if 'hosttags' in service_offering: - self.result['host_tags'] = service_offering['hosttags'].split(',') or [service_offering['hosttags']] + def get_result(self, resource): + super(AnsibleCloudStackServiceOffering, self).get_result(resource) + if resource: + if 'hosttags' in resource: + self.result['host_tags'] = resource['hosttags'].split(',') or [resource['hosttags']] # Prevent confusion, the api returns a tags key for storage tags. - if 'tags' in service_offering: - self.result['storage_tags'] = service_offering['tags'].split(',') or [service_offering['tags']] + if 'tags' in resource: + self.result['storage_tags'] = resource['tags'].split(',') or [resource['tags']] if 'tags' in self.result: del self.result['tags'] diff --git a/plugins/modules/cs_snapshot_policy.py b/plugins/modules/cs_snapshot_policy.py index bd11f367..875ac5d1 100644 --- a/plugins/modules/cs_snapshot_policy.py +++ b/plugins/modules/cs_snapshot_policy.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -186,11 +187,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackSnapshotPolicy(AnsibleCloudStack): @@ -286,11 +285,11 @@ def absent_snapshot_policy(self): self.query_api('deleteSnapshotPolicies', **args) return policy - def get_result(self, policy): - super(AnsibleCloudStackSnapshotPolicy, self).get_result(policy) - if policy and 'intervaltype' in policy: + def get_result(self, resource): + super(AnsibleCloudStackSnapshotPolicy, self).get_result(resource) + if resource and 'intervaltype' in resource: for key, value in self.interval_types.items(): - if value == policy['intervaltype']: + if value == resource['intervaltype']: self.result['interval_type'] = key break volume = self.get_volume() diff --git a/plugins/modules/cs_storage_pool.py b/plugins/modules/cs_storage_pool.py index 819a722d..5f5b0388 100644 --- a/plugins/modules/cs_storage_pool.py +++ b/plugins/modules/cs_storage_pool.py @@ -6,6 +6,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -228,11 +229,9 @@ # import cloudstack common from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together, -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackStoragePool(AnsibleCloudStack): @@ -432,13 +431,13 @@ def get_cluster(self, key=None): self.fail_json(msg="Cluster %s not found" % cluster) - def get_result(self, pool): - super(AnsibleCloudStackStoragePool, self).get_result(pool) - if pool: - self.result['storage_url'] = "%s://%s/%s" % (pool['type'], pool['ipaddress'], pool['path']) - self.result['scope'] = pool['scope'].lower() - self.result['storage_tags'] = pool['tags'].split(',') if pool.get('tags') else [] - self.result['allocation_state'] = self.allocation_states.get(pool['state']) + def get_result(self, resource): + super(AnsibleCloudStackStoragePool, self).get_result(resource) + if resource: + self.result['storage_url'] = "%s://%s/%s" % (resource['type'], resource['ipaddress'], resource['path']) + self.result['scope'] = resource['scope'].lower() + self.result['storage_tags'] = resource['tags'].split(',') if resource.get('tags') else [] + self.result['allocation_state'] = self.allocation_states.get(resource['state']) return self.result diff --git a/plugins/modules/cs_template.py b/plugins/modules/cs_template.py index fc93f52e..87e73928 100644 --- a/plugins/modules/cs_template.py +++ b/plugins/modules/cs_template.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -369,11 +370,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together, -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackTemplate(AnsibleCloudStack): @@ -657,15 +656,15 @@ def remove_template(self): res = self.poll_job(res, 'template') return template - def get_result(self, template): - super(AnsibleCloudStackTemplate, self).get_result(template) - if template: - if 'isextractable' in template: - self.result['is_extractable'] = True if template['isextractable'] else False - if 'isfeatured' in template: - self.result['is_featured'] = True if template['isfeatured'] else False - if 'ispublic' in template: - self.result['is_public'] = True if template['ispublic'] else False + def get_result(self, resource): + super(AnsibleCloudStackTemplate, self).get_result(resource) + if resource: + if 'isextractable' in resource: + self.result['is_extractable'] = True if resource['isextractable'] else False + if 'isfeatured' in resource: + self.result['is_featured'] = True if resource['isfeatured'] else False + if 'ispublic' in resource: + self.result['is_public'] = True if resource['ispublic'] else False return self.result diff --git a/plugins/modules/cs_user.py b/plugins/modules/cs_user.py index 816e5f70..ac1be69c 100644 --- a/plugins/modules/cs_user.py +++ b/plugins/modules/cs_user.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -185,11 +186,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together, -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackUser(AnsibleCloudStack): @@ -368,18 +367,18 @@ def absent_user(self): return user - def get_result(self, user): - super(AnsibleCloudStackUser, self).get_result(user) - if user: - if 'accounttype' in user: + def get_result(self, resource): + super(AnsibleCloudStackUser, self).get_result(resource) + if resource: + if 'accounttype' in resource: for key, value in self.account_types.items(): - if value == user['accounttype']: + if value == resource['accounttype']: self.result['account_type'] = key break # secretkey has been removed since CloudStack 4.10 from listUsers API - if self.module.params.get('keys_registered') and 'apikey' in user and 'secretkey' not in user: - user_keys = self.query_api('getUserKeys', id=user['id']) + if self.module.params.get('keys_registered') and 'apikey' in resource and 'secretkey' not in resource: + user_keys = self.query_api('getUserKeys', id=resource['id']) if user_keys: self.result['user_api_secret'] = user_keys['userkeys'].get('secretkey') diff --git a/plugins/modules/cs_vpn_connection.py b/plugins/modules/cs_vpn_connection.py index 1b4fa920..edcb4468 100644 --- a/plugins/modules/cs_vpn_connection.py +++ b/plugins/modules/cs_vpn_connection.py @@ -298,16 +298,16 @@ def absent_vpn_connection(self): return vpn_conn - def get_result(self, vpn_conn): - super(AnsibleCloudStackVpnConnection, self).get_result(vpn_conn) - if vpn_conn: - if 'cidrlist' in vpn_conn: - self.result['cidrs'] = vpn_conn['cidrlist'].split(',') or [vpn_conn['cidrlist']] + def get_result(self, resource): + super(AnsibleCloudStackVpnConnection, self).get_result(resource) + if resource: + if 'cidrlist' in resource: + self.result['cidrs'] = resource['cidrlist'].split(',') or [resource['cidrlist']] # Ensure we return a bool - self.result['force_encap'] = True if vpn_conn.get('forceencap') else False + self.result['force_encap'] = True if resource.get('forceencap') else False args = { 'key': 'name', - 'identifier': vpn_conn['s2scustomergatewayid'], + 'identifier': resource['s2scustomergatewayid'], 'refresh': True, } self.result['vpn_customer_gateway'] = self.get_vpn_customer_gateway(**args) diff --git a/plugins/modules/cs_vpn_customer_gateway.py b/plugins/modules/cs_vpn_customer_gateway.py index 915784cc..628ea213 100644 --- a/plugins/modules/cs_vpn_customer_gateway.py +++ b/plugins/modules/cs_vpn_customer_gateway.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = r''' @@ -184,11 +185,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackVpnCustomerGateway(AnsibleCloudStack): @@ -291,13 +290,13 @@ def absent_vpn_customer_gateway(self): return vpn_customer_gateway - def get_result(self, vpn_customer_gateway): - super(AnsibleCloudStackVpnCustomerGateway, self).get_result(vpn_customer_gateway) - if vpn_customer_gateway: - if 'cidrlist' in vpn_customer_gateway: - self.result['cidrs'] = vpn_customer_gateway['cidrlist'].split(',') or [vpn_customer_gateway['cidrlist']] + def get_result(self, resource): + super(AnsibleCloudStackVpnCustomerGateway, self).get_result(resource) + if resource: + if 'cidrlist' in resource: + self.result['cidrs'] = resource['cidrlist'].split(',') or [resource['cidrlist']] # Ensure we return a bool - self.result['force_encap'] = True if vpn_customer_gateway.get('forceencap') else False + self.result['force_encap'] = True if resource.get('forceencap') else False return self.result diff --git a/plugins/modules/cs_vpn_gateway.py b/plugins/modules/cs_vpn_gateway.py index a28918c1..22f0d3e9 100644 --- a/plugins/modules/cs_vpn_gateway.py +++ b/plugins/modules/cs_vpn_gateway.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type @@ -102,11 +103,9 @@ ''' from ansible.module_utils.basic import AnsibleModule -from ..module_utils.cloudstack import ( - AnsibleCloudStack, - cs_argument_spec, - cs_required_together -) + +from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec, + cs_required_together) class AnsibleCloudStackVpnGateway(AnsibleCloudStack): @@ -164,9 +163,9 @@ def absent_vpn_gateway(self): return vpn_gateway - def get_result(self, vpn_gateway): - super(AnsibleCloudStackVpnGateway, self).get_result(vpn_gateway) - if vpn_gateway: + def get_result(self, resource): + super(AnsibleCloudStackVpnGateway, self).get_result(resource) + if resource: self.result['vpc'] = self.get_vpc(key='name') return self.result diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/sanity/requirements.txt b/tests/sanity/requirements.txt deleted file mode 100644 index 3e3a9669..00000000 --- a/tests/sanity/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -packaging # needed for update-bundled and changelog -sphinx ; python_version >= '3.5' # docs build requires python 3+ -sphinx-notfound-page ; python_version >= '3.5' # docs build requires python 3+ -straight.plugin ; python_version >= '3.5' # needed for hacking/build-ansible.py which will host changelog generation and requires python 3+