mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-12 11:24:00 -07:00
scaleway: Refactor modules
This commit is contained in:
parent
29cfebe332
commit
8f9d55529d
13 changed files with 544 additions and 652 deletions
|
@ -25,19 +25,16 @@ author: Henryk Konsek (@hekonsek)
|
|||
description:
|
||||
- This module manages volumes on Scaleway account
|
||||
U(https://developer.scaleway.com)
|
||||
extends_documentation_fragment: scaleway
|
||||
|
||||
options:
|
||||
state:
|
||||
description:
|
||||
- Indicate desired state of the volume.
|
||||
required: true
|
||||
default: present
|
||||
choices:
|
||||
- present
|
||||
- absent
|
||||
oauth_token:
|
||||
description:
|
||||
- Scaleway OAuth token.
|
||||
required: true
|
||||
region:
|
||||
description:
|
||||
- Scaleway region to use (for example par1).
|
||||
|
@ -60,10 +57,6 @@ options:
|
|||
volume_type:
|
||||
description:
|
||||
- Type of the volume (for example 'l_ssd').
|
||||
timeout:
|
||||
description:
|
||||
- Timeout for API calls
|
||||
default: 30
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -103,24 +96,18 @@ data:
|
|||
}
|
||||
'''
|
||||
|
||||
from ansible.module_utils.scaleway import ScalewayAPI, SCALEWAY_LOCATION
|
||||
from ansible.module_utils.scaleway import SCALEWAY_LOCATION, scaleway_argument_spec, Scaleway
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import env_fallback
|
||||
from ansible.module_utils.scaleway import ScalewayAPI
|
||||
|
||||
|
||||
def core(module):
|
||||
api_token = module.params['oauth_token']
|
||||
region = module.params['region']
|
||||
state = module.params['state']
|
||||
name = module.params['name']
|
||||
organization = module.params['organization']
|
||||
size = module.params['size']
|
||||
volume_type = module.params['volume_type']
|
||||
|
||||
account_api = ScalewayAPI(module,
|
||||
headers={'X-Auth-Token': api_token},
|
||||
base_url=SCALEWAY_LOCATION[region]['api_endpoint'])
|
||||
account_api = Scaleway(module)
|
||||
response = account_api.get('volumes')
|
||||
status_code = response.status_code
|
||||
volumes_json = response.json
|
||||
|
@ -164,22 +151,17 @@ def core(module):
|
|||
|
||||
|
||||
def main():
|
||||
argument_spec = scaleway_argument_spec()
|
||||
argument_spec.update(dict(
|
||||
state=dict(default='present', choices=['absent', 'present']),
|
||||
name=dict(required=True),
|
||||
size=dict(type='int'),
|
||||
organization=dict(),
|
||||
volume_type=dict(),
|
||||
region=dict(required=True, choices=SCALEWAY_LOCATION.keys()),
|
||||
))
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
region=dict(required=True, choices=SCALEWAY_LOCATION.keys()),
|
||||
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),
|
||||
name=dict(required=True),
|
||||
size=dict(type='int'),
|
||||
organization=dict(),
|
||||
volume_type=dict(),
|
||||
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