move resize_and_check from module to state
authorPaul Tonelli <paul.tonelli@logilab.fr>
Tue, 05 Mar 2013 15:56:42 +0100
changeset 22 6cd919e309f1
parent 21 1a60c5146af3
child 23 b6572bd0293c
move resize_and_check from module to state small correction in mount_image help
_modules/vm_create.py
_states/tmp_func.py
--- a/_modules/vm_create.py	Tue Mar 05 15:49:50 2013 +0100
+++ b/_modules/vm_create.py	Tue Mar 05 15:56:42 2013 +0100
@@ -63,36 +63,13 @@
     for file_to_delete in files_to_delete:
         remove(path + '/' + file_to_delete)
 
-def resize_and_check(path, image_name, new_size=0):
-    '''
-    resize partition and filesystem whenever possible (size in Mb)
-    and check the integrity (for ext* fs)
-
-    CLI Example::
-
-        salt '*' vm_create.resize_and_check /mnt raring_image.img 4
-        salt '*' vm_create.resize_and_check /mnt raring_image.img
-    '''
-    current_size = stat(path + '/' + image_name).st_size/pow(1024, 2)
-    if new_size > current_size:
-        log.info('increasing size of ' + path + '/' + image_name + ' to ' + str(new_size) + 'Gb')
-        log.debug(__salt__['cmd.run_all']('dd if=/dev/zero bs=1024k count='
-                + str(new_size - current_size) + ' >> ' + path + '/'
-                + image_name))
-        minimize = ''
-    else:
-        minimize = '-M '
-    log.info(__salt__['cmd.run_all']('e2fsck -n -f ' + path + '/' + image_name))
-    log.info(__salt__['cmd.run_all']('resize2fs -f ' + minimize + path + '/'
-            + image_name))
-
 def mount_image(path, archive_name, new_size = 4):
     '''
     unrar, resize, mount image in path, add /proc and console
 
     CLI Example::
 
-        salt '*' vm_create.resize_and_check /mnt raring_image.tar.gz
+        salt '*' vm_create.mount_image /mnt raring_image.tar.gz
     '''
     log.info(__salt__['file.makedirs'](path + '/'))
     assert archive_name.split('.')[-1] == 'gz'
--- a/_states/tmp_func.py	Tue Mar 05 15:49:50 2013 +0100
+++ b/_states/tmp_func.py	Tue Mar 05 15:56:42 2013 +0100
@@ -58,3 +58,27 @@
                 ret['comment'] = output
     return ret
 
+def resize_and_check(name, new_size=0):
+    '''
+    resize partition and filesystem whenever possible (size in Mb)
+    and check the integrity (for ext* fs)
+
+    CLI Example::
+
+        salt '*' vm_create.resize_and_check /mnt raring_image.img 4
+        salt '*' vm_create.resize_and_check /mnt raring_image.img
+    '''
+    current_size = stat(path + '/' + image_name).st_size/pow(1024, 2)
+    if new_size > current_size:
+        log.info('increasing size of ' + path + '/' + image_name + ' to ' + str(new_size) + 'Gb')
+        log.debug(__salt__['cmd.run_all']('dd if=/dev/zero bs=1024k count='
+                + str(new_size - current_size) + ' >> ' + path + '/'
+                + image_name))
+        minimize = ''
+    else:
+        minimize = '-M '
+    log.info(__salt__['cmd.run_all']('e2fsck -n -f ' + path + '/' + image_name))
+    log.info(__salt__['cmd.run_all']('resize2fs -f ' + minimize + path + '/'
+            + image_name))
+
+