Repository: ansible/ansible
Pull request: Port cs_facts to the ansible 2.4 facts API
Fixes #27256
References #27254

##### SUMMARY
The facts API has changed in 2.4.  Need to port cs_facts to the new API as it calls facts to figure out dhcp leases.

This is also needed for enabling pylint tests for undefined varialbes.

##### ISSUE TYPE
 - Bugfix Pull Request

##### COMPONENT NAME
<!--- Name of the module/plugin/module/task -->
lib/ansible/modules/cloud/cloudstack/cs_facts.py

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
devel
```

Problem statement:
cs_facts needs porting to the new facts API
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
lib/ansible/modules/cloud/cloudstack/cs_facts.py

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
devel
```

##### SUMMARY
Cleaning up all undefined variables so that we can enable static analysis checks to keep new undefined variables from entering the code base.  the cs_facts module has two undefined variables that are caused by the 2.4 facts rewrite and needs to be fixed.

Here's the pylint output:
```
************* Module ansible.modules.cloud.cloudstack.cs_facts
E0611:109, 0: No name 'ansible_facts' in module 'ansible.module_utils.facts' (no-name-in-module)
E0611:109, 0: No name 'module' in module 'ansible.module_utils.facts' (no-name-in-module)
```

Hints from issue discussion:
@alikins are you able to look into this?  There's only a few problems left before we can enable the pylint tests.
cc @resmo
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Commit message: Port cs_facts to the ansible 2.4 facts API

Fixes #27256
Referenes #27254

Patch to review:
diff --git a/lib/ansible/modules/cloud/cloudstack/cs_facts.py b/lib/ansible/modules/cloud/cloudstack/cs_facts.py
index b6056e724ef8f2..b42104d4bb1d61 100644
--- a/lib/ansible/modules/cloud/cloudstack/cs_facts.py
+++ b/lib/ansible/modules/cloud/cloudstack/cs_facts.py
@@ -106,7 +106,7 @@
 import os
 from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils.urls import fetch_url
-from ansible.module_utils.facts import ansible_facts, module
+from ansible.module_utils.facts import ansible_collector, default_collectors
 
 try:
     import yaml
@@ -121,7 +121,12 @@
 class CloudStackFacts(object):
 
     def __init__(self):
-        self.facts = ansible_facts(module)
+        collector = ansible_collector.get_ansible_collector(all_collector_classes=default_collectors.collectors,
+                                                            filter_spec='default_ipv4',
+                                                            gather_subset=['network'],
+                                                            gather_timeout=10)
+        self.facts = fact_collector.collect(module)
+
         self.api_ip = None
         self.fact_paths = {
             'cloudstack_service_offering': 'service-offering',


Code review comments:
diff_hunk: @@ -121,7 +121,12 @@
 class CloudStackFacts(object):
 
     def __init__(self):
-        self.facts = ansible_facts(module)
+        collector = ansible_collector.get_ansible_collector(all_collector_classes=default_collectors.collectors,
+                                                            filter_spec='default_ipv4',
+                                                            gather_subset=['network'],
path: lib/ansible/modules/cloud/cloudstack/cs_facts.py
text: @user1:
once https://github.com/ansible/ansible/pull/27085 is merged, this could become
``` python
collector = ansible_collector.get_ansible_collector(all_collector_classes=default_collectors.collectors,
                                                            filter_spec='default_ipv4'
                                                            gather_subset=['!all', '!min', 'network'],
                                                            gather_timeout=10)
```

The '!all !min' will then prevent gathering the other 'minimal' facts and just grab the network facts.  


@user2:
you realize you need the min facts to decide which network facts to collect?