in scripts/postprocess.py [0:0]
def main():
parser = argparse.ArgumentParser(description='Process AdvancedOptions ')
try:
args = parser.parse_args()
read_config()
advanced = os.environ['ADVANCED_JSON'].rstrip()
cmd = 'curl -s http://169.254.169.254/latest/dynamic/instance-identity/document'
output = exe_cmd(cmd)
mydoc = json.loads(output['out'])
myid = mydoc['instanceId']
cmd = '/bin/hostname'
output = exe_cmd(cmd)
myhostname = output['out'].rstrip()
stack = os.environ['MyStackId'].rstrip()
options = {}
if os.path.isfile(advanced):
with open(advanced) as f:
options = json.load(f)
if 'CreateAMI' in options:
# Create AMI at the end of deployment!
if options['CreateAMI'] == 'True':
cmd = aws_cmd
cmd = cmd + ' ec2 create-image '
cmd = cmd + ' --instance-id ' + myid
name = "SAP HANA AMI of " + myhostname
cmd = cmd + ' --name ' + '"' + name + '"'
desc = "AMI of " + myhostname + " Created via " + stack
cmd = cmd + ' --description ' + '"' + desc + '"'
cmd = cmd + ' --no-reboot '
cmd = cmd + ' --region ' + os.environ['REGION'].rstrip()
print 'executing ' + cmd
output = exe_cmd(cmd)
except Exception:
print 'Unknown exception while processing advanced options'
print 'Ignoring all advanced options'
print Exception