FRTc@sdZddlZddlZddlmZddlmZddlmZm Z ddl m Z ddl m Z ddlmZddlZd efd YZd e fd YZdS( s) High-level abstraction of an EC2 server iN(tStringIO(tIObject(tConfigtBotoConfigPath(tinteractive_shell(tModel(tStringPropertyt ServerSetcBseZdZdZRS(cCsg}t}xZ|D]R}y5t||}t|r@t}n|j|Wq|jdqXqW|r||_|jS|S(N(tFalsetgetattrtcallabletTruetappendtNonetmap_listtmap(tselftnametresultst is_callabletservertval((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt __getattr__&s    cGs1g}x$|jD]}|j||qW|S(N(RR (RtargsRtfn((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyR6s(t__name__t __module__RR(((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyR$s tServercBseZedZedZeddZd8dZe de ddZ e ddZ e Z e dd Ze dd Ze dd d d Ze dd Ze ddZe ddZe ddZe ZdZdZeeed8dZdZeeed8dZdZeeed8dZdZeeed8dZdZeeed8dZ dZ!ee!ed8dZ"dZ#ee#ed8dZ$d Z%ee%ed8d!Z&d"Z'd#Z(ee'e(d8d$Z)d%Z*d&Z+d'Z,d(Z-d)Z.d8d*d+d,Z/d-Z0d.Z1d/Z2d8d0Z3d1Z4d2Z5d8d8d8d8d8d3Z6d4d5Z7d6Z8d7Z9RS(9cCs(|jdkr!tj|_n|jS(N(t_ec2R tbotot connect_ec2(R((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pytec2>scCs7t}|j}x|D]}|j|qW|S(sl Returns a list of Server instances, one for each Server object persisted in the db (RtfindR (tclstltrsR((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt InventoryDs    tcCs2|}||_||_||_|j|S(N(Rt instance_idt descriptiontsave(R!RR&R'ts((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pytRegisterPs      cKsStt|j||d|_d|_d|_d|_d|_d|_ dS(N( tsuperRt__init__R t _reservationt _instancet _ssh_clientt_pkeyt_configR(Rtidtkw((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyR,Ys     tuniquet verbose_nametNames Instance IDsAMI IDsAvailability ZonesSecurity GrouptdefaultsKey Names Elastic IPs Instance Typet DescriptioncCs tdS(N(tAttributeError(Rtvalue((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt setReadOnlynscCs{|jst|jrty|jj|jg}WndSXt|dkrq|d|_|jjd|_qqqtn|jS(Ni(R.R&Rtget_all_reservationsR tlenR-t instances(RR#((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt getInstanceqs   sThe Instance for the servercCs|jr|jjSdS(N(tinstancetimage_id(R((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pytgetAMIs sThe AMI for the servercCs$|jr |jj|jjSdS(N(R@tupdatetstate(R((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt getStatuss  sThe status of the servercCs|jr|jjSdS(N(R@tpublic_dns_name(R((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt getHostnames s!The public DNS name of the servercCs|jr|jjSdS(N(R@tprivate_dns_name(R((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pytgetPrivateHostnames s"The private DNS name of the servercCs|jr|jjSdS(N(R@t launch_time(R((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt getLaunchTimes sThe time the Server was startedcCs|jr|jjSdS(N(R@tget_console_output(R((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pytgetConsoleOutputs s&Retrieve the console output for servercCs|jr|jjSdSdS(N(R-tgroupsR (R((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt getGroupss  s5The Security Groups controlling access to this servercCsH|jsAt}d|jj}|j||t||_n|jS(Ns%s.ini(R1RR@R2tget_fileR(Rt remote_filet local_file((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt getConfigs  cCsPd|jj}t|}|j||j|j|t||_dS(Ns%s.ini(R@R2topentwritetclosetput_fileRR1(RtconfigRRtfp((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt setConfigs    s!The instance data for this servercCs#||_|jjd|jdS(s& Set SDB based config t botoConfigsN(R1t dump_to_sdbR2(RRX((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt set_configs cCs,tdt|_|jjd|jdS(Ntdo_loadR[(RRR1t load_from_sdbR2(R((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt load_configscCs|jr|jjndS(N(R@tstop(R((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyRas cCs|jtj}|jdt|jgd}|jdt|jg}|jsl|j n|jj ds|jj d|jj dd|j |jj dd|jn|jj ds|jj dn|jjr/|jj dd|jjj|jj dd |jnt}|jj||j}|jd d d d d |jd|d|jd|jd|}|jd}|j|_|j|jr|j|j|jndS(Nt image_idsit groupnamest Credentialstaws_access_key_idtaws_secret_access_keytPyamitserver_sdb_domaintserver_sdb_namet min_countit max_counttkey_nametsecurity_groupst instance_typet placementt user_data(RaRRtget_all_imageststrtami_idtget_all_security_groupstsecurity_groupR1R`t has_sectiont add_sectiontsetReRft_managertdomainRRRUtgetvaluetrunRlRntzoneR>R2R&tputt elastic_iptassociate_address(RRtamiRNtcfgtrti((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pytstarts<  "             cCs|jr|jjndS(N(R@treboot(R((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyRs s~/.ssh/known_hoststrootcCsddl}|jsdGHdS|js|sHt}|jd}n|jj||_|j|_|jj |jj t j j ||jj|j|jj|jjd|d|jn|jS(NisNo instance yet!sPath to OpenSSH Key filetusernametpkey(tparamikoR@R/Rt get_filenametRSAKeytfrom_private_key_fileR0t SSHClienttload_system_host_keystload_host_keystostpatht expandusertset_missing_host_key_policyt AutoAddPolicytconnectRF(Rtkey_filet host_key_filetunameRtiobject((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pytget_ssh_clients      cCs,|j}|j}|j||dS(N(Rt open_sftptget(Rt remotepatht localpatht ssh_clientt sftp_client((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyRPs  cCs,|j}|j}|j||dS(N(RRR~(RRRRR((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyRWs  cCs%|j}|j}|j|S(N(RRtlistdir(RRRR((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyRs  cCs)|j|}|j}t|dS(N(Rt invoke_shellR(RRRtchannel((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pytshells cCsdGHdGH|j}|j}tjj|\}}d|} |j|| tjj|\}}d|} |j|| dtGHy|jtWnnXd} | d| | f7} | d|jj 7} | d|7} | d |7} | d 7} |j j d ks|j d kr,| d 7} n | d7} d| GH|j | } | dj } d| GHd| dj GHdGHdS(Nsbundling image...s5 copying cert and pk over to /mnt directory on servers/mnt/%ss deleting %sssudo ec2-bundle-vol s -c %s -k %s s-u %s s-p %s s-s %d s-d /mnt sm1.smalls c1.mediums-r i386s -r x86_64s %siis ...complete!(RRRRtsplitRWRtremoveR-towner_idR@Rnt exec_commandtread(RtprefixRt cert_filetsizeRRRRtremote_key_filetremote_cert_filetcommandtttresponse((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt bundle_image"s<      !    cCsdGHd}|d|7}|d|7}|d|jj7}|d|jj7}d|GH|j}|j|}|dj}d|GHd|d jGHd GHdS( Nsuploading bundle...sec2-upload-bundle s-m /mnt/%s.manifest.xml s-b %s s-a %s s-s %s s %siis ...complete!(RReRfRRR(RtbucketRRRRR((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt upload_bundleDs   cCst}|s!|jd}n|s9|jd}n|sQ|jd}n|si|jd}n|s|jd}n|j|||||j||dGH|jjd||f|_|jS(NsName of S3 bucketsPrefix for AMI filesPath to RSA private key filesPath to RSA public cert filesSize (in MB) of bundled imagesregistering image...s%s/%s.manifest.xml( Rt get_stringRtget_intRRRtregister_imageRA(RRRRRRR((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyt create_imageSs  s/dev/sdpcCsCt|dr|j}n|}|jjd|d|jd|S(s Attach an EBS volume to this server :param volume: EBS Volume to attach :type volume: boto.ec2.volume.Volume :param device: Device to attach to (default to /dev/sdp) :type device: string R2t volume_idR&tdevice(thasattrR2Rt attach_volumeR&(RtvolumeRR((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyRes  cCs=t|dr|j}n|}|jjd|d|jS(s Detach an EBS volume from this server :param volume: EBS Volume to detach :type volume: boto.ec2.volume.Volume R2RR&(RR2Rt detach_volumeR&(RRR((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyRus cCsld|GHd|}d|GH|j}|j|}|dj}d|GHd|djGHdGHdS(Nsinstalling %s...syum -y install %ss %siis ...complete!(RRR(Rt package_nameRRRR((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pytinstall_packages     N(:RRtpropertyRt classmethodR$R*R R,RR RR&t config_uriRsR}RuRlRRnR'tlogR;R?R@RBRREtstatusRGthostnameRItprivate_hostnameRKRJRMtconsole_outputRORNRSRZRXR]R`RaRRRRPRWRRRRRRRR(((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyR<sx                                 #       "   (t__doc__Rt boto.utilst boto.compatRtboto.mashups.iobjectRtboto.pyami.configRRtboto.mashups.interactiveRtboto.sdb.db.modelRtboto.sdb.db.propertyRRtlistRR(((s@/opt/freeware/lib/python2.7/site-packages/boto/mashups/server.pyts