Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
contego / home / tvault / .virtenv / lib / python2.7 / site-packages / nova / api / ec2 / ec2utils.pyc
Size: Mime:
ó
±EYc@smddlZddlZddlmZddlmZddlmZddlZddl	m
Z
ddl	mZddl	mZddl
mZdd	l
mZdd
lmZddl	mZddlmZejeƒZd6Zdad„Zd„Zd„Zd„Z ed„ƒZ!ed„ƒZ"d„Z#dd„Z$d„Z%dd„Z&d„Z'd„Z(dd„Z)d„Z*d „Z+ed!„ƒZ,d"„Z-d#„Z.d$„Z/ej0d%ƒZ1d&„Z2dd'„Z3ed(„ƒZ4ed)„ƒZ5ed*„ƒZ6d+„Z7ed,„ƒZ8ed-„ƒZ9ej0d.ƒZ:d/„Z;d0„Z<d1„Z=d2„Z>d3„Z?dS(7iÿÿÿÿN(tlog(t	timeutils(t	uuidutils(tcache_utils(tcontext(t	exception(t_(t_LI(tmodel(tobjects(tbaseiii<cs"tjˆƒ‡fd†ƒ}|S(Ncs{tstjdtƒandˆj|f}t|ƒ}tj|ƒ}|dkrwˆ||ƒ}tj||ƒn|S(Ntexpiration_times%s:%s(	t_CACHERt
get_clientt_CACHE_TIMEt__name__tstrtgettNonetset(Rtreqidtkeytvalue(tfunc(sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytmemoizer)s(t	functoolstwraps(RR((RsJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytmemoize(scCs
dadS(N(RR(((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytreset_cache8scCs4|dkrdS|dkr dS|dkr0dS|S(suConverts to a three letter image type.

    aki, kernel => aki
    ari, ramdisk => ari
    anything else => ami

    tkerneltakitramdisktaritami(RR ((t
image_type((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyR"=scCsWidd6dd6dd6dd6d	d
6d	d6d	d6}|jd
ƒd}|j|ƒS(sóGet resource type by ID

    Returns a string representation of the Amazon resource type, if known.
    Returns None on failure.

    :param context: context under which the method is called
    :param resource_id: resource_id to evaluate
    tinstancetitreservationtrtvolumetvoltsnapshottsnaptimageR!RR t-i(tsplitR(Rtresource_idtknown_typesttype_marker((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytresource_type_from_idNs

cCstjj||ƒjS(s+Convert an internal (db) id to a glance id.(R	tS3ImageMappingt	get_by_idtuuid(Rtimage_id((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytid_to_glance_idgscCsb|s
dSytjj||ƒjSWn7tjk
r]tj|d|ƒ}|jƒ|jSXdS(s+Convert a glance id to an internal (db) id.NR4(R	R2tget_by_uuidtidRtNotFoundtcreate(Rt	glance_idts3imap((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytglance_id_to_idms
cCst|ƒ}t||ƒS(N(tec2_id_to_idR6(Rtec2_idR5((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytec2_id_to_glance_idzsR!cCs/t||ƒ}|dkrdSt|d|ƒS(NR"(R=Rtimage_ec2_id(RR;R"R5((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytglance_id_to_ec2_idscCsHyt|jdƒddƒSWn#tk
rCtjd|ƒ‚nXdS(s?Convert an ec2 ID (i-[base 16 number]) to an instance id (int).R,iÿÿÿÿiR?N(tintR-t
ValueErrorRtInvalidEc2Id(R?((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyR>†s
cCs|d}t|d|ƒS(s4Returns image ec2_id using id and three letter type.s-%08xttemplate(tid_to_ec2_id(R5R"RF((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyRAŽs
cCsÆt|tjƒs'tjj|ƒ}ni}|jƒ}g|D] }|ddkr@|d^q@|d<g|D] }|ddkrq|d^qq|d<g|jƒD]}|d^q¨|d<|S(Ntversionitaddresst	fixed_ipsit
fixed_ip6stfloating_ips(t
isinstancet
network_modeltNetworkInfothydrateRJRL(tnw_infotip_infoRJtip((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyt%get_ip_info_for_instance_from_nw_info”s
$
$'cCsXt|tjƒr!|jj}n|jp-i}|jdƒ}|sNg}nt|ƒS(s6Return a dictionary of IP information for an instance.tnetwork_info(RMtobj_baset
NovaObjectt
info_cacheRURRT(RR#RQRX((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytget_ip_info_for_instance£s	si-%08xcCs|t|ƒS(s?Convert an instance ID (int) to an ec2 ID (i-[base 16 number]).(RC(tinstance_idRF((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyRG²scCsR|dkrdStj|ƒrDtjƒ}t||ƒ}t|ƒSt|ƒSdS(s@Get or create an ec2 instance ID (i-[base 16 number]) from uuid.N(RRtis_uuid_likeRtget_admin_contexttget_int_id_from_instance_uuidRG(RZtctxttint_id((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytid_to_ec2_inst_id·s
cCst|ƒ}t||ƒS(s "Convert an instance id to uuid.(R>tget_instance_uuid_from_int_id(RR?R_((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytec2_inst_id_to_uuidÃscCstjj||ƒ}|jS(N(R	tEC2InstanceMappingR3R4(RR_timap((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyRaÉscCsHtj|ƒr7tjƒ}t||ƒ}t|dƒSt|dƒSdS(s@Get or create an ec2 volume ID (vol-[base 16 number]) from uuid.s	snap-%08xN(RR[RR\tget_int_id_from_snapshot_uuidRG(tsnapshot_idR^R_((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytid_to_ec2_snap_idÏs

cCsHtj|ƒr7tjƒ}t||ƒ}t|dƒSt|dƒSdS(s@Get or create an ec2 volume ID (vol-[base 16 number]) from uuid.svol-%08xN(RR[RR\tget_int_id_from_volume_uuidRG(t	volume_idR^R_((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytid_to_ec2_vol_idÙs

cCs%tjƒ}t|ƒ}t||ƒS(s0Get the corresponding UUID for the given ec2-id.(RR\R>tget_volume_uuid_from_int_id(R?R^R_((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytec2_vol_id_to_uuidãss/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3,6}Z$cCsk|jdƒ}|jdƒ}|dkr3|}n4|d	krH|}ntdƒ|}tj|ƒ‚|S(
s§Get the corresponding EC2 attachment state.

    According to EC2 API, the valid attachment status in response is:
    attaching | attached | detaching | detached
    tstatust
attach_statust	attachingt	detachingtattachedtdetacheds*Unacceptable attach status:%s for ec2 API.(RoRp(Rqsdetached(RRRtInvalid(R't
volume_statusRntec2_attach_statustmsg((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytstatus_to_ec2_attach_statusïs		cCs÷|jdƒ}|jdƒ}d„}y¤|ra|ratdƒ}tj|ƒtj|ƒ‚ne|rƒ||ƒ}tj|dƒS|rÆ||ƒ}|rÆ|rÆtj||ƒpÂtj||ƒSnt	SWn%t
k
ròtjtdƒƒt
SXdS(srChecks the timestamp or expiry time included in an EC2 request
    and returns true if the request is expired
    t	TimestamptExpirescSs.tj|ƒrd}nd}tj||ƒS(Ns%Y-%m-%dT%H:%M:%S.%fZs%Y-%m-%dT%H:%M:%SZ(t_ms_time_regextmatchRt
parse_strtime(tstrtimettime_format((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyR|s	sIRequest must include either Timestamp or Expires, but cannot contain bothiÿÿÿÿsTimestamp is invalid.N(RRtLOGterrorRtInvalidRequestRt
is_older_thant
is_newer_thantFalseRDtinfoRtTrue(trequesttexpirest	timestamptexpiry_timeR|Rvt
query_time((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytis_ec2_timestamp_expireds(	

cCsq|dkrdSy tjj||ƒ}|jSWn:tjk
rltj|ƒ}||_|jƒ|jSXdS(N(	RR	RcR7R8RR9R4R:(Rt
instance_uuidRd((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyR](s	
cCsq|dkrdSy tjj||ƒ}|jSWn:tjk
rltj|ƒ}||_|jƒ|jSXdS(N(	RR	tEC2VolumeMappingR7R8RR9R4R:(Rtvolume_uuidtvmap((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyRh6s	
cCstjj||ƒ}|jS(N(R	RŽR3R4(RR_R((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyRkDscCs%tjƒ}t|ƒ}t||ƒS(s0Get the corresponding UUID for the given ec2-id.(RR\R>tget_snapshot_uuid_from_int_id(R?R^R_((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytec2_snap_id_to_uuidJscCsn|dkrdSy tjj||ƒ}|jSWn7tjk
ritj|d|ƒ}|jƒ|jSXdS(NR4(RR	tEC2SnapshotMappingR7R8RR9R:(Rt
snapshot_uuidtsmap((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyReSs
cCstjj||ƒ}|jS(N(R	R“R3R4(RR_R•((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyR‘`ss&(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))cCstjd|ƒjƒjdƒS(Ns_\1R(t_c2utsubtlowertstrip(R((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytcamelcase_to_underscoreiscCséd„}t|ƒdkrdS|dkr/dS|jƒ}|dkrKtS|dkr[tSx^ddddgD]J\}}y*|j|d|fƒr£t||ƒSWqntk
r·qnXqnWy|t|ƒƒSWntk
rä|SXdS(s?Return a non-string from a string or unicode, if possible.

    ============= =====================================================
    When value is returns
    ============= =====================================================
    zero-length   ''
    'None'        None
    'True'        True case insensitive
    'False'       False case insensitive
    '0', '-0'     0
    0xN, -0xN     int from hex (positive) (N is any number)
    0bN, -0bN     int from binary (positive) (N is any number)
    *             try conversion to int, float, complex, fallback value

    cSs d}t|ƒ|krdS|S(NgH¯¼šò×z>i(tabs(Rtepsilon((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyt_negative_zero}sitRttruetfalset0xit0bit0ii
R,N(s0xi(s0bi(R£i(Rži
(	tlenRR˜R†R„t
startswithRCRDtfloat(RRt
lowered_valuetprefixR
((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyt_try_convertms(	

cCsüi}xï|D]ç\}}|jdƒ}tt|dƒƒ}t|tjƒr
t|ƒ}t|ƒdkrç|j|iƒ}|||<xC|dd!D]4}t|ƒ}|j|iƒ}|||<|}q˜W||t|dƒ<qô|||<q
q
W|S(sìparse multi dot-separated argument into dict.
    EBS boot uses multi dot-separated arguments like
    BlockDeviceMapping.1.DeviceName=snap-id
    Convert the above into
    {'block_device_mapping': {'1': {'device_name': snap-id}}}
    t.iiiÿÿÿÿ(	R-RRšRMtsixtstring_typesR©R¤R(titemstargsRRtpartstdtktv((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytdict_from_dotted_str–s"


cCs|rd„|DƒSiS(NcSs?i|]5}|ddr|dd|djddƒ“qS(Rt1tnameR,R(treplace(t.0tf((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pys
<dictcomp>¶s	((tfilters((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytsearch_opts_from_filtersµscCsàt|ƒ}d}xÃ|D]»}|dkr8|d7}q|dkrQ|d7}q|dkrÁyt|ƒ}Wntk
r†d}nX|dksŸ|dkr°|d|7}qÔ|d|7}q|tj|ƒ7}qWd	|S(
s\Converts an EC2-style regex to a python regex.
    Approach is based on python fnmatch.
    Ržt*s.*t?Rªs\s[%s]s\\s
\A%s\Z(?s)(titertnextt
StopIterationtretescape(tec2_retiter_ec2_retpy_retchart	next_char((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pytregex_from_ec2_regexºs"




i¨i`'i€:	(@RRÀtoslo_logRtloggingt
oslo_utilsRRR«tnovaRRRt	nova.i18nRRtnova.networkRRNR	tnova.objectsR
RVt	getLoggerRRRRRRRR"R1R6R=R@RBR>RARTRYRGR`RbRaRgRjRltcompileRzRwRŒR]RhRkR’ReR‘R–RšR©R³RºRÇ(((sJ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/api/ec2/ec2utils.pyt<module>sd				
							
	
			'		
		)