Skip to content

Commit dc9ed28

Browse files
committed
WIP - Add module vfs_info module
This module pulls a list of virtual file systems from Vultr. This commit is a WIP because the unit tests require the upcoming vfs module, which does not exist.
1 parent 7a3dddc commit dc9ed28

File tree

8 files changed

+269
-0
lines changed

8 files changed

+269
-0
lines changed

plugins/modules/vfs_info.py

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2025, Samuel Hunter <samuel (at) shunter (dot) xyz>
5+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6+
7+
from __future__ import absolute_import, division, print_function
8+
9+
__metaclass__ = type
10+
11+
12+
DOCUMENTATION = """
13+
---
14+
module: vfs_info
15+
short_description: Get information about Vultr VFS subscriptions
16+
version_added: "1.14.0"
17+
description:
18+
- Get infos about Vultr virtual file system subscriptions available.
19+
author:
20+
- "Samuel Hunter (@samuel-hunter)"
21+
extends_documentation_fragment:
22+
- vultr.cloud.vultr_v2
23+
"""
24+
25+
EXAMPLES = """
26+
- name: Get Vultr vfs infos
27+
vultr.cloud.vfs_info:
28+
register: result
29+
30+
- name: Print the infos
31+
ansible.builtin.debug:
32+
var: result.vultr_vfs_info
33+
"""
34+
35+
RETURN = """
36+
---
37+
vultr_api:
38+
description: Response from Vultr API with a few additions/modification.
39+
returned: success
40+
type: dict
41+
contains:
42+
api_timeout:
43+
description: Timeout used for the API requests.
44+
returned: success
45+
type: int
46+
sample: 60
47+
api_retries:
48+
description: Amount of max retries for the API requests.
49+
returned: success
50+
type: int
51+
sample: 5
52+
api_retry_max_delay:
53+
description: Exponential backoff delay in seconds between retries up to this max delay value.
54+
returned: success
55+
type: int
56+
sample: 12
57+
api_results_per_page:
58+
description: Number of results returned per call to API.
59+
returned: success
60+
type: int
61+
sample: 100
62+
api_endpoint:
63+
description: Endpoint used for the API requests.
64+
returned: success
65+
type: str
66+
sample: "https://api.vultr.com/v2"
67+
vultr_vfs_info:
68+
description: Response from Vultr API as list.
69+
returned: success
70+
type: list
71+
contains:
72+
billing:
73+
description: Billing info
74+
returned: success
75+
type: dict
76+
contains:
77+
charges:
78+
description: Current billing charges
79+
returned: success
80+
type: float
81+
sample: 10.5
82+
monthly:
83+
description: Monthly billing amount
84+
returned: success
85+
type: float
86+
sample: 30
87+
date_created:
88+
description: Creation timestamp of the VFS
89+
returned: success
90+
type: str
91+
sample: "2024-01-01T12:00:00Z"
92+
disk_type:
93+
description: Type of storage disk
94+
returned: success
95+
type: str
96+
sample: nvme
97+
label:
98+
description: User-defined label for the VFS
99+
returned: success
100+
type: str
101+
sample: my file system
102+
id:
103+
description: Unique identifier for the VFS
104+
returned: success
105+
type: str
106+
sample: cb676a46-66fd-4dfb-b839-443f2e6c0b60
107+
region:
108+
description: Region identifier where the VFS is located
109+
returned: success
110+
type: str
111+
sample: ewr
112+
status:
113+
description: Current status of the VFS
114+
returned: success
115+
type: str
116+
sample: active
117+
storage_size:
118+
description: Storage provisioned
119+
returned: success
120+
type: dict
121+
contains:
122+
bytes:
123+
description: Size in bytes
124+
returned: success
125+
type: int
126+
sample: 10737418240
127+
gb:
128+
description: Size in gigabytes
129+
returned: success
130+
type: int
131+
sample: 10
132+
storage_used:
133+
description: Storage used
134+
returned: success
135+
type: dict
136+
contains:
137+
bytes:
138+
description: Size in bytes
139+
returned: success
140+
type: int
141+
sample: 10737418240
142+
gb:
143+
description: Size in gigabytes
144+
returned: success
145+
type: int
146+
sample: 10
147+
tags:
148+
description: List of tags associated with the VFS
149+
returned: success
150+
type: list
151+
elements: str
152+
sample: [ prod, web ]
153+
"""
154+
155+
from ansible.module_utils.basic import AnsibleModule
156+
157+
from ..module_utils.vultr_v2 import AnsibleVultr, vultr_argument_spec
158+
159+
160+
def main():
161+
argument_spec = vultr_argument_spec()
162+
163+
module = AnsibleModule(
164+
argument_spec=argument_spec,
165+
supports_check_mode=True,
166+
)
167+
168+
vultr = AnsibleVultr(
169+
module=module,
170+
namespace="vultr_vfs_info",
171+
resource_path="/vfs",
172+
ressource_result_key_singular="vfs",
173+
ressource_result_key_plural="vfs",
174+
)
175+
176+
vultr.get_result(vultr.query_list())
177+
178+
179+
if __name__ == "__main__":
180+
main()

tests/integration/inventory

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[testgroup]
2+
testhost ansible_connection="local" ansible_pipelining="yes" ansible_python_interpreter="/usr/bin/python"

tests/integration/targets/cleanup/tasks/cleanup_all.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- ansible.builtin.import_tasks: cleanup_user.yml
1515
- ansible.builtin.import_tasks: cleanup_dns_domain.yml
1616
- ansible.builtin.import_tasks: cleanup_block_storage.yml
17+
- ansible.builtin.import_tasks: cleanup_vfs.yml
1718
- ansible.builtin.import_tasks: cleanup_startup_script.yml
1819
- ansible.builtin.import_tasks: cleanup_reserved_ip.yml
1920
- ansible.builtin.import_tasks: cleanup_network.yml
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
- name: cleanup
3+
when: vultr_api_key
4+
block:
5+
- name: List file systems
6+
ansible.builtin.uri:
7+
url: "{{ vultr_api_url }}/vfs"
8+
headers:
9+
Authorization: Bearer {{ vultr_api_key }}
10+
status_code: 200
11+
register: res
12+
no_log: true
13+
14+
- name: Compile results
15+
ansible.builtin.set_fact:
16+
vfs: "{{ res.json.vfs }}"
17+
18+
- name: Found resources
19+
ansible.builtin.debug:
20+
var: vfs
21+
22+
- name: Remove all file systems created by this test run
23+
ansible.builtin.uri:
24+
url: "{{ vultr_api_url }}/vfs/{{ item.id }}"
25+
method: "DELETE"
26+
headers:
27+
Authorization: Bearer {{ vultr_api_key }}
28+
status_code: 204
29+
when: vultr_resource_prefix in item.label
30+
with_items: "{{ vfs }}"
31+
loop_control:
32+
label: "{{ item.label }}"
33+
no_log: true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cloud/vultr
2+
needs/target/common
3+
needs/target/cleanup
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
vultr_resource_prefix: "vultr-test-prefix"
3+
vultr_vfs_name: "{{ vultr_resource_prefix }}-filesystem"
4+
vultr_vfs_size: 10
5+
vultr_vfs_storage_region: ewr
6+
vultr_vfs_disk_type: nvme
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- block:
3+
- ansible.builtin.import_tasks: tests.yml
4+
always:
5+
- ansible.builtin.import_role:
6+
name: cleanup
7+
tasks_from: cleanup_vfs
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) 2025, Samuel Hunter <samuel (at) shunter (dot) xyz>
2+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3+
---
4+
- name: test gather vultr file system info - empty resource
5+
vultr.cloud.vfs_info:
6+
7+
- name: Create the virtual file system
8+
vultr.cloud.vfs:
9+
label: "{{ vultr_vfs_name }}"
10+
storage_size:
11+
gb: "{{ vultr_vfs_size }}"
12+
region: "{{ vultr_vfs_region }}"
13+
disk_type: "{{ vultr_vfs_disk_type }}"
14+
15+
- name: test gather vultr file system info in check mode
16+
vultr.cloud.vfs_info:
17+
check_mode: true
18+
register: result
19+
20+
- name: verify test gather vultr file system info in check mode
21+
ansible.builtin.assert:
22+
that:
23+
- result.vultr_vfs_info|selectattr('label','equalto',vultr_vfs_name) | list | count == 1
24+
25+
- name: test gather vultr file system info
26+
vultr.cloud.vfs_info:
27+
register: result
28+
29+
- name: verify test gather vultr file system info
30+
ansible.builtin.assert:
31+
that:
32+
- result.vultr_vfs_info|selectattr('label','equalto',vultr_vfs_name) | list | count == 1
33+
34+
- name: Delete the block storage volume
35+
vultr.cloud.vfs:
36+
label: "{{ vultr_vfs_name }}"
37+
state: absent

0 commit comments

Comments
 (0)