Skip to content

Commit af4df05

Browse files
committed
Add rack module
Addded the rack module code as a starting point to fix #133. **Warning**: This code will not work until a `customers` controller is available.
1 parent 3f2942e commit af4df05

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

plugins/modules/rack.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# (c) Christian Meißner 2023
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
from __future__ import absolute_import, division, print_function
19+
__metaclass__ = type
20+
21+
DOCUMENTATION = '''
22+
---
23+
module: rack
24+
version_added: 1.8.0
25+
short_description: Manage racks
26+
description:
27+
- create, update and delete racks
28+
author:
29+
- "Christian Meißner (@cmeissner)"
30+
notes:
31+
- This module needs a phpIPAM backend with version 1.3 or highter.
32+
33+
options:
34+
name:
35+
description: Name of the rack to manage
36+
type: str
37+
required: true
38+
description:
39+
description: A short optional description for the given rack
40+
type: str
41+
required: false
42+
customer:
43+
Description: The customer name to which the rack belongs to
44+
type: str
45+
required: false
46+
location:
47+
description: Name of the location where the rack can be found
48+
type: str
49+
required: false
50+
units:
51+
description: Amount of available units in the given rack
52+
type: int
53+
required: false
54+
default: 42
55+
row:
56+
description: Row where to find the rack
57+
type: int
58+
required: false
59+
default: 1
60+
has_back:
61+
description: Does the rack have a accessible back side
62+
type: bool
63+
required: false
64+
default: false
65+
top_down:
66+
description: Counting units from top to down
67+
type: bool
68+
required: false
69+
default: true
70+
extends_documentation_fragment:
71+
- codeaffen.phpipam.phpipam
72+
- codeaffen.phpipam.phpipam.entity_state
73+
'''
74+
75+
EXAMPLES = '''
76+
- name: "Create a folder"
77+
codeaffen.phpipam.folder:
78+
username: "admin"
79+
password: "s3cr3t"
80+
server_url: "https://ipam.example.com"
81+
name: "Example rack"
82+
Customer: "EXAMPLE INC"
83+
state: present
84+
85+
- name: "Create a folder with parent"
86+
codeaffen.phpipam.folder:
87+
username: "admin"
88+
password: "s3cr3t"
89+
server_url: "https://ipam.example.com"
90+
name: "Example rack"
91+
Customer: "EXAMPLE INC"
92+
units: 22
93+
state: present
94+
'''
95+
96+
RETURN = '''
97+
entity:
98+
description: Final state of the affected entities grouped by their type.
99+
returned: success
100+
type: dict
101+
contains:
102+
racs:
103+
description: List of racks.
104+
type: list
105+
elements: dict
106+
'''
107+
108+
from ansible_collections.codeaffen.phpipam.plugins.module_utils.phpipam_helper import PhpipamEntityAnsibleModule
109+
110+
111+
class PhpipamRackModule(PhpipamEntityAnsibleModule):
112+
pass
113+
114+
115+
def main():
116+
module = PhpipamRackModule(
117+
phpipam_spec=dict(
118+
name=dict(type='str', required=True),
119+
description=dict(type='str'),
120+
customer=dict(type='entity', controller='customer', phpipam_name='customer_id'),
121+
location=dict(type='entity', controller='location'),
122+
untis=dict(type='int', required=True, default=42, phpipam_name='size'),
123+
row=dict(type='int', default=1),
124+
has_back=dict(type='bool', default=False, phpipam_name='hasBack'),
125+
top_down=dict(type='bool', default=True, phpipam_name='topDown'),
126+
),
127+
)
128+
129+
with module.api_connection():
130+
module.run()
131+
132+
133+
if __name__ == "__main__":
134+
main()

0 commit comments

Comments
 (0)