Skip to content

Commit d9c7898

Browse files
committed
feat: add project_id and organization_id options
1 parent 4c8a60e commit d9c7898

File tree

3 files changed

+79
-44
lines changed

3 files changed

+79
-44
lines changed

plugins/doc_fragments/scaleway.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ class ModuleDocFragment(object):
3838
- Scaleway API URL.
3939
type: str
4040
default: https://api.scaleway.com
41+
project_id:
42+
description:
43+
- Scaleway project ID.
44+
type: str
45+
required: false
46+
organization_id:
47+
description:
48+
- Scaleway organization ID.
49+
type: str
50+
required: false
4151
api_allow_insecure:
4252
description:
4353
- Allow insecure connection to Scaleway API.

plugins/inventory/scaleway.py

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,55 @@
1111
DOCUMENTATION = r"""
1212
name: scaleway
1313
author:
14-
- Nathanael Demacon (@quantumsheep)
14+
- Nathanael Demacon (@quantumsheep)
1515
short_description: Scaleway inventory source
1616
version_added: "1.0.0"
1717
requirements:
18-
- scaleway >= 0.6.0
18+
- scaleway >= 0.6.0
1919
description:
20-
- Scaleway inventory plugin.
21-
- Uses configuration file that ends with '(scaleway|scw).(yaml|yml)'.
20+
- Scaleway inventory plugin.
21+
- Uses configuration file that ends with '(scaleway|scw).(yaml|yml)'.
2222
extends_documentation_fragment:
23-
- scaleway.scaleway.scaleway
24-
- constructed
25-
- inventory_cache
23+
- scaleway.scaleway.scaleway
24+
- constructed
25+
- inventory_cache
2626
options:
27-
plugin:
28-
description:
29-
- The name of the Scaleway Inventory Plugin, this should always be C(scaleway.scaleway.scaleway).
30-
required: true
31-
choices: ['scaleway.scaleway.scaleway']
32-
zones:
33-
description:
34-
- List of zones to filter on.
35-
type: list
36-
elements: str
37-
default:
38-
- fr-par-1
39-
- fr-par-2
40-
- fr-par-3
41-
- nl-ams-1
42-
- nl-ams-2
43-
- pl-waw-1
44-
- pl-waw-2
45-
tags:
46-
description:
47-
- List of tags to filter on.
48-
type: list
49-
elements: str
50-
default: []
51-
hostnames:
52-
description: List of preference about what to use as an hostname.
53-
type: list
54-
elements: str
55-
default:
56-
- public_ipv4
57-
choices:
58-
- public_ipv4
59-
- private_ipv4
60-
- public_ipv6
61-
- hostname
62-
- id
27+
plugin:
28+
description:
29+
- The name of the Scaleway Inventory Plugin, this should always be C(scaleway.scaleway.scaleway).
30+
required: true
31+
choices: ['scaleway.scaleway.scaleway']
32+
zones:
33+
description:
34+
- List of zones to filter on.
35+
type: list
36+
elements: str
37+
default:
38+
- fr-par-1
39+
- fr-par-2
40+
- fr-par-3
41+
- nl-ams-1
42+
- nl-ams-2
43+
- pl-waw-1
44+
- pl-waw-2
45+
tags:
46+
description:
47+
- List of tags to filter on.
48+
type: list
49+
elements: str
50+
default: []
51+
hostnames:
52+
description: List of preference about what to use as an hostname.
53+
type: list
54+
elements: str
55+
default:
56+
- public_ipv4
57+
choices:
58+
- public_ipv4
59+
- private_ipv4
60+
- public_ipv6
61+
- hostname
62+
- id
6363
"""
6464

6565
EXAMPLES = r"""
@@ -177,7 +177,12 @@ def populate(self, results: List[_Host]):
177177

178178
for result in results:
179179
groups = self.get_host_groups(result)
180-
hostname = self._get_hostname(result, hostnames)
180+
181+
try:
182+
hostname = self._get_hostname(result, hostnames)
183+
except AnsibleError as e:
184+
self.display.warning(f"Skipping host {result.id}: {e}")
185+
continue
181186

182187
for group in groups:
183188
self.inventory.add_group(group=group)
@@ -308,6 +313,8 @@ def _get_client(self):
308313
profile = self.get_option("profile")
309314
access_key = self.get_option("access_key")
310315
secret_key = self.get_option("secret_key")
316+
organization_id = self.get_option("organization_id")
317+
project_id = self.get_option("project_id")
311318
api_url = self.get_option("api_url")
312319
api_allow_insecure = self.get_option("api_allow_insecure")
313320
user_agent = self.get_option("user_agent")
@@ -326,6 +333,12 @@ def _get_client(self):
326333
if secret_key:
327334
client.secret_key = secret_key
328335

336+
if organization_id:
337+
client.default_organization_id = organization_id
338+
339+
if project_id:
340+
client.default_project_id = project_id
341+
329342
if api_url:
330343
client.api_url = api_url
331344

plugins/module_utils/scaleway.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def scaleway_argument_spec() -> Dict[str, Dict[str, Any]]:
5353
fallback=(env_fallback, [ENV_KEY_SCW_API_URL]),
5454
default="https://api.scaleway.com",
5555
),
56+
organization_id=dict(type="str", required=False),
57+
project_id=dict(type="str", required=False),
5658
api_allow_insecure=dict(type="bool", default=False),
5759
user_agent=dict(type="str", required=False),
5860
)
@@ -73,6 +75,8 @@ def scaleway_get_client_from_module(module: AnsibleModule):
7375
profile = module.params["profile"]
7476
access_key = module.params["access_key"]
7577
secret_key = module.params["secret_key"]
78+
organization_id = module.params["organization_id"]
79+
project_id = module.params["project_id"]
7680
api_url = module.params["api_url"]
7781
api_allow_insecure = module.params["api_allow_insecure"]
7882
user_agent = module.params["user_agent"]
@@ -91,6 +95,12 @@ def scaleway_get_client_from_module(module: AnsibleModule):
9195
if secret_key:
9296
client.secret_key = secret_key
9397

98+
if organization_id:
99+
client.default_organization_id = organization_id
100+
101+
if project_id:
102+
client.default_project_id = project_id
103+
94104
if api_url:
95105
client.api_url = api_url
96106

@@ -109,6 +119,8 @@ def scaleway_pop_client_params(module: AnsibleModule) -> None:
109119
"profile",
110120
"access_key",
111121
"secret_key",
122+
"organization_id",
123+
"project_id",
112124
"api_url",
113125
"api_allow_insecure",
114126
"user_agent",

0 commit comments

Comments
 (0)