#!/usr/bin/python
'''
get a new ami given a running instance 
'''

import datetime
import logging

from bellatrix.lib.ec2_lib import Ec2lib
from bellatrix.lib.bellatrix_util import *


class Run():
    def __init__(self, key, sec): 
        self._ec2 = Ec2lib(key, sec) 

    def burnInstance(self, instance, config_name):
        new_ami = self._ec2.createImage(instance, config_name + "-" 
                                        + datetime.datetime.now().isoformat(), "generated by " 
                                        + self._app_name)
        logging.info("ami: %s is being generated for configuration: %s" 
                     % (new_ami, config_name))

def run(instance, config_name):
    r = Run(getKey(), getSecret(), instance, config_name)
    r.burnInstance(instance, config_name)
    return 0

if __name__ == '__main__':
    sys.exit(run(*sys.argv[1:])) 

