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ÚdZddlZddlZddlZddlmZddlZddl	m
Z
ddlmZddlm
ZddlZddlmZddlmZmZmZdd	lmZdd
lmZddlmZddlmZejeƒZej j!Z!ej"d
dddgƒZ#dd„Z%d„Z&d„Z'd„Z(d„Z)d„Z*d„Z+de,dd„Z-d„Z.d„Z/da0da1da2da3dd„Z4d„Z5dd „Z6e6e!j7dƒZ8dS(!sUtility methods for scheduling.iÿÿÿÿN(tlog(t	jsonutils(tflavors(tutils(t	exception(t_t_LEt_LW(tobjects(tbase(tinstance(trpctGroupDetailsthoststpoliciestmemberscCs|d}|dkrIt|tjƒr7|jƒ}qItj|ƒ}nt|tjƒr‰tj|ƒ}t	|j
diƒƒ|d<nt|tjƒrátj|ƒ}y tj
|j
diƒ|ƒWqátk
rÝqáXni|píid6|d6|d6t|ƒd6}tj|ƒS(s„Build a request_spec for the scheduler.

    The request_spec assumes that all instances to be scheduled are the same
    type.
    itsystem_metadatatimagetinstance_propertiest
instance_typet
num_instancesN(tNonet
isinstancetobj_instancetInstancet
get_flavorRtextract_flavortobj_basetobj_to_primitivetdicttgetRtFlavortsave_flavor_infotKeyErrortlenRtto_primitive(tctxtRt	instancesRR
trequest_spec((sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pytbuild_request_spec,s*


c
Cs#tjtdƒi|d6|d6|d6ƒ|d}|jdiƒ}tj|ƒ}	|jƒ}
tjtdƒ|
d|ƒtjd	|d
||}|j	d
gƒ|j
ƒtj|||t
jƒƒtd|d|d|d
|d|d|ƒ}d||f}
|	j||
|ƒdS(schanges VM state and notifies.s(Failed to %(service)s_%(method)s: %(ex)stservicetmethodtextvm_stateRsSetting instance to %s state.t
instance_uuidtcontexttuuidR&tinstance_idtstatetreasons%s.%sN(tLOGtwarningRRRtget_notifiertupperRRtobj_reset_changestsavet
compute_utilstadd_instance_fault_from_exctsystexc_infoRterror(R-R,R(R)tupdatesR*R&R+t
propertiestnotifierR0R
tpayloadt
event_type((sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pytset_vm_state_and_notifyUs,
	
		cCsItd|ƒ}||d<|r/|g|d<n|rE|g|d<n|S(s?Build the filter_properties dict from data in the boot request.tscheduler_hintsRtforce_hoststforce_nodes(R(RCtforced_hosttforced_nodeRtfilter_properties((sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pytbuild_filter_propertiesvs
cCs{t|tƒr0|d}|d}|d}n|j}|j}|j}t|||ƒ|jdƒsw||d<ndS(svAdd additional information to the filter properties after a node has
    been selected by the scheduling process.
    thosttnodenametlimitsRDN(RRRJRKRLt_add_retry_hostR(RHt
host_stateRJRKRL((sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pytpopulate_filter_properties„s


			cCsþtj}|jdgƒ}|jdgƒ}|dks]t|ƒdks]t|ƒdkradS|jdidd6gd6ƒ}|dcd7<t||ƒ|jddƒ}|d|krútd	ƒi|d
6|d6|d6}t	j
d|ƒ‚ndS(
NRDREitretryitnum_attemptsR
t
exc_reasonspExceeded max scheduling attempts %(max_attempts)d for instance %(instance_uuid)s. Last exception: %(exc_reason)stmax_attemptsR,R1(tCONFtscheduler_max_attemptsRR"t
setdefaultt_log_compute_errortpopRRRtMaxRetriesExceeded(RHR,RSRDRERPRRtmsg((sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pytpopulate_retry™s&	

	
cCsz|jdƒ}|sdS|jddƒ}|s5dS|d\}}tjtdƒi|d6|d6|d6d|ƒdS(	svIf the request contained an exception from a previous compute
    build/resize operation, log it to aid debugging
    texcNR
iÿÿÿÿsAError from last host: %(last_host)s (node %(last_node)s): %(exc)st	last_hostt	last_nodeR,(RRR2R<R(R,RPR\R
R]R^((sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pyRW»s

cCs=|jddƒ}|sdS|d}|j||gƒdS(s±Add a retry entry for the selected compute node. In the event that
    the request gets re-scheduled, this entry will signal that the given
    node has already been tried.
    RPNR
(RRtappend(RHRJtnodeRPR
((sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pyRMÐs

t=tc
CsÚg}g}x‘|D]‰}y(|j|ƒ\}}}	||	ƒ}	Wntk
r`d}d}	nX|r|r|	dk	r|j||	fƒq|j|ƒqW|rÖtjtdƒi|d6dj|ƒd6ƒn|S(s×Parse a list of options, each in the format of <key><sep><value>. Also
    use the converter to convert the value into desired type.

    :params opts: list of options, e.g. from oslo_config.cfg.ListOpt
    :params sep: the separator
    :params converter: callable object to convert the value, should raise
                       ValueError for conversion failure
    :params name: name of the option

    :returns: a lists of tuple of values (key, converted_value)
    sAIgnoring the invalid elements of the option %(name)s: %(options)stnames, toptionsN(t	partitiont
ValueErrorRR_R2R3Rtjoin(
toptstsept	converterRctgoodtbadtopttkeytseen_septvalue((sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pyt
parse_optionsÜs"



cCs
|tjkS(s?Validates that the filter is configured in the default filters.(RTtscheduler_default_filters(tfilter((sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pytvalidate_filterýscCs dtjkrtS|tjkS(sAValidates that the weigher is configured in the default weighers.s#nova.scheduler.weights.all_weighers(RTtscheduler_weight_classestTrue(tweigher((sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pytvalidate_weigherscs6tdkrtdƒantdkr6tdƒantdkrQtdƒantdkrltdƒan|svdSytjj	||ƒ}Wnt
jk
r¦dSXtdƒ‰t
‡fd
†|jDƒƒr2trd|jkrtdƒ}tj|ƒt
jd|ƒ‚ntrZd|jkrZtd
ƒ}tj|ƒt
jd|ƒ‚ntržd|jkržtdƒ}tj|ƒt
jd|ƒ‚ntrâd	|jkrâtdƒ}tj|ƒt
jd|ƒ‚nt|jƒƒ}|rt|ƒntƒ}td||Bd|jd|jƒSdS(sJProvide group_hosts and group_policies sets related to instances if
    those instances are belonging to a group and if corresponding filters are
    enabled.

    :param instance_uuid: UUID of the instance to check
    :param user_group_hosts: Hosts from the group or empty set

    :returns: None or namedtuple GroupDetails
    tServerGroupAffinityFiltertServerGroupAntiAffinityFilters>nova.scheduler.weights.affinity.ServerGroupSoftAffinityWeighersBnova.scheduler.weights.affinity.ServerGroupSoftAntiAffinityWeigherNs
anti-affinitytaffinitys
soft-affinityssoft-anti-affinityc3s|]}|ˆkVqdS(N((t.0tpolicy(R(sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pys	<genexpr>6ss(ServerGroupAffinityFilter not configuredR1s,ServerGroupAntiAffinityFilter not configureds-ServerGroupSoftAffinityWeigher not configureds1ServerGroupSoftAntiAffinityWeigher not configuredR
RR(s
anti-affinityR{s
soft-affinityssoft-anti-affinity(t_SUPPORTS_AFFINITYRRtt_SUPPORTS_ANTI_AFFINITYt_SUPPORTS_SOFT_AFFINITYRxt_SUPPORTS_SOFT_ANTI_AFFINITYRt
InstanceGrouptget_by_instance_uuidRtInstanceGroupNotFoundtsettanyRRR2R<tUnsupportedPolicyExceptiont	get_hostsRR(R-R,tuser_group_hoststgroupRZtgroup_hostst
user_hosts((RsI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pyt_get_group_detailssX
	



cCs€|jdƒ}|jdiƒjdƒ}t|||ƒ}|dk	r|t|d<|j|d<|j|d<|j|d<ndS(sAdd group_hosts and group_policies fields to filter_properties dict
    based on instance uuids provided in request_spec, if those instances are
    belonging to a group.

    :param request_spec: Request spec
    :param filter_properties: Filter properties
    R‹RR.t
group_updatedtgroup_policiest
group_membersN(RRRRvR
RR(R-R&RHR‹R,t
group_info((sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pytsetup_instance_groupOs


ics‡fd†}|S(s½Retry the call in case a MessagingTimeout is raised.

    A decorator for retrying calls when a service dies mid-request.

    :param retries: Number of retries
    :returns: Decorator
    cs%tjˆƒ‡‡fd†ƒ}|S(Ncs‰d}x|tr„yˆ||ŽSWq	tjk
r€|d7}|ˆkrztjtdƒi|d6ˆd6ˆjd6ƒq‚q	Xq	WdS(NiisORetrying %(name)s after a MessagingTimeout, attempt %(attempt)s of %(retries)s.tattempttretriesRc(Rvt	messagingtMessagingTimeoutR2R3Rt__name__(targstkwargsR“(tfuncR”(sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pytwrappedms	
	(t	functoolstwraps(RšR›(R”(RšsI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pytouterls!((R”Rž((R”sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pytretry_on_timeoutds(9t__doc__tcollectionsRœR:toslo_logRtloggingtoslo_messagingR•toslo_serializationRtnova.computeRRR8t	nova.conftnovaRt	nova.i18nRRRRtnova.objectsR	RR
RRt	getLoggerR—R2tconfRTt
namedtupleRRR'RBRIROR[RWRMtstrRqRtRxR~RR€RRR’RŸRUtretry_select_destinations(((sI/home/tvault/.virtenv/lib/python2.7/site-packages/nova/scheduler/utils.pyt<module>sJ)	!			"		!		@