corrected bugs on ec2-run-data(.py) modified scripts
authorPaul Tonelli <paul.tonelli@logilab.fr>
Mon, 11 Mar 2013 14:27:03 +0100
changeset 53 037d03aca265
parent 52 543be5448292
child 54 7e33d0c7f399
corrected bugs on ec2-run-data(.py) modified scripts
others/ec2-run-user-data
others/ec2-run-user-data.py
--- a/others/ec2-run-user-data	Mon Mar 11 11:45:41 2013 +0100
+++ b/others/ec2-run-user-data	Mon Mar 11 14:27:03 2013 +0100
@@ -18,7 +18,7 @@
 prog=$(basename $0)
 logger="logger -t $prog"
 instance_data_url="http://169.254.169.254/2008-02-01"
-python_handler=/etc/salt/srv/othes/ec2-run-user-data.py
+python_handler=/etc/salt/srv/others/ec2-run-user-data.py
 
 
 # Retrieve the instance user-data and run it if it looks like a script
@@ -46,5 +46,12 @@
 fi
 rm -f $user_data_file
 
+### Specific to salt-call machine creation
+
+/usr/bin/env salt-call state.highstate
+/usr/bin/env salt-call state.highstate
+/usr/bin/env salt-call vm_create.create_variation 
+
+
 # Disable this script, it may only run once
 insserv -r $0
--- a/others/ec2-run-user-data.py	Mon Mar 11 11:45:41 2013 +0100
+++ b/others/ec2-run-user-data.py	Mon Mar 11 14:27:03 2013 +0100
@@ -3,6 +3,7 @@
 # author: Paul Tonelli <ptonelli@logilab.fr>
 
 import urllib, os
+from time import sleep
 from salt import grains
 from sys import argv
 from subprocess import Popen
@@ -17,26 +18,26 @@
 url = 'http://169.254.169.254/2008-02-01/user-data'
 
 def parse_line(line):
-    if 'http' or 'ssh' in line:
-        #grains.present(name='custom_hg_address', value=line)
-        Popen(['salt-call', 'state.single', 'grains.present',
-        'name=custom_hg_address', 'value=' + line.replace(' ', '')])
-    if 'rev' in line:
-        Popen(['salt-call', 'state.single', 'grains.present',
-            'name=custom_hg_revision', 'value=' + line.split(':')[-1].replace(' ','')])
-
-
-def exec_highstate():
     '''
     ugly, but did not find how to do it more cleanly
 
     from salt.modules import state
     state.highstate() #does not work and requires __salt__ dict
     '''
-    Popen(['salt-call','state.highstate'])
-    Popen(['salt-call','state.highstate'])
-    Popen(['salt-call','state.sls','ami_creator_pre'])
-    Popen(['salt-call','state.sls','ami_creator_pre'])
+    if 'address:' in line:
+        #grains.present(name='custom_hg_address', value=line)
+        Popen(['salt-call', 'state.single', 'grains.present',
+        'name=custom_hg_address', 'value=' + line.split(':')[-1].replace(' ','')])
+        sleep(1)
+    elif 'http://' in line:
+        #grains.present(name='custom_hg_address', value=line)
+        Popen(['salt-call', 'state.single', 'grains.present',
+        'name=custom_hg_address', 'value=' + line.replace(' ', '')])
+        sleep(1)
+    elif ('rev:' or 'revision:') in line:
+        Popen(['salt-call', 'state.single', 'grains.present',
+            'name=custom_hg_revision', 'value=' + line.split(':')[-1].replace(' ','')])
+        sleep(1)
 
 if __name__ == "__main__":
     os.chdir('/tmp')
@@ -46,5 +47,3 @@
         myfile = open(urllib.urlretrieve(url)[0],'r')
     for line in myfile:
         parse_line(line)
-    #exec_highstate()
-