passed the main function from vmcreate to ami_creation.sls file:
authorPaul Tonelli <paul.tonelli@logilab.fr>
Fri, 15 Mar 2013 10:28:04 +0100
changeset 84 40a8790380af
parent 83 09fdf067e0b7
child 85 8010f73133e5
passed the main function from vmcreate to ami_creation.sls file: - added multiple steps in ami_create.sls - added return values (True) to functions in vm_create so that they can fill grains - changed rc.local (which should be on ami_creator image) to call the state instead of the function (commented until functionnal)
_modules/vm_create.py
ami_creator.sls
others/rc.local
--- a/_modules/vm_create.py	Fri Mar 15 10:17:58 2013 +0100
+++ b/_modules/vm_create.py	Fri Mar 15 10:28:04 2013 +0100
@@ -30,6 +30,7 @@
     '''
     _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 True
 
 def variate_image(chroot_dirname, variation_filename=DEFAULT_VARIATION_NAME):
     '''
@@ -42,7 +43,7 @@
 
     '''
     log.info(_chroot_exec(chroot_dirname, 'salt-call  --local state.highstate'))
-
+    return True
 
 def create_variation(path=DEFAULT_PATH):
     '''
--- a/ami_creator.sls	Fri Mar 15 10:17:58 2013 +0100
+++ b/ami_creator.sls	Fri Mar 15 10:28:04 2013 +0100
@@ -1,28 +1,33 @@
 # /srv/salt/init_machine.sls
-my_pkgs:
-  pkg.installed:
-    - pkgs:
-      - salt-minion
-      - python
-      - mercurial
-      - tar
-      - rsync
-      - glance
+preparation:
+    sls:
+        - ami_pre
+    require:
+        - hg.latest: hg_code
+
+update_variant:
+    grains.present: 
+        - value: {{ salt['vm_create.update_image']('/mnt/variation') }}
+    require:
+        - preparation
 
-{% if 'ami.hg_address' not in grains %}
-ami.hg_address:
-    grains.present:
-        - value : http://hg.logilab.fr/users/ptonelli/srv_salt
+variate_variant:
+    grains.present: 
+        - value: {{ salt['vm_create.variate_image']('/mnt/variation') }}
+    require:
+        - update_variant
+
+cleaning:
+    sls:
+        - ami_post
+    require:
+        - variate_variant
+
+{% if  grains['keystone.user'] %}
+upload_variant:
+    grains.present: 
+        - value: {{ salt['vm_create.upload_to_glance']('/mnt/variation') }}
+    require:
+        - cleaning
 {% endif %}
 
-hg_ami_creation:
-    hg.latest:
-        - name: {{ grains['ami.hg_address'] }}
-{% if  grains['ami.hg_rev'] %}
-        - rev: {{ grains['ami.hg_rev'] }}
-{% endif %}
-        - target: /etc/salt/srv
-        - require:
-            - pkg: my_pkgs
-
-
--- a/others/rc.local	Fri Mar 15 10:17:58 2013 +0100
+++ b/others/rc.local	Fri Mar 15 10:28:04 2013 +0100
@@ -13,8 +13,12 @@
 
 ### Specific to salt-call machine creation
 
+## should get everything up to date
 /usr/bin/env salt-call state.highstate
+## should source everything in /var/salt 
 /usr/bin/env salt-call state.highstate
+## should create the vm 
+#/usr/bin/env salt-call state.sls ami_creator 
 /usr/bin/env salt-call vm_create.create_variation
 
 exit 0