FRTc@sdZddlmZddlmZdefdYZdefdYZdefd YZ d efd YZ d S( s" Represents an EC2 Security Group i(tTaggedEC2Object(tBotoClientErrort SecurityGroupcBseZd d d d d dZdZdZdZedZedZ edZ d d d d d edZ d d d d d edZ d ed Z ed ZRS( cCs_tt|j|||_||_||_||_d|_t |_ t |_ dS(N( tsuperRt__init__tidtowner_idtnamet descriptiontNonetvpc_idtIPPermissionsListtrulest rules_egress(tselft connectionRRRR((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyR s      cCs d|jS(NsSecurityGroup:%s(R(R((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyt__repr__+scCs\tt|j|||}|dk r.|S|dkrA|jS|dkrT|jSdSdS(Nt ipPermissionstipPermissionsEgress(RRt startElementR R R (RRtattrsRtretval((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyR.s   cCs|dkr||_n|dkr0||_n|dkrH||_n|dkr`||_n|dkrx||_nw|dkrnh|dkr|dkrt|_q|d krt|_qtd ||jfnt |||dS( NtownerIdtgroupIdt groupNametvpcIdtgroupDescriptiontipRangestreturntfalsettrues*Unexpected value of status %s for group %s( RRRR RtFalsetstatustTruet Exceptiontsetattr(RRtvalueR((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyt endElement9s,                cCsB|jr%|jjd|jd|S|jj|jd|SdS(Ntgroup_idtdry_run(R Rtdelete_security_groupRR(RR'((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pytdeleteUs     c CsWt|} || _|| _|| _|jj| | j||||d|dS(s Add a rule to the SecurityGroup object. Note that this method only changes the local version of the object. No information is sent to EC2. R'N(t IPPermissionst ip_protocolt from_porttto_portR tappendt add_grant( RR+R,R-tsrc_group_nametsrc_group_owner_idtcidr_iptsrc_group_group_idR'trule((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pytadd_ruleas    c Cs|jstdnd} x|jD]} | j|kr| j|kr| j|kr| } d} x\| jD]Q} | j|ks| j|krq| j |kr| j |kr| } qqqqqqW| r| jj | qqqnt | jdkr(|jj | q(q(WdS(s Remove a rule to the SecurityGroup object. Note that this method only changes the local version of the object. No information is sent to EC2. sThe security group has no rulesiN( R t ValueErrorR R+R,R-tgrantsRR&RR2tremovetlen( RR+R,R-R0R1R2R3R't target_ruleR4t target_granttgrant((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyt remove_rulevs$ c Cs'd}|js|j}nd}|jr6|j}nd} d} d} |rd}|j} |jsr|j} qt|dr|j} q|j} n|jj|| | |||||| d| } | r#t |t s|g}nx6|D]+} |j |||| | | | d|qWn| S(s Add a new rule to this security group. You need to pass in either src_group_name OR ip_protocol, from_port, to_port, and cidr_ip. In other words, either you are authorizing another group or you are authorizing some ip-based rule. :type ip_protocol: string :param ip_protocol: Either tcp | udp | icmp :type from_port: int :param from_port: The beginning port number you are enabling :type to_port: int :param to_port: The ending port number you are enabling :type cidr_ip: string or list of strings :param cidr_ip: The CIDR block you are providing access to. See http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing :type src_group: :class:`boto.ec2.securitygroup.SecurityGroup` or :class:`boto.ec2.securitygroup.GroupOrCIDR` :param src_group: The Security Group you are granting access to. :rtype: bool :return: True if successful. R&R'N( R R RRRthasattrR&Rtauthorize_security_groupt isinstancetlistR5(RR+R,R-R2t src_groupR't group_nameR&R0R1R3R tsingle_cidr_ip((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyt authorizesF             c Csd}|js|j}nd}|jr6|j}nd} d} d} |rd}|j} |jsr|j} qt|dr|j} q|j} n|jj|| | |||||| d| } | r|j |||| | || d|n| S(NR&R'( R R RRRR>R&Rtrevoke_security_groupR=( RR+R,R-R2RBR'RCR&R0R1R3R ((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pytrevokes@             c Cs|j|jkr!tdn|jj}|j|}|j|pQ|j|jd|}g}x|jD]}x|j D]} | jp| j } | r| |kr|j | |j dddd| d|qq|j |j|j|j| jd|qWqsW|S(s{ Create a copy of this security group in another region. Note that the new security group will be a separate entity and will not stay in sync automatically after the copy operation. :type region: :class:`boto.ec2.regioninfo.RegionInfo` :param region: The region to which this security group will be copied. :type name: string :param name: The name of the copy. If not supplied, the copy will have the same name as this security group. :rtype: :class:`boto.ec2.securitygroup.SecurityGroup` :return: The new security group. s!Unable to copy to the same RegionR'N(RtregionRRt get_paramstconnecttcreate_security_groupRR R7R&R.RER R+R,R-R2( RRHRR't conn_paramstrconntsgt source_groupsR4R<t grant_nom((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pytcopy_to_regions(      cCsg}|jr>|j|jjdi|jd6d|n,|j|jjdi|jd6d|g|D]}|jD] }|^q~qq}|S(s Find all of the current instances that are running within this security group. :rtype: list of :class:`boto.ec2.instance.Instance` :return: A list of Instance objects tfilterssinstance.group-idR'sgroup-id(R textendRtget_all_reservationsRt instances(RR'trstrtiRU((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyRU"s   )N(t__name__t __module__R RRRR%RR)R5R=RERGRQRU(((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyRs      B $(R cBseZdZdZRS(cCs+|dkr'|jt||dSdS(Ntitemi(R.R*R (RRRR((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyR;s cCsdS(N((RRR$R((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyR%As(RYRZRR%(((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyR 9s R*cBsGeZddZdZdZdZddddedZRS(cCs1||_d|_d|_d|_g|_dS(N(tparentR R+R,R-R7(RR\((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyRGs     cCsd|j|j|jfS(NsIPPermissions:%s(%s-%s)(R+R,R-(R((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyRNs cCs1|dkr-|jjt||jdSdS(NR[i(R7R.t GroupOrCIDRR (RRRR((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyRRs  cCs\|dkr||_n@|dkr0||_n(|dkrH||_nt|||dS(Nt ipProtocoltfromPortttoPort(R+R,R-R#(RRR$R((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyR%Xs      cCsDt|}||_||_||_||_|jj||S(N(R]RR&RR2R7R.(RRRR2R&R'R<((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyR/bs     N( RYRZR RRRR%RR/(((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyR*Es     R]cBs/eZddZdZdZdZRS(cCs(d|_d|_d|_d|_dS(N(R RR&RR2(RR\((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyRos   cCs5|jrd|jSd|jp&|j|jfSdS(Ns%ss%s-%s(R2RR&R(R((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyRus  cCsdS(N(R (RRRR((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyR{scCst|dkr||_n0|dkr0||_n|dkrH||_n|dkr`||_nt|||dS(NtuserIdRRtcidrIp(RR&RR2R#(RRR$R((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyR%~s        N(RYRZR RRRR%(((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyR]ms   N( t__doc__tboto.ec2.ec2objectRtboto.exceptionRRRAR tobjectR*R](((sC/opt/freeware/lib/python2.7/site-packages/boto/ec2/securitygroup.pyts (