diff --git a/lib/ansible/modules/cloud/vultr/vultr_block_storage_facts.py b/lib/ansible/modules/cloud/vultr/_vultr_block_storage_facts.py similarity index 95% rename from lib/ansible/modules/cloud/vultr/vultr_block_storage_facts.py rename to lib/ansible/modules/cloud/vultr/_vultr_block_storage_facts.py index 61f6f7ca624..0e28b2b6b32 100644 --- a/lib/ansible/modules/cloud/vultr/vultr_block_storage_facts.py +++ b/lib/ansible/modules/cloud/vultr/_vultr_block_storage_facts.py @@ -7,7 +7,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], + 'status': ['deprecated'], 'supported_by': 'community'} DOCUMENTATION = r''' @@ -18,6 +18,10 @@ description: - Gather facts about block storage volumes available in Vultr. version_added: "2.7" author: "Yanis Guenane (@Spredzy)" +deprecated: + removed_in: "2.12" + why: Transformed into an info module. + alternative: Use M(vultr_block_storage_info) instead. extends_documentation_fragment: vultr ''' diff --git a/lib/ansible/modules/cloud/vultr/vultr_block_storage_info.py b/lib/ansible/modules/cloud/vultr/vultr_block_storage_info.py new file mode 100644 index 00000000000..7ad74709a3f --- /dev/null +++ b/lib/ansible/modules/cloud/vultr/vultr_block_storage_info.py @@ -0,0 +1,156 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2018, Yanis Guenane +# Copyright (c) 2019, René Moser +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community'} + +DOCUMENTATION = r''' +--- +module: vultr_block_storage_info +short_description: Get infos about the Vultr block storage volumes available. +description: + - Get infos about block storage volumes available in Vultr. +version_added: "2.9" +author: + - "Yanis Guenane (@Spredzy)" + - "René Moser (@resmo)" +extends_documentation_fragment: vultr +''' + +EXAMPLES = r''' +- name: Get Vultr block storage infos + vultr_block_storage_info: + register: result + +- name: Print the infos + debug: + var: result.vultr_block_storage_info +''' + +RETURN = r''' +--- +vultr_api: + description: Response from Vultr API with a few additions/modification + returned: success + type: complex + contains: + api_account: + description: Account used in the ini file to select the key + returned: success + type: str + sample: default + api_timeout: + description: Timeout used for the API requests + returned: success + type: int + sample: 60 + api_retries: + description: Amount of max retries for the API requests + returned: success + type: int + sample: 5 + api_endpoint: + description: Endpoint used for the API requests + returned: success + type: str + sample: "https://api.vultr.com" +vultr_block_storage_info: + description: Response from Vultr API as list + returned: success + type: complex + contains: + id: + description: ID of the block storage. + returned: success + type: int + sample: 17332323 + size: + description: Size in GB of the block storage. + returned: success + type: int + sample: 10 + region: + description: Region the block storage is located in. + returned: success + type: str + sample: New Jersey + name: + description: Name of the block storage. + returned: success + type: str + sample: my volume + cost_per_month: + description: Cost per month of the block storage. + returned: success + type: float + sample: 1.0 + date_created: + description: Date created of the block storage. + returned: success + type: str + sample: 2018-07-24 12:59:59 + status: + description: Status of the block storage. + returned: success + type: str + sample: active + attached_to_id: + description: Block storage is attached to this server ID. + returned: success + type: str + sample: null +''' + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vultr import ( + Vultr, + vultr_argument_spec, +) + + +class AnsibleVultrBlockStorageFacts(Vultr): + + def __init__(self, module): + super(AnsibleVultrBlockStorageFacts, self).__init__(module, "vultr_block_storage_info") + + self.returns = { + 'attached_to_SUBID': dict(key='attached_to_id'), + 'cost_per_month': dict(convert_to='float'), + 'date_created': dict(), + 'SUBID': dict(key='id'), + 'label': dict(key='name'), + 'DCID': dict(key='region', transform=self._get_region_name), + 'size_gb': dict(key='size', convert_to='int'), + 'status': dict() + } + + def _get_region_name(self, region): + return self.get_region(region, 'DCID').get('name') + + def get_block_storage_volumes(self): + return self.api_query(path="/v1/block/list") + + +def main(): + argument_spec = vultr_argument_spec() + + module = AnsibleModule( + argument_spec=argument_spec, + supports_check_mode=True, + ) + + volume_info = AnsibleVultrBlockStorageFacts(module) + result = volume_info.get_result(volume_info.get_block_storage_volumes()) + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/vultr_block_storage_facts/tasks/main.yml b/test/integration/targets/vultr_block_storage_facts/tasks/main.yml deleted file mode 100644 index 40fc0e1d536..00000000000 --- a/test/integration/targets/vultr_block_storage_facts/tasks/main.yml +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (c) 2018, Yanis Guenane -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) ---- -- name: test gather vultr block storage volume facts - empty resource - vultr_block_storage_facts: - -- name: Create the block storage volume - vultr_block_storage: - name: '{{ vultr_block_storage_name }}' - size: '{{ vultr_block_storage_size }}' - region: '{{ vultr_block_storage_region }}' - -- name: test gather vultr block storage volume facts in check mode - vultr_block_storage_facts: - check_mode: yes - -- name: verify test gather vultr block storage volume facts in check mode - assert: - that: - - ansible_facts.vultr_block_storage_facts|selectattr('name','equalto','{{ vultr_block_storage_name }}') | list | count == 1 - -- name: test gather vultr block storage volume facts - vultr_block_storage_facts: - -- name: verify test gather vultr block storage volume facts - assert: - that: - - ansible_facts.vultr_block_storage_facts|selectattr('name','equalto','{{ vultr_block_storage_name }}') | list | count == 1 - -- name: Delete the block storage volume - vultr_block_storage: - name: '{{ vultr_block_storage_name }}' - state: absent diff --git a/test/integration/targets/vultr_block_storage_facts/aliases b/test/integration/targets/vultr_block_storage_info/aliases similarity index 100% rename from test/integration/targets/vultr_block_storage_facts/aliases rename to test/integration/targets/vultr_block_storage_info/aliases diff --git a/test/integration/targets/vultr_block_storage_facts/defaults/main.yml b/test/integration/targets/vultr_block_storage_info/defaults/main.yml similarity index 100% rename from test/integration/targets/vultr_block_storage_facts/defaults/main.yml rename to test/integration/targets/vultr_block_storage_info/defaults/main.yml diff --git a/test/integration/targets/vultr_block_storage_info/tasks/main.yml b/test/integration/targets/vultr_block_storage_info/tasks/main.yml new file mode 100644 index 00000000000..1777c25e3a9 --- /dev/null +++ b/test/integration/targets/vultr_block_storage_info/tasks/main.yml @@ -0,0 +1,35 @@ +# Copyright (c) 2018, Yanis Guenane +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +--- +- name: test gather vultr block storage volume info - empty resource + vultr_block_storage_info: + +- name: Create the block storage volume + vultr_block_storage: + name: '{{ vultr_block_storage_name }}' + size: '{{ vultr_block_storage_size }}' + region: '{{ vultr_block_storage_region }}' + +- name: test gather vultr block storage volume info in check mode + vultr_block_storage_info: + check_mode: yes + register: result + +- name: verify test gather vultr block storage volume info in check mode + assert: + that: + - result.vultr_block_storage_info|selectattr('name','equalto','{{ vultr_block_storage_name }}') | list | count == 1 + +- name: test gather vultr block storage volume info + vultr_block_storage_info: + register: result + +- name: verify test gather vultr block storage volume info + assert: + that: + - result.vultr_block_storage_info|selectattr('name','equalto','{{ vultr_block_storage_name }}') | list | count == 1 + +- name: Delete the block storage volume + vultr_block_storage: + name: '{{ vultr_block_storage_name }}' + state: absent