add possibility to put custom name for image in glance
authorPaul Tonelli <paul.tonelli@logilab.fr>
Wed, 13 Mar 2013 16:07:36 +0100
changeset 72 a66ccae3aca2
parent 71 d13233afb293
child 73 dae7b424b347
add possibility to put custom name for image in glance
_modules/vm_create.py
readme.txt
--- a/_modules/vm_create.py	Thu Mar 21 14:52:58 2013 +0100
+++ b/_modules/vm_create.py	Wed Mar 13 16:07:36 2013 +0100
@@ -67,6 +67,9 @@
 
 def upload_to_glance(path):
     log.info('will now try to upload to glance server')
+    ami_name = __salt__['grains.item']('ami.name')
+    if not ami_name:
+        ami_name = "variation"
     object_id = {}
     object_types = {'kernel':'aki','ramdisk':'ari'}
     ok_for_image = True
@@ -78,7 +81,7 @@
             o_path = _find_objects(path, o_type)
             if len(o_path) == 1:
                 object_id[o_type] = __salt__['openstack_client.upload_to_glance'](
-                        o_path[0], object_types[o_type], '')
+                        o_path[0], object_types[o_type], image_name=o_type + '_' + ami_name)
             else:
                 log.error('no ' + object_types[o_type] + ' found in ' + path)
                 ok_for_image = False
@@ -87,7 +90,7 @@
         if len(o_path) == 1:
             image_id = __salt__['openstack_client.upload_to_glance'](
                  o_path[0], 'ami', 'kernel_id=' + object_id['kernel'] +
-                 ' ramdisk_id=' + object_id['ramdisk'])
+                 ' ramdisk_id=' + object_id['ramdisk'], image_name=ami_name)
         return image_id
     return False
 
--- a/readme.txt	Thu Mar 21 14:52:58 2013 +0100
+++ b/readme.txt	Wed Mar 13 16:07:36 2013 +0100
@@ -20,6 +20,7 @@
 
 ami.hg_rev: cd5da6d9d4fe
 ami.hg_address: http://hg.logilab.fr/users/ptonelli/srv_salt
+ami.name: my_variation 
 ami.type: debian #or ubuntu
 
 ### optionnal ###