Add flexible management of lvm filters

Allow user to flexibly manage filters in lvm.conf via
linux:storage:lvm_filters dictionary

Change-Id: I37928610f0ec2bd3ef6f5eac2e5d555a0ce39aa2
Related-Prod: PROD-26396
diff --git a/README.rst b/README.rst
index cdbfeae..4efa5e2 100644
--- a/README.rst
+++ b/README.rst
@@ -2106,6 +2106,20 @@
                 data:
                   size: 40G
                   mount: ${linux:storage:mount:data}
+          # When set they will take precedence over filters aget from volume groups.
+          lvm_filters:
+            10:
+              enabled: True
+              value: "a|loop|"
+            20:
+              enabled: True
+              value: "r|/dev/hdc|"
+            30:
+              enabled: True
+              value: "a|/dev/ide|"
+            40:
+              enabled: True
+              value: "r|.*|"
 
 Create partitions on disk. Specify size in MB. It expects empty
 disk without any existing partitions.
diff --git a/linux/files/lvm.conf b/linux/files/lvm.conf
index a72870e..6f61439 100644
--- a/linux/files/lvm.conf
+++ b/linux/files/lvm.conf
@@ -141,15 +141,26 @@
         # This configuration option has an automatic default value.
         # filter = [ "a|.*/|" ]
         {% set filter_list=[] %}
-        {%- for vgname, vg in storage.lvm.items() %}
-          {%- if vg.get('enabled', True) %}
-            {%- for dev in vg.devices %}
-              {%- do filter_list.append("a|" + dev + "*|") %}
-            {%- endfor %}
+        {%- if storage.lvm_filters is defined %}
+          {%- set lvm_filters_dict_inted = salt['sharedlib.call']('misc.cast_dict_keys_to_int', storage.lvm_filters ) %}
+          {%- for id,filter in lvm_filters_dict_inted|dictsort -%}
+            {%- if filter.get('enabled', False) %}
+              {%- do filter_list.append(filter.value) %}
+            {%- endif %}
+          {%- endfor %}
+        {%- else %}
+          {%- for vgname, vg in storage.lvm.items() %}
+            {%- if vg.get('enabled', True) %}
+              {%- for dev in vg.devices %}
+                {%- do filter_list.append("a|" + dev + "*|") %}
+              {%- endfor %}
+            {%- endif %}
+          {%- endfor %}
+          {%- if filter_list|length > 0 %}
+            {%- do filter_list.append('r|.*|') %}
           {%- endif %}
-        {%- endfor %}
+        {%- endif %}
         {%- if filter_list|length > 0 %}
-        {%- do filter_list.append('r|.*|') %}
         filter = {{ filter_list }}
         {%- endif %}