Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cernvm/amiconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jblomer committed Apr 14, 2014
2 parents 81a2ed5 + 05e8041 commit 9eefa9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hepix/commands/amiconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
14 changes: 14 additions & 0 deletions rpath/amiconfig/instancedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 9eefa9b

Please sign in to comment.