#!/usr/bin/python

import boto
from boto.utils import get_instance_metadata
from datetime import timedelta
from datetime import datetime

ec2 = boto.connect_ec2()
instance_id = get_instance_metadata()['instance-id']
reservations = ec2.get_all_instances(instance_ids=[instance_id])
instance = reservations[0].instances[0]

if instance.tags.has_key('instance_termination_time'):
    terminate_time = datetime.strptime(str(instance.tags['instance_termination_time']), "%m-%d-%Y %H:%M:%S")
else:
    terminate_time = datetime.strptime(instance.launch_time, "%Y-%m-%dT%H:%M:%S.%fZ") + timedelta(days=7)

print('This system will be terminated on {:%b %d, %Y}'.format(terminate_time))
