mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-09 01:44:03 -07:00
scaleway: Refactor modules
This commit is contained in:
parent
29cfebe332
commit
8f9d55529d
13 changed files with 544 additions and 652 deletions
|
@ -26,12 +26,13 @@ author: Remy Leone (@sieben)
|
|||
description:
|
||||
- This module manages SSH keys on Scaleway account
|
||||
U(https://developer.scaleway.com)
|
||||
extends_documentation_fragment: scaleway
|
||||
|
||||
options:
|
||||
state:
|
||||
description:
|
||||
- Indicate desired state of the SSH key.
|
||||
required: true
|
||||
default: present
|
||||
choices:
|
||||
- present
|
||||
- absent
|
||||
|
@ -39,18 +40,11 @@ options:
|
|||
description:
|
||||
- The public SSH key as a string to add.
|
||||
required: true
|
||||
oauth_token:
|
||||
api_url:
|
||||
description:
|
||||
- Scaleway OAuth token.
|
||||
required: true
|
||||
timeout:
|
||||
description:
|
||||
- Timeout for API calls
|
||||
default: 30
|
||||
base_url:
|
||||
description:
|
||||
- Base URL for account API
|
||||
default: "https://account.scaleway.com"
|
||||
- Scaleway API URL
|
||||
default: 'https://account.scaleway.com'
|
||||
aliases: ['base_url']
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -83,9 +77,8 @@ data:
|
|||
}
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import env_fallback
|
||||
from ansible.module_utils.scaleway import ScalewayAPI
|
||||
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
||||
from ansible.module_utils.scaleway import scaleway_argument_spec, Scaleway
|
||||
|
||||
|
||||
def extract_present_sshkeys(raw_organization_dict):
|
||||
|
@ -105,12 +98,9 @@ def sshkey_user_patch(ssh_lookup):
|
|||
|
||||
|
||||
def core(module):
|
||||
api_token = module.params['oauth_token']
|
||||
ssh_pub_key = module.params['ssh_pub_key']
|
||||
state = module.params["state"]
|
||||
account_api = ScalewayAPI(module,
|
||||
headers={'X-Auth-Token': api_token},
|
||||
base_url=module.params["base_url"])
|
||||
account_api = Scaleway(module)
|
||||
response = account_api.get('organizations')
|
||||
|
||||
status_code = response.status_code
|
||||
|
@ -166,19 +156,14 @@ def core(module):
|
|||
|
||||
|
||||
def main():
|
||||
argument_spec = scaleway_argument_spec()
|
||||
argument_spec.update(dict(
|
||||
state=dict(default='present', choices=['absent', 'present']),
|
||||
ssh_pub_key=dict(required=True),
|
||||
api_url=dict(fallback=(env_fallback, ['SCW_API_URL']), default='https://account.scaleway.com', aliases=['base_url']),
|
||||
))
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
base_url=dict(default='https://account.scaleway.com'),
|
||||
oauth_token=dict(
|
||||
no_log=True,
|
||||
# Support environment variable for Scaleway OAuth Token
|
||||
fallback=(env_fallback, ['SCW_TOKEN', 'SCW_API_KEY', 'SCW_OAUTH_TOKEN']),
|
||||
required=True,
|
||||
),
|
||||
state=dict(choices=['present', 'absent'], required=True),
|
||||
ssh_pub_key=dict(required=True),
|
||||
timeout=dict(type='int', default=30),
|
||||
),
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue