removed unused commands / cleaned
authorPaul Tonelli <paul.tonelli@logilab.fr>
Mon, 11 Mar 2013 14:29:12 +0100
changeset 55 a8fc89e61f2b
parent 54 7e33d0c7f399
child 56 b9b71002538b
removed unused commands / cleaned
_modules/vm_create.py
--- a/_modules/vm_create.py	Mon Mar 11 14:28:35 2013 +0100
+++ b/_modules/vm_create.py	Mon Mar 11 14:29:12 2013 +0100
@@ -8,11 +8,8 @@
 APT_PROXY_FILENAME = '/etc/apt/apt.conf.d/01proxy'
 POLICY_FILENAME = '/usr/sbin/policy-rc.d'
 POLICY_CONTENT =  'exit 101'
-DEFAULT_VARIATION_NAME = 'variation.sls'
 DEFAULT_MOUNT_DIR = 'variation'
-DEFAULT_IMAGE_NAME = DEFAULT_MOUNT_DIR + '.img'
-DEFAULT_KERNEL_NAME = '/mnt/vmlinuz_variation'
-DEFAULT_RAMDISK_NAME = '/mnt/initrd_variation'
+DEFAULT_VARIATION_NAME = DEFAULT_MOUNT_DIR + '.sls'
 
 from os import listdir, remove, stat, environ
 import shutil
@@ -31,12 +28,8 @@
 
         salt '*' vm_create.update_image /mnt/variation
     '''
-    #files_to_delete = []
-    #log.info(__salt__['file.remove'](chroot_dirname + "/etc/resolv.conf"))
-    #log.info(salt.utils.copyfile('/etc/resolv.conf', chroot_dirname + '/etc/resolv.conf'))
     _print_if_error(_chroot_exec(chroot_dirname, 'apt-get update'))
     _print_if_error(_chroot_exec(chroot_dirname, 'apt-get --force-yes -y install salt-minion'))
-    #return files_to_delete
 
 def variate_image(chroot_dirname, variation_filename=DEFAULT_VARIATION_NAME):
     '''
@@ -48,10 +41,6 @@
         salt '*' vm_create.variate_image /mnt/variation
 
     '''
-    #file_origin = 'salt://' + variation_filename
-
-    #salt.utils.copyfile('/etc/salt/srv/' + variation_filename, chroot_dirname + '/etc/salt/srv')
-    #__salt__['file.patch'](chroot_dirname + '/etc/salt/minion', '/etc/salt/srv/minion.patch')
     log.info(_chroot_exec(chroot_dirname, 'salt-call  --local state.highstate'))
 
 
@@ -69,27 +58,20 @@
     update_image(path + '/' + image_dirname)
     variate_image(path + '/' + image_dirname)
     log.info(__salt__['state.sls']('ami_creator_post'))
-    kernel_name = DEFAULT_KERNEL_NAME
-    ramdisk_name = DEFAULT_RAMDISK_NAME
-    kernel_name = "vmlinuz_" + DEFAULT_MOUNT_DIR
-    ramdisk_name = "ramdisk_" + DEFAULT_MOUNT_DIR
-    #resize_and_check(path, image_name)
-    if bool(upload_to_glance):
-        log.info('will now upload to glance server')
-        id_kernel = __salt__['openstack_client.upload_to_glance'](
+    log.info('Image Not uploaded to glance !')
+    return True
+
+def upload_to_glance(path=DEFAULT_PATH, kernel_id=None, ramdisk_id=None):
+    if not kernel_id:
+        kernel_id = __salt__['openstack_client.upload_to_glance'](
                 path, kernel_name, 'aki', '', image_dirname)
-        id_ramdisk = __salt__['openstack_client.upload_to_glance'](
+    if not ramdisk_id:
+        ramdisk_id = __salt__['openstack_client.upload_to_glance'](
                 path, ramdisk_name, 'ari', '', image_dirname)
-        id_image = __salt__['openstack_client.upload_to_glance'](
-                path, image_name, 'ami', 'kernel_id='
-                + id_kernel + ' ramdisk_id=' + id_ramdisk)
-        log.info("Reverting to initial state")
-        revert_all(path, (kernel_name, ramdisk_name))
-    else:
-        log.info('Not uploading to glance')
-        log.info("kernel name " + kernel_name)
-        log.info("ramdisk name " + ramdisk_name)
-    return True
+    image_id = __salt__['openstack_client.upload_to_glance'](
+            path, image_name, 'ami', 'kernel_id='
+            + kernel_id + ' ramdisk_id=' + ramdisk_id)
+    return image_id
 
 def _chroot_exec(chroot_path, command):
     return __salt__['cmd.run_all']('chroot ' + chroot_path + ' ' + command)