From c576773ddb446328bc749054a20b3e770cb16b32 Mon Sep 17 00:00:00 2001 From: Jakob Blomer Date: Tue, 8 Apr 2014 10:58:57 +0200 Subject: [PATCH 1/2] read ec2 user data locally --- hepix/commands/amiconfig.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hepix/commands/amiconfig.sh b/hepix/commands/amiconfig.sh index 3cf5058..940d853 100644 --- a/hepix/commands/amiconfig.sh +++ b/hepix/commands/amiconfig.sh @@ -482,6 +482,8 @@ Main() { case "$MODE" in user) RunUserDataScript before + # Hack: read meta-data from HTTP, user-data locally to include extra user data + export AMICONFIG_EC2_USER_DATA_URL="file:$(dirname ${AMICONFIG_LOCAL_USER_DATA})" $AMICONFIG 2>&1 #| $PIPELOGGER RunUserDataScript after mkdir -p `dirname "$AMI_DONE_USER"` From d5bab6fb5fe427e618c78dbb24d2225c165536a7 Mon Sep 17 00:00:00 2001 From: Jakob Blomer Date: Tue, 8 Apr 2014 11:00:05 +0200 Subject: [PATCH 2/2] read ec2 user data locally --- rpath/amiconfig/instancedata.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rpath/amiconfig/instancedata.py b/rpath/amiconfig/instancedata.py index 5292bb2..e307204 100644 --- a/rpath/amiconfig/instancedata.py +++ b/rpath/amiconfig/instancedata.py @@ -42,6 +42,20 @@ def open(self, path): return results def read(self, path): + ec2_user_data_url = os.getenv("AMICONFIG_EC2_USER_DATA_URL") + if ec2_user_data_url is not None: + try: + results = urllib.urlopen('%s/user-data' % (ec2_user_data_url)) + except Exception, e: + raise EC2DataRetrievalError, '[Errno %s] %s' % (e.errno, e.strerror) + if results.headers.gettype() == 'text/html': + # Eucalyptus returns text/html and no Server: header + # We want to protect ourselves from HTTP servers returning real + # HTML, so let's hope at least they're conformant and return a + # Server: header + if 'server' in results.headers: + raise EC2DataRetrievalError, '%s' % results.read() + return results.read() return self.open(path).read() def getUserData(self):