add a description to uploaded machines
authorPaul Tonelli <paul.tonelli@logilab.fr>
Thu, 25 Jul 2013 15:24:36 +0200
changeset 164 2c69483615c1
parent 163 d6b522b1315f
child 165 92431f3fb4ee
add a description to uploaded machines in order to identify images, the origin and revision of the sls files used are added in amazon aws. Openstack (in the current version) does not provide a description option when uploading with glance modifications: - make sure ami.hg_address_variation and ami.hg_rev_variation are set in ami_pre - use the information in the description field when uploading to amazon
_modules/aws_client.py
ami_post/upload.sls
ami_pre/files.sls
--- a/_modules/aws_client.py	Thu Jun 27 13:44:37 2013 +0200
+++ b/_modules/aws_client.py	Thu Jul 25 15:24:36 2013 +0200
@@ -47,7 +47,9 @@
         ami_name,
         region="eu-west-1",
         cert_path="/tmp/certificate.pem",
-        pk_path="/tmp/private-key.pem"):
+        pk_path="/tmp/private-key.pem",
+        description="no_description"
+        ):
     '''
     upload .img file to amazon aws using the ec2 interface
     performs the following steps:
@@ -76,8 +78,9 @@
     snapshot_id = create_snapshot(volume_id, ami_name, region, cert_path, pk_path)
     while not snapshot_complete(snapshot_id, region, cert_path, pk_path):
         sleep(10)
-    log.info(__salt__['cmd.run']("ec2-register -n " + ami_name + " -a x86_64  -s " +
-            snapshot_id + " --kernel aki-71665e05  --region " + region + " -K "
+    log.info(__salt__['cmd.run']("ec2-register -n " + ami_name + " -a x86_64 -d "
+            + description + " -s " + snapshot_id
+            + " --kernel aki-71665e05  --region " + region + " -K "
             + pk_path + " -C " + cert_path))
     log.info(__salt__['cmd.run']("ec2-delete-volume --region " + region + " -K " +
         pk_path + " -C " + cert_path + " " + volume_id ))
--- a/ami_post/upload.sls	Thu Jun 27 13:44:37 2013 +0200
+++ b/ami_post/upload.sls	Thu Jul 25 15:24:36 2013 +0200
@@ -60,6 +60,9 @@
 {% if 'ami.size' in grains %}
         - size: {{grains['ami.size']}}
 {% endif %}
+{% if 'ami.hg_rev_variation' in grains and 'ami.hg_address_variation' in grains %}
+        - description: {{ grains['ami.hg_address_variation'] }}/file/{{ grains['ami.hg_rev_variation'] }}/
+{% endif %}
         - require:
             - tmp_state.resized: resize_variation
             - cmd.run: space_remove_pk
--- a/ami_pre/files.sls	Thu Jun 27 13:44:37 2013 +0200
+++ b/ami_pre/files.sls	Thu Jul 25 15:24:36 2013 +0200
@@ -1,5 +1,10 @@
+{% set default_address =
+'http://hg.logilab.org/users/ptonelli/salt-ami-cloud-builder/variation' %}
+
 {% if 'ami.type' not in grains or grains['ami.type'] in ('ubuntu', 'debian') %}
 {% if 'keystone.user' in grains %}
+
+
 01proxy:
     file.managed:
         - name: /mnt/variation/etc/apt/apt.conf.d/01proxy
@@ -124,7 +129,7 @@
 {% if 'ami.hg_address_variation' in grains %}
         - name: {{ grains['ami.hg_address_variation'] }}
 {% else %}
-        - name: http://hg.logilab.org/users/ptonelli/salt-ami-cloud-builder/variation
+        - name: {{ default_address }} 
 {% endif %}
 {% if 'ami.hg_rev_variation' in grains %}
         - rev: {{ grains['ami.hg_rev_variation'] }}
@@ -132,3 +137,19 @@
         - target: /mnt/variation/etc/salt/srv
         - require:
             - mount.mounted: mounted_variation
+
+{% if 'ami.hg_address_variation' not in grains %}
+ami.hg_address_variation:
+  grains.present:
+    - value: {{ default_address }} 
+{% endif %}
+
+{% if 'ami.hg_rev_variation' not in grains %}
+ami.hg_rev_variation:
+  grains.present:
+{% if 'ami.hg_address_variation' in grains %}
+    - value: {{ salt['cmd.run']('hg identify --id ' + grains['ami.hg_address_variation']) }} 
+{% else %}
+    - value: {{ salt['cmd.run']('hg identify --id ' + default_address) }} 
+{% endif %}
+{% endif %}