Skip to content

Commit a548124

Browse files
authored
Merge branch 'develop' into issue/33
2 parents 670cb0c + 25c0e84 commit a548124

File tree

6 files changed

+21
-75
lines changed

6 files changed

+21
-75
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ A clear and concise description of what you expected to happen.
2020
**Versions:**
2121

2222
- Ansible:
23-
- phpipam-ansible-modules
24-
- phpypam
23+
- phpipam-ansible-modules:
24+
- phpypam:
2525

2626
**Additional context**
2727
Add any other context about the problem here.

doc_fragments/phpipam.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

plugins/filter/phpipam.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Copyright (c) 2020 Christian Meißner
22
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3-
4-
53
from __future__ import (absolute_import, division, print_function)
64
__metaclass__ = type
75

@@ -10,7 +8,6 @@
108

119

1210
class FilterModule(object):
13-
1411
"""Define useful filter in collection."""
1512

1613
def filters(self):
@@ -29,12 +26,12 @@ def is_subnet(children, parent):
2926
3027
First argument is a subnet second another. If the first subnet belongs to second
3128
32-
:param children: [description]
33-
:type children: [type]
34-
:param parent: [description]
35-
:type parent: [type]
36-
:return: [description]
37-
:rtype: [type]
29+
:param children: First subnet in cidr format which should belongs to parent
30+
:type children: string
31+
:param parent: Second subnet where children should belongs to
32+
:type parent: string
33+
:return: True if children belongs to parent and false if not or both networks are the same.
34+
:rtype: bool
3835
"""
3936
c = ipaddress.ip_network(children)
4037
p = ipaddress.ip_network(parent)

plugins/module_utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Utilities module."""

plugins/module_utils/phpipam_helper.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
__metaclass__ = type
99

1010
import re
11-
import json
1211
import traceback
1312
import inflection
1413

1514
from contextlib import contextmanager
1615

1716
try:
1817
import phpypam
19-
from phpypam.core.exceptions import PHPyPAMInvalidSyntax
2018
from phpypam import PHPyPAMEntityNotFoundException
2119
HAS_PHPIPAM = True
2220
except ImportError:
@@ -37,6 +35,7 @@ class PhpipamAnsibleException(Exception):
3735

3836
class PhpipamAnsibleModule(AnsibleModule):
3937
""" Baseclass for all phpIPAM related ansible modules.
38+
4039
Here we handle connection parameters.
4140
"""
4241

@@ -52,6 +51,7 @@ class PhpipamAnsibleModule(AnsibleModule):
5251
)
5352

5453
def __init__(self, **kwargs):
54+
"""Generate PhpipamAnsibleModule."""
5555
# State recording for changed and diff reporting
5656
self._changed = False
5757
self._before = defaultdict(list)
@@ -94,9 +94,9 @@ def __init__(self, **kwargs):
9494

9595
@contextmanager
9696
def api_connection(self):
97-
"""
98-
Context manager. Run a given code block after successful api connect.
97+
"""Context manager.
9998
99+
Run a given code block after successful api connect.
100100
If the execution is done call `exit_json` to report the module has finished.
101101
"""
102102
self.connect()
@@ -126,8 +126,8 @@ def find_entity(self, controller, path, params=None):
126126
except PHPyPAMEntityNotFoundException:
127127
return None
128128

129-
if type(result) == list:
130-
if len(result) >= 1:
129+
if isinstance(result, list):
130+
if len(result) == 1:
131131
result = result
132132
else:
133133
self.fail_json(msg="Found no results while searching for {0} at {1}".format(controller, path))
@@ -232,7 +232,8 @@ def _resolve_entity(self, key):
232232
return result
233233

234234
def _auto_resolve_entities(self):
235-
"""
235+
"""Resolve entities to the needed id.
236+
236237
Here we resolve each parameter of type entity and create a updated_entity dict with
237238
all params and resolved params
238239
"""
@@ -418,7 +419,9 @@ def __init__(self, **kwargs):
418419

419420
@property
420421
def controller_name_from_class(self):
421-
""" Convert class name to controller name. The class name must follow folowing name convention:
422+
""" Convert class name to controller name.
423+
424+
The class name must follow folowing name convention:
422425
* Starts with Phpipam
423426
* Ends with Module
424427
@@ -460,19 +463,6 @@ def controller_pluralize(self, controller):
460463

461464
return controller
462465

463-
def entity_name_to_id(self, entity_name):
464-
try:
465-
result = self.find_entity(controller=self.controller_uri, controller_path='/' + entity_name)
466-
except PHPyPAMEntityNotFoundException:
467-
raise PhpipamAnsibleException
468-
469-
entity = json.load(result)
470-
471-
try:
472-
return entity['id']
473-
except KeyError:
474-
raise PhpipamAnsibleException
475-
476466
def record_before(self, controller, entity):
477467
self._before[controller].append(entity)
478468

plugins/modules/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Modules init"""

0 commit comments

Comments
 (0)