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 / pci / manager.pyc
Size: Mime:
ó
±EYc@sÚddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlmZddl
mZdd	lmZdd
lmZejZejeƒZdefd„ƒYZed
„ZdS(iÿÿÿÿN(tcfg(tlog(t	jsonutils(t	exception(t_LW(tobjects(tfields(tstats(t	whitelistt
PciDevTrackercBs¹eZdZdd„Zd„Zd„Zed„ƒZd„Z	e
d„ƒZd„Zd„Z
d	„Zd
„Zd„Zd„Zdd
„Zd„Zd„Zd„Zd„ZRS(sjManage pci devices in a compute node.

    This class fetches pci passthrough information from hypervisor
    and tracks the usage of these devices.

    It's called by compute node resource tracker to allocate and free
    devices to/from instances, and to update the available pci passthrough
    devices information from hypervisor periodically.

    `pci_devs` attribute of this class is the in-memory "master copy" of all
    devices on each compute host, and all data changes that happen when
    claiming/allocating/freeing
    devices HAVE TO be made against instances contained in `pci_devs` list,
    because they are periodically flushed to the DB when the save()
    method is called.

    It is unsafe to fetch PciDevice objects elsewhere in the code for update
    purposes as those changes will end up being overwritten when the `pci_devs`
    are saved.
    cCs¯tt|ƒjƒi|_||_tjtjƒ|_	t
jd|j	ƒ|_
||_|r|t
jj||ƒ|_nt
jdgƒ|_|j|jƒ|jƒdS(sCreate a pci device tracker.

        If a node_id is passed in, it will fetch pci devices information
        from database, otherwise, it will create an empty devices list
        and the resource tracker will update the node_id information later.
        t
dev_filterRN(tsuperR	t__init__tstaletnode_idRt	WhitelisttCONFtpci_passthrough_whitelistR
RtPciDeviceStatst_contextRt
PciDeviceListtget_by_compute_nodetpci_devst_build_device_treet_initial_instance_usage(tselftcontextR((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyR8s				cCsÅtjtƒ|_tjtƒ|_xš|jD]}|j}|jtj	j
kri|j|j|ƒq.|jtj	jkr•|j|j|ƒq.|jtj	j
kr.|jj|ƒq.q.WdS(N(tcollectionstdefaultdicttlisttallocationstclaimsRt
instance_uuidtstatusRtPciDeviceStatustCLAIMEDtappendt	ALLOCATEDt	AVAILABLERt
add_device(Rtdevtuuid((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyRNs	cCsrxk|jD]`}|jƒr
|j|ƒ:|jƒ|jtjjkra|jjj	|ƒnWdQXq
q
WdS(N(
Rtobj_what_changedtobj_alternate_contexttsaveR!RR"tDELETEDRtremove(RRR(((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyR,Zs
cCs|jS(N(R(R((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyt	pci_statsbscCsSg}x9tj|ƒD](}|jj|ƒr|j|ƒqqW|j|ƒdS(sûSync the pci device tracker with hypervisor information.

        To support pci device hot plug, we sync with the hypervisor
        periodically, fetching all devices information from hypervisor,
        update the tracker and sync the DB information.

        Devices should not be hot-plugged when assigned to a guest,
        but possibly the hypervisor has no such guarantee. The best
        we can do is to give a warning if a device is changed
        or removed while assigned.

        :param devices_json: The JSON-ified string of device information
                             that is returned from the virt driver's
                             get_available_resource() call in the
                             pci_passthrough_devices key.
        N(RtloadsR
tdevice_assignableR$t_set_hvdevs(Rtdevices_jsontdevicesR(((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyt(update_devices_from_hypervisor_resourcesfs
cCsÓ|jdd„ƒi}x³|D]«}|jtjjtjjfkrMq n|jtjjkr{g|_	|||j
<q |jtjjkr |j|j
ƒ|_|jrË||j
j	j|ƒqËq q WdS(sþBuild a tree of devices that represents parent-child relationships.

        We need to have the relationships set up so that we can easily make
        all the necessary changes to parent/child devices without having to
        figure it out at each call site.

        This method just adds references to relevant instances already found
        in `pci_devs` to `child_devices` and `parent_device` fields of each
        one.

        Currently relationships are considered for SR-IOV PFs/VFs only.
        tkeycSs|jS(N(taddress(tx((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyt<lambda>sN(tsortR!RR"tREMOVEDR-tdev_typet
PciDeviceTypetSRIOV_PFt
child_devicesR7tSRIOV_VFtgettparent_addrt
parent_deviceR$(tall_devstparentsR(((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyR~s
		csîtg|jD]}|j^q
ƒ}tg|D]}|d^q/ƒ}x|jD]‰ˆj||krëyˆjƒWn\tjk
r×}tjtdƒiˆj	d6ˆj
d6|jƒd6ƒtj
jˆ_	qVX|jjˆƒqRt‡fd†|Dƒƒ}|j|d<ˆj	tj
jtj
jfkrI||j|d<qRˆj|ƒqRWx}g|D] }|d||krd|^qdD]N}|j|d<tjj|j|ƒ}|jjj|ƒ|jj|ƒqˆW|j|jƒdS(NR7s`Trying to remove device with %(status)s ownership %(instance_uuid)s because of %(pci_exception)sR!R t
pci_exceptionc3s(|]}|dˆjkr|VqdS(R7N(R7(t.0R((texisted(sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pys	<genexpr>¹stcompute_node_id(tsetRR7R.RtPciDeviceInvalidStatustLOGtwarningRR!R tformat_messageRR"R;Rt
remove_devicetnextRR#R%R
t
update_deviceRt	PciDevicetcreateRR$R'R(RR4R(texist_addrst	new_addrstet	new_valuetdev_obj((RHsE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyR2¢s4%#


$
cCs¡d}|r|j}n|jj|j|ƒ}|s:dS|j}x|D]}|j|ƒqJW|rtd„|Dƒƒrtj	t
dƒi|d6ƒn|S(Ncss|]}|jdkVqdS(N(t	numa_nodetNone(RGR(((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pys	<genexpr>æss\Assigning a pci device without numa affinity toinstance %(instance)s which has numa topologytinstance(RZtcellsRtconsume_requeststrequestsR tclaimtanyRLRMR(RRtpci_requeststinstance_numa_topologytinstance_cellstdevsR R(((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyt_claim_instanceØs		
	cCs"x|D]}|j|ƒqWdS(N(tallocate(RR[RdR(((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyt_allocate_instanceìs
cCsM|jj|dgƒ}|j||ƒ|rI|j|dc|7<ndS(NR)(RtpopRgR(RR[Rd((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pytallocate_instanceðscCsSg}|jrO|jrO|j}|j|||ƒ}|rO||j|<qOn|S(N(RR^R ReR(RRRaRbRdR ((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pytclaim_instanceös		cCsGx@|jD]5}||kr
|j|dkr
|j|ƒq
q
WdS(sÖFree device from pci resource tracker

        :param dev: cloned pci device object that needs to be free
        :param instance: the instance that this pci device
                         is allocated to
        R)N(RR t_free_device(RR(R[tpci_dev((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pytfree_devicescCsb|j|ƒ}|jj|jdƒ}|r=|j|ƒnx|D]}|jj|ƒqDWdS(N(tfreeR
RhR7RZRQRR'(RR(R[t
freed_devsR
((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyRk
s
cCs_xX|jD]M}|jtjjtjjfkr
|j|dkrW|j|ƒqWq
q
WdS(NR)(RR!RR"R#R%R Rk(RR[R(((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyt_free_instances
cCsV|jj|ddƒr)|j|ƒn)|jj|ddƒrR|j|ƒndS(NR)(RRhRZRpR(RRR[((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyt
free_instance!scCsL|js
dS|dkr,|j||ƒn|dkrH|j|ƒndS(sBUpdate PCI usage information if devices are de/allocated.
        Niÿÿÿÿi(RRqRi(RRR[tsign((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pytupdate_pci_for_instance's	cCstd„|Dƒƒ}|td„|DƒƒO}|td„|DƒƒO}xYt|jƒD]H}||krZ|jj|gƒ}x|D]}|j|ƒqˆWqZqZWxYt|jƒD]H}||kr¶|jj|gƒ}x|D]}|j|ƒqäWq¶q¶WdS(s‰Remove all usages for instances not passed in the parameter.

        The caller should hold the COMPUTE_RESOURCE_SEMAPHORE lock
        css|]}|dVqdS(R)N((RGtinst((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pys	<genexpr>7scss|]}|dVqdS(R N((RGtmig((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pys	<genexpr>8scss|]}|dVqdS(R)N((RGRt((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pys	<genexpr>9sN(RJRRRhRkR(Rt	instancest
migrationstorphansRHR)RdR(((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pytclean_usage2s

N(t__name__t
__module__t__doc__RZRRR,tpropertyR/R5tstaticmethodRR2ReRgRiRjRmRkRpRqRsRy(((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyR	"s$			$	6				
	
			cCsK|j}|dkrgSg|D]'}|j|ksA|dkr |^q S(sƒGet the devices allocated to one or all requests for an instance.

    - For generic PCI request, the request id is None.
    - For sr-iov networking, the request id is a valid uuid
    - There are a couple of cases where all the PCI devices allocated to an
      instance need to be returned. Refer to libvirt driver that handles
      soft_reboot and hard_boot of 'xen' instances.
    tallN(tpci_devicesRZt
request_id(RtRR€tdevice((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pytget_instance_pci_devsIs
		
(Rtoslo_configRtoslo_logRtloggingtoslo_serializationRtnovaRt	nova.i18nRRtnova.objectsRtnova.pciRRRt	getLoggerRzRLtobjectR	RZRƒ(((sE/home/tvault/.virtenv/lib/python2.7/site-packages/nova/pci/manager.pyt<module>s	ÿ(