forked from codeaffen/phpipam-ansible-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice.py
More file actions
196 lines (182 loc) · 6.56 KB
/
Copy pathdevice.py
File metadata and controls
196 lines (182 loc) · 6.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# (c) Christian Meißner 2020
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = '''
---
module: device
version_added: 0.5.0
short_description: Manage devices
description:
- create, update and delete devices
author:
- "Christian Meißner (@cmeissner)"
options:
hostname:
description: Hostname of the given device
type: str
required: true
ipaddress:
description: IP address of the given device
type: str
required: false
type:
description:
- Device type of this device.
- The value has to reflect values from device types configured.
- Default device types are I(Switch), I(Router), I(Firewall), I(Hub), I(Wireless), I(Database), I(Workstation), I(Laptop) and I(Other).
- User defined types can be created either via UI, API (e.g. I(device_type) ansible module within this collection).
type: str
required: false
description:
description: A descriptive text for that entity
type: str
required: false
sections:
description: List of sections where the device belongs to
type: list
required: false
rack:
description:
- Rack where the device belongs to.
- If set I(starting_rack_unit) and I(rack_units) are also required.
type: str
required: false
starting_rack_unit:
description:
- Which is the starting rack unit where the device is mounted.
- If set I(rack) and I(racK_units) are also required.
rack_units:
description:
- Size of device in I(U).
- If set I(rack) and I(starting_rack_unit) are also required.
type: int
required: false
snmp_community:
description: The SNMP community string
type: str
required: false
snmp_version:
description: The used SNMP version
type: str
required: false
snmp_port:
description: The used SNMP port
type: str
required: false
default: 161
snmp_timeout:
description: The SNMP connection timeout
type: str
required: false
snmp_queries:
description:
type: str
required: false
snmp_v3_sec_level:
description: The used SNMPv3 security level
type: str
required: false
snmp_v3_auth_protocol:
description: The used SNMPv3 auth protocol
type: str
required: false
snmp_v3_auth_pass:
description: The password to authenticate via SNMPv3
type: str
required: false
snmp_v3_priv_protocol:
description: The used SNMPv3 privacy protocol
type: str
required: false
snmp_v3_priv_pass:
description: The password to authenticate via SNMPv3 in privacy mode
type: str
required: false
snmp_v3_ctx_name:
description: CTX name when using SNMPv3
type: str
required: false
snmp_v3_ctx_engine_id:
description: CTX engine id when using SNMPv3
type: str
required: false
location:
description: Device location
version_added: 1.8.0
type: str
required: false
extends_documentation_fragment:
- codeaffen.phpipam.phpipam
- codeaffen.phpipam.phpipam.entity_state
'''
EXAMPLES = '''
- name: "Create device"
codeaffen.phpipam.device:
username: "admin"
password: "s3cr3t"
server_url: "https://ipam.example.com"
hostname: "leaf-example-01"
ipaddress: "192.0.2.222"
sections:
- Example Inc.
- DEVOPS department
state: present
- name: "Remove device"
codeaffen.phpipam.device:
username: "admin"
password: "s3cr3t"
server_url: "https://ipam.example.com"
name: "leaf-example-001"
state: absent
'''
from ansible_collections.codeaffen.phpipam.plugins.module_utils.phpipam_helper import PhpipamEntityAnsibleModule
class PhpipamDeviceModule(PhpipamEntityAnsibleModule):
pass
def main():
module = PhpipamDeviceModule(
phpipam_spec=dict(
hostname=dict(type='str', required=True),
ipaddress=dict(type='str', phpipam_name='ip'),
type=dict(type='entity', controller='tools/device_types', default='Switch'),
description=dict(type='str'),
sections=dict(type='entity_list', controller='sections', flatten=True, separator=';'),
rack=dict(type='entity', controller='racks'),
starting_rack_unit=dict(type='int', phpipam_name='rack_start'),
rack_units=dict(type='int', phpipam_name='rack_size'),
snmp_community=dict(type='str', no_log=True, phpipam_name='snmp_community'),
snmp_version=dict(type='str', phpipam_name='snmp_version'),
snmp_port=dict(type='str', phpipam_name='snmp_port', default='161'),
snmp_timeout=dict(type='str', phpipam_name='snmp_timeout'),
snmp_queries=dict(type='str', phpipam_name='snmp_queries'),
snmp_v3_sec_level=dict(type='str', phpipam_name='snmp_v3_sec_level'),
snmp_v3_auth_protocol=dict(type='str', phpipam_name='snmp_v3_auth_protocol'),
snmp_v3_auth_pass=dict(type='str', no_log=True, phpipam_name='snmp_v3_auth_pass'),
snmp_v3_priv_protocol=dict(type='str', phpipam_name='snmp_v3_priv_protocol'),
snmp_v3_priv_pass=dict(type='str', no_log=True, phpipam_name='snmp_v3_priv_pass'),
snmp_v3_ctx_name=dict(type='str', phpipam_name='snmp_v3_ctx_name'),
snmp_v3_ctx_engine_id=dict(type='str', phpipam_name='snmp_v3_ctx_engine_id'),
location=dict(type='entity', controller='tools/locations'),
),
required_together=['rack', 'starting_rack', 'rack_units'],
)
if not module.desired_absent:
pass
with module.api_connection():
module.run()
if __name__ == "__main__":
main()