9
9
10
10
__metaclass__ = type
11
11
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
+ """
13
80
14
- DOCUMENTATION = r""""""
15
81
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
17
93
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
+ """
19
127
20
128
from ansible .module_utils .basic import AnsibleModule
21
129
from ansible_collections .community .proxmox .plugins .module_utils .proxmox import (
24
132
ProxmoxAnsible
25
133
)
26
134
135
+
27
136
def get_proxmox_args ():
28
137
return dict (
29
138
state = dict (type = "str" , choices = ["present" , "absent" , "update" ], default = 'present' , required = False ),
@@ -32,13 +141,14 @@ def get_proxmox_args():
32
141
zone = dict (type = "str" , required = False ),
33
142
alias = dict (type = "str" , required = False ),
34
143
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 ),
36
145
tag = dict (type = "int" , required = False ),
37
146
type = dict (type = "str" , choices = ['vnet' ], required = False ),
38
147
vlanaware = dict (type = "bool" , required = False ),
39
148
delete = dict (type = "str" , required = False )
40
149
)
41
150
151
+
42
152
def get_ansible_module ():
43
153
module_args = proxmox_auth_argument_spec ()
44
154
module_args .update (get_proxmox_args ())
@@ -52,6 +162,7 @@ def get_ansible_module():
52
162
]
53
163
)
54
164
165
+
55
166
class ProxmoxVnetAnsible (ProxmoxAnsible ):
56
167
def __init__ (self , module ):
57
168
super (ProxmoxVnetAnsible , self ).__init__ (module )
@@ -161,9 +272,10 @@ def vnet_absent(self, vnet_name, lock):
161
272
self .module .warn (f'Failed to update vnet - { e } ' )
162
273
self .rollback_sdn_changes_and_release_lock (lock )
163
274
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 } '
165
276
)
166
277
278
+
167
279
def main ():
168
280
module = get_ansible_module ()
169
281
proxmox = ProxmoxVnetAnsible (module )
@@ -173,5 +285,6 @@ def main():
173
285
except Exception as e :
174
286
module .fail_json (msg = f'An error occurred: { e } ' )
175
287
288
+
176
289
if __name__ == "__main__" :
177
- main ()
290
+ main ()
0 commit comments