renames sls files for respecting salt conventions
authorPaul Tonelli <paul.tonelli@logilab.fr>
Tue, 05 Mar 2013 15:43:01 +0100
changeset 16 5cb811380247
parent 15 9256bbfc10d6
child 17 05455a83e87e
renames sls files for respecting salt conventions
_modules/vm_create.py
_states/flavors.py
ami_creator_post.sls
ami_creator_pre.sls
--- a/_modules/vm_create.py	Tue Mar 05 11:27:38 2013 +0100
+++ b/_modules/vm_create.py	Tue Mar 05 15:43:01 2013 +0100
@@ -12,8 +12,10 @@
 POLICY_CONTENT =  'exit 101'
 DEFAULT_VARIATION_NAME = 'variation.sls'
 DEFAULT_MOUNT_DIR = 'variation'
+DEFAULT_IMAGE_NAME = DEFAULT_MOUNT_DIR + '.img'
 
 from os import listdir, remove, stat, environ
+import shutil
 import salt.utils
 import logging
 
@@ -102,18 +104,19 @@
             + ' --wildcards -C ' + path + ' "*.img" ')
     images = _get_images(path)
     assert len(images) == 1
-    __salt__['file.find']('/mnt',iname='*.img')
     image_name = images[0]
+    log.info(shutil.move(path + '/' + image_name, path + '/' + DEFAULT_IMAGE_NAME))
+    image_name = DEFAULT_IMAGE_NAME
     resize_and_check(path, image_name, new_size * 1024)
     image_dirname = DEFAULT_MOUNT_DIR
-    log.info(__salt__['file.makedirs'](path + '/' + image_dirname + '/'))
-    log.info(__salt__['mount.mount'](path + '/' + image_dirname, path + '/'
-            + image_name, opts='loop'))
-    log.info(__salt__['mount.mount'](path + '/' + image_dirname + '/proc', 'none',
-            fstype='proc'))
-    log.info(__salt__['mount.mount'](path + '/' + image_dirname + '/dev/pts',
-            'none', fstype='devpts'))
-    return image_name
+    #log.info(__salt__['file.makedirs'](path + '/' + image_dirname + '/'))
+    #log.info(__salt__['mount.mount'](path + '/' + image_dirname, path + '/'
+    #        + image_name, opts='loop'))
+    #log.info(__salt__['mount.mount'](path + '/' + image_dirname + '/proc', 'none',
+    #        fstype='proc'))
+    #log.info(__salt__['mount.mount'](path + '/' + image_dirname + '/dev/pts',
+    #        'none', fstype='devpts'))
+    #return image_name
 
 def update_image(chroot_dirname):
     '''
@@ -126,12 +129,10 @@
         salt '*' vm_create.resize_and_check /mnt raring_image.tar.gz
     '''
     files_to_delete = []
-    _create_apt_proxy(chroot_dirname + '/etc/apt/apt.conf.d/01proxy')
-    _create_policy_ubuntu(chroot_dirname)
+    #_create_apt_proxy(chroot_dirname + '/etc/apt/apt.conf.d/01proxy')
+    #_create_policy_ubuntu(chroot_dirname)
     log.info(__salt__['file.remove'](chroot_dirname + "/etc/resolv.conf"))
-    ################ bug here ####################"
-    print '/etc/resolv.conf' +", "+ chroot_dirname + '/etc'
-    log.info(salt.utils.copyfile('/etc/resolv.conf', 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 --force-yes -y update && apt-get upgrade'))
     _print_if_error(_chroot_exec(chroot_dirname, 'apt-get --force-yes -y install salt-minion'))
     return files_to_delete
@@ -177,14 +178,17 @@
 
         salt '*' vm_create.create_variation raring_image.tar.gz vanilla
     '''
-    image_name =  mount_image(path, archive_name)
+    mount_image(path, archive_name)
     image_dirname = DEFAULT_MOUNT_DIR
-    update_image(path + '/' + image_dirname)
-    variate_image(path + '/' + image_dirname, variation_filename)
-    kernel_name, ramdisk_name = get_initrd_kernel(path, image_dirname)
-    clean_images(path,image_dirname)
-    umount_images(path)
-    resize_and_check(path, image_name)
+    ### Exec pre state here ###
+    #update_image(path + '/' + image_dirname)
+    #variate_image(path + '/' + image_dirname, variation_filename)
+    #kernel_name, ramdisk_name = get_initrd_kernel(path, image_dirname)
+    kernel_name = "vmlinuz_" + DEFAULT_MOUNT_DIR
+    ramdisk_name = "ramdisk_" + DEFAULT_MOUNT_DIR
+    #clean_images(path,image_dirname)
+    #umount_images(path)
+    #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'](
--- a/_states/flavors.py	Tue Mar 05 11:27:38 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-
-def created(name, value):
-    ret = {'name': name,
-            'changes': {},
-            'result': True,
-            'comment':  ''}
-    if __opts__['test']:
-        ret['result'] = None
-        ret['comment'] = 'State created will check if flavor {0} is available on logilab openstack'.format(value)
-        return ret
-    ret['comment'] = "should have added the flavor value"
-    return ret
-
-
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ami_creator_post.sls	Tue Mar 05 15:43:01 2013 +0100
@@ -0,0 +1,6 @@
+# /srv/salt/init_machine.sls
+#
+chroot_proc:
+    tmp_func.umounted:
+        - name: /mnt/variation/proc
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ami_creator_pre.sls	Tue Mar 05 15:43:01 2013 +0100
@@ -0,0 +1,70 @@
+# /srv/salt/init_machine.sls
+#
+
+base_pkgs:
+    pkg.installed:
+        - pkgs:
+            - salt-minion
+            - python
+            - mercurial
+            - tar
+            - glance
+#          - eca2ools
+
+hg_ami_creation:
+    hg.latest:
+        - name: http://hg.logilab.fr/users/ptonelli/srv_salt
+        - target: /etc/salt/srv
+
+### Mounts ###
+mounted_variation:
+    mount.mounted:
+        - device: /mnt/variation.img
+        - name: /mnt/variation
+        - fstype: ext4
+        - mkmnt: False
+        - opts:
+            - loop
+
+chroot_proc:
+    mount.mounted:
+        - device: none
+        - name: /mnt/variation/proc
+        - fstype: proc
+        - mkmnt: false
+        - require:
+            - mount.mounted: mounted_variation
+
+chroot_devpts:
+    mount.mounted:
+        - device: none
+        - name: /mnt/variation/dev/pts
+        - fstype: devpts
+        - mkmnt: False
+        - require:
+            - mount.mounted: mounted_variation
+
+### Temporary Files ###
+01proxy:
+    file.managed:
+        - name: /mnt/variation/etc/apt/apt.conf.d/01proxy
+        - source: salt://others/01proxy
+        - mode: 644
+        - require:
+            - mount.mounted: mounted_variation
+
+
+policy-rc.d:
+    file.managed:
+        - name: /mnt/variation/usr/sbin/policy-rc.d
+        - source: salt://others/policy-rc.d
+        - mode: 755
+        - require:
+            - mount.mounted: mounted_variation
+
+resolv.conf:
+    tmp_func.local_managed:
+        - name: /mnt/variation/etc/resolv.conf
+        - source: /etc/resolv.conf
+        - require:
+            - mount.mounted: mounted_variation