Merge "Fix cloud-init Python syntax for Python < 2.6"
This commit is contained in:
commit
c511d076b8
@ -35,7 +35,7 @@ def init_logging():
|
|||||||
LOG.setLevel(logging.INFO)
|
LOG.setLevel(logging.INFO)
|
||||||
LOG.addHandler(logging.StreamHandler())
|
LOG.addHandler(logging.StreamHandler())
|
||||||
fh = logging.FileHandler("/var/log/heat-provision.log")
|
fh = logging.FileHandler("/var/log/heat-provision.log")
|
||||||
os.chmod(fh.baseFilename, 0o600)
|
os.chmod(fh.baseFilename, int("600", 8))
|
||||||
LOG.addHandler(fh)
|
LOG.addHandler(fh)
|
||||||
|
|
||||||
|
|
||||||
@ -55,14 +55,16 @@ def call(args):
|
|||||||
if data:
|
if data:
|
||||||
for x in data:
|
for x in data:
|
||||||
ls.write(x)
|
ls.write(x)
|
||||||
except OSError as ex:
|
except OSError:
|
||||||
|
ex_type, ex, tb = sys.exc_info()
|
||||||
if ex.errno == errno.ENOEXEC:
|
if ex.errno == errno.ENOEXEC:
|
||||||
LOG.error('Userdata empty or not executable: %s', ex)
|
LOG.error('Userdata empty or not executable: %s', ex)
|
||||||
return os.EX_OK
|
return os.EX_OK
|
||||||
else:
|
else:
|
||||||
LOG.error('OS error running userdata: %s', ex)
|
LOG.error('OS error running userdata: %s', ex)
|
||||||
return os.EX_OSERR
|
return os.EX_OSERR
|
||||||
except Exception as ex:
|
except Exception:
|
||||||
|
ex_type, ex, tb = sys.exc_info()
|
||||||
LOG.error('Unknown error running userdata: %s', ex)
|
LOG.error('Unknown error running userdata: %s', ex)
|
||||||
return os.EX_SOFTWARE
|
return os.EX_SOFTWARE
|
||||||
return p.returncode
|
return p.returncode
|
||||||
@ -77,7 +79,7 @@ def main():
|
|||||||
return -1
|
return -1
|
||||||
|
|
||||||
userdata_path = os.path.join(VAR_PATH, 'cfn-userdata')
|
userdata_path = os.path.join(VAR_PATH, 'cfn-userdata')
|
||||||
os.chmod(userdata_path, 0o700)
|
os.chmod(userdata_path, int("700", 8))
|
||||||
|
|
||||||
LOG.info('Provision began: %s', datetime.datetime.now())
|
LOG.info('Provision began: %s', datetime.datetime.now())
|
||||||
returncode = call([userdata_path])
|
returncode = call([userdata_path])
|
||||||
@ -96,5 +98,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
provision_log = os.path.join(VAR_PATH, 'provision-finished')
|
provision_log = os.path.join(VAR_PATH, 'provision-finished')
|
||||||
# touch the file so it is timestamped with when finished
|
# touch the file so it is timestamped with when finished
|
||||||
with file(provision_log, 'a'):
|
pl = file(provision_log, 'a')
|
||||||
|
try:
|
||||||
os.utime(provision_log, None)
|
os.utime(provision_log, None)
|
||||||
|
finally:
|
||||||
|
pl.close()
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import errno
|
import errno
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def list_types():
|
def list_types():
|
||||||
@ -24,8 +25,9 @@ def list_types():
|
|||||||
def handle_part(data, ctype, filename, payload):
|
def handle_part(data, ctype, filename, payload):
|
||||||
if ctype == "__begin__":
|
if ctype == "__begin__":
|
||||||
try:
|
try:
|
||||||
os.makedirs('/var/lib/heat-cfntools', 0o700)
|
os.makedirs('/var/lib/heat-cfntools', int("700", 8))
|
||||||
except OSError as e:
|
except OSError:
|
||||||
|
ex_type, e, tb = sys.exc_info()
|
||||||
if e.errno != errno.EEXIST:
|
if e.errno != errno.EEXIST:
|
||||||
raise
|
raise
|
||||||
return
|
return
|
||||||
@ -33,14 +35,23 @@ def handle_part(data, ctype, filename, payload):
|
|||||||
if ctype == "__end__":
|
if ctype == "__end__":
|
||||||
return
|
return
|
||||||
|
|
||||||
with open('/var/log/part-handler.log', 'a') as log:
|
log = open('/var/log/part-handler.log', 'a')
|
||||||
|
try:
|
||||||
timestamp = datetime.datetime.now()
|
timestamp = datetime.datetime.now()
|
||||||
log.write('%s filename:%s, ctype:%s\n' % (timestamp, filename, ctype))
|
log.write('%s filename:%s, ctype:%s\n' % (timestamp, filename, ctype))
|
||||||
|
finally:
|
||||||
|
log.close()
|
||||||
|
|
||||||
if ctype == 'text/x-cfninitdata':
|
if ctype == 'text/x-cfninitdata':
|
||||||
with open('/var/lib/heat-cfntools/%s' % filename, 'w') as f:
|
f = open('/var/lib/heat-cfntools/%s' % filename, 'w')
|
||||||
|
try:
|
||||||
f.write(payload)
|
f.write(payload)
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
|
|
||||||
# TODO(sdake) hopefully temporary until users move to heat-cfntools-1.3
|
# TODO(sdake) hopefully temporary until users move to heat-cfntools-1.3
|
||||||
with open('/var/lib/cloud/data/%s' % filename, 'w') as f:
|
f = open('/var/lib/cloud/data/%s' % filename, 'w')
|
||||||
|
try:
|
||||||
f.write(payload)
|
f.write(payload)
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user