Debian Codegraph @

ansible_collections/community/general/plugins/modules/scaleway_image_info.py

raw
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2018, Yanis Guenane <[email protected]>
4 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6
7 from __future__ import annotations
8
9 DOCUMENTATION = r"""
10 module: scaleway_image_info
11 short_description: Gather information about the Scaleway images available
12 description:
13 - Gather information about the Scaleway images available.
14 author:
15 - "Yanis Guenane (@Spredzy)"
16 - "Remy Leone (@remyleone)"
17 extends_documentation_fragment:
18 - community.general._scaleway
19 - community.general._attributes
20 - community.general._scaleway.actiongroup_scaleway
21 - community.general._attributes.info_module
22
23 attributes:
24 action_group:
25 version_added: 11.3.0
26
27 options:
28 region:
29 type: str
30 description:
31 - Scaleway compute zone.
32 required: true
33 choices:
34 - ams1
35 - EMEA-NL-EVS
36 - ams2
37 - ams3
38 - par1
39 - EMEA-FR-PAR1
40 - par2
41 - EMEA-FR-PAR2
42 - par3
43 - waw1
44 - EMEA-PL-WAW1
45 - waw2
46 - waw3
47 """
48
49 EXAMPLES = r"""
50 - name: Gather Scaleway images information
51 community.general.scaleway_image_info:
52 region: par1
53 register: result
54
55 - ansible.builtin.debug:
56 msg: "{{ result.scaleway_image_info }}"
57 """
58
59 RETURN = r"""
60 scaleway_image_info:
61 description:
62 - Response from Scaleway API.
63 - 'For more details please refer to: U(https://developers.scaleway.com/en/products/instance/api/).'
64 returned: success
65 type: list
66 elements: dict
67 sample:
68 [
69 {
70 "arch": "x86_64",
71 "creation_date": "2018-07-17T16:18:49.276456+00:00",
72 "default_bootscript": {
73 "architecture": "x86_64",
74 "bootcmdargs": "LINUX_COMMON scaleway boot=local nbd.max_part=16",
75 "default": false,
76 "dtb": "",
77 "id": "15fbd2f7-a0f9-412b-8502-6a44da8d98b8",
78 "initrd": "http://169.254.42.24/initrd/initrd-Linux-x86_64-v3.14.5.gz",
79 "kernel": "http://169.254.42.24/kernel/x86_64-mainline-lts-4.9-4.9.93-rev1/vmlinuz-4.9.93",
80 "organization": "11111111-1111-4111-8111-111111111111",
81 "public": true,
82 "title": "x86_64 mainline 4.9.93 rev1"
83 },
84 "extra_volumes": [],
85 "from_server": null,
86 "id": "00ae4a88-3252-4eda-9feb-5f6b56bf5ef0",
87 "modification_date": "2018-07-17T16:42:06.319315+00:00",
88 "name": "Debian Stretch",
89 "organization": "51b656e3-4865-41e8-adbc-0c45bdd780db",
90 "public": true,
91 "root_volume": {
92 "id": "da32dfbb-c5ff-476d-ae2d-c297dd09b7dd",
93 "name": "snapshot-2a7229dc-d431-4dc5-b66e-95db08b773af-2018-07-17_16:18",
94 "size": 25000000000,
95 "volume_type": "l_ssd"
96 },
97 "state": "available"
98 }
99 ]
100 """
101
102 from ansible.module_utils.basic import AnsibleModule
103
104 from ansible_collections.community.general.plugins.module_utils._scaleway import (
105 SCALEWAY_LOCATION,
106 Scaleway,
107 ScalewayException,
108 scaleway_argument_spec,
109 )
110
111
112 class ScalewayImageInfo(Scaleway):
113 def __init__(self, module):
114 super().__init__(module)
115 self.name = "images"
116
117 region = module.params["region"]
118 self.module.params["api_url"] = SCALEWAY_LOCATION[region]["api_endpoint"]
119
120
121 def main():
122 argument_spec = scaleway_argument_spec()
123 argument_spec.update(
124 dict(
125 region=dict(required=True, choices=list(SCALEWAY_LOCATION.keys())),
126 )
127 )
128 module = AnsibleModule(
129 argument_spec=argument_spec,
130 supports_check_mode=True,
131 )
132
133 try:
134 module.exit_json(scaleway_image_info=ScalewayImageInfo(module).get_resources())
135 except ScalewayException as exc:
136 module.fail_json(msg=exc.message)
137
138
139 if __name__ == "__main__":
140 main()