o ckF[@sRddlZddlZddlZddlZddlZdZddZddZedkr'edSdS)Nai SYNOPSIS launch_ami.py -a ami_id [-b script_bucket] [-s script_name] [-m module] [-c class_name] [-r] [-g group] [-k key_name] [-n num_instances] [-w] [extra_data] Where: ami_id - the id of the AMI you wish to launch module - The name of the Python module containing the class you want to run when the instance is started. If you use this option the Python module must already be stored on the instance in a location that is on the Python path. script_file - The name of a local Python module that you would like to have copied to S3 and then run on the instance when it is started. The specified module must be import'able (i.e. in your local Python path). It will then be copied to the specified bucket in S3 (see the -b option). Once the new instance(s) start up the script will be copied from S3 and then run locally on the instance. class_name - The name of the class to be instantiated within the module or script file specified. script_bucket - the name of the bucket in which the script will be stored group - the name of the security group the instance will run in key_name - the name of the keypair to use when launching the AMI num_instances - how many instances of the AMI to launch (default 1) input_queue_name - Name of SQS to read input messages from output_queue_name - Name of SQS to write output messages to extra_data - additional name-value pairs that will be passed as userdata to the newly launched instance. These should be of the form "name=value" The -r option reloads the Python module to S3 without launching another instance. This can be useful during debugging to allow you to test a new version of your script without shutting down your instance and starting up another one. The -w option tells the script to run synchronously, meaning to wait until the instance is actually up and running. It then prints the IP address and internal and external DNS names before exiting. cCstttdS)N)print usage_stringsysexitrr7/usr/lib/python3/dist-packages/boto/pyami/launch_ami.pyusageFs rc Csvzttjdddgd\}}WntYddddddddddd }d}d}|D]i\}}|dvr9||d<|dvrA||d <|d vrI||d <|d vrQ||d <|dvrXt|dvr`||d<|dvrh||d<|dvrp||d<|dvrzt||d<|dvr||d<|dvrd}|dvr||d<|dvrd}q-dg}|D]}||dstd|tq|dr|rtd|dntd |dt|d} t } | |d } | |dd!} | | d"| j|d#<g} |D]\} }|r| d$| |fqt } | d%| j| d&| j|D]}| |qd'| }|s| |dg}|d"}|j||d|d g|ddd(}td)|d|jftd*|j|jD] }td+|jq]|rd,}|std-d.d/|jDd0d/|jD}t||d1t|jkrd}|rp|jD]}td2|jtd3|jtd4|j qdSdSdS)5Nza:b:c:g:hi:k:m:n:o:rs:w) amibucketclassgrouphelp inputqueuekeypairmodule numinstances outputqueuereload script_namewaitdefault) module_namer class_name script_bucketr rr num_instancesinput_queue_nameoutput_queue_name)z-az--amir )z-bz--bucketr)z-cz--classr)z-gz--groupr )z-hz--help)z-iz --inputqueuer)z-kz --keypairr)z-mz--moduler)z-nz--num_instancesr)z-oz --outputqueuer)z-rz--reloadT)z-sz--scriptr)z-wz--waitz%s is requiredzReloading module %s to S3zCopying module %s to S3z.pyr script_md5z%s=%szaws_access_key_id=%szaws_secret_access_key=%s|) user_datakey_namesecurity_groups max_countzAMI: %s - %s (Started)z0Reservation %s contains the following instances:z %sFcSsg|]}|qSr)update.0irrr szmain..cSsg|]}|jqSr)stater&rrrr)srunningz Instance: %szPublic DNS Name: %szPrivate DNS Name: %s)!getoptrargvrintgetrimp find_moduleboto connect_s3 get_bucketnew_keyset_contents_from_filemd5itemsappend connect_ec2aws_access_key_idaws_secret_access_keyjoinget_all_imagesrunlocationid instancestimesleepcountlenami_launch_indexpublic_dns_nameprivate_dns_name)optsargsparamsrroarequiredpnamelcr keykvkvsrsimgrr(r+statusrrrmainJs               r\__main__) r,rr0rCr2rrr\__name__rrrrs)f