Browse code

Various fixes (#34815)

This patch was primarily an effort to reduce traceback errors for
work that sivel was doing. Part of (and in some cases in addition to)
that, the following was done.

* Removed re-def of cleanup_tokens.
* Changed parameter args to be keywords.
* Changed imports to include new module_util locations.
* Imports also include developing (sideband) module_util locations.
* Changed to using F5Client and plain AnsibleModule to prevent tracebacks caused by missing libraries.
* Removed init and update methods from most Parameter classes (optimization) as its now included in module_utils.
* Changed module and module param references to take into account the new self.module arg.
* Minor bug fixes made during this refactor.

Tim Rupp authored on 2018/01/13 05:08:49
Showing 22 changed files
... ...
@@ -98,8 +98,6 @@ options:
98 98
       - Device partition to manage resources on.
99 99
     default: Common
100 100
 extends_documentation_fragment: f5
101
-requirements:
102
-  - f5-sdk >= 3.0.4
103 101
 author:
104 102
   - Wojciech Wypior (@wojtek0806)
105 103
   - Tim Rupp (@caphrim007)
... ...
@@ -219,50 +217,42 @@ name:
219 219
 import os
220 220
 import time
221 221
 
222
-from ansible.module_utils.f5_utils import AnsibleF5Client
223
-from ansible.module_utils.f5_utils import AnsibleF5Parameters
224
-from ansible.module_utils.f5_utils import HAS_F5SDK
225
-from ansible.module_utils.f5_utils import F5ModuleError
226
-from ansible.module_utils.six import iteritems
227
-from collections import defaultdict
228 222
 from distutils.version import LooseVersion
223
+from ansible.module_utils.basic import AnsibleModule
224
+from ansible.module_utils.basic import env_fallback
225
+
226
+HAS_DEVEL_IMPORTS = False
229 227
 
230 228
 try:
231
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
229
+    # Sideband repository used for dev
230
+    from library.module_utils.network.f5.bigip import HAS_F5SDK
231
+    from library.module_utils.network.f5.bigip import F5Client
232
+    from library.module_utils.network.f5.common import F5ModuleError
233
+    from library.module_utils.network.f5.common import AnsibleF5Parameters
234
+    from library.module_utils.network.f5.common import cleanup_tokens
235
+    from library.module_utils.network.f5.common import fqdn_name
236
+    from library.module_utils.network.f5.common import f5_argument_spec
237
+    try:
238
+        from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
239
+    except ImportError:
240
+        HAS_F5SDK = False
241
+    HAS_DEVEL_IMPORTS = True
232 242
 except ImportError:
233
-    HAS_F5SDK = False
243
+    # Upstream Ansible
244
+    from ansible.module_utils.network.f5.bigip import HAS_F5SDK
245
+    from ansible.module_utils.network.f5.bigip import F5Client
246
+    from ansible.module_utils.network.f5.common import F5ModuleError
247
+    from ansible.module_utils.network.f5.common import AnsibleF5Parameters
248
+    from ansible.module_utils.network.f5.common import cleanup_tokens
249
+    from ansible.module_utils.network.f5.common import fqdn_name
250
+    from ansible.module_utils.network.f5.common import f5_argument_spec
251
+    try:
252
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
253
+    except ImportError:
254
+        HAS_F5SDK = False
234 255
 
235 256
 
236 257
 class Parameters(AnsibleF5Parameters):
237
-    def __init__(self, params=None):
238
-        self._values = defaultdict(lambda: None)
239
-        if params:
240
-            self.update(params=params)
241
-
242
-    def update(self, params=None):
243
-        if params:
244
-            for k, v in iteritems(params):
245
-                if self.api_map is not None and k in self.api_map:
246
-                    map_key = self.api_map[k]
247
-                else:
248
-                    map_key = k
249
-
250
-                # Handle weird API parameters like `dns.proxy.__iter__` by
251
-                # using a map provided by the module developer
252
-                class_attr = getattr(type(self), map_key, None)
253
-                if isinstance(class_attr, property):
254
-                    # There is a mapped value for the api_map key
255
-                    if class_attr.fset is None:
256
-                        # If the mapped value does not have
257
-                        # an associated setter
258
-                        self._values[map_key] = v
259
-                    else:
260
-                        # The mapped value has a setter
261
-                        setattr(self, map_key, v)
262
-                else:
263
-                    # If the mapped value is not a @property
264
-                    self._values[map_key] = v
265
-
266 258
     updatables = [
267 259
         'active'
268 260
     ]
... ...
@@ -290,17 +280,12 @@ class Parameters(AnsibleF5Parameters):
290 290
 
291 291
     @property
292 292
     def full_path(self):
293
-        return self._fqdn_name(self.name)
293
+        return fqdn_name(self.name)
294 294
 
295 295
     def _templates_from_device(self):
296 296
         collection = self.client.api.tm.asm.policy_templates_s.get_collection()
297 297
         return collection
298 298
 
299
-    def _fqdn_name(self, value):
300
-        if value is not None and not value.startswith('/'):
301
-            return '/{0}/{1}'.format(self.partition, value)
302
-        return value
303
-
304 299
     def to_return(self):
305 300
         result = {}
306 301
         for returnable in self.returnables:
... ...
@@ -308,16 +293,6 @@ class Parameters(AnsibleF5Parameters):
308 308
         result = self._filter_params(result)
309 309
         return result
310 310
 
311
-    def api_params(self):
312
-        result = {}
313
-        for api_attribute in self.api_attributes:
314
-            if self.api_map is not None and api_attribute in self.api_map:
315
-                result[api_attribute] = getattr(self, self.api_map[api_attribute])
316
-            else:
317
-                result[api_attribute] = getattr(self, api_attribute)
318
-        result = self._filter_params(result)
319
-        return result
320
-
321 311
 
322 312
 class V1Parameters(Parameters):
323 313
     @property
... ...
@@ -483,8 +458,9 @@ class Difference(object):
483 483
 
484 484
 
485 485
 class BaseManager(object):
486
-    def __init__(self, client):
487
-        self.client = client
486
+    def __init__(self, *args, **kwargs):
487
+        self.client = kwargs.get('client', None)
488
+        self.module = kwargs.get('module', None)
488 489
         self.have = None
489 490
         self.changes = Changes()
490 491
 
... ...
@@ -512,7 +488,7 @@ class BaseManager(object):
512 512
             if getattr(self.want, key) is not None:
513 513
                 changed[key] = getattr(self.want, key)
514 514
         if changed:
515
-            self.changes = Changes(changed)
515
+            self.changes = Changes(params=changed)
516 516
 
517 517
     def should_update(self):
518 518
         result = self._update_changed_options()
... ...
@@ -534,7 +510,7 @@ class BaseManager(object):
534 534
                 else:
535 535
                     changed[k] = change
536 536
         if changed:
537
-            self.changes = Changes(changed)
537
+            self.changes = Changes(params=changed)
538 538
             return True
539 539
         return False
540 540
 
... ...
@@ -554,9 +530,12 @@ class BaseManager(object):
554 554
         policies = self.client.api.tm.asm.policies_s.get_collection()
555 555
         if any(p.name == self.want.name and p.partition == self.want.partition for p in policies):
556 556
             return True
557
+
557 558
         return False
558 559
 
559 560
     def _file_is_missing(self):
561
+        if self.want.template and self.want.file is None:
562
+            return False
560 563
         if not os.path.exists(self.want.file):
561 564
             return True
562 565
         return False
... ...
@@ -570,7 +549,7 @@ class BaseManager(object):
570 570
                 "The specified ASM policy file does not exist"
571 571
             )
572 572
         self._set_changed_options()
573
-        if self.client.check_mode:
573
+        if self.module.check_mode:
574 574
             return True
575 575
 
576 576
         if self.want.template is None and self.want.file is None:
... ...
@@ -595,7 +574,7 @@ class BaseManager(object):
595 595
         self.have = self.read_current_from_device()
596 596
         if not self.should_update():
597 597
             return False
598
-        if self.client.check_mode:
598
+        if self.module.check_mode:
599 599
             return True
600 600
         self.update_on_device()
601 601
         if self.changes.active:
... ...
@@ -641,7 +620,7 @@ class BaseManager(object):
641 641
             )
642 642
 
643 643
     def remove(self):
644
-        if self.client.check_mode:
644
+        if self.module.check_mode:
645 645
             return True
646 646
         self.remove_from_device()
647 647
         if self.exists():
... ...
@@ -662,7 +641,7 @@ class BaseManager(object):
662 662
             if policy.name == self.want.name and policy.partition == self.want.partition:
663 663
                 params = policy.attrs
664 664
                 params.update(dict(self_link=policy.selfLink))
665
-                return Parameters(params)
665
+                return Parameters(params=params)
666 666
         raise F5ModuleError("The policy was not found")
667 667
 
668 668
     def import_to_device(self):
... ...
@@ -710,8 +689,9 @@ class BaseManager(object):
710 710
 
711 711
 
712 712
 class ModuleManager(object):
713
-    def __init__(self, client):
714
-        self.client = client
713
+    def __init__(self, *args, **kwargs):
714
+        self.client = kwargs.get('client', None)
715
+        self.kwargs = kwargs
715 716
 
716 717
     def exec_module(self):
717 718
         if self.version_is_less_than_13():
... ...
@@ -722,9 +702,9 @@ class ModuleManager(object):
722 722
 
723 723
     def get_manager(self, type):
724 724
         if type == 'v1':
725
-            return V1Manager(self.client)
725
+            return V1Manager(**self.kwargs)
726 726
         elif type == 'v2':
727
-            return V2Manager(self.client)
727
+            return V2Manager(**self.kwargs)
728 728
 
729 729
     def version_is_less_than_13(self):
730 730
         version = self.client.api.tmos_version
... ...
@@ -735,19 +715,19 @@ class ModuleManager(object):
735 735
 
736 736
 
737 737
 class V1Manager(BaseManager):
738
-    def __init__(self, client):
739
-        super(V1Manager, self).__init__(client)
740
-        self.want = V1Parameters()
741
-        self.want.client = self.client
742
-        self.want.update(self.client.module.params)
738
+    def __init__(self, *args, **kwargs):
739
+        client = kwargs.get('client', None)
740
+        module = kwargs.get('module', None)
741
+        super(V1Manager, self).__init__(client=client, module=module)
742
+        self.want = V1Parameters(params=module.params, client=client)
743 743
 
744 744
 
745 745
 class V2Manager(BaseManager):
746
-    def __init__(self, client):
747
-        super(V2Manager, self).__init__(client)
748
-        self.want = V2Parameters()
749
-        self.want.client = self.client
750
-        self.want.update(self.client.module.params)
746
+    def __init__(self, *args, **kwargs):
747
+        client = kwargs.get('client', None)
748
+        module = kwargs.get('module', None)
749
+        super(V2Manager, self).__init__(client=client, module=module)
750
+        self.want = V2Parameters(params=module.params, client=client)
751 751
 
752 752
 
753 753
 class ArgumentSpec(object):
... ...
@@ -790,7 +770,7 @@ class ArgumentSpec(object):
790 790
             'Wordpress',
791 791
         ]
792 792
         self.supports_check_mode = True
793
-        self.argument_spec = dict(
793
+        argument_spec = dict(
794 794
             name=dict(
795 795
                 required=True,
796 796
             ),
... ...
@@ -800,44 +780,43 @@ class ArgumentSpec(object):
800 800
             ),
801 801
             active=dict(
802 802
                 type='bool'
803
+            ),
804
+            state=dict(
805
+                default='present',
806
+                choices=['present', 'absent']
807
+            ),
808
+            partition=dict(
809
+                default='Common',
810
+                fallback=(env_fallback, ['F5_PARTITION'])
803 811
             )
804 812
         )
805
-        self.f5_product_name = 'bigip'
806
-
807
-
808
-def cleanup_tokens(client):
809
-    try:
810
-        resource = client.api.shared.authz.tokens_s.token.load(
811
-            name=client.api.icrs.token
812
-        )
813
-        resource.delete()
814
-    except Exception:
815
-        pass
813
+        self.argument_spec = {}
814
+        self.argument_spec.update(f5_argument_spec)
815
+        self.argument_spec.update(argument_spec)
816 816
 
817 817
 
818 818
 def main():
819
-    if not HAS_F5SDK:
820
-        raise F5ModuleError("The python f5-sdk module is required")
821
-
822 819
     spec = ArgumentSpec()
823 820
 
824
-    client = AnsibleF5Client(
821
+    module = AnsibleModule(
825 822
         argument_spec=spec.argument_spec,
826 823
         supports_check_mode=spec.supports_check_mode,
827
-        f5_product_name=spec.f5_product_name,
828 824
         mutually_exclusive=[
829 825
             ['file', 'template']
830 826
         ]
831 827
     )
828
+    if not HAS_F5SDK:
829
+        module.fail_json(msg="The python f5-sdk module is required")
832 830
 
833 831
     try:
834
-        mm = ModuleManager(client)
832
+        client = F5Client(**module.params)
833
+        mm = ModuleManager(module=module, client=client)
835 834
         results = mm.exec_module()
836 835
         cleanup_tokens(client)
837
-        client.module.exit_json(**results)
836
+        module.exit_json(**results)
838 837
     except F5ModuleError as e:
839 838
         cleanup_tokens(client)
840
-        client.module.fail_json(msg=str(e))
839
+        module.fail_json(msg=str(e))
841 840
 
842 841
 if __name__ == '__main__':
843 842
     main()
... ...
@@ -162,66 +162,55 @@ failed_conditions:
162 162
 import re
163 163
 import time
164 164
 
165
-from ansible.module_utils.basic import env_fallback
166
-from ansible.module_utils.f5_utils import AnsibleF5Client
167
-from ansible.module_utils.f5_utils import AnsibleF5Parameters
168
-from ansible.module_utils.f5_utils import HAS_F5SDK
169
-from ansible.module_utils.f5_utils import F5ModuleError
170
-
171 165
 try:
172 166
     from ansible.module_utils.f5_utils import run_commands
173 167
     HAS_CLI_TRANSPORT = True
174 168
 except ImportError:
175 169
     HAS_CLI_TRANSPORT = False
176 170
 
171
+from ansible.module_utils.basic import AnsibleModule
172
+from ansible.module_utils.basic import env_fallback
177 173
 from ansible.module_utils.six import string_types
178 174
 from ansible.module_utils.network.common.parsing import FailedConditionsError
179 175
 from ansible.module_utils.network.common.parsing import Conditional
180 176
 from ansible.module_utils.network.common.utils import ComplexList
181 177
 from ansible.module_utils.network.common.utils import to_list
182
-from ansible.module_utils.six import iteritems
183
-from collections import defaultdict
184 178
 from collections import deque
185 179
 
180
+HAS_DEVEL_IMPORTS = False
181
+
186 182
 try:
187
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
183
+    # Sideband repository used for dev
184
+    from library.module_utils.network.f5.bigip import HAS_F5SDK
185
+    from library.module_utils.network.f5.bigip import F5Client
186
+    from library.module_utils.network.f5.common import F5ModuleError
187
+    from library.module_utils.network.f5.common import AnsibleF5Parameters
188
+    from library.module_utils.network.f5.common import cleanup_tokens
189
+    from library.module_utils.network.f5.common import fqdn_name
190
+    from library.module_utils.network.f5.common import f5_argument_spec
191
+    try:
192
+        from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
193
+    except ImportError:
194
+        HAS_F5SDK = False
195
+    HAS_DEVEL_IMPORTS = True
188 196
 except ImportError:
189
-    HAS_F5SDK = False
197
+    # Upstream Ansible
198
+    from ansible.module_utils.network.f5.bigip import HAS_F5SDK
199
+    from ansible.module_utils.network.f5.bigip import F5Client
200
+    from ansible.module_utils.network.f5.common import F5ModuleError
201
+    from ansible.module_utils.network.f5.common import AnsibleF5Parameters
202
+    from ansible.module_utils.network.f5.common import cleanup_tokens
203
+    from ansible.module_utils.network.f5.common import fqdn_name
204
+    from ansible.module_utils.network.f5.common import f5_argument_spec
205
+    try:
206
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
207
+    except ImportError:
208
+        HAS_F5SDK = False
190 209
 
191 210
 
192 211
 class Parameters(AnsibleF5Parameters):
193 212
     returnables = ['stdout', 'stdout_lines', 'warnings']
194 213
 
195
-    def __init__(self, params=None):
196
-        self._values = defaultdict(lambda: None)
197
-        self._values['__warnings'] = []
198
-        if params:
199
-            self.update(params=params)
200
-
201
-    def update(self, params=None):
202
-        if params:
203
-            for k, v in iteritems(params):
204
-                if self.api_map is not None and k in self.api_map:
205
-                    map_key = self.api_map[k]
206
-                else:
207
-                    map_key = k
208
-
209
-                # Handle weird API parameters like `dns.proxy.__iter__` by
210
-                # using a map provided by the module developer
211
-                class_attr = getattr(type(self), map_key, None)
212
-                if isinstance(class_attr, property):
213
-                    # There is a mapped value for the api_map key
214
-                    if class_attr.fset is None:
215
-                        # If the mapped value does not have
216
-                        # an associated setter
217
-                        self._values[map_key] = v
218
-                    else:
219
-                        # The mapped value has a setter
220
-                        setattr(self, map_key, v)
221
-                else:
222
-                    # If the mapped value is not a @property
223
-                    self._values[map_key] = v
224
-
225 214
     def to_return(self):
226 215
         result = {}
227 216
         for returnable in self.returnables:
... ...
@@ -260,9 +249,10 @@ class Parameters(AnsibleF5Parameters):
260 260
 
261 261
 
262 262
 class ModuleManager(object):
263
-    def __init__(self, client):
264
-        self.client = client
265
-        self.want = Parameters(self.client.module.params)
263
+    def __init__(self, *args, **kwargs):
264
+        self.module = kwargs.get('module', None)
265
+        self.client = kwargs.get('client', None)
266
+        self.want = Parameters(params=self.module.params)
266 267
         self.changes = Parameters()
267 268
 
268 269
     def _to_lines(self, stdout):
... ...
@@ -278,7 +268,7 @@ class ModuleManager(object):
278 278
             'list', 'show',
279 279
             'modify cli preference pager disabled'
280 280
         ]
281
-        if self.client.module.params['transport'] != 'cli':
281
+        if self.module.params['transport'] != 'cli':
282 282
             valid_configs = list(map(self.want._ensure_tmsh_prefix, valid_configs))
283 283
         if any(cmd.startswith(x) for x in valid_configs):
284 284
             return True
... ...
@@ -308,12 +298,12 @@ class ModuleManager(object):
308 308
 
309 309
         conditionals = [Conditional(c) for c in wait_for]
310 310
 
311
-        if self.client.check_mode:
311
+        if self.module.check_mode:
312 312
             return
313 313
 
314 314
         while retries > 0:
315
-            if self.client.module.params['transport'] == 'cli' and HAS_CLI_TRANSPORT:
316
-                responses = self._run_commands(self.client.module, commands)
315
+            if self.module.params['transport'] == 'cli' and HAS_CLI_TRANSPORT:
316
+                responses = self._run_commands(self.module, commands)
317 317
             else:
318 318
                 responses = self.execute_on_device(commands)
319 319
 
... ...
@@ -334,11 +324,12 @@ class ModuleManager(object):
334 334
             errmsg = 'One or more conditional statements have not been satisfied'
335 335
             raise FailedConditionsError(errmsg, failed_conditions)
336 336
 
337
-        self.changes = Parameters({
337
+        changes = {
338 338
             'stdout': responses,
339 339
             'stdout_lines': self._to_lines(responses),
340 340
             'warnings': warnings
341
-        })
341
+        }
342
+        self.changes = Parameters(params=changes)
342 343
         if any(x for x in self.want.user_commands if x.startswith(changed)):
343 344
             return True
344 345
         return False
... ...
@@ -354,11 +345,11 @@ class ModuleManager(object):
354 354
             ),
355 355
         )
356 356
 
357
-        transform = ComplexList(spec, self.client.module)
357
+        transform = ComplexList(spec, self.module)
358 358
         commands = transform(commands)
359 359
 
360 360
         for index, item in enumerate(commands):
361
-            if not self._is_valid_mode(item['command']) and self.client.module.params['transport'] != 'cli':
361
+            if not self._is_valid_mode(item['command']) and self.module.params['transport'] != 'cli':
362 362
                 warnings.append(
363 363
                     'Using "write" commands is not idempotent. You should use '
364 364
                     'a module that is specifically made for that. If such a '
... ...
@@ -394,7 +385,7 @@ class ModuleManager(object):
394 394
 class ArgumentSpec(object):
395 395
     def __init__(self):
396 396
         self.supports_check_mode = True
397
-        self.argument_spec = dict(
397
+        argument_spec = dict(
398 398
             commands=dict(
399 399
                 type='raw',
400 400
                 required=True
... ...
@@ -421,44 +412,38 @@ class ArgumentSpec(object):
421 421
                 choices=['cli', 'rest']
422 422
             ),
423 423
             password=dict(
424
-                required=False,
425 424
                 fallback=(env_fallback, ['F5_PASSWORD']),
426 425
                 no_log=True
426
+            ),
427
+            partition=dict(
428
+                default='Common',
429
+                fallback=(env_fallback, ['F5_PARTITION'])
427 430
             )
428 431
         )
429
-        self.f5_product_name = 'bigip'
430
-
431
-
432
-def cleanup_tokens(client):
433
-    try:
434
-        resource = client.api.shared.authz.tokens_s.token.load(
435
-            name=client.api.icrs.token
436
-        )
437
-        resource.delete()
438
-    except Exception:
439
-        pass
432
+        self.argument_spec = {}
433
+        self.argument_spec.update(f5_argument_spec)
434
+        self.argument_spec.update(argument_spec)
440 435
 
441 436
 
442 437
 def main():
443 438
     spec = ArgumentSpec()
444 439
 
445
-    client = AnsibleF5Client(
440
+    module = AnsibleModule(
446 441
         argument_spec=spec.argument_spec,
447
-        supports_check_mode=spec.supports_check_mode,
448
-        f5_product_name=spec.f5_product_name
442
+        supports_check_mode=spec.supports_check_mode
449 443
     )
450
-
451
-    if client.module.params['transport'] != 'cli' and not HAS_F5SDK:
452
-        raise F5ModuleError("The python f5-sdk module is required to use the rest api")
444
+    if module.params['transport'] != 'cli' and not HAS_F5SDK:
445
+        module.fail_json(msg="The python f5-sdk module is required to use the rest api")
453 446
 
454 447
     try:
455
-        mm = ModuleManager(client)
448
+        client = F5Client(**module.params)
449
+        mm = ModuleManager(module=module, client=client)
456 450
         results = mm.exec_module()
457 451
         cleanup_tokens(client)
458
-        client.module.exit_json(**results)
452
+        module.exit_json(**results)
459 453
     except F5ModuleError as e:
460 454
         cleanup_tokens(client)
461
-        client.module.fail_json(msg=str(e))
455
+        module.fail_json(msg=str(e))
462 456
 
463 457
 
464 458
 if __name__ == '__main__':
... ...
@@ -34,18 +34,14 @@ options:
34 34
         no changes are made, the configuration is still saved to the
35 35
         startup config. This option will always cause the module to
36 36
         return changed.
37
-    choices:
38
-      - yes
39
-      - no
37
+    type: bool
40 38
     default: no
41 39
   reset:
42 40
     description:
43 41
       - Loads the default configuration on the device. If this option
44 42
         is specified, the default configuration will be loaded before
45 43
         any commands or other provided configuration is run.
46
-    choices:
47
-      - yes
48
-      - no
44
+    type: bool
49 45
     default: no
50 46
   merge_content:
51 47
     description:
... ...
@@ -59,15 +55,8 @@ options:
59 59
       - Validates the specified configuration to see whether they are
60 60
         valid to replace the running configuration. The running
61 61
         configuration will not be changed.
62
-    choices:
63
-      - yes
64
-      - no
65
-    default: yes
66
-notes:
67
-  - Requires the f5-sdk Python package on the host. This is as easy as pip
68
-    install f5-sdk.
69
-requirements:
70
-  - f5-sdk >= 2.2.3
62
+    type: bool
63
+    default: no
71 64
 extends_documentation_fragment: f5
72 65
 author:
73 66
   - Tim Rupp (@caphrim007)
... ...
@@ -125,27 +114,42 @@ try:
125 125
 except ImportError:
126 126
     from io import StringIO
127 127
 
128
-from ansible.module_utils.f5_utils import AnsibleF5Client
129
-from ansible.module_utils.f5_utils import AnsibleF5Parameters
130
-from ansible.module_utils.f5_utils import HAS_F5SDK
131
-from ansible.module_utils.f5_utils import F5ModuleError
132
-from ansible.module_utils.six import iteritems
133
-from collections import defaultdict
128
+from ansible.module_utils.basic import AnsibleModule
129
+
130
+HAS_DEVEL_IMPORTS = False
134 131
 
135 132
 try:
136
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
133
+    # Sideband repository used for dev
134
+    from library.module_utils.network.f5.bigip import HAS_F5SDK
135
+    from library.module_utils.network.f5.bigip import F5Client
136
+    from library.module_utils.network.f5.common import F5ModuleError
137
+    from library.module_utils.network.f5.common import AnsibleF5Parameters
138
+    from library.module_utils.network.f5.common import cleanup_tokens
139
+    from library.module_utils.network.f5.common import fqdn_name
140
+    from library.module_utils.network.f5.common import f5_argument_spec
141
+    try:
142
+        from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
143
+    except ImportError:
144
+        HAS_F5SDK = False
145
+    HAS_DEVEL_IMPORTS = True
137 146
 except ImportError:
138
-    HAS_F5SDK = False
147
+    # Upstream Ansible
148
+    from ansible.module_utils.network.f5.bigip import HAS_F5SDK
149
+    from ansible.module_utils.network.f5.bigip import F5Client
150
+    from ansible.module_utils.network.f5.common import F5ModuleError
151
+    from ansible.module_utils.network.f5.common import AnsibleF5Parameters
152
+    from ansible.module_utils.network.f5.common import cleanup_tokens
153
+    from ansible.module_utils.network.f5.common import fqdn_name
154
+    from ansible.module_utils.network.f5.common import f5_argument_spec
155
+    try:
156
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
157
+    except ImportError:
158
+        HAS_F5SDK = False
139 159
 
140 160
 
141 161
 class Parameters(AnsibleF5Parameters):
142 162
     returnables = ['stdout', 'stdout_lines']
143 163
 
144
-    def __init__(self, params=None):
145
-        self._values = defaultdict(lambda: None)
146
-        if params:
147
-            self.update(params)
148
-
149 164
     def to_return(self):
150 165
         result = {}
151 166
         for returnable in self.returnables:
... ...
@@ -153,34 +157,12 @@ class Parameters(AnsibleF5Parameters):
153 153
         result = self._filter_params(result)
154 154
         return result
155 155
 
156
-    def update(self, params=None):
157
-        if params:
158
-            for k, v in iteritems(params):
159
-                if self.api_map is not None and k in self.api_map:
160
-                    map_key = self.api_map[k]
161
-                else:
162
-                    map_key = k
163
-
164
-                # Handle weird API parameters like `dns.proxy.__iter__` by
165
-                # using a map provided by the module developer
166
-                class_attr = getattr(type(self), map_key, None)
167
-                if isinstance(class_attr, property):
168
-                    # There is a mapped value for the api_map key
169
-                    if class_attr.fset is None:
170
-                        # If the mapped value does not have an associated setter
171
-                        self._values[map_key] = v
172
-                    else:
173
-                        # The mapped value has a setter
174
-                        setattr(self, map_key, v)
175
-                else:
176
-                    # If the mapped value is not a @property
177
-                    self._values[map_key] = v
178
-
179 156
 
180 157
 class ModuleManager(object):
181
-    def __init__(self, client):
182
-        self.client = client
183
-        self.want = Parameters(self.client.module.params)
158
+    def __init__(self, *args, **kwargs):
159
+        self.module = kwargs.get('module', None)
160
+        self.client = kwargs.get('client', None)
161
+        self.want = Parameters(params=self.module.params)
184 162
         self.changes = Parameters()
185 163
 
186 164
     def _set_changed_options(self):
... ...
@@ -189,7 +171,7 @@ class ModuleManager(object):
189 189
             if getattr(self.want, key) is not None:
190 190
                 changed[key] = getattr(self.want, key)
191 191
         if changed:
192
-            self.changes = Parameters(changed)
192
+            self.changes = Parameters(params=changed)
193 193
 
194 194
     def _to_lines(self, stdout):
195 195
         lines = list()
... ...
@@ -229,13 +211,14 @@ class ModuleManager(object):
229 229
             response = self.save()
230 230
             responses.append(response)
231 231
 
232
-        self.changes = Parameters({
232
+        changes = {
233 233
             'stdout': responses,
234 234
             'stdout_lines': self._to_lines(responses)
235
-        })
235
+        }
236
+        self.changes = Parameters(params=changes)
236 237
 
237 238
     def reset(self):
238
-        if self.client.check_mode:
239
+        if self.module.check_mode:
239 240
             return True
240 241
         return self.reset_device()
241 242
 
... ...
@@ -254,7 +237,7 @@ class ModuleManager(object):
254 254
         remote_path = "/var/config/rest/downloads/{0}".format(temp_name)
255 255
         temp_path = '/tmp/' + temp_name
256 256
 
257
-        if self.client.check_mode:
257
+        if self.module.check_mode:
258 258
             return True
259 259
 
260 260
         self.upload_to_device(temp_name)
... ...
@@ -302,7 +285,7 @@ class ModuleManager(object):
302 302
         upload.upload_stringio(template, temp_name)
303 303
 
304 304
     def save(self):
305
-        if self.client.check_mode:
305
+        if self.module.check_mode:
306 306
             return True
307 307
         return self.save_on_device()
308 308
 
... ...
@@ -321,7 +304,7 @@ class ModuleManager(object):
321 321
 class ArgumentSpec(object):
322 322
     def __init__(self):
323 323
         self.supports_check_mode = True
324
-        self.argument_spec = dict(
324
+        argument_spec = dict(
325 325
             reset=dict(
326 326
                 type='bool',
327 327
                 default=False
... ...
@@ -329,46 +312,37 @@ class ArgumentSpec(object):
329 329
             merge_content=dict(),
330 330
             verify=dict(
331 331
                 type='bool',
332
-                default=True
332
+                default=False
333 333
             ),
334 334
             save=dict(
335 335
                 type='bool',
336 336
                 default=True
337 337
             )
338 338
         )
339
-        self.f5_product_name = 'bigip'
340
-
341
-
342
-def cleanup_tokens(client):
343
-    try:
344
-        resource = client.api.shared.authz.tokens_s.token.load(
345
-            name=client.api.icrs.token
346
-        )
347
-        resource.delete()
348
-    except Exception:
349
-        pass
339
+        self.argument_spec = {}
340
+        self.argument_spec.update(f5_argument_spec)
341
+        self.argument_spec.update(argument_spec)
350 342
 
351 343
 
352 344
 def main():
353
-    if not HAS_F5SDK:
354
-        raise F5ModuleError("The python f5-sdk module is required")
355
-
356 345
     spec = ArgumentSpec()
357 346
 
358
-    client = AnsibleF5Client(
347
+    module = AnsibleModule(
359 348
         argument_spec=spec.argument_spec,
360
-        supports_check_mode=spec.supports_check_mode,
361
-        f5_product_name=spec.f5_product_name
349
+        supports_check_mode=spec.supports_check_mode
362 350
     )
351
+    if not HAS_F5SDK:
352
+        module.fail_json(msg="The python f5-sdk module is required")
363 353
 
364 354
     try:
365
-        mm = ModuleManager(client)
355
+        client = F5Client(**module.params)
356
+        mm = ModuleManager(module=module, client=client)
366 357
         results = mm.exec_module()
367 358
         cleanup_tokens(client)
368
-        client.module.exit_json(**results)
369
-    except F5ModuleError as e:
359
+        module.exit_json(**results)
360
+    except F5ModuleError as ex:
370 361
         cleanup_tokens(client)
371
-        client.module.fail_json(msg=str(e))
362
+        module.fail_json(msg=str(ex))
372 363
 
373 364
 
374 365
 if __name__ == '__main__':
... ...
@@ -53,12 +53,8 @@ options:
53 53
       - yes
54 54
       - no
55 55
 notes:
56
-  - Requires the f5-sdk Python package on the host. This is as easy as pip
57
-    install f5-sdk.
58
-  - Requires the objectpath Python package on the host. This is as easy as pip
59
-    install objectpath.
60
-requirements:
61
-  - f5-sdk >= 2.2.3
56
+  - Requires the objectpath Python package on the host. This is as easy as
57
+    C(pip install objectpath).
62 58
 extends_documentation_fragment: f5
63 59
 author:
64 60
   - Tim Rupp (@caphrim007)
... ...
@@ -100,8 +96,8 @@ RETURN = r'''
100 100
 # only common fields returned
101 101
 '''
102 102
 
103
-import time
104 103
 import re
104
+import time
105 105
 
106 106
 try:
107 107
     from objectpath import Tree
... ...
@@ -109,16 +105,38 @@ try:
109 109
 except ImportError:
110 110
     HAS_OBJPATH = False
111 111
 
112
+from ansible.module_utils.basic import AnsibleModule
112 113
 from ansible.module_utils.basic import BOOLEANS_TRUE
113
-from ansible.module_utils.f5_utils import AnsibleF5Client
114
-from ansible.module_utils.f5_utils import AnsibleF5Parameters
115
-from ansible.module_utils.f5_utils import HAS_F5SDK
116
-from ansible.module_utils.f5_utils import F5ModuleError
114
+
115
+HAS_DEVEL_IMPORTS = False
117 116
 
118 117
 try:
119
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
118
+    # Sideband repository used for dev
119
+    from library.module_utils.network.f5.bigip import HAS_F5SDK
120
+    from library.module_utils.network.f5.bigip import F5Client
121
+    from library.module_utils.network.f5.common import F5ModuleError
122
+    from library.module_utils.network.f5.common import AnsibleF5Parameters
123
+    from library.module_utils.network.f5.common import cleanup_tokens
124
+    from library.module_utils.network.f5.common import fqdn_name
125
+    from library.module_utils.network.f5.common import f5_argument_spec
126
+    try:
127
+        from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
128
+    except ImportError:
129
+        HAS_F5SDK = False
130
+    HAS_DEVEL_IMPORTS = True
120 131
 except ImportError:
121
-    HAS_F5SDK = False
132
+    # Upstream Ansible
133
+    from ansible.module_utils.network.f5.bigip import HAS_F5SDK
134
+    from ansible.module_utils.network.f5.bigip import F5Client
135
+    from ansible.module_utils.network.f5.common import F5ModuleError
136
+    from ansible.module_utils.network.f5.common import AnsibleF5Parameters
137
+    from ansible.module_utils.network.f5.common import cleanup_tokens
138
+    from ansible.module_utils.network.f5.common import fqdn_name
139
+    from ansible.module_utils.network.f5.common import f5_argument_spec
140
+    try:
141
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
142
+    except ImportError:
143
+        HAS_F5SDK = False
122 144
 
123 145
 
124 146
 class Parameters(AnsibleF5Parameters):
... ...
@@ -184,9 +202,11 @@ class Parameters(AnsibleF5Parameters):
184 184
 
185 185
 
186 186
 class ModuleManager(object):
187
-    def __init__(self, client):
188
-        self.client = client
189
-        self.want = Parameters(self.client.module.params)
187
+    def __init__(self, *args, **kwargs):
188
+        self.module = kwargs.get('module', None)
189
+        self.client = kwargs.get('client', None)
190
+        self.want = Parameters(params=self.module.params)
191
+        self.changes = Parameters()
190 192
 
191 193
     def exec_module(self):
192 194
         result = dict()
... ...
@@ -319,8 +339,9 @@ class ModuleManager(object):
319 319
 
320 320
 class ArgumentSpec(object):
321 321
     def __init__(self):
322
-        self.supports_check_mode = True
323
-        self.argument_spec = dict(
322
+        self.supports_check_mode = False
323
+
324
+        argument_spec = dict(
324 325
             sync_device_to_group=dict(
325 326
                 type='bool'
326 327
             ),
... ...
@@ -335,7 +356,10 @@ class ArgumentSpec(object):
335 335
                 required=True
336 336
             )
337 337
         )
338
-        self.f5_product_name = 'bigip'
338
+        self.argument_spec = {}
339
+        self.argument_spec.update(f5_argument_spec)
340
+        self.argument_spec.update(argument_spec)
341
+
339 342
         self.required_one_of = [
340 343
             ['sync_device_to_group', 'sync_most_recent_to_device']
341 344
         ]
... ...
@@ -347,45 +371,27 @@ class ArgumentSpec(object):
347 347
         ]
348 348
 
349 349
 
350
-def cleanup_tokens(client):
351
-    try:
352
-        resource = client.api.shared.authz.tokens_s.token.load(
353
-            name=client.api.icrs.token
354
-        )
355
-        resource.delete()
356
-    except Exception:
357
-        pass
358
-
359
-
360 350
 def main():
361
-    if not HAS_F5SDK:
362
-        raise F5ModuleError(
363
-            "The python 'f5-sdk' module is required. This can be done with 'pip install f5-sdk'"
364
-        )
365
-
366
-    if not HAS_OBJPATH:
367
-        raise F5ModuleError(
368
-            "The python 'objectpath' module is required. This can be done with 'pip install objectpath'"
369
-        )
370
-
371 351
     spec = ArgumentSpec()
372 352
 
373
-    client = AnsibleF5Client(
353
+    module = AnsibleModule(
374 354
         argument_spec=spec.argument_spec,
375 355
         supports_check_mode=spec.supports_check_mode,
376 356
         mutually_exclusive=spec.mutually_exclusive,
377
-        required_one_of=spec.required_one_of,
378
-        f5_product_name=spec.f5_product_name
357
+        required_one_of=spec.required_one_of
379 358
     )
359
+    if not HAS_F5SDK:
360
+        module.fail_json(msg="The python f5-sdk module is required")
380 361
 
381 362
     try:
382
-        mm = ModuleManager(client)
363
+        client = F5Client(**module.params)
364
+        mm = ModuleManager(module=module, client=client)
383 365
         results = mm.exec_module()
384 366
         cleanup_tokens(client)
385
-        client.module.exit_json(**results)
386
-    except F5ModuleError as e:
367
+        module.exit_json(**results)
368
+    except F5ModuleError as ex:
387 369
         cleanup_tokens(client)
388
-        client.module.fail_json(msg=str(e))
370
+        module.fail_json(msg=str(ex))
389 371
 
390 372
 
391 373
 if __name__ == '__main__':
392 374
deleted file mode 120000
... ...
@@ -1 +0,0 @@
1
-bigip_configsync_action.py
2 1
\ No newline at end of file
... ...
@@ -70,13 +70,9 @@ options:
70 70
         provided, a default of C(62960) will be used. This value must be between
71 71
         0 and 65535.
72 72
 notes:
73
-  - Requires the f5-sdk Python package on the host. This is as easy as pip
74
-    install f5-sdk.
75 73
   - This module is primarily used as a component of configuring HA pairs of
76 74
     BIG-IP devices.
77 75
   - Requires BIG-IP >= 12.0.0
78
-requirements:
79
-  - f5-sdk >= 2.2.3
80 76
 extends_documentation_fragment: f5
81 77
 author:
82 78
   - Tim Rupp (@caphrim007)
... ...
@@ -142,26 +138,49 @@ multicast_port:
142 142
   sample: 1026
143 143
 '''
144 144
 
145
-from ansible.module_utils.f5_utils import AnsibleF5Client
146
-from ansible.module_utils.f5_utils import AnsibleF5Parameters
147
-from ansible.module_utils.f5_utils import HAS_F5SDK
148
-from ansible.module_utils.f5_utils import F5ModuleError
145
+from ansible.module_utils.basic import AnsibleModule
149 146
 from ansible.module_utils.six import iteritems
150 147
 
148
+HAS_DEVEL_IMPORTS = False
149
+
151 150
 try:
152
-    from netaddr import IPAddress, AddrFormatError
153
-    HAS_NETADDR = True
151
+    # Sideband repository used for dev
152
+    from library.module_utils.network.f5.bigip import HAS_F5SDK
153
+    from library.module_utils.network.f5.bigip import F5Client
154
+    from library.module_utils.network.f5.common import F5ModuleError
155
+    from library.module_utils.network.f5.common import AnsibleF5Parameters
156
+    from library.module_utils.network.f5.common import cleanup_tokens
157
+    from library.module_utils.network.f5.common import fqdn_name
158
+    from library.module_utils.network.f5.common import f5_argument_spec
159
+    try:
160
+        from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
161
+    except ImportError:
162
+        HAS_F5SDK = False
163
+    HAS_DEVEL_IMPORTS = True
154 164
 except ImportError:
155
-    HAS_NETADDR = False
165
+    # Upstream Ansible
166
+    from ansible.module_utils.network.f5.bigip import HAS_F5SDK
167
+    from ansible.module_utils.network.f5.bigip import F5Client
168
+    from ansible.module_utils.network.f5.common import F5ModuleError
169
+    from ansible.module_utils.network.f5.common import AnsibleF5Parameters
170
+    from ansible.module_utils.network.f5.common import cleanup_tokens
171
+    from ansible.module_utils.network.f5.common import fqdn_name
172
+    from ansible.module_utils.network.f5.common import f5_argument_spec
173
+    try:
174
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
175
+    except ImportError:
176
+        HAS_F5SDK = False
156 177
 
157 178
 try:
158
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
179
+    from netaddr import IPAddress, AddrFormatError
180
+    HAS_NETADDR = True
159 181
 except ImportError:
160
-    HAS_F5SDK = False
182
+    HAS_NETADDR = False
161 183
 
162 184
 
163 185
 class Parameters(AnsibleF5Parameters):
164 186
     api_map = {
187
+        'unicastAddress': 'unicast_failover',
165 188
         'configsyncIp': 'config_sync_ip',
166 189
         'multicastInterface': 'multicast_interface',
167 190
         'multicastIp': 'multicast_address',
... ...
@@ -234,44 +253,6 @@ class Parameters(AnsibleF5Parameters):
234 234
         result = self._get_validated_ip_address('config_sync_ip')
235 235
         return result
236 236
 
237
-    @property
238
-    def unicastAddress(self):
239
-        return self.unicast_failover
240
-
241
-    @unicastAddress.setter
242
-    def unicastAddress(self, value):
243
-        result = []
244
-        for item in value:
245
-            item['address'] = item.pop('ip')
246
-            result.append(item)
247
-        if result:
248
-            self._values['unicast_failover'] = result
249
-
250
-    @property
251
-    def unicast_failover(self):
252
-        if self._values['unicast_failover'] is None:
253
-            return None
254
-        if self._values['unicast_failover'] == ['none']:
255
-            return []
256
-        result = []
257
-        for item in self._values['unicast_failover']:
258
-            address = item.get('address', None)
259
-            port = item.get('port', None)
260
-            address = self._validate_unicast_failover_address(address)
261
-            port = self._validate_unicast_failover_port(port)
262
-            result.append(
263
-                dict(
264
-                    effectiveIp=address,
265
-                    effectivePort=port,
266
-                    ip=address,
267
-                    port=port
268
-                )
269
-            )
270
-        if result:
271
-            return result
272
-        else:
273
-            return None
274
-
275 237
     def _validate_unicast_failover_port(self, port):
276 238
         try:
277 239
             result = int(port)
... ...
@@ -310,15 +291,36 @@ class Parameters(AnsibleF5Parameters):
310 310
                 )
311 311
             )
312 312
 
313
-    def api_params(self):
314
-        result = {}
315
-        for api_attribute in self.api_attributes:
316
-            if self.api_map is not None and api_attribute in self.api_map:
317
-                result[api_attribute] = getattr(self, self.api_map[api_attribute])
318
-            else:
319
-                result[api_attribute] = getattr(self, api_attribute)
320
-        result = self._filter_params(result)
321
-        return result
313
+
314
+class ApiParameters(Parameters):
315
+    pass
316
+
317
+
318
+class ModuleParameters(Parameters):
319
+    @property
320
+    def unicast_failover(self):
321
+        if self._values['unicast_failover'] is None:
322
+            return None
323
+        if self._values['unicast_failover'] == ['none']:
324
+            return []
325
+        result = []
326
+        for item in self._values['unicast_failover']:
327
+            address = item.get('address', None)
328
+            port = item.get('port', None)
329
+            address = self._validate_unicast_failover_address(address)
330
+            port = self._validate_unicast_failover_port(port)
331
+            result.append(
332
+                dict(
333
+                    effectiveIp=address,
334
+                    effectivePort=port,
335
+                    ip=address,
336
+                    port=port
337
+                )
338
+            )
339
+        if result:
340
+            return result
341
+        else:
342
+            return None
322 343
 
323 344
 
324 345
 class Changes(Parameters):
... ...
@@ -459,9 +461,10 @@ class Difference(object):
459 459
 
460 460
 
461 461
 class ModuleManager(object):
462
-    def __init__(self, client):
463
-        self.client = client
464
-        self.want = Parameters(self.client.module.params)
462
+    def __init__(self, *args, **kwargs):
463
+        self.module = kwargs.get('module', None)
464
+        self.client = kwargs.get('client', None)
465
+        self.want = ModuleParameters(params=self.module.params)
465 466
         self.changes = UsableChanges()
466 467
 
467 468
     def _update_changed_options(self):
... ...
@@ -478,7 +481,7 @@ class ModuleManager(object):
478 478
                 else:
479 479
                     changed[k] = change
480 480
         if changed:
481
-            self.changes = UsableChanges(changed)
481
+            self.changes = UsableChanges(params=changed)
482 482
             return True
483 483
         return False
484 484
 
... ...
@@ -499,7 +502,7 @@ class ModuleManager(object):
499 499
         except iControlUnexpectedHTTPError as e:
500 500
             raise F5ModuleError(str(e))
501 501
 
502
-        reportable = ReportableChanges(self.changes.to_return())
502
+        reportable = ReportableChanges(params=self.changes.to_return())
503 503
         changes = reportable.to_return()
504 504
         result.update(**changes)
505 505
         result.update(dict(changed=changed))
... ...
@@ -509,7 +512,7 @@ class ModuleManager(object):
509 509
         self.have = self.read_current_from_device()
510 510
         if not self.should_update():
511 511
             return False
512
-        if self.client.check_mode:
512
+        if self.module.check_mode:
513 513
             return True
514 514
         self.update_on_device()
515 515
         return True
... ...
@@ -530,7 +533,7 @@ class ModuleManager(object):
530 530
         for resource in collection:
531 531
             if resource.selfDevice == 'true':
532 532
                 result = resource.attrs
533
-                return Parameters(result)
533
+                return ApiParameters(params=result)
534 534
         raise F5ModuleError(
535 535
             "The host device was not found."
536 536
         )
... ...
@@ -539,7 +542,7 @@ class ModuleManager(object):
539 539
 class ArgumentSpec(object):
540 540
     def __init__(self):
541 541
         self.supports_check_mode = True
542
-        self.argument_spec = dict(
542
+        argument_spec = dict(
543 543
             multicast_port=dict(
544 544
                 type='int'
545 545
             ),
... ...
@@ -559,45 +562,37 @@ class ArgumentSpec(object):
559 559
                 choices=['present']
560 560
             )
561 561
         )
562
-        self.f5_product_name = 'bigip'
562
+        self.argument_spec = {}
563
+        self.argument_spec.update(f5_argument_spec)
564
+        self.argument_spec.update(argument_spec)
563 565
         self.required_together = [
564 566
             ['multicast_address', 'multicast_interface', 'multicast_port']
565 567
         ]
566 568
 
567 569
 
568
-def cleanup_tokens(client):
569
-    try:
570
-        resource = client.api.shared.authz.tokens_s.token.load(
571
-            name=client.api.icrs.token
572
-        )
573
-        resource.delete()
574
-    except Exception:
575
-        pass
576
-
577
-
578 570
 def main():
579
-    if not HAS_F5SDK:
580
-        raise F5ModuleError("The python f5-sdk module is required")
581
-
582
-    if not HAS_NETADDR:
583
-        raise F5ModuleError("The python netaddr module is required")
584
-
585 571
     spec = ArgumentSpec()
586 572
 
587
-    client = AnsibleF5Client(
573
+    module = AnsibleModule(
588 574
         argument_spec=spec.argument_spec,
589 575
         supports_check_mode=spec.supports_check_mode,
590
-        f5_product_name=spec.f5_product_name
576
+        required_together=spec.required_together
591 577
     )
578
+    if not HAS_F5SDK:
579
+        module.fail_json(msg="The python f5-sdk module is required")
580
+
581
+    if not HAS_NETADDR:
582
+        module.fail_json(msg="The python netaddr module is required")
592 583
 
593 584
     try:
594
-        mm = ModuleManager(client)
585
+        client = F5Client(**module.params)
586
+        mm = ModuleManager(module=module, client=client)
595 587
         results = mm.exec_module()
596 588
         cleanup_tokens(client)
597
-        client.module.exit_json(**results)
598
-    except F5ModuleError as e:
589
+        module.exit_json(**results)
590
+    except F5ModuleError as ex:
599 591
         cleanup_tokens(client)
600
-        client.module.fail_json(msg=str(e))
592
+        module.fail_json(msg=str(ex))
601 593
 
602 594
 
603 595
 if __name__ == '__main__':
... ...
@@ -55,12 +55,7 @@ options:
55 55
     choices:
56 56
       - absent
57 57
       - present
58
-notes:
59
-  - Requires the f5-sdk Python package on the host. This is as easy as pip
60
-    install f5-sdk.
61 58
 extends_documentation_fragment: f5
62
-requirements:
63
-  - f5-sdk
64 59
 author:
65 60
   - Tim Rupp (@caphrim007)
66 61
 '''
... ...
@@ -109,15 +104,37 @@ warnings:
109 109
   sample: ['...', '...']
110 110
 '''
111 111
 
112
-from ansible.module_utils.f5_utils import AnsibleF5Client
113
-from ansible.module_utils.f5_utils import AnsibleF5Parameters
114
-from ansible.module_utils.f5_utils import HAS_F5SDK
115
-from ansible.module_utils.f5_utils import F5ModuleError
112
+from ansible.module_utils.basic import AnsibleModule
113
+
114
+HAS_DEVEL_IMPORTS = False
116 115
 
117 116
 try:
118
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
117
+    # Sideband repository used for dev
118
+    from library.module_utils.network.f5.bigip import HAS_F5SDK
119
+    from library.module_utils.network.f5.bigip import F5Client
120
+    from library.module_utils.network.f5.common import F5ModuleError
121
+    from library.module_utils.network.f5.common import AnsibleF5Parameters
122
+    from library.module_utils.network.f5.common import cleanup_tokens
123
+    from library.module_utils.network.f5.common import fqdn_name
124
+    from library.module_utils.network.f5.common import f5_argument_spec
125
+    try:
126
+        from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
127
+    except ImportError:
128
+        HAS_F5SDK = False
129
+    HAS_DEVEL_IMPORTS = True
119 130
 except ImportError:
120
-    HAS_F5SDK = False
131
+    # Upstream Ansible
132
+    from ansible.module_utils.network.f5.bigip import HAS_F5SDK
133
+    from ansible.module_utils.network.f5.bigip import F5Client
134
+    from ansible.module_utils.network.f5.common import F5ModuleError
135
+    from ansible.module_utils.network.f5.common import AnsibleF5Parameters
136
+    from ansible.module_utils.network.f5.common import cleanup_tokens
137
+    from ansible.module_utils.network.f5.common import fqdn_name
138
+    from ansible.module_utils.network.f5.common import f5_argument_spec
139
+    try:
140
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
141
+    except ImportError:
142
+        HAS_F5SDK = False
121 143
 
122 144
 
123 145
 class Parameters(AnsibleF5Parameters):
... ...
@@ -151,16 +168,6 @@ class Parameters(AnsibleF5Parameters):
151 151
         result = self._filter_params(result)
152 152
         return result
153 153
 
154
-    def api_params(self):
155
-        result = {}
156
-        for api_attribute in self.api_attributes:
157
-            if self.api_map is not None and api_attribute in self.api_map:
158
-                result[api_attribute] = getattr(self, self.api_map[api_attribute])
159
-            else:
160
-                result[api_attribute] = getattr(self, api_attribute)
161
-        result = self._filter_params(result)
162
-        return result
163
-
164 154
     @property
165 155
     def search(self):
166 156
         result = []
... ...
@@ -211,10 +218,11 @@ class Parameters(AnsibleF5Parameters):
211 211
 
212 212
 
213 213
 class ModuleManager(object):
214
-    def __init__(self, client):
215
-        self.client = client
214
+    def __init__(self, *args, **kwargs):
215
+        self.module = kwargs.get('module', None)
216
+        self.client = kwargs.get('client', None)
217
+        self.want = Parameters(params=self.module.params)
216 218
         self.have = None
217
-        self.want = Parameters(self.client.module.params)
218 219
         self.changes = Parameters()
219 220
 
220 221
     def _update_changed_options(self):
... ...
@@ -226,7 +234,7 @@ class ModuleManager(object):
226 226
                 if attr1 != attr2:
227 227
                     changed[key] = attr1
228 228
         if changed:
229
-            self.changes = Parameters(changed)
229
+            self.changes = Parameters(params=changed)
230 230
             return True
231 231
         return False
232 232
 
... ...
@@ -260,13 +268,13 @@ class ModuleManager(object):
260 260
         if 'include' not in attrs:
261 261
             attrs['include'] = 4
262 262
         result.update(attrs)
263
-        return Parameters(result)
263
+        return Parameters(params=result)
264 264
 
265 265
     def update(self):
266 266
         self.have = self.read_current_from_device()
267 267
         if not self.should_update():
268 268
             return False
269
-        if self.client.check_mode:
269
+        if self.module.check_mode:
270 270
             return True
271 271
         self.update_on_device()
272 272
         return True
... ...
@@ -299,7 +307,7 @@ class ModuleManager(object):
299 299
                 if set_new != set_have:
300 300
                     changed[key] = list(set_new)
301 301
         if changed:
302
-            self.changes = Parameters(changed)
302
+            self.changes = Parameters(params=changed)
303 303
             return True
304 304
         return False
305 305
 
... ...
@@ -313,7 +321,7 @@ class ModuleManager(object):
313 313
         self.have = self.read_current_from_device()
314 314
         if not self.should_absent():
315 315
             return False
316
-        if self.client.check_mode:
316
+        if self.module.check_mode:
317 317
             return True
318 318
         self.absent_on_device()
319 319
         return True
... ...
@@ -327,11 +335,9 @@ class ModuleManager(object):
327 327
 class ArgumentSpec(object):
328 328
     def __init__(self):
329 329
         self.supports_check_mode = True
330
-        self.argument_spec = dict(
330
+        argument_spec = dict(
331 331
             cache=dict(
332
-                required=False,
333
-                choices=['disabled', 'enabled', 'disable', 'enable'],
334
-                default=None
332
+                choices=['disabled', 'enabled', 'disable', 'enable']
335 333
             ),
336 334
             name_servers=dict(
337 335
                 required=False,
... ...
@@ -355,48 +361,38 @@ class ArgumentSpec(object):
355 355
                 type='int'
356 356
             ),
357 357
             state=dict(
358
-                required=False,
359 358
                 default='present',
360 359
                 choices=['absent', 'present']
361 360
             )
362 361
         )
362
+        self.argument_spec = {}
363
+        self.argument_spec.update(f5_argument_spec)
364
+        self.argument_spec.update(argument_spec)
363 365
         self.required_one_of = [
364 366
             ['name_servers', 'search', 'forwarders', 'ip_version', 'cache']
365 367
         ]
366
-        self.f5_product_name = 'bigip'
367
-
368
-
369
-def cleanup_tokens(client):
370
-    try:
371
-        resource = client.api.shared.authz.tokens_s.token.load(
372
-            name=client.api.icrs.token
373
-        )
374
-        resource.delete()
375
-    except Exception:
376
-        pass
377 368
 
378 369
 
379 370
 def main():
380
-    if not HAS_F5SDK:
381
-        raise F5ModuleError("The python f5-sdk module is required")
382
-
383 371
     spec = ArgumentSpec()
384 372
 
385
-    client = AnsibleF5Client(
373
+    module = AnsibleModule(
386 374
         argument_spec=spec.argument_spec,
387 375
         supports_check_mode=spec.supports_check_mode,
388
-        f5_product_name=spec.f5_product_name,
389 376
         required_one_of=spec.required_one_of
390 377
     )
378
+    if not HAS_F5SDK:
379
+        module.fail_json(msg="The python f5-sdk module is required")
391 380
 
392 381
     try:
393
-        mm = ModuleManager(client)
382
+        client = F5Client(**module.params)
383
+        mm = ModuleManager(module=module, client=client)
394 384
         results = mm.exec_module()
395 385
         cleanup_tokens(client)
396
-        client.module.exit_json(**results)
397
-    except F5ModuleError as e:
386
+        module.exit_json(**results)
387
+    except F5ModuleError as ex:
398 388
         cleanup_tokens(client)
399
-        client.module.fail_json(msg=str(e))
389
+        module.fail_json(msg=str(ex))
400 390
 
401 391
 
402 392
 if __name__ == '__main__':
... ...
@@ -38,18 +38,18 @@ options:
38 38
   auth_pam_validate_ip:
39 39
     description:
40 40
       - Sets the authPamValidateIp setting.
41
-    choices: ['on', 'off']
41
+    type: bool
42 42
   auth_pam_dashboard_timeout:
43 43
     description:
44 44
       - Sets whether or not the BIG-IP dashboard will timeout.
45
-    choices: ['on', 'off']
45
+    type: bool
46 46
   fast_cgi_timeout:
47 47
     description:
48 48
       - Sets the timeout of FastCGI.
49 49
   hostname_lookup:
50 50
     description:
51 51
       - Sets whether or not to display the hostname, if possible.
52
-    choices: ['on', 'off']
52
+    type: bool
53 53
   log_level:
54 54
     description:
55 55
       - Sets the minimum httpd log level.
... ...
@@ -60,17 +60,14 @@ options:
60 60
   redirect_http_to_https:
61 61
     description:
62 62
       - Whether or not to redirect http requests to the GUI to https.
63
-    choices: ['yes', 'no']
63
+    type: bool
64 64
   ssl_port:
65 65
     description:
66 66
       - The HTTPS port to listen on.
67 67
 notes:
68
-  - Requires the f5-sdk Python package on the host. This is as easy as pip
69
-    install f5-sdk.
70 68
   - Requires the requests Python package on the host. This is as easy as
71
-    pip install requests.
69
+    C(pip install requests).
72 70
 requirements:
73
-  - f5-sdk >= 3.0.4
74 71
   - requests
75 72
 extends_documentation_fragment: f5
76 73
 author:
... ...
@@ -159,17 +156,37 @@ ssl_port:
159 159
 
160 160
 import time
161 161
 
162
-from ansible.module_utils.f5_utils import AnsibleF5Client
163
-from ansible.module_utils.f5_utils import AnsibleF5Parameters
164
-from ansible.module_utils.f5_utils import HAS_F5SDK
165
-from ansible.module_utils.f5_utils import F5ModuleError
166
-from ansible.module_utils.six import iteritems
167
-from collections import defaultdict
162
+from ansible.module_utils.basic import AnsibleModule
163
+
164
+HAS_DEVEL_IMPORTS = False
168 165
 
169 166
 try:
170
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
167
+    # Sideband repository used for dev
168
+    from library.module_utils.network.f5.bigip import HAS_F5SDK
169
+    from library.module_utils.network.f5.bigip import F5Client
170
+    from library.module_utils.network.f5.common import F5ModuleError
171
+    from library.module_utils.network.f5.common import AnsibleF5Parameters
172
+    from library.module_utils.network.f5.common import cleanup_tokens
173
+    from library.module_utils.network.f5.common import fqdn_name
174
+    from library.module_utils.network.f5.common import f5_argument_spec
175
+    try:
176
+        from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
177
+    except ImportError:
178
+        HAS_F5SDK = False
179
+    HAS_DEVEL_IMPORTS = True
171 180
 except ImportError:
172
-    HAS_F5SDK = False
181
+    # Upstream Ansible
182
+    from ansible.module_utils.network.f5.bigip import HAS_F5SDK
183
+    from ansible.module_utils.network.f5.bigip import F5Client
184
+    from ansible.module_utils.network.f5.common import F5ModuleError
185
+    from ansible.module_utils.network.f5.common import AnsibleF5Parameters
186
+    from ansible.module_utils.network.f5.common import cleanup_tokens
187
+    from ansible.module_utils.network.f5.common import fqdn_name
188
+    from ansible.module_utils.network.f5.common import f5_argument_spec
189
+    try:
190
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
191
+    except ImportError:
192
+        HAS_F5SDK = False
173 193
 
174 194
 try:
175 195
     from requests.exceptions import ConnectionError
... ...
@@ -212,46 +229,6 @@ class Parameters(AnsibleF5Parameters):
212 212
         'allow'
213 213
     ]
214 214
 
215
-    def __init__(self, params=None):
216
-        self._values = defaultdict(lambda: None)
217
-        self._values['__warnings'] = []
218
-        if params:
219
-            self.update(params=params)
220
-
221
-    def update(self, params=None):
222
-        if params:
223
-            for k, v in iteritems(params):
224
-                if self.api_map is not None and k in self.api_map:
225
-                    map_key = self.api_map[k]
226
-                else:
227
-                    map_key = k
228
-
229
-                # Handle weird API parameters like `dns.proxy.__iter__` by
230
-                # using a map provided by the module developer
231
-                class_attr = getattr(type(self), map_key, None)
232
-                if isinstance(class_attr, property):
233
-                    # There is a mapped value for the api_map key
234
-                    if class_attr.fset is None:
235
-                        # If the mapped value does not have
236
-                        # an associated setter
237
-                        self._values[map_key] = v
238
-                    else:
239
-                        # The mapped value has a setter
240
-                        setattr(self, map_key, v)
241
-                else:
242
-                    # If the mapped value is not a @property
243
-                    self._values[map_key] = v
244
-
245
-    def api_params(self):
246
-        result = {}
247
-        for api_attribute in self.api_attributes:
248
-            if self.api_map is not None and api_attribute in self.api_map:
249
-                result[api_attribute] = getattr(self, self.api_map[api_attribute])
250
-            else:
251
-                result[api_attribute] = getattr(self, api_attribute)
252
-        result = self._filter_params(result)
253
-        return result
254
-
255 215
     @property
256 216
     def auth_pam_idle_timeout(self):
257 217
         if self._values['auth_pam_idle_timeout'] is None:
... ...
@@ -395,9 +372,10 @@ class Difference(object):
395 395
 
396 396
 
397 397
 class ModuleManager(object):
398
-    def __init__(self, client):
399
-        self.client = client
400
-        self.want = ModuleParameters(params=self.client.module.params)
398
+    def __init__(self, *args, **kwargs):
399
+        self.module = kwargs.get('module', None)
400
+        self.client = kwargs.get('client', None)
401
+        self.want = ModuleParameters(params=self.module.params)
401 402
         self.have = ApiParameters()
402 403
         self.changes = UsableChanges()
403 404
 
... ...
@@ -407,7 +385,7 @@ class ModuleManager(object):
407 407
             if getattr(self.want, key) is not None:
408 408
                 changed[key] = getattr(self.want, key)
409 409
         if changed:
410
-            self.changes = Changes(changed)
410
+            self.changes = Changes(params=changed)
411 411
 
412 412
     def _update_changed_options(self):
413 413
         diff = Difference(self.want, self.have)
... ...
@@ -423,7 +401,7 @@ class ModuleManager(object):
423 423
                 else:
424 424
                     changed[k] = change
425 425
         if changed:
426
-            self.changes = UsableChanges(changed)
426
+            self.changes = UsableChanges(params=changed)
427 427
             return True
428 428
         return False
429 429
 
... ...
@@ -441,7 +419,7 @@ class ModuleManager(object):
441 441
         except iControlUnexpectedHTTPError as e:
442 442
             raise F5ModuleError(str(e))
443 443
 
444
-        reportable = ReportableChanges(self.changes.to_return())
444
+        reportable = ReportableChanges(params=self.changes.to_return())
445 445
         changes = reportable.to_return()
446 446
         result.update(**changes)
447 447
         result.update(dict(changed=changed))
... ...
@@ -451,7 +429,7 @@ class ModuleManager(object):
451 451
     def _announce_deprecations(self, result):
452 452
         warnings = result.pop('__warnings', [])
453 453
         for warning in warnings:
454
-            self.client.module.deprecate(
454
+            self.module.deprecate(
455 455
                 msg=warning['msg'],
456 456
                 version=warning['version']
457 457
             )
... ...
@@ -463,7 +441,7 @@ class ModuleManager(object):
463 463
         self.have = self.read_current_from_device()
464 464
         if not self.should_update():
465 465
             return False
466
-        if self.client.check_mode:
466
+        if self.module.check_mode:
467 467
             return True
468 468
         self.update_on_device()
469 469
         return True
... ...
@@ -494,7 +472,7 @@ class ModuleManager(object):
494 494
 class ArgumentSpec(object):
495 495
     def __init__(self):
496 496
         self.supports_check_mode = True
497
-        self.argument_spec = dict(
497
+        argument_spec = dict(
498 498
             allow=dict(
499 499
                 type='list'
500 500
             ),
... ...
@@ -530,42 +508,32 @@ class ArgumentSpec(object):
530 530
                 type='bool'
531 531
             )
532 532
         )
533
-        self.f5_product_name = 'bigip'
534
-
535
-
536
-def cleanup_tokens(client):
537
-    try:
538
-        resource = client.api.shared.authz.tokens_s.token.load(
539
-            name=client.api.icrs.token
540
-        )
541
-        resource.delete()
542
-    except Exception:
543
-        pass
533
+        self.argument_spec = {}
534
+        self.argument_spec.update(f5_argument_spec)
535
+        self.argument_spec.update(argument_spec)
544 536
 
545 537
 
546 538
 def main():
547
-    if not HAS_F5SDK:
548
-        raise F5ModuleError("The python f5-sdk module is required")
549
-
550
-    if not HAS_REQUESTS:
551
-        raise F5ModuleError("The python requests module is required")
552
-
553 539
     spec = ArgumentSpec()
554 540
 
555
-    client = AnsibleF5Client(
541
+    module = AnsibleModule(
556 542
         argument_spec=spec.argument_spec,
557
-        supports_check_mode=spec.supports_check_mode,
558
-        f5_product_name=spec.f5_product_name
543
+        supports_check_mode=spec.supports_check_mode
559 544
     )
545
+    if not HAS_F5SDK:
546
+        module.fail_json(msg="The python f5-sdk module is required")
547
+    if not HAS_REQUESTS:
548
+        module.fail_json(msg="The python requests module is required")
560 549
 
561 550
     try:
562
-        mm = ModuleManager(client)
551
+        client = F5Client(**module.params)
552
+        mm = ModuleManager(module=module, client=client)
563 553
         results = mm.exec_module()
564 554
         cleanup_tokens(client)
565
-        client.module.exit_json(**results)
566
-    except F5ModuleError as e:
555
+        module.exit_json(**results)
556
+    except F5ModuleError as ex:
567 557
         cleanup_tokens(client)
568
-        client.module.fail_json(msg=str(e))
558
+        module.fail_json(msg=str(ex))
569 559
 
570 560
 
571 561
 if __name__ == '__main__':
... ...
@@ -37,12 +37,7 @@ options:
37 37
       - The timezone to set for NTP lookups. At least one of C(ntp_servers) or
38 38
         C(timezone) is required.
39 39
     default: UTC
40
-notes:
41
-  - Requires the f5-sdk Python package on the host. This is as easy as pip
42
-    install f5-sdk.
43 40
 extends_documentation_fragment: f5
44
-requirements:
45
-  - f5-sdk
46 41
 author:
47 42
   - Tim Rupp (@caphrim007)
48 43
   - Wojciech Wypior (@wojtek0806)
... ...
@@ -82,16 +77,37 @@ timezone:
82 82
   sample: true
83 83
 '''
84 84
 
85
+from ansible.module_utils.basic import AnsibleModule
85 86
 
86
-from ansible.module_utils.f5_utils import AnsibleF5Client
87
-from ansible.module_utils.f5_utils import AnsibleF5Parameters
88
-from ansible.module_utils.f5_utils import HAS_F5SDK
89
-from ansible.module_utils.f5_utils import F5ModuleError
87
+HAS_DEVEL_IMPORTS = False
90 88
 
91 89
 try:
92
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
90
+    # Sideband repository used for dev
91
+    from library.module_utils.network.f5.bigip import HAS_F5SDK
92
+    from library.module_utils.network.f5.bigip import F5Client
93
+    from library.module_utils.network.f5.common import F5ModuleError
94
+    from library.module_utils.network.f5.common import AnsibleF5Parameters
95
+    from library.module_utils.network.f5.common import cleanup_tokens
96
+    from library.module_utils.network.f5.common import fqdn_name
97
+    from library.module_utils.network.f5.common import f5_argument_spec
98
+    try:
99
+        from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
100
+    except ImportError:
101
+        HAS_F5SDK = False
102
+    HAS_DEVEL_IMPORTS = True
93 103
 except ImportError:
94
-    HAS_F5SDK = False
104
+    # Upstream Ansible
105
+    from ansible.module_utils.network.f5.bigip import HAS_F5SDK
106
+    from ansible.module_utils.network.f5.bigip import F5Client
107
+    from ansible.module_utils.network.f5.common import F5ModuleError
108
+    from ansible.module_utils.network.f5.common import AnsibleF5Parameters
109
+    from ansible.module_utils.network.f5.common import cleanup_tokens
110
+    from ansible.module_utils.network.f5.common import fqdn_name
111
+    from ansible.module_utils.network.f5.common import f5_argument_spec
112
+    try:
113
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
114
+    except ImportError:
115
+        HAS_F5SDK = False
95 116
 
96 117
 
97 118
 class Parameters(AnsibleF5Parameters):
... ...
@@ -122,23 +138,13 @@ class Parameters(AnsibleF5Parameters):
122 122
         result = self._filter_params(result)
123 123
         return result
124 124
 
125
-    def api_params(self):
126
-        result = {}
127
-        for api_attribute in self.api_attributes:
128
-            if self.api_map is not None and api_attribute in self.api_map:
129
-                result[api_attribute] = getattr(self,
130
-                                                self.api_map[api_attribute])
131
-            else:
132
-                result[api_attribute] = getattr(self, api_attribute)
133
-        result = self._filter_params(result)
134
-        return result
135
-
136 125
 
137 126
 class ModuleManager(object):
138
-    def __init__(self, client):
139
-        self.client = client
127
+    def __init__(self, *args, **kwargs):
128
+        self.module = kwargs.get('module', None)
129
+        self.client = kwargs.get('client', None)
140 130
         self.have = None
141
-        self.want = Parameters(self.client.module.params)
131
+        self.want = Parameters(params=self.module.params)
142 132
         self.changes = Parameters()
143 133
 
144 134
     def _update_changed_options(self):
... ...
@@ -150,7 +156,7 @@ class ModuleManager(object):
150 150
                 if attr1 != attr2:
151 151
                     changed[key] = attr1
152 152
         if changed:
153
-            self.changes = Parameters(changed)
153
+            self.changes = Parameters(params=changed)
154 154
             return True
155 155
         return False
156 156
 
... ...
@@ -163,7 +169,7 @@ class ModuleManager(object):
163 163
                 if set_want != set_have:
164 164
                     changed[key] = list(set_want)
165 165
         if changed:
166
-            self.changes = Parameters(changed)
166
+            self.changes = Parameters(params=changed)
167 167
             return True
168 168
         return False
169 169
 
... ...
@@ -189,7 +195,7 @@ class ModuleManager(object):
189 189
         self.have = self.read_current_from_device()
190 190
         if not self.should_update():
191 191
             return False
192
-        if self.client.check_mode:
192
+        if self.module.check_mode:
193 193
             return True
194 194
         self.update_on_device()
195 195
         return True
... ...
@@ -210,7 +216,7 @@ class ModuleManager(object):
210 210
         self.have = self.read_current_from_device()
211 211
         if not self.should_absent():
212 212
             return False
213
-        if self.client.check_mode:
213
+        if self.module.check_mode:
214 214
             return True
215 215
         self.absent_on_device()
216 216
         return True
... ...
@@ -223,7 +229,7 @@ class ModuleManager(object):
223 223
     def read_current_from_device(self):
224 224
         resource = self.client.api.tm.sys.ntp.load()
225 225
         result = resource.attrs
226
-        return Parameters(result)
226
+        return Parameters(params=result)
227 227
 
228 228
     def absent_on_device(self):
229 229
         params = self.changes.api_params()
... ...
@@ -234,54 +240,45 @@ class ModuleManager(object):
234 234
 class ArgumentSpec(object):
235 235
     def __init__(self):
236 236
         self.supports_check_mode = True
237
-        self.argument_spec = dict(
237
+        argument_spec = dict(
238 238
             ntp_servers=dict(
239
-                required=False,
240
-                default=None,
241 239
                 type='list',
242 240
             ),
243
-            timezone=dict(
244
-                required=False,
245
-                default=None,
246
-            )
241
+            timezone=dict(),
242
+            state=dict(
243
+                default='present',
244
+                choices=['present', 'absent']
245
+            ),
247 246
         )
247
+        self.argument_spec = {}
248
+        self.argument_spec.update(f5_argument_spec)
249
+        self.argument_spec.update(argument_spec)
250
+
248 251
         self.required_one_of = [
249 252
             ['ntp_servers', 'timezone']
250 253
         ]
251
-        self.f5_product_name = 'bigip'
252
-
253
-
254
-def cleanup_tokens(client):
255
-    try:
256
-        resource = client.api.shared.authz.tokens_s.token.load(
257
-            name=client.api.icrs.token
258
-        )
259
-        resource.delete()
260
-    except Exception:
261
-        pass
262 254
 
263 255
 
264 256
 def main():
265
-    if not HAS_F5SDK:
266
-        raise F5ModuleError("The python f5-sdk module is required")
267
-
268 257
     spec = ArgumentSpec()
269 258
 
270
-    client = AnsibleF5Client(
259
+    module = AnsibleModule(
271 260
         argument_spec=spec.argument_spec,
272 261
         supports_check_mode=spec.supports_check_mode,
273
-        f5_product_name=spec.f5_product_name,
274 262
         required_one_of=spec.required_one_of
275 263
     )
264
+    if not HAS_F5SDK:
265
+        module.fail_json(msg="The python f5-sdk module is required")
276 266
 
277 267
     try:
278
-        mm = ModuleManager(client)
268
+        client = F5Client(**module.params)
269
+        mm = ModuleManager(module=module, client=client)
279 270
         results = mm.exec_module()
280 271
         cleanup_tokens(client)
281
-        client.module.exit_json(**results)
282
-    except F5ModuleError as e:
272
+        module.exit_json(**results)
273
+    except F5ModuleError as ex:
283 274
         cleanup_tokens(client)
284
-        client.module.fail_json(msg=str(e))
275
+        module.fail_json(msg=str(ex))
285 276
 
286 277
 
287 278
 if __name__ == '__main__':
... ...
@@ -66,12 +66,8 @@ options:
66 66
     description:
67 67
       - Port that you want the SSH daemon to run on.
68 68
 notes:
69
-  - Requires the f5-sdk Python package on the host This is as easy as pip
70
-    install f5-sdk.
71 69
   - Requires BIG-IP version 12.0.0 or greater
72 70
 extends_documentation_fragment: f5
73
-requirements:
74
-  - f5-sdk
75 71
 author:
76 72
   - Tim Rupp (@caphrim007)
77 73
 '''
... ...
@@ -149,16 +145,37 @@ port:
149 149
   sample: 22
150 150
 '''
151 151
 
152
+from ansible.module_utils.basic import AnsibleModule
152 153
 
153
-from ansible.module_utils.f5_utils import AnsibleF5Client
154
-from ansible.module_utils.f5_utils import AnsibleF5Parameters
155
-from ansible.module_utils.f5_utils import HAS_F5SDK
156
-from ansible.module_utils.f5_utils import F5ModuleError
154
+HAS_DEVEL_IMPORTS = False
157 155
 
158 156
 try:
159
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
157
+    # Sideband repository used for dev
158
+    from library.module_utils.network.f5.bigip import HAS_F5SDK
159
+    from library.module_utils.network.f5.bigip import F5Client
160
+    from library.module_utils.network.f5.common import F5ModuleError
161
+    from library.module_utils.network.f5.common import AnsibleF5Parameters
162
+    from library.module_utils.network.f5.common import cleanup_tokens
163
+    from library.module_utils.network.f5.common import fqdn_name
164
+    from library.module_utils.network.f5.common import f5_argument_spec
165
+    try:
166
+        from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
167
+    except ImportError:
168
+        HAS_F5SDK = False
169
+    HAS_DEVEL_IMPORTS = True
160 170
 except ImportError:
161
-    HAS_F5SDK = False
171
+    # Upstream Ansible
172
+    from ansible.module_utils.network.f5.bigip import HAS_F5SDK
173
+    from ansible.module_utils.network.f5.bigip import F5Client
174
+    from ansible.module_utils.network.f5.common import F5ModuleError
175
+    from ansible.module_utils.network.f5.common import AnsibleF5Parameters
176
+    from ansible.module_utils.network.f5.common import cleanup_tokens
177
+    from ansible.module_utils.network.f5.common import fqdn_name
178
+    from ansible.module_utils.network.f5.common import f5_argument_spec
179
+    try:
180
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
181
+    except ImportError:
182
+        HAS_F5SDK = False
162 183
 
163 184
 
164 185
 class Parameters(AnsibleF5Parameters):
... ...
@@ -190,16 +207,6 @@ class Parameters(AnsibleF5Parameters):
190 190
         result = self._filter_params(result)
191 191
         return result
192 192
 
193
-    def api_params(self):
194
-        result = {}
195
-        for api_attribute in self.api_attributes:
196
-            if self.api_map is not None and api_attribute in self.api_map:
197
-                result[api_attribute] = getattr(self, self.api_map[api_attribute])
198
-            else:
199
-                result[api_attribute] = getattr(self, api_attribute)
200
-        result = self._filter_params(result)
201
-        return result
202
-
203 193
     @property
204 194
     def inactivity_timeout(self):
205 195
         if self._values['inactivity_timeout'] is None:
... ...
@@ -223,10 +230,11 @@ class Parameters(AnsibleF5Parameters):
223 223
 
224 224
 
225 225
 class ModuleManager(object):
226
-    def __init__(self, client):
227
-        self.client = client
226
+    def __init__(self, *args, **kwargs):
227
+        self.module = kwargs.get('module', None)
228
+        self.client = kwargs.get('client', None)
228 229
         self.have = None
229
-        self.want = Parameters(self.client.module.params)
230
+        self.want = Parameters(params=self.module.params)
230 231
         self.changes = Parameters()
231 232
 
232 233
     def _update_changed_options(self):
... ...
@@ -238,7 +246,7 @@ class ModuleManager(object):
238 238
                 if attr1 != attr2:
239 239
                     changed[key] = attr1
240 240
         if changed:
241
-            self.changes = Parameters(changed)
241
+            self.changes = Parameters(params=changed)
242 242
             return True
243 243
         return False
244 244
 
... ...
@@ -258,13 +266,13 @@ class ModuleManager(object):
258 258
     def read_current_from_device(self):
259 259
         resource = self.client.api.tm.sys.sshd.load()
260 260
         result = resource.attrs
261
-        return Parameters(result)
261
+        return Parameters(params=result)
262 262
 
263 263
     def update(self):
264 264
         self.have = self.read_current_from_device()
265 265
         if not self.should_update():
266 266
             return False
267
-        if self.client.check_mode:
267
+        if self.module.check_mode:
268 268
             return True
269 269
         self.update_on_device()
270 270
         return True
... ...
@@ -289,7 +297,7 @@ class ArgumentSpec(object):
289 289
             'quiet', 'verbose'
290 290
         ]
291 291
         self.supports_check_mode = True
292
-        self.argument_spec = dict(
292
+        argument_spec = dict(
293 293
             allow=dict(
294 294
                 type='list'
295 295
             ),
... ...
@@ -308,45 +316,32 @@ class ArgumentSpec(object):
308 308
             ),
309 309
             port=dict(
310 310
                 type='int'
311
-            ),
312
-            state=dict(
313
-                default='present',
314
-                choices=['present']
315 311
             )
316 312
         )
317
-        self.f5_product_name = 'bigip'
318
-
319
-
320
-def cleanup_tokens(client):
321
-    try:
322
-        resource = client.api.shared.authz.tokens_s.token.load(
323
-            name=client.api.icrs.token
324
-        )
325
-        resource.delete()
326
-    except Exception:
327
-        pass
313
+        self.argument_spec = {}
314
+        self.argument_spec.update(f5_argument_spec)
315
+        self.argument_spec.update(argument_spec)
328 316
 
329 317
 
330 318
 def main():
331
-    if not HAS_F5SDK:
332
-        raise F5ModuleError("The python f5-sdk module is required")
333
-
334 319
     spec = ArgumentSpec()
335 320
 
336
-    client = AnsibleF5Client(
321
+    module = AnsibleModule(
337 322
         argument_spec=spec.argument_spec,
338
-        supports_check_mode=spec.supports_check_mode,
339
-        f5_product_name=spec.f5_product_name
323
+        supports_check_mode=spec.supports_check_mode
340 324
     )
325
+    if not HAS_F5SDK:
326
+        module.fail_json(msg="The python f5-sdk module is required")
341 327
 
342 328
     try:
343
-        mm = ModuleManager(client)
329
+        client = F5Client(**module.params)
330
+        mm = ModuleManager(module=module, client=client)
344 331
         results = mm.exec_module()
345 332
         cleanup_tokens(client)
346
-        client.module.exit_json(**results)
347
-    except F5ModuleError as e:
333
+        module.exit_json(**results)
334
+    except F5ModuleError as ex:
348 335
         cleanup_tokens(client)
349
-        client.module.fail_json(msg=str(e))
336
+        module.fail_json(msg=str(ex))
350 337
 
351 338
 
352 339
 if __name__ == '__main__':
... ...
@@ -60,11 +60,15 @@ options:
60 60
       - peer
61 61
       - subordinate
62 62
     default: peer
63
-notes:
64
-    - Requires the f5-sdk Python package on the host. This is as easy as
65
-      pip install f5-sdk.
63
+  state:
64
+    description:
65
+      - When C(present), ensures the specified devices are trusted.
66
+      - When C(absent), removes the device trusts.
67
+    default: present
68
+    choices:
69
+      - absent
70
+      - present
66 71
 requirements:
67
-  - f5-sdk
68 72
   - netaddr
69 73
 extends_documentation_fragment: f5
70 74
 author:
... ...
@@ -101,21 +105,43 @@ peer_hostname:
101 101
 
102 102
 import re
103 103
 
104
+from ansible.module_utils.basic import AnsibleModule
105
+
106
+HAS_DEVEL_IMPORTS = False
107
+
104 108
 try:
105
-    import netaddr
106
-    HAS_NETADDR = True
109
+    # Sideband repository used for dev
110
+    from library.module_utils.network.f5.bigip import HAS_F5SDK
111
+    from library.module_utils.network.f5.bigip import F5Client
112
+    from library.module_utils.network.f5.common import F5ModuleError
113
+    from library.module_utils.network.f5.common import AnsibleF5Parameters
114
+    from library.module_utils.network.f5.common import cleanup_tokens
115
+    from library.module_utils.network.f5.common import fqdn_name
116
+    from library.module_utils.network.f5.common import f5_argument_spec
117
+    try:
118
+        from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
119
+    except ImportError:
120
+        HAS_F5SDK = False
121
+    HAS_DEVEL_IMPORTS = True
107 122
 except ImportError:
108
-    HAS_NETADDR = False
109
-
110
-from ansible.module_utils.f5_utils import AnsibleF5Client
111
-from ansible.module_utils.f5_utils import AnsibleF5Parameters
112
-from ansible.module_utils.f5_utils import HAS_F5SDK
113
-from ansible.module_utils.f5_utils import F5ModuleError
123
+    # Upstream Ansible
124
+    from ansible.module_utils.network.f5.bigip import HAS_F5SDK
125
+    from ansible.module_utils.network.f5.bigip import F5Client
126
+    from ansible.module_utils.network.f5.common import F5ModuleError
127
+    from ansible.module_utils.network.f5.common import AnsibleF5Parameters
128
+    from ansible.module_utils.network.f5.common import cleanup_tokens
129
+    from ansible.module_utils.network.f5.common import fqdn_name
130
+    from ansible.module_utils.network.f5.common import f5_argument_spec
131
+    try:
132
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
133
+    except ImportError:
134
+        HAS_F5SDK = False
114 135
 
115 136
 try:
116
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
137
+    import netaddr
138
+    HAS_NETADDR = True
117 139
 except ImportError:
118
-    HAS_F5SDK = False
140
+    HAS_NETADDR = False
119 141
 
120 142
 
121 143
 class Parameters(AnsibleF5Parameters):
... ...
@@ -147,16 +173,6 @@ class Parameters(AnsibleF5Parameters):
147 147
         except Exception:
148 148
             return result
149 149
 
150
-    def api_params(self):
151
-        result = {}
152
-        for api_attribute in self.api_attributes:
153
-            if self.api_map is not None and api_attribute in self.api_map:
154
-                result[api_attribute] = getattr(self, self.api_map[api_attribute])
155
-            else:
156
-                result[api_attribute] = getattr(self, api_attribute)
157
-        result = self._filter_params(result)
158
-        return result
159
-
160 150
     @property
161 151
     def peer_server(self):
162 152
         if self._values['peer_server'] is None:
... ...
@@ -178,12 +194,6 @@ class Parameters(AnsibleF5Parameters):
178 178
         return result
179 179
 
180 180
     @property
181
-    def partition(self):
182
-        # Partitions are not supported when making peers.
183
-        # Everybody goes in Common.
184
-        return None
185
-
186
-    @property
187 181
     def type(self):
188 182
         if self._values['type'] == 'peer':
189 183
             return True
... ...
@@ -191,10 +201,11 @@ class Parameters(AnsibleF5Parameters):
191 191
 
192 192
 
193 193
 class ModuleManager(object):
194
-    def __init__(self, client):
195
-        self.client = client
194
+    def __init__(self, *args, **kwargs):
195
+        self.module = kwargs.get('module', None)
196
+        self.client = kwargs.get('client', None)
196 197
         self.have = None
197
-        self.want = Parameters(self.client.module.params)
198
+        self.want = Parameters(params=self.module.params)
198 199
         self.changes = Parameters()
199 200
 
200 201
     def _set_changed_options(self):
... ...
@@ -203,7 +214,7 @@ class ModuleManager(object):
203 203
             if getattr(self.want, key) is not None:
204 204
                 changed[key] = getattr(self.want, key)
205 205
         if changed:
206
-            self.changes = Parameters(changed)
206
+            self.changes = Parameters(params=changed)
207 207
 
208 208
     def exec_module(self):
209 209
         changed = False
... ...
@@ -237,8 +248,9 @@ class ModuleManager(object):
237 237
             self.want.update({'peer_password': self.want.password})
238 238
         if self.want.peer_hostname is None:
239 239
             self.want.update({'peer_hostname': self.want.server})
240
-        if self.client.check_mode:
240
+        if self.module.check_mode:
241 241
             return True
242
+
242 243
         self.create_on_device()
243 244
         return True
244 245
 
... ...
@@ -248,7 +260,7 @@ class ModuleManager(object):
248 248
         return False
249 249
 
250 250
     def remove(self):
251
-        if self.client.check_mode:
251
+        if self.module.check_mode:
252 252
             return True
253 253
         self.remove_from_device()
254 254
         if self.exists():
... ...
@@ -284,7 +296,7 @@ class ModuleManager(object):
284 284
 class ArgumentSpec(object):
285 285
     def __init__(self):
286 286
         self.supports_check_mode = True
287
-        self.argument_spec = dict(
287
+        argument_spec = dict(
288 288
             peer_server=dict(required=True),
289 289
             peer_hostname=dict(),
290 290
             peer_user=dict(),
... ...
@@ -292,44 +304,38 @@ class ArgumentSpec(object):
292 292
             type=dict(
293 293
                 choices=['peer', 'subordinate'],
294 294
                 default='peer'
295
+            ),
296
+            state=dict(
297
+                default='present',
298
+                choices=['present', 'absent']
295 299
             )
296 300
         )
297
-        self.f5_product_name = 'bigip'
298
-
299
-
300
-def cleanup_tokens(client):
301
-    try:
302
-        resource = client.api.shared.authz.tokens_s.token.load(
303
-            name=client.api.icrs.token
304
-        )
305
-        resource.delete()
306
-    except Exception:
307
-        pass
301
+        self.argument_spec = {}
302
+        self.argument_spec.update(f5_argument_spec)
303
+        self.argument_spec.update(argument_spec)
308 304
 
309 305
 
310 306
 def main():
311
-    if not HAS_F5SDK:
312
-        raise F5ModuleError("The python f5-sdk module is required")
313
-
314
-    if not HAS_NETADDR:
315
-        raise F5ModuleError("The python netaddr module is required")
316
-
317 307
     spec = ArgumentSpec()
318 308
 
319
-    client = AnsibleF5Client(
309
+    module = AnsibleModule(
320 310
         argument_spec=spec.argument_spec,
321
-        supports_check_mode=spec.supports_check_mode,
322
-        f5_product_name=spec.f5_product_name
311
+        supports_check_mode=spec.supports_check_mode
323 312
     )
313
+    if not HAS_F5SDK:
314
+        module.fail_json(msg="The python f5-sdk module is required")
315
+    if not HAS_NETADDR:
316
+        module.fail_json(msg="The python netaddr module is required")
324 317
 
325 318
     try:
326
-        mm = ModuleManager(client)
319
+        client = F5Client(**module.params)
320
+        mm = ModuleManager(module=module, client=client)
327 321
         results = mm.exec_module()
328 322
         cleanup_tokens(client)
329
-        client.module.exit_json(**results)
330
-    except F5ModuleError as e:
323
+        module.exit_json(**results)
324
+    except F5ModuleError as ex:
331 325
         cleanup_tokens(client)
332
-        client.module.fail_json(msg=str(e))
326
+        module.fail_json(msg=str(ex))
333 327
 
334 328
 
335 329
 if __name__ == '__main__':
... ...
@@ -41,16 +41,6 @@ lib/ansible/modules/net_tools/cloudflare_dns.py E317
41 41
 lib/ansible/modules/net_tools/haproxy.py E317
42 42
 lib/ansible/modules/net_tools/omapi_host.py E317
43 43
 lib/ansible/modules/network/cloudengine/ce_reboot.py E317
44
-lib/ansible/modules/network/f5/bigip_asm_policy.py E321
45
-lib/ansible/modules/network/f5/bigip_config.py E321
46
-lib/ansible/modules/network/f5/bigip_configsync_action.py E321
47
-lib/ansible/modules/network/f5/bigip_configsync_actions.py E321
48
-lib/ansible/modules/network/f5/bigip_device_connectivity.py E321
49
-lib/ansible/modules/network/f5/bigip_device_dns.py E321
50
-lib/ansible/modules/network/f5/bigip_device_httpd.py E321
51
-lib/ansible/modules/network/f5/bigip_device_ntp.py E321
52
-lib/ansible/modules/network/f5/bigip_device_sshd.py E321
53
-lib/ansible/modules/network/f5/bigip_device_trust.py E321
54 44
 lib/ansible/modules/network/f5/bigip_gtm_datacenter.py E321
55 45
 lib/ansible/modules/network/f5/bigip_gtm_facts.py E321
56 46
 lib/ansible/modules/network/f5/bigip_gtm_pool.py E321
... ...
@@ -18,8 +18,7 @@ if sys.version_info < (2, 7):
18 18
 from ansible.compat.tests import unittest
19 19
 from ansible.compat.tests.mock import Mock
20 20
 from ansible.compat.tests.mock import patch
21
-from ansible.module_utils.f5_utils import AnsibleF5Client
22
-from ansible.module_utils.f5_utils import F5ModuleError
21
+from ansible.module_utils.basic import AnsibleModule
23 22
 
24 23
 try:
25 24
     from library.bigip_asm_policy import V1Parameters
... ...
@@ -28,7 +27,8 @@ try:
28 28
     from library.bigip_asm_policy import V1Manager
29 29
     from library.bigip_asm_policy import V2Manager
30 30
     from library.bigip_asm_policy import ArgumentSpec
31
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
31
+    from library.module_utils.network.f5.common import F5ModuleError
32
+    from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
32 33
     from test.unit.modules.utils import set_module_args
33 34
 except ImportError:
34 35
     try:
... ...
@@ -38,7 +38,8 @@ except ImportError:
38 38
         from ansible.modules.network.f5.bigip_asm_policy import V1Manager
39 39
         from ansible.modules.network.f5.bigip_asm_policy import V2Manager
40 40
         from ansible.modules.network.f5.bigip_asm_policy import ArgumentSpec
41
-        from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
41
+        from ansible.module_utils.network.f5.common import F5ModuleError
42
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
42 43
         from units.modules.utils import set_module_args
43 44
     except ImportError:
44 45
         raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
... ...
@@ -66,7 +67,7 @@ class TestParameters(unittest.TestCase):
66 66
             file='/var/fake/fake.xml'
67 67
         )
68 68
 
69
-        p = V1Parameters(args)
69
+        p = V1Parameters(params=args)
70 70
         assert p.name == 'fake_policy'
71 71
         assert p.state == 'present'
72 72
         assert p.file == '/var/fake/fake.xml'
... ...
@@ -78,14 +79,12 @@ class TestParameters(unittest.TestCase):
78 78
             template='LotusDomino 6.5 (http)'
79 79
         )
80 80
 
81
-        p = V1Parameters(args)
81
+        p = V1Parameters(params=args)
82 82
         assert p.name == 'fake_policy'
83 83
         assert p.state == 'present'
84 84
         assert p.template == 'POLICY_TEMPLATE_LOTUSDOMINO_6_5_HTTP'
85 85
 
86 86
 
87
-@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
88
-       return_value=True)
89 87
 class TestManager(unittest.TestCase):
90 88
     def setUp(self):
91 89
         self.spec = ArgumentSpec()
... ...
@@ -102,14 +101,13 @@ class TestManager(unittest.TestCase):
102 102
             user='admin',
103 103
         ))
104 104
 
105
-        current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
106
-        client = AnsibleF5Client(
105
+        current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
106
+        module = AnsibleModule(
107 107
             argument_spec=self.spec.argument_spec,
108 108
             supports_check_mode=self.spec.supports_check_mode,
109
-            f5_product_name=self.spec.f5_product_name
110 109
         )
111 110
 
112
-        v1 = V1Manager(client)
111
+        v1 = V1Manager(module=module)
113 112
         v1.exists = Mock(return_value=False)
114 113
         v1.import_to_device = Mock(return_value=True)
115 114
         v1.wait_for_task = Mock(side_effect=[True, True])
... ...
@@ -117,7 +115,7 @@ class TestManager(unittest.TestCase):
117 117
         v1.apply_on_device = Mock(return_value=True)
118 118
 
119 119
         # Override methods to force specific logic in the module to happen
120
-        mm = ModuleManager(client)
120
+        mm = ModuleManager(module=module)
121 121
         mm.version_is_less_than_13 = Mock(return_value=False)
122 122
         mm.get_manager = Mock(return_value=v1)
123 123
 
... ...
@@ -139,14 +137,13 @@ class TestManager(unittest.TestCase):
139 139
             user='admin',
140 140
         ))
141 141
 
142
-        current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
143
-        client = AnsibleF5Client(
142
+        current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
143
+        module = AnsibleModule(
144 144
             argument_spec=self.spec.argument_spec,
145
-            supports_check_mode=self.spec.supports_check_mode,
146
-            f5_product_name=self.spec.f5_product_name
145
+            supports_check_mode=self.spec.supports_check_mode
147 146
         )
148 147
 
149
-        v1 = V1Manager(client)
148
+        v1 = V1Manager(module=module)
150 149
         v1.exists = Mock(return_value=False)
151 150
         v1.import_to_device = Mock(return_value=True)
152 151
         v1.wait_for_task = Mock(side_effect=[True, True])
... ...
@@ -156,7 +153,7 @@ class TestManager(unittest.TestCase):
156 156
         v1._file_is_missing = Mock(return_value=False)
157 157
 
158 158
         # Override methods to force specific logic in the module to happen
159
-        mm = ModuleManager(client)
159
+        mm = ModuleManager(module=module)
160 160
         mm.version_is_less_than_13 = Mock(return_value=False)
161 161
         mm.get_manager = Mock(return_value=v1)
162 162
 
... ...
@@ -177,14 +174,13 @@ class TestManager(unittest.TestCase):
177 177
             user='admin',
178 178
         ))
179 179
 
180
-        current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
181
-        client = AnsibleF5Client(
180
+        current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
181
+        module = AnsibleModule(
182 182
             argument_spec=self.spec.argument_spec,
183
-            supports_check_mode=self.spec.supports_check_mode,
184
-            f5_product_name=self.spec.f5_product_name
183
+            supports_check_mode=self.spec.supports_check_mode
185 184
         )
186 185
 
187
-        v1 = V1Manager(client)
186
+        v1 = V1Manager(module=module)
188 187
         v1.exists = Mock(return_value=False)
189 188
         v1.import_to_device = Mock(return_value=True)
190 189
         v1.wait_for_task = Mock(side_effect=[True, True])
... ...
@@ -195,7 +191,7 @@ class TestManager(unittest.TestCase):
195 195
         v1._file_is_missing = Mock(return_value=False)
196 196
 
197 197
         # Override methods to force specific logic in the module to happen
198
-        mm = ModuleManager(client)
198
+        mm = ModuleManager(module=module)
199 199
         mm.version_is_less_than_13 = Mock(return_value=False)
200 200
         mm.get_manager = Mock(return_value=v1)
201 201
 
... ...
@@ -215,14 +211,13 @@ class TestManager(unittest.TestCase):
215 215
             user='admin',
216 216
         ))
217 217
 
218
-        current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
219
-        client = AnsibleF5Client(
218
+        current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
219
+        module = AnsibleModule(
220 220
             argument_spec=self.spec.argument_spec,
221
-            supports_check_mode=self.spec.supports_check_mode,
222
-            f5_product_name=self.spec.f5_product_name
221
+            supports_check_mode=self.spec.supports_check_mode
223 222
         )
224 223
 
225
-        v1 = V1Manager(client)
224
+        v1 = V1Manager(module=module)
226 225
         v1.exists = Mock(return_value=True)
227 226
         v1.update_on_device = Mock(return_value=True)
228 227
         v1.wait_for_task = Mock(side_effect=[True, True])
... ...
@@ -230,7 +225,7 @@ class TestManager(unittest.TestCase):
230 230
         v1.apply_on_device = Mock(return_value=True)
231 231
 
232 232
         # Override methods to force specific logic in the module to happen
233
-        mm = ModuleManager(client)
233
+        mm = ModuleManager(module=module)
234 234
         mm.version_is_less_than_13 = Mock(return_value=False)
235 235
         mm.get_manager = Mock(return_value=v1)
236 236
 
... ...
@@ -249,20 +244,19 @@ class TestManager(unittest.TestCase):
249 249
             user='admin',
250 250
         ))
251 251
 
252
-        current = V1Parameters(load_fixture('load_asm_policy_active.json'))
253
-        client = AnsibleF5Client(
252
+        current = V1Parameters(params=load_fixture('load_asm_policy_active.json'))
253
+        module = AnsibleModule(
254 254
             argument_spec=self.spec.argument_spec,
255
-            supports_check_mode=self.spec.supports_check_mode,
256
-            f5_product_name=self.spec.f5_product_name
255
+            supports_check_mode=self.spec.supports_check_mode
257 256
         )
258 257
 
259 258
         # Override methods to force specific logic in the module to happen
260
-        v1 = V1Manager(client)
259
+        v1 = V1Manager(module=module)
261 260
         v1.exists = Mock(return_value=True)
262 261
         v1.read_current_from_device = Mock(return_value=current)
263 262
 
264 263
         # Override methods to force specific logic in the module to happen
265
-        mm = ModuleManager(client)
264
+        mm = ModuleManager(module=module)
266 265
         mm.version_is_less_than_13 = Mock(return_value=False)
267 266
         mm.get_manager = Mock(return_value=v1)
268 267
 
... ...
@@ -280,21 +274,20 @@ class TestManager(unittest.TestCase):
280 280
             active='no'
281 281
         ))
282 282
 
283
-        current = V1Parameters(load_fixture('load_asm_policy_active.json'))
284
-        client = AnsibleF5Client(
283
+        current = V1Parameters(params=load_fixture('load_asm_policy_active.json'))
284
+        module = AnsibleModule(
285 285
             argument_spec=self.spec.argument_spec,
286
-            supports_check_mode=self.spec.supports_check_mode,
287
-            f5_product_name=self.spec.f5_product_name
286
+            supports_check_mode=self.spec.supports_check_mode
288 287
         )
289 288
 
290 289
         # Override methods to force specific logic in the module to happen
291
-        v1 = V1Manager(client)
290
+        v1 = V1Manager(module=module)
292 291
         v1.exists = Mock(return_value=True)
293 292
         v1.read_current_from_device = Mock(return_value=current)
294 293
         v1.update_on_device = Mock(return_value=True)
295 294
 
296 295
         # Override methods to force specific logic in the module to happen
297
-        mm = ModuleManager(client)
296
+        mm = ModuleManager(module=module)
298 297
         mm.version_is_less_than_13 = Mock(return_value=False)
299 298
         mm.get_manager = Mock(return_value=v1)
300 299
 
... ...
@@ -313,20 +306,19 @@ class TestManager(unittest.TestCase):
313 313
             active='no'
314 314
         ))
315 315
 
316
-        current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
317
-        client = AnsibleF5Client(
316
+        current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
317
+        module = AnsibleModule(
318 318
             argument_spec=self.spec.argument_spec,
319
-            supports_check_mode=self.spec.supports_check_mode,
320
-            f5_product_name=self.spec.f5_product_name
319
+            supports_check_mode=self.spec.supports_check_mode
321 320
         )
322 321
 
323 322
         # Override methods to force specific logic in the module to happen
324
-        v1 = V1Manager(client)
323
+        v1 = V1Manager(module=module)
325 324
         v1.exists = Mock(return_value=True)
326 325
         v1.read_current_from_device = Mock(return_value=current)
327 326
 
328 327
         # Override methods to force specific logic in the module to happen
329
-        mm = ModuleManager(client)
328
+        mm = ModuleManager(module=module)
330 329
         mm.version_is_less_than_13 = Mock(return_value=False)
331 330
         mm.get_manager = Mock(return_value=v1)
332 331
 
... ...
@@ -344,22 +336,21 @@ class TestManager(unittest.TestCase):
344 344
             user='admin',
345 345
         ))
346 346
 
347
-        current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
348
-        client = AnsibleF5Client(
347
+        current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
348
+        module = AnsibleModule(
349 349
             argument_spec=self.spec.argument_spec,
350
-            supports_check_mode=self.spec.supports_check_mode,
351
-            f5_product_name=self.spec.f5_product_name
350
+            supports_check_mode=self.spec.supports_check_mode
352 351
         )
353 352
 
354 353
         # Override methods to force specific logic in the module to happen
355
-        v1 = V1Manager(client)
354
+        v1 = V1Manager(module=module)
356 355
         v1.exists = Mock(return_value=False)
357 356
         v1.import_to_device = Mock(return_value=True)
358 357
         v1.wait_for_task = Mock(side_effect=[True, True])
359 358
         v1.read_current_from_device = Mock(return_value=current)
360 359
 
361 360
         # Override methods to force specific logic in the module to happen
362
-        mm = ModuleManager(client)
361
+        mm = ModuleManager(module=module)
363 362
         mm.version_is_less_than_13 = Mock(return_value=False)
364 363
         mm.get_manager = Mock(return_value=v1)
365 364
 
... ...
@@ -380,15 +371,14 @@ class TestManager(unittest.TestCase):
380 380
             user='admin',
381 381
         ))
382 382
 
383
-        current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
384
-        client = AnsibleF5Client(
383
+        current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
384
+        module = AnsibleModule(
385 385
             argument_spec=self.spec.argument_spec,
386
-            supports_check_mode=self.spec.supports_check_mode,
387
-            f5_product_name=self.spec.f5_product_name
386
+            supports_check_mode=self.spec.supports_check_mode
388 387
         )
389 388
 
390 389
         # Override methods to force specific logic in the module to happen
391
-        v1 = V1Manager(client)
390
+        v1 = V1Manager(module=module)
392 391
         v1.exists = Mock(return_value=False)
393 392
         v1.create_from_template_on_device = Mock(return_value=True)
394 393
         v1.wait_for_task = Mock(side_effect=[True, True])
... ...
@@ -396,7 +386,7 @@ class TestManager(unittest.TestCase):
396 396
         v1._file_is_missing = Mock(return_value=False)
397 397
 
398 398
         # Override methods to force specific logic in the module to happen
399
-        mm = ModuleManager(client)
399
+        mm = ModuleManager(module=module)
400 400
         mm.version_is_less_than_13 = Mock(return_value=False)
401 401
         mm.get_manager = Mock(return_value=v1)
402 402
 
... ...
@@ -416,14 +406,13 @@ class TestManager(unittest.TestCase):
416 416
             user='admin',
417 417
         ))
418 418
 
419
-        current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
420
-        client = AnsibleF5Client(
419
+        current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
420
+        module = AnsibleModule(
421 421
             argument_spec=self.spec.argument_spec,
422
-            supports_check_mode=self.spec.supports_check_mode,
423
-            f5_product_name=self.spec.f5_product_name
422
+            supports_check_mode=self.spec.supports_check_mode
424 423
         )
425 424
 
426
-        v1 = V1Manager(client)
425
+        v1 = V1Manager(module=module)
427 426
         v1.exists = Mock(return_value=False)
428 427
         v1.import_to_device = Mock(return_value=True)
429 428
         v1.wait_for_task = Mock(side_effect=[True, True])
... ...
@@ -434,7 +423,7 @@ class TestManager(unittest.TestCase):
434 434
         v1._file_is_missing = Mock(return_value=False)
435 435
 
436 436
         # Override methods to force specific logic in the module to happen
437
-        mm = ModuleManager(client)
437
+        mm = ModuleManager(module=module)
438 438
         mm.version_is_less_than_13 = Mock(return_value=False)
439 439
         mm.get_manager = Mock(return_value=v1)
440 440
 
... ...
@@ -453,19 +442,18 @@ class TestManager(unittest.TestCase):
453 453
             user='admin',
454 454
         ))
455 455
 
456
-        client = AnsibleF5Client(
456
+        module = AnsibleModule(
457 457
             argument_spec=self.spec.argument_spec,
458
-            supports_check_mode=self.spec.supports_check_mode,
459
-            f5_product_name=self.spec.f5_product_name
458
+            supports_check_mode=self.spec.supports_check_mode
460 459
         )
461 460
 
462 461
         # Override methods to force specific logic in the module to happen
463
-        v1 = V1Manager(client)
462
+        v1 = V1Manager(module=module)
464 463
         v1.exists = Mock(side_effect=[True, False])
465 464
         v1.remove_from_device = Mock(return_value=True)
466 465
 
467 466
         # Override methods to force specific logic in the module to happen
468
-        mm = ModuleManager(client)
467
+        mm = ModuleManager(module=module)
469 468
         mm.version_is_less_than_13 = Mock(return_value=False)
470 469
         mm.get_manager = Mock(return_value=v1)
471 470
 
... ...
@@ -483,21 +471,20 @@ class TestManager(unittest.TestCase):
483 483
             user='admin',
484 484
         ))
485 485
 
486
-        client = AnsibleF5Client(
486
+        module = AnsibleModule(
487 487
             argument_spec=self.spec.argument_spec,
488
-            supports_check_mode=self.spec.supports_check_mode,
489
-            f5_product_name=self.spec.f5_product_name
488
+            supports_check_mode=self.spec.supports_check_mode
490 489
         )
491 490
 
492 491
         msg = 'Import policy task failed.'
493 492
         # Override methods to force specific logic in the module to happen
494
-        v1 = V1Manager(client)
493
+        v1 = V1Manager(module=module)
495 494
         v1.exists = Mock(return_value=False)
496 495
         v1.import_to_device = Mock(return_value=True)
497 496
         v1.wait_for_task = Mock(return_value=False)
498 497
 
499 498
         # Override methods to force specific logic in the module to happen
500
-        mm = ModuleManager(client)
499
+        mm = ModuleManager(module=module)
501 500
         mm.version_is_less_than_13 = Mock(return_value=False)
502 501
         mm.get_manager = Mock(return_value=v1)
503 502
 
... ...
@@ -515,16 +502,15 @@ class TestManager(unittest.TestCase):
515 515
             user='admin',
516 516
         ))
517 517
 
518
-        current = V1Parameters(load_fixture('load_asm_policy_inactive.json'))
519
-        client = AnsibleF5Client(
518
+        current = V1Parameters(params=load_fixture('load_asm_policy_inactive.json'))
519
+        module = AnsibleModule(
520 520
             argument_spec=self.spec.argument_spec,
521
-            supports_check_mode=self.spec.supports_check_mode,
522
-            f5_product_name=self.spec.f5_product_name
521
+            supports_check_mode=self.spec.supports_check_mode
523 522
         )
524 523
 
525 524
         msg = 'Apply policy task failed.'
526 525
         # Override methods to force specific logic in the module to happen
527
-        v1 = V1Manager(client)
526
+        v1 = V1Manager(module=module)
528 527
         v1.exists = Mock(return_value=True)
529 528
         v1.wait_for_task = Mock(return_value=False)
530 529
         v1.update_on_device = Mock(return_value=True)
... ...
@@ -532,7 +518,7 @@ class TestManager(unittest.TestCase):
532 532
         v1.apply_on_device = Mock(return_value=True)
533 533
 
534 534
         # Override methods to force specific logic in the module to happen
535
-        mm = ModuleManager(client)
535
+        mm = ModuleManager(module=module)
536 536
         mm.version_is_less_than_13 = Mock(return_value=False)
537 537
         mm.get_manager = Mock(return_value=v1)
538 538
 
... ...
@@ -549,21 +535,20 @@ class TestManager(unittest.TestCase):
549 549
             user='admin',
550 550
         ))
551 551
 
552
-        client = AnsibleF5Client(
552
+        module = AnsibleModule(
553 553
             argument_spec=self.spec.argument_spec,
554
-            supports_check_mode=self.spec.supports_check_mode,
555
-            f5_product_name=self.spec.f5_product_name
554
+            supports_check_mode=self.spec.supports_check_mode
556 555
         )
557 556
 
558 557
         msg = 'Failed to create ASM policy: fake_policy'
559 558
         # Override methods to force specific logic in the module to happen
560
-        v1 = V1Manager(client)
559
+        v1 = V1Manager(module=module)
561 560
         v1.exists = Mock(return_value=False)
562 561
         v1.create_on_device = Mock(return_value=False)
563 562
         v1._file_is_missing = Mock(return_value=False)
564 563
 
565 564
         # Override methods to force specific logic in the module to happen
566
-        mm = ModuleManager(client)
565
+        mm = ModuleManager(module=module)
567 566
         mm.version_is_less_than_13 = Mock(return_value=False)
568 567
         mm.get_manager = Mock(return_value=v1)
569 568
 
... ...
@@ -580,19 +565,18 @@ class TestManager(unittest.TestCase):
580 580
             user='admin',
581 581
         ))
582 582
 
583
-        client = AnsibleF5Client(
583
+        module = AnsibleModule(
584 584
             argument_spec=self.spec.argument_spec,
585
-            supports_check_mode=self.spec.supports_check_mode,
586
-            f5_product_name=self.spec.f5_product_name
585
+            supports_check_mode=self.spec.supports_check_mode
587 586
         )
588 587
         msg = 'Failed to delete ASM policy: fake_policy'
589 588
         # Override methods to force specific logic in the module to happen
590
-        v1 = V1Manager(client)
589
+        v1 = V1Manager(module=module)
591 590
         v1.exists = Mock(side_effect=[True, True])
592 591
         v1.remove_from_device = Mock(return_value=True)
593 592
 
594 593
         # Override methods to force specific logic in the module to happen
595
-        mm = ModuleManager(client)
594
+        mm = ModuleManager(module=module)
596 595
         mm.version_is_less_than_13 = Mock(return_value=False)
597 596
         mm.get_manager = Mock(return_value=v1)
598 597
 
... ...
@@ -17,20 +17,22 @@ if sys.version_info < (2, 7):
17 17
 from ansible.compat.tests import unittest
18 18
 from ansible.compat.tests.mock import patch
19 19
 from ansible.compat.tests.mock import Mock
20
-from ansible.module_utils.f5_utils import AnsibleF5Client
20
+from ansible.module_utils.basic import AnsibleModule
21 21
 
22 22
 try:
23 23
     from library.bigip_command import Parameters
24 24
     from library.bigip_command import ModuleManager
25 25
     from library.bigip_command import ArgumentSpec
26
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
26
+    from library.module_utils.network.f5.common import F5ModuleError
27
+    from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
27 28
     from test.unit.modules.utils import set_module_args
28 29
 except ImportError:
29 30
     try:
30 31
         from ansible.modules.network.f5.bigip_command import Parameters
31 32
         from ansible.modules.network.f5.bigip_command import ModuleManager
32 33
         from ansible.modules.network.f5.bigip_command import ArgumentSpec
33
-        from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
34
+        from ansible.module_utils.network.f5.common import F5ModuleError
35
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
34 36
         from units.modules.utils import set_module_args
35 37
     except ImportError:
36 38
         raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
... ...
@@ -61,12 +63,10 @@ class TestParameters(unittest.TestCase):
61 61
             user='admin',
62 62
             password='password'
63 63
         )
64
-        p = Parameters(args)
64
+        p = Parameters(params=args)
65 65
         assert len(p.commands) == 2
66 66
 
67 67
 
68
-@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
69
-       return_value=True)
70 68
 class TestManager(unittest.TestCase):
71 69
 
72 70
     def setUp(self):
... ...
@@ -82,12 +82,12 @@ class TestManager(unittest.TestCase):
82 82
             password='password'
83 83
         ))
84 84
 
85
-        client = AnsibleF5Client(
85
+        module = AnsibleModule(
86 86
             argument_spec=self.spec.argument_spec,
87
-            supports_check_mode=self.spec.supports_check_mode,
88
-            f5_product_name=self.spec.f5_product_name
87
+            supports_check_mode=self.spec.supports_check_mode
89 88
         )
90
-        mm = ModuleManager(client)
89
+
90
+        mm = ModuleManager(module=module)
91 91
         mm._run_commands = Mock(return_value=[])
92 92
         mm.execute_on_device = Mock(return_value=[])
93 93
 
... ...
@@ -107,12 +107,11 @@ class TestManager(unittest.TestCase):
107 107
             password='password'
108 108
         ))
109 109
 
110
-        client = AnsibleF5Client(
110
+        module = AnsibleModule(
111 111
             argument_spec=self.spec.argument_spec,
112
-            supports_check_mode=self.spec.supports_check_mode,
113
-            f5_product_name=self.spec.f5_product_name
112
+            supports_check_mode=self.spec.supports_check_mode
114 113
         )
115
-        mm = ModuleManager(client)
114
+        mm = ModuleManager(module=module)
116 115
         mm._run_commands = Mock(return_value=[])
117 116
         mm.execute_on_device = Mock(return_value=[])
118 117
 
... ...
@@ -132,12 +131,12 @@ class TestManager(unittest.TestCase):
132 132
             password='password',
133 133
             transport='cli'
134 134
         ))
135
-        client = AnsibleF5Client(
135
+
136
+        module = AnsibleModule(
136 137
             argument_spec=self.spec.argument_spec,
137
-            supports_check_mode=self.spec.supports_check_mode,
138
-            f5_product_name=self.spec.f5_product_name
138
+            supports_check_mode=self.spec.supports_check_mode
139 139
         )
140
-        mm = ModuleManager(client)
140
+        mm = ModuleManager(module=module)
141 141
         mm._run_commands = Mock(return_value=[])
142 142
         mm.execute_on_device = Mock(return_value=[])
143 143
 
... ...
@@ -159,12 +158,11 @@ class TestManager(unittest.TestCase):
159 159
             user='admin',
160 160
             password='password'
161 161
         ))
162
-        client = AnsibleF5Client(
162
+        module = AnsibleModule(
163 163
             argument_spec=self.spec.argument_spec,
164
-            supports_check_mode=self.spec.supports_check_mode,
165
-            f5_product_name=self.spec.f5_product_name
164
+            supports_check_mode=self.spec.supports_check_mode
166 165
         )
167
-        mm = ModuleManager(client)
166
+        mm = ModuleManager(module=module)
168 167
         mm._run_commands = Mock(return_value=[])
169 168
         mm.execute_on_device = Mock(return_value=[])
170 169
 
... ...
@@ -17,20 +17,22 @@ if sys.version_info < (2, 7):
17 17
 from ansible.compat.tests import unittest
18 18
 from ansible.compat.tests.mock import Mock
19 19
 from ansible.compat.tests.mock import patch
20
-from ansible.module_utils.f5_utils import AnsibleF5Client
20
+from ansible.module_utils.basic import AnsibleModule
21 21
 
22 22
 try:
23 23
     from library.bigip_config import Parameters
24 24
     from library.bigip_config import ModuleManager
25 25
     from library.bigip_config import ArgumentSpec
26
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
26
+    from library.module_utils.network.f5.common import F5ModuleError
27
+    from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
27 28
     from test.unit.modules.utils import set_module_args
28 29
 except ImportError:
29 30
     try:
30 31
         from ansible.modules.network.f5.bigip_config import Parameters
31 32
         from ansible.modules.network.f5.bigip_config import ModuleManager
32 33
         from ansible.modules.network.f5.bigip_config import ArgumentSpec
33
-        from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
34
+        from ansible.module_utils.network.f5.common import F5ModuleError
35
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
34 36
         from units.modules.utils import set_module_args
35 37
     except ImportError:
36 38
         raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
... ...
@@ -68,14 +70,12 @@ class TestParameters(unittest.TestCase):
68 68
             user='admin',
69 69
             password='password'
70 70
         )
71
-        p = Parameters(args)
71
+        p = Parameters(params=args)
72 72
         assert p.save == 'yes'
73 73
         assert p.reset == 'yes'
74 74
         assert p.merge_content == 'asdasd'
75 75
 
76 76
 
77
-@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
78
-       return_value=True)
79 77
 class TestManager(unittest.TestCase):
80 78
 
81 79
     def setUp(self):
... ...
@@ -92,12 +92,11 @@ class TestManager(unittest.TestCase):
92 92
             password='password'
93 93
         ))
94 94
 
95
-        client = AnsibleF5Client(
95
+        module = AnsibleModule(
96 96
             argument_spec=self.spec.argument_spec,
97
-            supports_check_mode=self.spec.supports_check_mode,
98
-            f5_product_name=self.spec.f5_product_name
97
+            supports_check_mode=self.spec.supports_check_mode
99 98
         )
100
-        mm = ModuleManager(client)
99
+        mm = ModuleManager(module=module)
101 100
 
102 101
         # Override methods to force specific logic in the module to happen
103 102
         mm.exit_json = Mock(return_value=True)
... ...
@@ -17,20 +17,22 @@ if sys.version_info < (2, 7):
17 17
 from ansible.compat.tests import unittest
18 18
 from ansible.compat.tests.mock import Mock
19 19
 from ansible.compat.tests.mock import patch
20
-from ansible.module_utils.f5_utils import AnsibleF5Client
20
+from ansible.module_utils.basic import AnsibleModule
21 21
 
22 22
 try:
23 23
     from library.bigip_configsync_actions import Parameters
24 24
     from library.bigip_configsync_actions import ModuleManager
25 25
     from library.bigip_configsync_actions import ArgumentSpec
26
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
26
+    from library.module_utils.network.f5.common import F5ModuleError
27
+    from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
27 28
     from test.unit.modules.utils import set_module_args
28 29
 except ImportError:
29 30
     try:
30 31
         from ansible.modules.network.f5.bigip_configsync_actions import Parameters
31 32
         from ansible.modules.network.f5.bigip_configsync_actions import ModuleManager
32 33
         from ansible.modules.network.f5.bigip_configsync_actions import ArgumentSpec
33
-        from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
34
+        from ansible.module_utils.network.f5.common import F5ModuleError
35
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
34 36
         from units.modules.utils import set_module_args
35 37
     except ImportError:
36 38
         raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
... ...
@@ -65,7 +67,7 @@ class TestParameters(unittest.TestCase):
65 65
             overwrite_config=True,
66 66
             device_group="foo"
67 67
         )
68
-        p = Parameters(args)
68
+        p = Parameters(params=args)
69 69
         assert p.sync_device_to_group is True
70 70
         assert p.sync_group_to_device is True
71 71
         assert p.overwrite_config is True
... ...
@@ -78,15 +80,13 @@ class TestParameters(unittest.TestCase):
78 78
             overwrite_config='yes',
79 79
             device_group="foo"
80 80
         )
81
-        p = Parameters(args)
81
+        p = Parameters(params=args)
82 82
         assert p.sync_device_to_group is True
83 83
         assert p.sync_group_to_device is False
84 84
         assert p.overwrite_config is True
85 85
         assert p.device_group == 'foo'
86 86
 
87 87
 
88
-@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
89
-       return_value=True)
90 88
 class TestManager(unittest.TestCase):
91 89
 
92 90
     def setUp(self):
... ...
@@ -101,12 +101,11 @@ class TestManager(unittest.TestCase):
101 101
             user='admin'
102 102
         ))
103 103
 
104
-        client = AnsibleF5Client(
104
+        module = AnsibleModule(
105 105
             argument_spec=self.spec.argument_spec,
106
-            supports_check_mode=self.spec.supports_check_mode,
107
-            f5_product_name=self.spec.f5_product_name
106
+            supports_check_mode=self.spec.supports_check_mode
108 107
         )
109
-        mm = ModuleManager(client)
108
+        mm = ModuleManager(module=module)
110 109
 
111 110
         # Override methods to force specific logic in the module to happen
112 111
         mm._device_group_exists = Mock(return_value=True)
... ...
@@ -18,21 +18,24 @@ if sys.version_info < (2, 7):
18 18
 from ansible.compat.tests import unittest
19 19
 from ansible.compat.tests.mock import Mock
20 20
 from ansible.compat.tests.mock import patch
21
-from ansible.module_utils.f5_utils import AnsibleF5Client
22
-from ansible.module_utils.f5_utils import F5ModuleError
21
+from ansible.module_utils.basic import AnsibleModule
23 22
 
24 23
 try:
25
-    from library.bigip_device_connectivity import Parameters
24
+    from library.bigip_device_connectivity import ApiParameters
25
+    from library.bigip_device_connectivity import ModuleParameters
26 26
     from library.bigip_device_connectivity import ModuleManager
27 27
     from library.bigip_device_connectivity import ArgumentSpec
28
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
28
+    from library.module_utils.network.f5.common import F5ModuleError
29
+    from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
29 30
     from test.unit.modules.utils import set_module_args
30 31
 except ImportError:
31 32
     try:
32
-        from ansible.modules.network.f5.bigip_device_connectivity import Parameters
33
+        from ansible.modules.network.f5.bigip_device_connectivity import ApiParameters
34
+        from ansible.modules.network.f5.bigip_device_connectivity import ModuleParameters
33 35
         from ansible.modules.network.f5.bigip_device_connectivity import ModuleManager
34 36
         from ansible.modules.network.f5.bigip_device_connectivity import ArgumentSpec
35
-        from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
37
+        from ansible.module_utils.network.f5.common import F5ModuleError
38
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
36 39
         from units.modules.utils import set_module_args
37 40
     except ImportError:
38 41
         raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
... ...
@@ -80,7 +83,7 @@ class TestParameters(unittest.TestCase):
80 80
             user='admin',
81 81
             password='password'
82 82
         )
83
-        p = Parameters(args)
83
+        p = ModuleParameters(params=args)
84 84
         assert p.multicast_port == 1010
85 85
         assert p.multicast_address == '10.10.10.10'
86 86
         assert p.multicast_interface == 'eth0'
... ...
@@ -100,7 +103,7 @@ class TestParameters(unittest.TestCase):
100 100
 
101 101
     def test_api_parameters(self):
102 102
         params = load_fixture('load_tm_cm_device.json')
103
-        p = Parameters(params)
103
+        p = ApiParameters(params=params)
104 104
         assert p.multicast_port == 62960
105 105
         assert p.multicast_address == '224.0.0.245'
106 106
         assert p.multicast_interface == 'eth0'
... ...
@@ -118,8 +121,6 @@ class TestParameters(unittest.TestCase):
118 118
         assert p.unicast_failover[0]['effectivePort'] == 1026
119 119
 
120 120
 
121
-@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
122
-       return_value=True)
123 121
 class TestManager(unittest.TestCase):
124 122
 
125 123
     def setUp(self):
... ...
@@ -141,14 +142,13 @@ class TestManager(unittest.TestCase):
141 141
 
142 142
         # Configure the parameters that would be returned by querying the
143 143
         # remote device
144
-        current = Parameters(load_fixture('load_tm_cm_device_default.json'))
144
+        current = ApiParameters(params=load_fixture('load_tm_cm_device_default.json'))
145 145
 
146
-        client = AnsibleF5Client(
146
+        module = AnsibleModule(
147 147
             argument_spec=self.spec.argument_spec,
148
-            supports_check_mode=self.spec.supports_check_mode,
149
-            f5_product_name=self.spec.f5_product_name
148
+            supports_check_mode=self.spec.supports_check_mode
150 149
         )
151
-        mm = ModuleManager(client)
150
+        mm = ModuleManager(module=module)
152 151
 
153 152
         # Override methods to force specific logic in the module to happen
154 153
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -159,7 +159,7 @@ class TestManager(unittest.TestCase):
159 159
         assert results['changed'] is True
160 160
         assert results['config_sync_ip'] == '10.1.30.1'
161 161
         assert results['mirror_primary_address'] == '10.1.30.1'
162
-        assert len(results.keys()) == 3
162
+        assert len(results.keys()) == 4
163 163
 
164 164
     def test_set_primary_mirror_address_none(self, *args):
165 165
         set_module_args(dict(
... ...
@@ -171,14 +171,13 @@ class TestManager(unittest.TestCase):
171 171
 
172 172
         # Configure the parameters that would be returned by querying the
173 173
         # remote device
174
-        current = Parameters(load_fixture('load_tm_cm_device.json'))
174
+        current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
175 175
 
176
-        client = AnsibleF5Client(
176
+        module = AnsibleModule(
177 177
             argument_spec=self.spec.argument_spec,
178
-            supports_check_mode=self.spec.supports_check_mode,
179
-            f5_product_name=self.spec.f5_product_name
178
+            supports_check_mode=self.spec.supports_check_mode
180 179
         )
181
-        mm = ModuleManager(client)
180
+        mm = ModuleManager(module=module)
182 181
 
183 182
         # Override methods to force specific logic in the module to happen
184 183
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -200,14 +199,13 @@ class TestManager(unittest.TestCase):
200 200
 
201 201
         # Configure the parameters that would be returned by querying the
202 202
         # remote device
203
-        current = Parameters(load_fixture('load_tm_cm_device.json'))
203
+        current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
204 204
 
205
-        client = AnsibleF5Client(
205
+        module = AnsibleModule(
206 206
             argument_spec=self.spec.argument_spec,
207
-            supports_check_mode=self.spec.supports_check_mode,
208
-            f5_product_name=self.spec.f5_product_name
207
+            supports_check_mode=self.spec.supports_check_mode
209 208
         )
210
-        mm = ModuleManager(client)
209
+        mm = ModuleManager(module=module)
211 210
 
212 211
         # Override methods to force specific logic in the module to happen
213 212
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -229,14 +227,13 @@ class TestManager(unittest.TestCase):
229 229
 
230 230
         # Configure the parameters that would be returned by querying the
231 231
         # remote device
232
-        current = Parameters(load_fixture('load_tm_cm_device.json'))
232
+        current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
233 233
 
234
-        client = AnsibleF5Client(
234
+        module = AnsibleModule(
235 235
             argument_spec=self.spec.argument_spec,
236
-            supports_check_mode=self.spec.supports_check_mode,
237
-            f5_product_name=self.spec.f5_product_name
236
+            supports_check_mode=self.spec.supports_check_mode
238 237
         )
239
-        mm = ModuleManager(client)
238
+        mm = ModuleManager(module=module)
240 239
 
241 240
         # Override methods to force specific logic in the module to happen
242 241
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -258,14 +255,13 @@ class TestManager(unittest.TestCase):
258 258
 
259 259
         # Configure the parameters that would be returned by querying the
260 260
         # remote device
261
-        current = Parameters(load_fixture('load_tm_cm_device.json'))
261
+        current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
262 262
 
263
-        client = AnsibleF5Client(
263
+        module = AnsibleModule(
264 264
             argument_spec=self.spec.argument_spec,
265
-            supports_check_mode=self.spec.supports_check_mode,
266
-            f5_product_name=self.spec.f5_product_name
265
+            supports_check_mode=self.spec.supports_check_mode
267 266
         )
268
-        mm = ModuleManager(client)
267
+        mm = ModuleManager(module=module)
269 268
 
270 269
         # Override methods to force specific logic in the module to happen
271 270
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -286,14 +282,13 @@ class TestManager(unittest.TestCase):
286 286
 
287 287
         # Configure the parameters that would be returned by querying the
288 288
         # remote device
289
-        current = Parameters(load_fixture('load_tm_cm_device.json'))
289
+        current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
290 290
 
291
-        client = AnsibleF5Client(
291
+        module = AnsibleModule(
292 292
             argument_spec=self.spec.argument_spec,
293
-            supports_check_mode=self.spec.supports_check_mode,
294
-            f5_product_name=self.spec.f5_product_name
293
+            supports_check_mode=self.spec.supports_check_mode
295 294
         )
296
-        mm = ModuleManager(client)
295
+        mm = ModuleManager(module=module)
297 296
 
298 297
         # Override methods to force specific logic in the module to happen
299 298
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -315,14 +310,13 @@ class TestManager(unittest.TestCase):
315 315
 
316 316
         # Configure the parameters that would be returned by querying the
317 317
         # remote device
318
-        current = Parameters(load_fixture('load_tm_cm_device.json'))
318
+        current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
319 319
 
320
-        client = AnsibleF5Client(
320
+        module = AnsibleModule(
321 321
             argument_spec=self.spec.argument_spec,
322
-            supports_check_mode=self.spec.supports_check_mode,
323
-            f5_product_name=self.spec.f5_product_name
322
+            supports_check_mode=self.spec.supports_check_mode
324 323
         )
325
-        mm = ModuleManager(client)
324
+        mm = ModuleManager(module=module)
326 325
 
327 326
         # Override methods to force specific logic in the module to happen
328 327
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -344,14 +338,13 @@ class TestManager(unittest.TestCase):
344 344
 
345 345
         # Configure the parameters that would be returned by querying the
346 346
         # remote device
347
-        current = Parameters(load_fixture('load_tm_cm_device.json'))
347
+        current = ApiParameters(params=load_fixture('load_tm_cm_device.json'))
348 348
 
349
-        client = AnsibleF5Client(
349
+        module = AnsibleModule(
350 350
             argument_spec=self.spec.argument_spec,
351
-            supports_check_mode=self.spec.supports_check_mode,
352
-            f5_product_name=self.spec.f5_product_name
351
+            supports_check_mode=self.spec.supports_check_mode
353 352
         )
354
-        mm = ModuleManager(client)
353
+        mm = ModuleManager(module=module)
355 354
 
356 355
         # Override methods to force specific logic in the module to happen
357 356
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -18,21 +18,22 @@ if sys.version_info < (2, 7):
18 18
 from ansible.compat.tests import unittest
19 19
 from ansible.compat.tests.mock import Mock
20 20
 from ansible.compat.tests.mock import patch
21
-from ansible.module_utils.f5_utils import AnsibleF5Client
22
-from ansible.module_utils.f5_utils import F5ModuleError
21
+from ansible.module_utils.basic import AnsibleModule
23 22
 
24 23
 try:
25 24
     from library.bigip_device_dns import Parameters
26 25
     from library.bigip_device_dns import ModuleManager
27 26
     from library.bigip_device_dns import ArgumentSpec
28
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
27
+    from library.module_utils.network.f5.common import F5ModuleError
28
+    from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
29 29
     from test.unit.modules.utils import set_module_args
30 30
 except ImportError:
31 31
     try:
32 32
         from ansible.modules.network.f5.bigip_device_dns import Parameters
33 33
         from ansible.modules.network.f5.bigip_device_dns import ModuleManager
34 34
         from ansible.modules.network.f5.bigip_device_dns import ArgumentSpec
35
-        from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
35
+        from ansible.module_utils.network.f5.common import F5ModuleError
36
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
36 37
         from units.modules.utils import set_module_args
37 38
     except ImportError:
38 39
         raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
... ...
@@ -71,7 +72,7 @@ class TestParameters(unittest.TestCase):
71 71
             user='admin',
72 72
             password='password'
73 73
         )
74
-        p = Parameters(args)
74
+        p = Parameters(params=args)
75 75
         assert p.cache == 'disable'
76 76
         assert p.name_servers == ['10.10.10.10', '11.11.11.11']
77 77
         assert p.search == ['14.14.14.14', '15.15.15.15']
... ...
@@ -83,16 +84,16 @@ class TestParameters(unittest.TestCase):
83 83
         args = dict(
84 84
             ip_version=6
85 85
         )
86
-        p = Parameters(args)
86
+        p = Parameters(params=args)
87 87
         assert p.ip_version == 'options inet6'
88 88
 
89 89
     def test_ensure_forwards_raises_exception(self):
90 90
         args = dict(
91 91
             forwarders=['12.12.12.12', '13.13.13.13'],
92 92
         )
93
-        p = Parameters(args)
93
+        p = Parameters(params=args)
94 94
         with pytest.raises(F5ModuleError) as ex:
95
-            foo = p.forwarders
95
+            p.forwarders
96 96
         assert 'The modifying of forwarders is not supported' in str(ex)
97 97
 
98 98
 
... ...
@@ -101,8 +102,6 @@ class TestManager(unittest.TestCase):
101 101
     def setUp(self):
102 102
         self.spec = ArgumentSpec()
103 103
 
104
-    @patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
105
-           return_value=True)
106 104
     def test_update_settings(self, *args):
107 105
         set_module_args(dict(
108 106
             cache='disable',
... ...
@@ -123,12 +122,11 @@ class TestManager(unittest.TestCase):
123 123
             )
124 124
         )
125 125
 
126
-        client = AnsibleF5Client(
126
+        module = AnsibleModule(
127 127
             argument_spec=self.spec.argument_spec,
128
-            supports_check_mode=self.spec.supports_check_mode,
129
-            f5_product_name=self.spec.f5_product_name
128
+            supports_check_mode=self.spec.supports_check_mode
130 129
         )
131
-        mm = ModuleManager(client)
130
+        mm = ModuleManager(module=module)
132 131
 
133 132
         # Override methods to force specific logic in the module to happen
134 133
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -17,20 +17,22 @@ if sys.version_info < (2, 7):
17 17
 from ansible.compat.tests import unittest
18 18
 from ansible.compat.tests.mock import Mock
19 19
 from ansible.compat.tests.mock import patch
20
-from ansible.module_utils.f5_utils import AnsibleF5Client
20
+from ansible.module_utils.basic import AnsibleModule
21 21
 
22 22
 try:
23 23
     from library.bigip_device_httpd import Parameters
24 24
     from library.bigip_device_httpd import ModuleManager
25 25
     from library.bigip_device_httpd import ArgumentSpec
26
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
26
+    from library.module_utils.network.f5.common import F5ModuleError
27
+    from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
27 28
     from test.unit.modules.utils import set_module_args
28 29
 except ImportError:
29 30
     try:
30 31
         from ansible.modules.network.f5.bigip_device_httpd import Parameters
31 32
         from ansible.modules.network.f5.bigip_device_httpd import ModuleManager
32 33
         from ansible.modules.network.f5.bigip_device_httpd import ArgumentSpec
33
-        from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
34
+        from ansible.module_utils.network.f5.common import F5ModuleError
35
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
34 36
         from units.modules.utils import set_module_args
35 37
     except ImportError:
36 38
         raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
... ...
@@ -65,20 +67,18 @@ class TestParameters(unittest.TestCase):
65 65
             auth_pam_validate_ip='on'
66 66
         )
67 67
 
68
-        p = Parameters(args)
68
+        p = Parameters(params=args)
69 69
         assert p.auth_name == 'BIG-IP'
70 70
         assert p.auth_pam_idle_timeout == 1200
71 71
         assert p.auth_pam_validate_ip == 'on'
72 72
 
73 73
     def test_api_parameters(self):
74 74
         args = load_fixture('load_sys_httpd.json')
75
-        p = Parameters(args)
75
+        p = Parameters(params=args)
76 76
         assert p.auth_name == 'BIG-IP'
77 77
         assert p.auth_pam_idle_timeout == 1200
78 78
 
79 79
 
80
-@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
81
-       return_value=True)
82 80
 class TestModuleManager(unittest.TestCase):
83 81
 
84 82
     def setUp(self):
... ...
@@ -103,16 +103,13 @@ class TestModuleManager(unittest.TestCase):
103 103
             )
104 104
         )
105 105
 
106
-        current = Parameters(
107
-            load_fixture('load_sys_httpd.json')
108
-        )
106
+        current = Parameters(params=load_fixture('load_sys_httpd.json'))
109 107
 
110
-        client = AnsibleF5Client(
108
+        module = AnsibleModule(
111 109
             argument_spec=self.spec.argument_spec,
112
-            supports_check_mode=self.spec.supports_check_mode,
113
-            f5_product_name=self.spec.f5_product_name
110
+            supports_check_mode=self.spec.supports_check_mode
114 111
         )
115
-        mm = ModuleManager(client)
112
+        mm = ModuleManager(module=module)
116 113
 
117 114
         # Override methods to force specific logic in the module to happen
118 115
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -17,20 +17,22 @@ if sys.version_info < (2, 7):
17 17
 from ansible.compat.tests import unittest
18 18
 from ansible.compat.tests.mock import Mock
19 19
 from ansible.compat.tests.mock import patch
20
-from ansible.module_utils.f5_utils import AnsibleF5Client
20
+from ansible.module_utils.basic import AnsibleModule
21 21
 
22 22
 try:
23 23
     from library.bigip_device_ntp import Parameters
24 24
     from library.bigip_device_ntp import ModuleManager
25 25
     from library.bigip_device_ntp import ArgumentSpec
26
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
26
+    from library.module_utils.network.f5.common import F5ModuleError
27
+    from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
27 28
     from test.unit.modules.utils import set_module_args
28 29
 except ImportError:
29 30
     try:
30 31
         from ansible.modules.network.f5.bigip_device_ntp import Parameters
31 32
         from ansible.modules.network.f5.bigip_device_ntp import ModuleManager
32 33
         from ansible.modules.network.f5.bigip_device_ntp import ArgumentSpec
33
-        from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
34
+        from ansible.module_utils.network.f5.common import F5ModuleError
35
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
34 36
         from units.modules.utils import set_module_args
35 37
     except ImportError:
36 38
         raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
... ...
@@ -65,7 +67,7 @@ class TestParameters(unittest.TestCase):
65 65
             timezone='Arctic/Longyearbyen'
66 66
         )
67 67
 
68
-        p = Parameters(args)
68
+        p = Parameters(params=args)
69 69
         assert p.ntp_servers == ntp
70 70
         assert p.timezone == 'Arctic/Longyearbyen'
71 71
 
... ...
@@ -76,13 +78,11 @@ class TestParameters(unittest.TestCase):
76 76
             timezone='Arctic/Longyearbyen'
77 77
         )
78 78
 
79
-        p = Parameters(args)
79
+        p = Parameters(params=args)
80 80
         assert p.ntp_servers == ntp
81 81
         assert p.timezone == 'Arctic/Longyearbyen'
82 82
 
83 83
 
84
-@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
85
-       return_value=True)
86 84
 class TestModuleManager(unittest.TestCase):
87 85
 
88 86
     def setUp(self):
... ...
@@ -101,16 +101,13 @@ class TestModuleManager(unittest.TestCase):
101 101
 
102 102
         # Configure the parameters that would be returned by querying the
103 103
         # remote device
104
-        current = Parameters(
105
-            load_fixture('load_ntp.json')
106
-        )
104
+        current = Parameters(params=load_fixture('load_ntp.json'))
107 105
 
108
-        client = AnsibleF5Client(
106
+        module = AnsibleModule(
109 107
             argument_spec=self.spec.argument_spec,
110
-            supports_check_mode=self.spec.supports_check_mode,
111
-            f5_product_name=self.spec.f5_product_name
108
+            supports_check_mode=self.spec.supports_check_mode
112 109
         )
113
-        mm = ModuleManager(client)
110
+        mm = ModuleManager(module=module)
114 111
 
115 112
         # Override methods to force specific logic in the module to happen
116 113
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -132,16 +129,13 @@ class TestModuleManager(unittest.TestCase):
132 132
 
133 133
         # Configure the parameters that would be returned by querying the
134 134
         # remote device
135
-        current = Parameters(
136
-            load_fixture('load_ntp.json')
137
-        )
135
+        current = Parameters(params=load_fixture('load_ntp.json'))
138 136
 
139
-        client = AnsibleF5Client(
137
+        module = AnsibleModule(
140 138
             argument_spec=self.spec.argument_spec,
141
-            supports_check_mode=self.spec.supports_check_mode,
142
-            f5_product_name=self.spec.f5_product_name
139
+            supports_check_mode=self.spec.supports_check_mode
143 140
         )
144
-        mm = ModuleManager(client)
141
+        mm = ModuleManager(module=module)
145 142
 
146 143
         # Override methods to force specific logic in the module to happen
147 144
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -165,16 +159,13 @@ class TestModuleManager(unittest.TestCase):
165 165
 
166 166
         # Configure the parameters that would be returned by querying the
167 167
         # remote device
168
-        current = Parameters(
169
-            load_fixture('load_ntp.json')
170
-        )
168
+        current = Parameters(params=load_fixture('load_ntp.json'))
171 169
 
172
-        client = AnsibleF5Client(
170
+        module = AnsibleModule(
173 171
             argument_spec=self.spec.argument_spec,
174
-            supports_check_mode=self.spec.supports_check_mode,
175
-            f5_product_name=self.spec.f5_product_name
172
+            supports_check_mode=self.spec.supports_check_mode
176 173
         )
177
-        mm = ModuleManager(client)
174
+        mm = ModuleManager(module=module)
178 175
 
179 176
         # Override methods to force specific logic in the module to happen
180 177
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -200,16 +191,13 @@ class TestModuleManager(unittest.TestCase):
200 200
 
201 201
         # Configure the parameters that would be returned by querying the
202 202
         # remote device
203
-        current = Parameters(
204
-            load_fixture('load_ntp.json')
205
-        )
203
+        current = Parameters(params=load_fixture('load_ntp.json'))
206 204
 
207
-        client = AnsibleF5Client(
205
+        module = AnsibleModule(
208 206
             argument_spec=self.spec.argument_spec,
209
-            supports_check_mode=self.spec.supports_check_mode,
210
-            f5_product_name=self.spec.f5_product_name
207
+            supports_check_mode=self.spec.supports_check_mode
211 208
         )
212
-        mm = ModuleManager(client)
209
+        mm = ModuleManager(module=module)
213 210
 
214 211
         # Override methods to force specific logic in the module to happen
215 212
         mm.absent_on_device = Mock(return_value=True)
... ...
@@ -233,16 +221,13 @@ class TestModuleManager(unittest.TestCase):
233 233
 
234 234
         # Configure the parameters that would be returned by querying the
235 235
         # remote device
236
-        current = Parameters(
237
-            load_fixture('load_ntp.json')
238
-        )
236
+        current = Parameters(params=load_fixture('load_ntp.json'))
239 237
 
240
-        client = AnsibleF5Client(
238
+        module = AnsibleModule(
241 239
             argument_spec=self.spec.argument_spec,
242
-            supports_check_mode=self.spec.supports_check_mode,
243
-            f5_product_name=self.spec.f5_product_name
240
+            supports_check_mode=self.spec.supports_check_mode
244 241
         )
245
-        mm = ModuleManager(client)
242
+        mm = ModuleManager(module=module)
246 243
 
247 244
         # Override methods to force specific logic in the module to happen
248 245
         mm.absent_on_device = Mock(return_value=True)
... ...
@@ -17,20 +17,22 @@ if sys.version_info < (2, 7):
17 17
 from ansible.compat.tests import unittest
18 18
 from ansible.compat.tests.mock import Mock
19 19
 from ansible.compat.tests.mock import patch
20
-from ansible.module_utils.f5_utils import AnsibleF5Client
20
+from ansible.module_utils.basic import AnsibleModule
21 21
 
22 22
 try:
23 23
     from library.bigip_device_sshd import Parameters
24 24
     from library.bigip_device_sshd import ModuleManager
25 25
     from library.bigip_device_sshd import ArgumentSpec
26
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
26
+    from library.module_utils.network.f5.common import F5ModuleError
27
+    from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
27 28
     from test.unit.modules.utils import set_module_args
28 29
 except ImportError:
29 30
     try:
30 31
         from ansible.modules.network.f5.bigip_device_sshd import Parameters
31 32
         from ansible.modules.network.f5.bigip_device_sshd import ModuleManager
32 33
         from ansible.modules.network.f5.bigip_device_sshd import ArgumentSpec
33
-        from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
34
+        from ansible.module_utils.network.f5.common import F5ModuleError
35
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
34 36
         from units.modules.utils import set_module_args
35 37
     except ImportError:
36 38
         raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
... ...
@@ -71,7 +73,7 @@ class TestParameters(unittest.TestCase):
71 71
             user='admin',
72 72
             password='password'
73 73
         )
74
-        p = Parameters(args)
74
+        p = Parameters(params=args)
75 75
         assert p.allow == ['all']
76 76
         assert p.banner == 'enabled'
77 77
         assert p.banner_text == 'asdf'
... ...
@@ -86,8 +88,6 @@ class TestManager(unittest.TestCase):
86 86
     def setUp(self):
87 87
         self.spec = ArgumentSpec()
88 88
 
89
-    @patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
90
-           return_value=True)
91 89
     def test_update_settings(self, *args):
92 90
         set_module_args(dict(
93 91
             allow=['all'],
... ...
@@ -110,12 +110,11 @@ class TestManager(unittest.TestCase):
110 110
             )
111 111
         )
112 112
 
113
-        client = AnsibleF5Client(
113
+        module = AnsibleModule(
114 114
             argument_spec=self.spec.argument_spec,
115
-            supports_check_mode=self.spec.supports_check_mode,
116
-            f5_product_name=self.spec.f5_product_name
115
+            supports_check_mode=self.spec.supports_check_mode
117 116
         )
118
-        mm = ModuleManager(client)
117
+        mm = ModuleManager(module=module)
119 118
 
120 119
         # Override methods to force specific logic in the module to happen
121 120
         mm.update_on_device = Mock(return_value=True)
... ...
@@ -17,7 +17,7 @@ if sys.version_info < (2, 7):
17 17
 from ansible.compat.tests import unittest
18 18
 from ansible.compat.tests.mock import Mock
19 19
 from ansible.compat.tests.mock import patch
20
-from ansible.module_utils.f5_utils import AnsibleF5Client
20
+from ansible.module_utils.basic import AnsibleModule
21 21
 
22 22
 try:
23 23
     from library.bigip_device_trust import Parameters
... ...
@@ -25,7 +25,8 @@ try:
25 25
     from library.bigip_device_trust import ArgumentSpec
26 26
     from library.bigip_device_trust import HAS_F5SDK
27 27
     from library.bigip_device_trust import HAS_NETADDR
28
-    from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
28
+    from library.module_utils.network.f5.common import F5ModuleError
29
+    from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
29 30
     from test.unit.modules.utils import set_module_args
30 31
 except ImportError:
31 32
     try:
... ...
@@ -34,7 +35,8 @@ except ImportError:
34 34
         from ansible.modules.network.f5.bigip_device_trust import ArgumentSpec
35 35
         from ansible.modules.network.f5.bigip_device_trust import HAS_F5SDK
36 36
         from ansible.modules.network.f5.bigip_device_trust import HAS_NETADDR
37
-        from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
37
+        from ansible.module_utils.network.f5.common import F5ModuleError
38
+        from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
38 39
         from units.modules.utils import set_module_args
39 40
     except ImportError:
40 41
         raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
... ...
@@ -74,7 +76,7 @@ class TestParameters(unittest.TestCase):
74 74
             peer_password='secret'
75 75
         )
76 76
 
77
-        p = Parameters(args)
77
+        p = Parameters(params=args)
78 78
         assert p.peer_server == '10.10.10.10'
79 79
         assert p.peer_hostname == 'foo.bar.baz'
80 80
         assert p.peer_user == 'admin'
... ...
@@ -89,7 +91,7 @@ class TestParameters(unittest.TestCase):
89 89
             type='peer'
90 90
         )
91 91
 
92
-        p = Parameters(args)
92
+        p = Parameters(params=args)
93 93
         assert p.peer_server == '10.10.10.10'
94 94
         assert p.peer_hostname == 'foo.bar.baz'
95 95
         assert p.peer_user == 'admin'
... ...
@@ -105,7 +107,7 @@ class TestParameters(unittest.TestCase):
105 105
             type='subordinate'
106 106
         )
107 107
 
108
-        p = Parameters(args)
108
+        p = Parameters(params=args)
109 109
         assert p.peer_server == '10.10.10.10'
110 110
         assert p.peer_hostname == 'foo.bar.baz'
111 111
         assert p.peer_user == 'admin'
... ...
@@ -113,8 +115,6 @@ class TestParameters(unittest.TestCase):
113 113
         assert p.type is False
114 114
 
115 115
 
116
-@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
117
-       return_value=True)
118 116
 class TestManager(unittest.TestCase):
119 117
 
120 118
     def setUp(self):
... ...
@@ -131,15 +131,14 @@ class TestManager(unittest.TestCase):
131 131
             user='admin'
132 132
         ))
133 133
 
134
-        client = AnsibleF5Client(
134
+        module = AnsibleModule(
135 135
             argument_spec=self.spec.argument_spec,
136
-            supports_check_mode=self.spec.supports_check_mode,
137
-            f5_product_name=self.spec.f5_product_name
136
+            supports_check_mode=self.spec.supports_check_mode
138 137
         )
139 138
 
140 139
         # Override methods in the specific type of manager
141
-        mm = ModuleManager(client)
142
-        mm.exists = Mock(side_effect=[False, True])
140
+        mm = ModuleManager(module=module)
141
+        mm.exists = Mock(return_value=False)
143 142
         mm.create_on_device = Mock(return_value=True)
144 143
 
145 144
         results = mm.exec_module()
... ...
@@ -157,14 +156,13 @@ class TestManager(unittest.TestCase):
157 157
             user='admin'
158 158
         ))
159 159
 
160
-        client = AnsibleF5Client(
160
+        module = AnsibleModule(
161 161
             argument_spec=self.spec.argument_spec,
162
-            supports_check_mode=self.spec.supports_check_mode,
163
-            f5_product_name=self.spec.f5_product_name
162
+            supports_check_mode=self.spec.supports_check_mode
164 163
         )
165 164
 
166 165
         # Override methods in the specific type of manager
167
-        mm = ModuleManager(client)
166
+        mm = ModuleManager(module=module)
168 167
         mm.exists = Mock(return_value=True)
169 168
 
170 169
         results = mm.exec_module()