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    
Size: Mime:
ó
±EYc@sàdZddlZddlZddlZddlZddlZddlZddlmZddl	Z	ddl
mZddlm
Z
ddlmZddlZ
ddl
mZddlmZdd	lmZdd
l
mZddlmZddlmZdd
l
mZddlmZddl
mZddl
m Z ddl
m!Z!ddl"m#Z#e
j$j%Z%ej&e'ƒZ(dd„Z*d„Z+ddd„Z,d„Z-d„Z.ddd„Z/dd„Z0dd„Z1d„Z2d„Z3e4e5ddd„Z6ddddd„Z7ddd „Z8d!„Z9d"„Z:d#„Z;d$„Z<d%„Z=d&„Z>d'„Z?d(„Z@d)„ZAd*„ZBd+„ZCd,„ZDd-„ZEd.„ZFd/eGfd0„ƒYZHd1„ZId2eGfd3„ƒYZJdS(4s&Compute-related Utilities and helpers.iÿÿÿÿN(tlog(tblock_device(tpower_state(ttask_states(t	exception(t_LW(tmodel(t
notifications(tbase(tinstance(tobjects(tfields(trpc(t
safe_utils(tutils(tdrivercCsÕd}t|dƒr-|jjddƒ}ny|sE|jƒ}nWn>tk
r†ytj|ƒ}Wq‡tk
r‚d}q‡XnX|sœ|jj	}nt
j|dƒ}td|ƒ}||d<||d<|S(s7Converts exceptions to a dict for use in notifications.iôtkwargstcodeiÿRtmessageN(
thasattrRtgettformat_messaget	Exceptiontsixt	text_typetNonet	__class__t__name__Rt
safe_truncatetdict(tfaultRRt	u_messaget
fault_dict((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytexception_to_dict0s$



cCsSd}|rF|dkrF|d}|rFdjtj|ƒƒ}qFntj|ƒS(Ntiôi(tjoint	tracebackt	format_tbRR(texc_infot
error_codetdetailsttb((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyt_get_fault_detailsPs
cCsltjd|ƒ}tj|_|j|_|jt|d|ƒƒ|j}t	||ƒ|_
|jƒdS(s)Adds the specified fault to the database.tcontextRN(R
t
InstanceFaulttCONFthosttuuidt
instance_uuidtupdateR!RR*R(tcreate(R+R	RR&t
fault_messaget	fault_objR((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytadd_instance_fault_from_excYs	cCs/tj||ƒ}t||jƒ|d|ƒS(sÈValidates (or generates) a device name for instance.

    This method is a wrapper for get_next_device_name that gets the list
    of used devices and the root device from a block device mapping.
    troot(Rtinstance_block_mappingtget_next_device_nametvalues(R	tbdmstdevicetmappings((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytget_device_name_for_instancefscGs¬gtj|ŒD]}|jr|j^q}||krJ|j|ƒnx[tj|ŒD]J}|j}|sZt|||ƒ}||_|jƒ|j|ƒqZqZWdS(s.Generate missing device names for an instance.N(t	itertoolstchaintdevice_nametappendR8tsave(R	troot_device_nametblock_device_liststbdmtdev_listtdev((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyt!default_device_names_for_instanceqs				
cCsÁd	}d	}|r]ytj|ƒ\}}Wq]tttfk
rYtjd|ƒ‚q]Xn|sotj}ny tjtj	|ƒƒd}Wn,tttfk
r½tjd|ƒ‚nXt
jƒrÓd}n||krtj
di|d6|d6ƒntƒ}x*|D]"}tj|ƒ}	|j|	ƒqWt
jƒrƒ|jƒ}
|
jrg|jdƒn|
jrƒ|jdƒqƒn|s˜t|ƒ}n||kr¹tjd|ƒ‚n||S(
sÎValidates (or generates) a device name for instance.

    If device is not set, it will generate a unique device appropriate
    for the instance. It uses the root_device_name (if provided) and
    the list of used devices to find valid device names. If the device
    name is valid but applicable to a different backend (for example
    /dev/vdc is specified but the backend uses /dev/xvdc), the device
    name will be converted to the appropriate format.
    tpathis/dev/xvds*Using %(prefix)s instead of %(req_prefix)stprefixt
req_prefixtbtcN(RRtmatch_devicet	TypeErrortAttributeErrort
ValueErrorRtInvalidDevicePathtDEFAULT_ROOT_DEV_NAMEtprepend_devRt	is_xenapitLOGtdebugtsettget_device_lettertaddt
get_flavortephemeral_gbtswapt_get_unused_lettertDevicePathInUse(R	tdevice_name_listRCR;RKt
req_letterRJtused_letterstdevice_pathtlettertflavor((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyR8…sD			
		cCsV|dkrLt|tjƒr*|j}n
|d}tjj||ƒ}n|jƒS(NR/(Rt
isinstanceR
tInstanceR/tBlockDeviceMappingListtget_by_instance_uuidtroot_bdm(R+R	R:R/((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytget_root_bdmÃs
	cCsHt|||ƒ}|dk	r%|jSt|tjƒr?|jS|dS(Nt	image_ref(RkRt	is_volumeRfR
RgRl(R+R	R:Rj((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytis_volume_backed_instanceÏscCstgtjD] }tjD]}||^qq
}tttjƒ|ƒ}t||ƒ}|jdd„ƒ|dS(NtkeycSs|jddƒS(Nit`(trjust(tx((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyt<lambda>ási(tstringtascii_lowercaseRXtlisttsort(Rbtsecondtfirsttdoublestall_letterstletters((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyR^Ûs cCst|jj||ƒ}y||ƒSWnJtk
rotjtdƒi|d6|d6|d6|d6d|ƒ|SXdS(s Get a value of a specified type from image metadata.

    @param instance: The instance object
    @param key: The name of the property to get
    @param type: The python type the value is be returned as
    @param default: The value to return if key is not set or not the right type
    s^Metadata value %(value)s for %(key)s is not of type %(type)s. Using default value %(default)s.tvalueRottypetdefaultR	N(tsystem_metadataRRQRVtwarningR(R	RoR~RR}((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytget_value_from_system_metadataås
c	Cs½tj|ƒ\}}tj|||ƒ}	|dkrHtj|ƒ}ntj|ƒ}
tdt|ƒdt|ƒd|	d|
ƒ}|rš|j	|ƒnt
|||dd|d|ƒdS(	sþGenerates 'exists' notification for an instance for usage auditing
    purposes.

    :param notifier: a messaging.Notifier

    :param current_period: if True, this will generate a usage for the
        current usage period; if False, this will generate a usage for the
        previous audit period.

    :param ignore_missing_network_data: if True, log any exceptions generated
        while getting network info; if False, raise the exception.
    :param system_metadata: system_metadata DB entries for the instance,
        if not None.  *NOTE*: Currently unused here in trunk, but needed for
        potential custom modifications.
    :param extra_usage_info: Dictionary containing extra values to add or
        override in the notification if not None.
    taudit_period_beginningtaudit_period_endingt	bandwidtht
image_metatexistsR€textra_usage_infoN(Rtaudit_period_boundstbandwidth_usageRRtinstance_sys_metaR†RtstrR1tnotify_about_instance_usage(tnotifierR+tinstance_reftcurrent_periodtignore_missing_network_dataR€Rˆtaudit_startt	audit_endtbwR†t
extra_info((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytnotify_usage_existsøs	cCsŸ|si}ntj|||||}|rct|ƒ}	tj|	dd|ƒ|j|	ƒn|jdƒr~|j}
n	|j}
|
|d||ƒdS(s¦Send a notification about an instance.

    :param notifier: a messaging.Notifier
    :param event_suffix: Event type like "delete.start" or "exists"
    :param network_info: Networking information, if provided.
    :param system_metadata: system_metadata DB entries for the instance,
        if provided.
    :param extra_usage_info: Dictionary containing extra values to add or
        override in the notification.
    RR	terrorscompute.instance.%sN(	Rtinfo_from_instanceR!RVRWR1tendswithR—tinfo(RŽR+R	tevent_suffixtnetwork_infoR€RˆRt
usage_infot
fault_payloadtmethod((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyR#s
		snova-computec
CsMt|ƒ}g}|dk	r¦x…|D]z}xq|jƒD]c}	|jtjd|ddd|dd|dd|dd|	dd|	dd	|d
ƒƒq8Wq%Wntjd|ƒ}
tjd|ddd
|d|
ƒ}tjd|dt	j
jdtj
d|d|d|ƒdtjddd|d|ƒd|ƒ}|j|ƒdS(sFSend versioned notification about the action made on the instance
    :param instance: the instance which the action performed on
    :param host: the host emitting the notification
    :param action: the name of the action
    :param phase: the phase of the action
    :param binary: the binary emitting the notification
    tlabeltnetworktmactaddresstmetat	port_uuidtidtversionR@tdevnameR	Rtip_addressesReR+tpriorityt	publisherR.tbinaryt
event_typetobjecttactiontphasetpayloadN(tget_nw_info_for_instanceRt	fixed_ipsRAtinstance_notificationt	IpPayloadt
FlavorPayloadtInstanceActionPayloadtInstanceActionNotificationRtNotificationPrioritytINFOtnotification_basetNotificationPublishert	EventTypetemit(
R+R	R.R¯R°R¬RœtipstviftipReR±tnotification((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytnotify_about_instance_actionDs<	





							cCs-tjddƒ}|j|d||ƒdS(s³Send a notification about server group update.

    :param event_suffix: Event type like "create.start" or "create.end"
    :param sg_payload: payload for server group update
    tservicetservergroupsservergroup.%sN(Rtget_notifierRš(R+R›t
sg_payloadRŽ((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyt notify_about_server_group_updateoscCsw|jddƒ}|sD|jddƒ}|sDtjdƒdSntjddd|ƒ}|j|d||ƒdS(	s´Send a notification about aggregate update.

    :param event_suffix: Event type like "create.start" or "create.end"
    :param aggregate_payload: payload for aggregate update
    taggregate_idtnamesNNo aggregate id or name specified for this notification and it will be ignoredNRÄt	aggregateR.saggregate.%s(RRRVRWRRÆRš(R+R›taggregate_payloadtaggregate_identifierRŽ((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytnotify_about_aggregate_updatezs
	cCsb|jdƒ}|s/tjtdƒ|ƒdStjddd|ƒ}|j|d||ƒdS(s$Send a notification about host update.

    :param event_suffix: Event type like "create.start" or "create.end"
    :param host_payload: payload for host update. It is a dict and there
                         should be at least the 'host_name' key in this
                         dict.
    t	host_namesPNo host name specified for the notification of HostAPI.%s and it will be ignoredNRÄtapiR.s
HostAPI.%s(RRVRRRRÆRš(R+R›thost_payloadthost_identifierRŽ((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytnotify_about_host_updateŽscCs)|jdkrtjjgƒS|jjS(N(t
info_cacheRt
network_modeltNetworkInfothydrateRœ(R	((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyR²¡scCs#|jdk	r|jjƒndS(sWRefresh the info cache for an instance.

    :param instance: The instance object.
    N(RÔRtrefresh(R+R	((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytrefresh_info_cache_for_instance§scCsÔd„}|j}|j}|r9|r9t||ƒ}n|rH|}n|}td|jd|jd|jd|jd|jd||ƒd|j	|j
d	|j|jd
|j
|jd|j|jƒ
}|S(NcSs|rt|ƒSdS(NR"(RŒ(ts((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyt
null_safe_str±st	volume_idt	tenant_idtuser_idtavailability_zonetinstance_idtlast_refreshedtreadst
read_bytestwritestwrite_bytes(ttot_last_refreshedtcurr_last_refreshedtmaxRRÜt
project_idRÞRßR0t	tot_readst
curr_readsttot_read_bytestcurr_read_bytest
tot_writestcurr_writesttot_write_bytestcurr_write_bytes(t	vol_usageRÛt
tot_refreshedtcurr_refreshedtlast_refreshed_timeR((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytusage_volume_info°s,									

cCsG|tjkrdStjtjtjg}||kr=dnd}|S(s<Checks if the current instance state requires a HARD reboot.tHARDtSOFT(RtRUNNINGRtREBOOT_STARTEDtREBOOT_PENDINGt	REBOOTING(t
task_statetcurrent_power_statet
soft_typestreboot_type((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytget_reboot_typeÏscCsÈg}x»tjƒD]­}y“tj|ƒ}x}|D]u}|tjtjfkrVq2nxN||D]B}|d}|tjkr–|jdƒd}n|j|ƒqaWq2WWqtk
r¿qXqW|S(sRGet the machine's ip addresses

    :returns: list of Strings of ip addresses
    taddrt%i(t	netifacest
interfacestifaddressestAF_INETtAF_INET6tsplitRARQ(t	addressest	interfacet
iface_datatfamilyR£R((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytget_machine_ipsÙs


csq‡‡‡fd†}i}||dƒdkrD|dƒ|d<n||dƒdkrm|dƒ|d<n|S(sCCalculate any quota adjustment required at a particular point
    in the resize cycle.

    :param context: the request context
    :param new_flavor: the target instance type
    :param old_flavor: the original instance type
    :param sense: the sense of the adjustment, 1 indicates a
                  forward adjustment, whereas -1 indicates a
                  reversal of a prior adjustment
    :param compare: the direction of the comparison, 1 indicates
                    we're checking for positive deltas, whereas
                    -1 indicates negative deltas
    csˆˆ|ˆ|S(N((tresource(t
new_flavort
old_flavortsense(sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyt_quota_deltastvcpusitcorest	memory_mbtram((R+RRRtcompareRtdeltas((RRRsG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytresize_quota_deltaòscCst|||ddƒS(sFCalculate deltas required to adjust quota for an instance upsize.
    i(R(R+RR((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytupsize_quota_deltascCst||j|jddƒS(sPCalculate deltas required to reverse a prior upsizing
    quota adjustment.
    iÿÿÿÿ(RRR(R+R	((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytreverse_upsize_quota_deltascCs4|jdƒ}|jdƒ}t|||ddƒS(sHCalculate deltas required to adjust quota for an instance downsize.
    toldtnewiiÿÿÿÿ(R[R(R+R	RR((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytdownsize_quota_deltascCsStjd|ƒ}|rOtjj||ƒ\}}|jd|d||n|S(s“If there are deltas to reserve, construct a Quotas object and
    reserve the deltas for the given project.

    :param context:    The nova request context.
    :param deltas:     A dictionary of the proposed delta changes.
    :param instance:   The instance we're operating on, so that
                       quotas can use the correct project_id/user_id.
    :return: nova.objects.quotas.Quotas
    R+RéRÞ(R
tQuotastquotastids_from_instancetreserve(R+RR	R!RéRÞ((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytreserve_quota_delta"s

cCs:x3dddgD]"}||jkr|j|=qqWdS(Nt
shelved_attshelved_image_idtshelved_host(R€(R	Ro((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyt(remove_shelved_keys_from_system_metadata5st
EventReportercBs)eZdZd„Zd„Zd„ZRS(s1Context manager to report instance action events.cGs||_||_||_dS(N(R+t
event_nametinstance_uuids(tselfR+R*R+((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyt__init__?s		cCs:x3|jD](}tjj|j||jdtƒq
W|S(Ntwant_result(R+R
tInstanceActionEventtevent_startR+R*tFalse(R,R/((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyt	__enter__Ds	cCsFx?|jD]4}tjj|j||jd|d|dtƒq
WtS(Ntexc_valtexc_tbR.(R+R
R/tevent_finish_with_failureR+R*R1(R,texc_typeR3R4R/((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyt__exit__Ks
	(Rt
__module__t__doc__R-R2R7(((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyR)<s		cs"tjdƒ‡fd†ƒ}|S(sÂWraps a method to log the event taken on the instance, and result.

    This decorator wraps a method to log the start and result of an event, as
    part of an action taken on an instance.
    R	cs%tjˆƒ‡‡fd†ƒ}|S(Nc	s}tjˆƒ}tj|||||Ž}|dd}djˆˆjƒ}t|||ƒˆ||||ŽSWdQXdS(NR	R/s{0}_{1}(R
tget_wrapped_functiontinspecttgetcallargstformatRR)(R,R+targsRtwrapped_funct
keyed_argsR0R*(tfunctionRJ(sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytdecorated_function\s(t	functoolstwraps(RARB(RJ(RAsG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pythelperYs!
(Rtexpects_func_args(RJRE((RJsG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytwrap_instance_eventSstUnlimitedSemaphorecBs)eZd„Zd„Zed„ƒZRS(cCsdS(N((R,((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyR2kscCsdS(N((R,R6R3R4((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyR7nscCsdS(Ni((R,((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pytbalanceqs(RR8R2R7tpropertyRI(((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyRHjs		(KR9RCR;R>RtR$Rtoslo_logRRtnovaRtnova.computeRRt	nova.confRt	nova.i18nRtnova.networkRRÕRtnova.notifications.objectsRR»R	R´R
tnova.objectsRRR
Rt	nova.virtRtconfR-t	getLoggerRRVRR!R*R5R=RHR8RkRnR^R‚R1tTrueR–RRÃRÈRÎRÓR²RÙRöRRRRRRR$R(R®R)RGRH(((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/compute/utils.pyt<module>sz 				=	
	**