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,7 +126,7 @@ def find_entity(self, controller, path, params=None):
126126 except PHPyPAMEntityNotFoundException :
127127 return None
128128
129- if type (result ) == list :
129+ if isinstance (result , list ) :
130130 if len (result ) == 1 :
131131 result = result [0 ]
132132 else :
@@ -229,7 +229,8 @@ def _resolve_entity(self, key):
229229 return result
230230
231231 def _auto_resolve_entities (self ):
232- """
232+ """Resolve entities to the needed id.
233+
233234 Here we resolve each parameter of type entity and create a updated_entity dict with
234235 all params and resolved params
235236 """
@@ -415,7 +416,9 @@ def __init__(self, **kwargs):
415416
416417 @property
417418 def controller_name_from_class (self ):
418- """ Convert class name to controller name. The class name must follow folowing name convention:
419+ """ Convert class name to controller name.
420+
421+ The class name must follow folowing name convention:
419422 * Starts with Phpipam
420423 * Ends with Module
421424
@@ -457,19 +460,6 @@ def controller_pluralize(self, controller):
457460
458461 return controller
459462
460- def entity_name_to_id (self , entity_name ):
461- try :
462- result = self .find_entity (controller = self .controller_uri , controller_path = '/' + entity_name )
463- except PHPyPAMEntityNotFoundException :
464- raise PhpipamAnsibleException
465-
466- entity = json .load (result )
467-
468- try :
469- return entity ['id' ]
470- except KeyError :
471- raise PhpipamAnsibleException
472-
473463 def record_before (self , controller , entity ):
474464 self ._before [controller ].append (entity )
475465
0 commit comments