remove update-image method, (closes #249331)
authorPaul Tonelli <paul.tonelli@logilab.fr>
Mon, 13 May 2013 16:30:56 +0200
changeset 132 ebe7a4805f96
parent 131 1c0ac68a3211
child 133 8b3f7b082539
remove update-image method, (closes #249331) - the method is replaced by two sls calls to vm_create.chroot_exec in ami_pre/files.sls - this required heavy changes in ami_pre/files.sls to keep conditions
_modules/vm_create.py
ami_creator.sls
ami_pre/files.sls
--- a/_modules/vm_create.py	Mon May 13 11:04:44 2013 +0200
+++ b/_modules/vm_create.py	Mon May 13 16:30:56 2013 +0200
@@ -18,20 +18,6 @@
 
 log = logging.getLogger(__name__)
 
-def update_image(path):
-    '''
-    update image using apt-get. Doing so, it creates a few files.
-    In order to be executed in chroot, you should use is with
-    create_proxy=True unless you have /run mounted
-
-    CLI Example::
-
-        salt '*' vm_create.update_image /mnt/variation
-    '''
-    _print_if_error(_chroot_exec(path, 'apt-get update'))
-    _print_if_error(_chroot_exec(path, 'apt-get --force-yes -y install salt-minion'))
-    return True
-
 def variate_image(path, variation_filename=DEFAULT_VARIATION_NAME):
     '''
     do all code relevant to personalizing the machine here
@@ -75,8 +61,8 @@
         return image_id
     return False
 
-def _chroot_exec(chroot_path, command):
-    return __salt__['cmd.run_all']('chroot ' + chroot_path + ' ' + command)
+def chroot_exec(path, command):
+    return __salt__['cmd.run_all']('chroot ' + path + ' ' + command)
 
 def _print_if_error(ret, info=False):
     if info:
--- a/ami_creator.sls	Mon May 13 11:04:44 2013 +0200
+++ b/ami_creator.sls	Mon May 13 16:30:56 2013 +0200
@@ -5,19 +5,12 @@
         - name: state.sls
         - mods: ami_pre
 
-update_variant:
-    module.run:
-        - name: vm_create.update_image
-        - path: /mnt/variation
-        - require:
-            - module.run: preparation 
-
 variate_variant:
     module.run:
         - name: vm_create.variate_image
         - path: /mnt/variation
         - require:
-            - module.run: vm_create.update_image
+            - module.run: preparation
 
 cleaning:
     module.run:
--- a/ami_pre/files.sls	Mon May 13 11:04:44 2013 +0200
+++ b/ami_pre/files.sls	Mon May 13 16:30:56 2013 +0200
@@ -1,3 +1,4 @@
+{% if 'ami.type' not in grains or grains['ami.type'] in ('ubuntu', 'debian') %}
 {% if 'keystone.user' in grains %}
 01proxy:
     file.managed:
@@ -24,12 +25,31 @@
         - require:
             - mount.mounted: mounted_variation
 
-resolv.conf:
-    tmp_state.local_managed:
-        - name: /mnt/variation/etc/resolv.conf
-        - source: /etc/resolv.conf
+chroot_apt_get_update:
+    module.run:
+        - name: vm_create.chroot_exec
+        - path: /mnt/variation
+        - command: apt-get update
         - require:
-            - mount.mounted: mounted_variation
+            - tmp_state.local_managed: resolv.conf
+            - file.managed: policy-rc.d
+            - file.managed: 02confold
+{% if 'ami.type' not in grains or grains['ami.type'] == 'ubuntu' %}
+            - cmd.run: salt_ppa
+{% endif %}
+{% if 'ami.type' in grains and grains['ami.type'] == 'debian' %}
+            - file.managed: unstable.list
+            - file.managed: pinning 
+{% endif %}
+
+chroot_install_salt:
+    module.run:
+        - name: vm_create.chroot_exec
+        - path: /mnt/variation
+        - command: apt-get --force-yes -y install salt-minion python-apt
+        - require:
+            - module.run: chroot_apt_get_update
+{% endif %}
 
 {% if 'ami.type' not in grains or grains['ami.type'] == 'ubuntu' %}
 salt_ppa:
@@ -60,6 +80,13 @@
             - mount.mounted: mounted_variation
 {% endif %}
 
+resolv.conf:
+    tmp_state.local_managed:
+        - name: /mnt/variation/etc/resolv.conf
+        - source: /etc/resolv.conf
+        - require:
+            - mount.mounted: mounted_variation
+
 minion:
     file.managed:
         - name: /mnt/variation/etc/salt/minion