| 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_server_info |
| 11 |
short_description: Gather information about the Scaleway servers available |
| 12 |
description: |
| 13 |
- Gather information about the Scaleway servers 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 region to use (for example C(par1)). |
| 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 servers information |
| 51 |
community.general.scaleway_server_info: |
| 52 |
region: par1 |
| 53 |
register: result |
| 54 |
|
| 55 |
- ansible.builtin.debug: |
| 56 |
msg: "{{ result.scaleway_server_info }}" |
| 57 |
""" |
| 58 |
|
| 59 |
RETURN = r""" |
| 60 |
scaleway_server_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 |
"boot_type": "local", |
| 72 |
"bootscript": { |
| 73 |
"architecture": "x86_64", |
| 74 |
"bootcmdargs": "LINUX_COMMON scaleway boot=local nbd.max_part=16", |
| 75 |
"default": true, |
| 76 |
"dtb": "", |
| 77 |
"id": "b1e68c26-a19c-4eac-9222-498b22bd7ad9", |
| 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.4-4.4.127-rev1/vmlinuz-4.4.127", |
| 80 |
"organization": "11111111-1111-4111-8111-111111111111", |
| 81 |
"public": true, |
| 82 |
"title": "x86_64 mainline 4.4.127 rev1" |
| 83 |
}, |
| 84 |
"commercial_type": "START1-XS", |
| 85 |
"creation_date": "2018-08-14T21:36:56.271545+00:00", |
| 86 |
"dynamic_ip_required": false, |
| 87 |
"enable_ipv6": false, |
| 88 |
"extra_networks": [], |
| 89 |
"hostname": "scw-e0d256", |
| 90 |
"id": "12f19bc7-108c-4517-954c-e6b3d0311363", |
| 91 |
"image": { |
| 92 |
"arch": "x86_64", |
| 93 |
"creation_date": "2018-04-26T12:42:21.619844+00:00", |
| 94 |
"default_bootscript": { |
| 95 |
"architecture": "x86_64", |
| 96 |
"bootcmdargs": "LINUX_COMMON scaleway boot=local nbd.max_part=16", |
| 97 |
"default": true, |
| 98 |
"dtb": "", |
| 99 |
"id": "b1e68c26-a19c-4eac-9222-498b22bd7ad9", |
| 100 |
"initrd": "http://169.254.42.24/initrd/initrd-Linux-x86_64-v3.14.5.gz", |
| 101 |
"kernel": "http://169.254.42.24/kernel/x86_64-mainline-lts-4.4-4.4.127-rev1/vmlinuz-4.4.127", |
| 102 |
"organization": "11111111-1111-4111-8111-111111111111", |
| 103 |
"public": true, |
| 104 |
"title": "x86_64 mainline 4.4.127 rev1" |
| 105 |
}, |
| 106 |
"extra_volumes": [], |
| 107 |
"from_server": null, |
| 108 |
"id": "67375eb1-f14d-4f02-bb42-6119cecbde51", |
| 109 |
"modification_date": "2018-04-26T12:49:07.573004+00:00", |
| 110 |
"name": "Ubuntu Xenial", |
| 111 |
"organization": "51b656e3-4865-41e8-adbc-0c45bdd780db", |
| 112 |
"public": true, |
| 113 |
"root_volume": { |
| 114 |
"id": "020b8d61-3867-4a0e-84a4-445c5393e05d", |
| 115 |
"name": "snapshot-87fc282d-f252-4262-adad-86979d9074cf-2018-04-26_12:42", |
| 116 |
"size": 25000000000, |
| 117 |
"volume_type": "l_ssd" |
| 118 |
}, |
| 119 |
"state": "available" |
| 120 |
}, |
| 121 |
"ipv6": null, |
| 122 |
"location": { |
| 123 |
"cluster_id": "5", |
| 124 |
"hypervisor_id": "412", |
| 125 |
"node_id": "2", |
| 126 |
"platform_id": "13", |
| 127 |
"zone_id": "par1" |
| 128 |
}, |
| 129 |
"maintenances": [], |
| 130 |
"modification_date": "2018-08-14T21:37:28.630882+00:00", |
| 131 |
"name": "scw-e0d256", |
| 132 |
"organization": "3f709602-5e6c-4619-b80c-e841c89734af", |
| 133 |
"private_ip": "10.14.222.131", |
| 134 |
"protected": false, |
| 135 |
"public_ip": { |
| 136 |
"address": "163.172.170.197", |
| 137 |
"dynamic": false, |
| 138 |
"id": "ea081794-a581-4495-8451-386ddaf0a451" |
| 139 |
}, |
| 140 |
"security_group": { |
| 141 |
"id": "a37379d2-d8b0-4668-9cfb-1233fc436f7e", |
| 142 |
"name": "Default security group" |
| 143 |
}, |
| 144 |
"state": "running", |
| 145 |
"state_detail": "booted", |
| 146 |
"tags": [], |
| 147 |
"volumes": { |
| 148 |
"0": { |
| 149 |
"creation_date": "2018-08-14T21:36:56.271545+00:00", |
| 150 |
"export_uri": "device://dev/vda", |
| 151 |
"id": "68386fae-4f55-4fbf-aabb-953036a85872", |
| 152 |
"modification_date": "2018-08-14T21:36:56.271545+00:00", |
| 153 |
"name": "snapshot-87fc282d-f252-4262-adad-86979d9074cf-2018-04-26_12:42", |
| 154 |
"organization": "3f709602-5e6c-4619-b80c-e841c89734af", |
| 155 |
"server": { |
| 156 |
"id": "12f19bc7-108c-4517-954c-e6b3d0311363", |
| 157 |
"name": "scw-e0d256" |
| 158 |
}, |
| 159 |
"size": 25000000000, |
| 160 |
"state": "available", |
| 161 |
"volume_type": "l_ssd" |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
] |
| 166 |
""" |
| 167 |
|
| 168 |
from ansible.module_utils.basic import AnsibleModule |
| 169 |
|
| 170 |
from ansible_collections.community.general.plugins.module_utils._scaleway import ( |
| 171 |
SCALEWAY_LOCATION, |
| 172 |
Scaleway, |
| 173 |
ScalewayException, |
| 174 |
scaleway_argument_spec, |
| 175 |
) |
| 176 |
|
| 177 |
|
| 178 |
class ScalewayServerInfo(Scaleway): |
| 179 |
def __init__(self, module): |
| 180 |
super().__init__(module) |
| 181 |
self.name = "servers" |
| 182 |
|
| 183 |
region = module.params["region"] |
| 184 |
self.module.params["api_url"] = SCALEWAY_LOCATION[region]["api_endpoint"] |
| 185 |
|
| 186 |
|
| 187 |
def main(): |
| 188 |
argument_spec = scaleway_argument_spec() |
| 189 |
argument_spec.update( |
| 190 |
dict( |
| 191 |
region=dict(required=True, choices=list(SCALEWAY_LOCATION.keys())), |
| 192 |
) |
| 193 |
) |
| 194 |
|
| 195 |
module = AnsibleModule( |
| 196 |
argument_spec=argument_spec, |
| 197 |
supports_check_mode=True, |
| 198 |
) |
| 199 |
|
| 200 |
try: |
| 201 |
module.exit_json(scaleway_server_info=ScalewayServerInfo(module).get_resources()) |
| 202 |
except ScalewayException as exc: |
| 203 |
module.fail_json(msg=exc.message) |
| 204 |
|
| 205 |
|
| 206 |
if __name__ == "__main__": |
| 207 |
main() |