Repository: RedHatInsights/insights-core

Issue:
Create a PS combiner to consolidate data from PS parsers 
Create a PS combiner that consolidates processes data (PS command based) from all the PS parsers. The combiner should have unified interface and standardized set of data attributes.  


Discussion:

Resolving patch:
diff --git a/insights/parsers/cloud_init_custom_network.py b/insights/parsers/cloud_init_custom_network.py
new file mode 100644
--- /dev/null
+++ b/insights/parsers/cloud_init_custom_network.py
@@ -0,0 +1,36 @@
+"""
+CloudInitCustomeNetwork - file ``/etc/cloud/cloud.cfg.d/99-custom-networking.cfg``
+==================================================================================
+
+This module provides parsing for cloudinit custom networking configuration file.
+``CloudInitCustomNetworking`` is a parser for ``/etc/cloud/cloud.cfg.d/99-custom-networking.cfg`` files.
+
+Typical output is::
+
+    network:
+      version: 1
+      config:
+      - type: physical
+        name: eth0
+        subnets:
+          - type: dhcp
+          - type: dhcp6
+
+Examples:
+    >>> cloud_init_custom_network_config.data['network']['config'][0]['name']
+    'eth0'
+    >>> cloud_init_custom_network_config.data['network']['config'][0]['subnets'][0]['type'] == 'dhcp'
+    True
+    >>> cloud_init_custom_network_config.data['network']['config'][0]['subnets'][1]['type'] == 'dhcp6'
+    True
+"""
+
+
+from insights import YAMLParser, parser
+from insights.specs import Specs
+
+
+@parser(Specs.cloud_init_custom_network)
+class CloudInitCustomNetworking(YAMLParser):
+    """ Class for parsing the content of ``/etc/cloud/cloud.cfg.d/99-custom-networking.cfg``."""
+    pass
diff --git a/insights/specs/__init__.py b/insights/specs/__init__.py
--- a/insights/specs/__init__.py
+++ b/insights/specs/__init__.py
@@ -70,6 +70,7 @@ class Specs(SpecSet):
     cinder_api_log = RegistryPoint(filterable=True)
     cinder_conf = RegistryPoint()
     cinder_volume_log = RegistryPoint(filterable=True)
+    cloud_init_custom_network = RegistryPoint()
     cloud_init_log = RegistryPoint(filterable=True)
     cluster_conf = RegistryPoint(filterable=True)
     cmdline = RegistryPoint()
diff --git a/insights/specs/default.py b/insights/specs/default.py
--- a/insights/specs/default.py
+++ b/insights/specs/default.py
@@ -187,6 +187,7 @@ def is_ceph_monitor(broker):
     cinder_api_log = first_file(["/var/log/containers/cinder/cinder-api.log", "/var/log/cinder/cinder-api.log"])
     cinder_conf = first_file(["/var/lib/config-data/puppet-generated/cinder/etc/cinder/cinder.conf", "/etc/cinder/cinder.conf"])
     cinder_volume_log = simple_file("/var/log/cinder/volume.log")
+    cloud_init_custom_network = simple_file("/etc/cloud/cloud.cfg.d/99-custom-networking.cfg")
     cloud_init_log = simple_file("/var/log/cloud-init.log")
     cluster_conf = simple_file("/etc/cluster/cluster.conf")
     cmdline = simple_file("/proc/cmdline")


Test patch:
diff --git a/insights/parsers/tests/test_cloud_init_custom_network.py b/insights/parsers/tests/test_cloud_init_custom_network.py
new file mode 100644
--- /dev/null
+++ b/insights/parsers/tests/test_cloud_init_custom_network.py
@@ -0,0 +1,30 @@
+from insights.parsers import cloud_init_custom_network
+from insights.parsers.cloud_init_custom_network import CloudInitCustomNetworking
+from insights.tests import context_wrap
+import doctest
+
+CLOUD_INIT_CONFIG = """
+network:
+    version: 1
+    config:
+    - type: physical
+      name: eth0
+      subnets:
+        - type: dhcp
+        - type: dhcp6
+"""
+
+
+def test_cloud_init_custom_network():
+    result = cloud_init_custom_network.CloudInitCustomNetworking(context_wrap(CLOUD_INIT_CONFIG))
+    assert result.data['network']['config'][0]['name'] == 'eth0'
+    assert result.data['network']['config'][0]['subnets'][0]['type'] == 'dhcp'
+    assert result.data['network']['config'][0]['subnets'][1]['type'] == 'dhcp6'
+
+
+def test_cloud_init_custom_networks_doc_examples():
+    env = {
+        'cloud_init_custom_network_config': CloudInitCustomNetworking(context_wrap(CLOUD_INIT_CONFIG)),
+    }
+    failed, total = doctest.testmod(cloud_init_custom_network, globs=env)
+    assert failed == 0