Skip to content

Commit e48c9bc

Browse files
JanaHochThulium-Drake
authored andcommitted
proxmox_vnet added docs
- and fix Sanity issues
1 parent ec58f94 commit e48c9bc

File tree

1 file changed

+120
-7
lines changed

1 file changed

+120
-7
lines changed

plugins/modules/proxmox_vnet.py

Lines changed: 120 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,121 @@
99

1010
__metaclass__ = type
1111

12-
from pygments.lexer import default
12+
DOCUMENTATION = r"""
13+
module: proxmox_vnet
14+
short_description: Manage virtual networks in Proxmox SDN
15+
description:
16+
- Create, update, or delete virtual networks in Proxmox SDN.
17+
- Configure network isolation, VLAN awareness, and other network settings.
18+
author: 'Jana Hoch <[email protected]> (!UNKNOWN)'
19+
attributes:
20+
check_mode:
21+
support: none
22+
diff_mode:
23+
support: none
24+
options:
25+
state:
26+
description:
27+
- Desired state of the virtual network.
28+
- Choices include present (create), absent (delete), or update (modify).
29+
type: str
30+
choices: ['present', 'absent', 'update']
31+
default: present
32+
force:
33+
description:
34+
- If true it will create vnet when state is update but vnet is missing and update the vnet when state is present and vnet already exists
35+
type: bool
36+
default: False
37+
vnet:
38+
description:
39+
- The name of the virtual network to be managed.
40+
type: str
41+
zone:
42+
description:
43+
- zone for the virtual network.
44+
type: str
45+
alias:
46+
description:
47+
- An optional alias for the virtual network.
48+
type: str
49+
isolate_ports:
50+
description:
51+
- Enable isolation of ports within the virtual network.
52+
type: bool
53+
default: False
54+
lock_token:
55+
description:
56+
- the token for unlocking the global SDN configuration.
57+
type: str
58+
tag:
59+
description:
60+
- tag for the virtual network.
61+
type: int
62+
type:
63+
description:
64+
- Type of network configuration.
65+
type: str
66+
choices: ['vnet']
67+
vlanaware:
68+
description:
69+
- Enable VLAN awareness for the virtual network.
70+
type: bool
71+
delete:
72+
description:
73+
- A list of settings you want to delete.
74+
type: str
75+
extends_documentation_fragment:
76+
- community.proxmox.proxmox.actiongroup_proxmox
77+
- community.proxmox.proxmox.documentation
78+
- community.proxmox.attributes
79+
"""
1380

14-
DOCUMENTATION = r""""""
1581

16-
EXAMPLES = r""""""
82+
EXAMPLES = r"""
83+
- name: Create a vnet
84+
community.proxmox.proxmox_vnet:
85+
api_user: "{{ pc.proxmox.api_user }}"
86+
api_token_id: "{{ pc.proxmox.api_token_id }}"
87+
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
88+
api_host: "{{ pc.proxmox.api_host }}"
89+
validate_certs: no
90+
vnet: anstest
91+
zone: ans1
92+
state: present
1793
18-
RETURN = r""""""
94+
- name: Update a vnet
95+
community.proxmox.proxmox_vnet:
96+
api_user: "{{ pc.proxmox.api_user }}"
97+
api_token_id: "{{ pc.proxmox.api_token_id }}"
98+
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
99+
api_host: "{{ pc.proxmox.api_host }}"
100+
validate_certs: no
101+
vnet: anstest
102+
zone: ans1
103+
alias: anst
104+
state: update
105+
106+
- name: Delete a vnet
107+
community.proxmox.proxmox_vnet:
108+
api_user: "{{ pc.proxmox.api_user }}"
109+
api_token_id: "{{ pc.proxmox.api_token_id }}"
110+
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
111+
api_host: "{{ pc.proxmox.api_host }}"
112+
validate_certs: no
113+
vnet: anstest
114+
zone: ans1
115+
state: absent
116+
"""
117+
118+
RETURN = r"""
119+
vnet:
120+
description:
121+
- vnet name which was created/updated/deleted
122+
returned: on success
123+
type: str
124+
sample:
125+
anstest
126+
"""
19127

20128
from ansible.module_utils.basic import AnsibleModule
21129
from ansible_collections.community.proxmox.plugins.module_utils.proxmox import (
@@ -24,6 +132,7 @@
24132
ProxmoxAnsible
25133
)
26134

135+
27136
def get_proxmox_args():
28137
return dict(
29138
state=dict(type="str", choices=["present", "absent", "update"], default='present', required=False),
@@ -32,13 +141,14 @@ def get_proxmox_args():
32141
zone=dict(type="str", required=False),
33142
alias=dict(type="str", required=False),
34143
isolate_ports=dict(type="bool", default=False, required=False),
35-
lock_token=dict(type="str", required=False),
144+
lock_token=dict(type="str", required=False, no_log=False),
36145
tag=dict(type="int", required=False),
37146
type=dict(type="str", choices=['vnet'], required=False),
38147
vlanaware=dict(type="bool", required=False),
39148
delete=dict(type="str", required=False)
40149
)
41150

151+
42152
def get_ansible_module():
43153
module_args = proxmox_auth_argument_spec()
44154
module_args.update(get_proxmox_args())
@@ -52,6 +162,7 @@ def get_ansible_module():
52162
]
53163
)
54164

165+
55166
class ProxmoxVnetAnsible(ProxmoxAnsible):
56167
def __init__(self, module):
57168
super(ProxmoxVnetAnsible, self).__init__(module)
@@ -161,9 +272,10 @@ def vnet_absent(self, vnet_name, lock):
161272
self.module.warn(f'Failed to update vnet - {e}')
162273
self.rollback_sdn_changes_and_release_lock(lock)
163274
self.module.fail_json(
164-
msg=f'Failed to delete vnet - {e}. Rolling back all changes.'
275+
msg=f'Failed to delete vnet. Rolling back all changes - {e}'
165276
)
166277

278+
167279
def main():
168280
module = get_ansible_module()
169281
proxmox = ProxmoxVnetAnsible(module)
@@ -173,5 +285,6 @@ def main():
173285
except Exception as e:
174286
module.fail_json(msg=f'An error occurred: {e}')
175287

288+
176289
if __name__ == "__main__":
177-
main()
290+
main()

0 commit comments

Comments
 (0)