Mount options for partitions and LVM volumes

Related-Prod: PROD-35384
Change-Id: Id6e684548f4ca993e21fd4884bf058a2e39a9bbb
diff --git a/README.rst b/README.rst
index a10c96b..57ac725 100644
--- a/README.rst
+++ b/README.rst
@@ -298,6 +298,8 @@
                     mount: '/'
                   part2:
                     size: 2G
+                    mount: '/var/tmp'
+                    mount_options: defaults,nodev,noexec,nosuid
                   part3:
                     size: 3G
               vdc:
@@ -338,6 +340,7 @@
                     size: 5G
                     type: ext4
                     mount: '/tmp'
+                    mount_options: defaults,nodev,noexec,nosuid
                   log:
                     size: 7G
                     type: ext4
diff --git a/_modules/maasng.py b/_modules/maasng.py
index 4002e05..06d9ef6 100644
--- a/_modules/maasng.py
+++ b/_modules/maasng.py
@@ -501,7 +501,7 @@
     return list_partitions(partition)[name]
 
 
-def create_partition(hostname, disk, size, fs_type=None, mount=None):
+def create_partition(hostname, disk, size, fs_type=None, mount=None, mount_options=None):
     """
     Create new partition on device.
 
@@ -551,6 +551,8 @@
         data = {
             "mount_point": mount
         }
+        if mount_options:
+            data["mount_options"] = mount_options
 
         # TODO validation
         json_res = json.loads(maas.post(u"api/2.0/nodes/{0}/blockdevices/{1}/partition/{2}".format(
@@ -1063,7 +1065,7 @@
 
 
 def create_volume(hostname, volume_name, volume_group, size, fs_type=None,
-                  mount=None):
+                  mount=None, mount_options=None):
     """
     Create volume on volume group.
 
@@ -1100,7 +1102,7 @@
 
     if fs_type != None or mount != None:
         ret = create_volume_filesystem(
-            hostname, volume_group + "-" + volume_name, fs_type, mount)
+            hostname, volume_group + "-" + volume_name, fs_type, mount, mount_options)
 
     return True
 
@@ -1156,7 +1158,7 @@
 # END LVM
 
 
-def create_volume_filesystem(hostname, device, fs_type=None, mount=None):
+def create_volume_filesystem(hostname, device, fs_type=None, mount=None, mount_options=None):
 
     maas = _create_maas_client()
     system_id = get_machine(hostname)["system_id"]
@@ -1172,6 +1174,8 @@
 
     if mount != None:
         data["mount_point"] = mount
+        if mount_options:
+            data["mount_options"] = mount_options
         # TODO validation
         json_res = json.loads(maas.post(u"/api/2.0/nodes/{0}/blockdevices/{1}/".format(
             system_id, blockdevices_id), "mount", **data).read())
diff --git a/_states/maasng.py b/_states/maasng.py
index 5c68652..763795d 100644
--- a/_states/maasng.py
+++ b/_states/maasng.py
@@ -229,10 +229,13 @@
         LOG.info(part)
         if "mount" not in part:
             part["mount"] = None
+        if "mount_options" not in part:
+            part["mount_options"] = None
         if "type" not in part:
             part["type"] = None
         ret["changes"] = __salt__['maasng.create_partition'](
-            hostname, name, part["size"], part["type"], part["mount"])
+            hostname, name, part["size"], part["type"], part["mount"],
+            part["mount_options"])
 
     if "error" in ret["changes"]:
         ret["result"] = False
@@ -290,7 +293,7 @@
 
 
 def volume_present(hostname, name, volume_group_name, size, type=None,
-                   mount=None):
+                   mount=None, mount_options=None):
     """
     Ensure that the disk layout does exist
 
@@ -326,7 +329,7 @@
     # TODO validation if exists
 
     ret["changes"] = __salt__['maasng.create_volume'](
-        hostname, name, volume_group_name, size, type, mount)
+        hostname, name, volume_group_name, size, type, mount, mount_options)
 
     return ret
 
diff --git a/maas/machines/storage.sls b/maas/machines/storage.sls
index d632c90..b6c174a 100644
--- a/maas/machines/storage.sls
+++ b/maas/machines/storage.sls
@@ -141,6 +141,9 @@
     {%- endif %}
     {%- if volume.mount is defined %}
     - mount: {{ volume.mount }}
+    {%- if volume.mount_options is defined %}
+    - mount_options: {{ volume.mount_options }}
+    {%- endif %}
     {%- endif %}
     - require:
       - maasng: maas_machine_vg_{{ machine_name }}_{{ disk_name }}
diff --git a/tests/pillar/maas_storage.sls b/tests/pillar/maas_storage.sls
index 1f3a35b..7a5b08d 100644
--- a/tests/pillar/maas_storage.sls
+++ b/tests/pillar/maas_storage.sls
@@ -32,6 +32,8 @@
                   mount: '/'
                 part2:
                   size: 2G
+                  mount: '/var/tmp'
+                  mount_options: defaults,nodev,noexec,nosuid
                 part3:
                   size: 3G
             vdc:
@@ -72,6 +74,7 @@
                   size: 5G
                   fs_type: ext4
                   mount: '/tmp'
+                  mount_options: defaults,nodev,noexec,nosuid
                 log:
                   size: 7G
                   fs_type: ext4