Example #1
0
#   limitations under the License.

import logging
import sys
from aws_utils import EBSHelper, AMIHelper
from pvgrub_utils import do_pw_sub

if len(sys.argv) != 7:
    print
    print "Create an AMI on EC2 by running a native installer contained in a pre-existing AMI"
    print
    print "usage: %s <ec2_region> <ec2_key> <ec2_secret> <install_ami> <install_script> <root_pw>" % sys.argv[0]
    print
    sys.exit(1)

region = sys.argv[1]
key = sys.argv[2]
secret = sys.argv[3]
install_ami = sys.argv[4]
install_script = sys.argv[5]
root_pw = sys.argv[6]

logging.basicConfig(level=logging.DEBUG, format='%(message)s')

ami_helper = AMIHelper(region, key, secret)

user_data = do_pw_sub(install_script, root_pw)
install_ami = ami_helper.launch_wait_snapshot(install_ami, user_data, 10)

print "Got AMI: %s" % install_ami
Example #2
0
def get_opts():
    usage="""
%prog <install_ami> <kickstart>

Create an AMI on EC2 by running a native installer contained in a
pre-existing AMI."""
    parser = OptionParser(usage=usage)
    parser.add_option('-i', '--instance-type', default='m1.small',
        help='Choose an instance type to install in', dest='inst_type')
    parser.add_option('-r', '--region', default='us-east-1',
        help='Set the EC2 region we are working in')
    parser.add_option('-s', '--disk-size', default=10, type='int',
        help='Set the size in G of the disk Anaconda will install to')
    options, args = parser.parse_args()
    if len(args) != 2:
        parser.error('You must provide an AMI and a kickstart file')
    if not os.path.exists(args[1]):
        parser.error('could not read %s!' % args[1])
    return options, args[0], args[1]

logging.basicConfig(level=logging.DEBUG, format='%(message)s')

if __name__ == '__main__':
    opts, install_ami, kickstart = get_opts()
    ami_helper = AMIHelper(opts.region)
    user_data = open(kickstart).read()
    install_ami = ami_helper.launch_wait_snapshot(
        install_ami, user_data, int(opts.disk_size), opts.inst_type)
    print "Got AMI: %s" % install_ami