88__metaclass__ = type
99
1010import re
11- import json
1211import traceback
1312import inflection
1413
1514from contextlib import contextmanager
1615
1716try :
1817 import phpypam
19- from phpypam .core .exceptions import PHPyPAMInvalidSyntax
2018 from phpypam import PHPyPAMEntityNotFoundException
2119 HAS_PHPIPAM = True
2220except ImportError :
@@ -37,6 +35,7 @@ class PhpipamAnsibleException(Exception):
3735
3836class 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
0 commit comments