1#!/usr/local/bin/python3.8
2# -*- coding: utf-8 -*-
3#
4# (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
5# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7from __future__ import (absolute_import, division, print_function)
8__metaclass__ = type
9
10DOCUMENTATION = r'''
11---
12module: scaleway_organization_info
13short_description: Gather information about the Scaleway organizations available.
14description:
15  - Gather information about the Scaleway organizations available.
16author:
17  - "Yanis Guenane (@Spredzy)"
18  - "Remy Leone (@sieben)"
19options:
20  api_url:
21    description:
22      - Scaleway API URL
23    default: 'https://account.scaleway.com'
24    aliases: ['base_url']
25extends_documentation_fragment:
26- community.general.scaleway
27
28'''
29
30EXAMPLES = r'''
31- name: Gather Scaleway organizations information
32  community.general.scaleway_organization_info:
33  register: result
34
35- ansible.builtin.debug:
36    msg: "{{ result.scaleway_organization_info }}"
37'''
38
39RETURN = r'''
40---
41scaleway_organization_info:
42  description: Response from Scaleway API
43  returned: success
44  type: complex
45  sample:
46    "scaleway_organization_info": [
47        {
48            "address_city_name": "Paris",
49            "address_country_code": "FR",
50            "address_line1": "42 Rue de l'univers",
51            "address_line2": null,
52            "address_postal_code": "75042",
53            "address_subdivision_code": "FR-75",
54            "creation_date": "2018-08-06T13:43:28.508575+00:00",
55            "currency": "EUR",
56            "customer_class": "individual",
57            "id": "3f709602-5e6c-4619-b80c-e8432ferewtr",
58            "locale": "fr_FR",
59            "modification_date": "2018-08-06T14:56:41.401685+00:00",
60            "name": "James Bond",
61            "support_id": "694324",
62            "support_level": "basic",
63            "support_pin": "9324",
64            "users": [],
65            "vat_number": null,
66            "warnings": []
67        }
68    ]
69'''
70
71from ansible.module_utils.basic import AnsibleModule, env_fallback
72from ansible_collections.community.general.plugins.module_utils.scaleway import (
73    Scaleway, ScalewayException, scaleway_argument_spec
74)
75
76
77class ScalewayOrganizationInfo(Scaleway):
78
79    def __init__(self, module):
80        super(ScalewayOrganizationInfo, self).__init__(module)
81        self.name = 'organizations'
82
83
84def main():
85    argument_spec = scaleway_argument_spec()
86    argument_spec.update(dict(
87        api_url=dict(fallback=(env_fallback, ['SCW_API_URL']), default='https://account.scaleway.com', aliases=['base_url']),
88    ))
89
90    module = AnsibleModule(
91        argument_spec=argument_spec,
92        supports_check_mode=True,
93    )
94
95    try:
96        module.exit_json(
97            scaleway_organization_info=ScalewayOrganizationInfo(module).get_resources()
98        )
99    except ScalewayException as exc:
100        module.fail_json(msg=exc.message)
101
102
103if __name__ == '__main__':
104    main()
105