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 / virt / libvirt / blockinfo.pyc
Size: Mime:
ó
±EYc@sàdZddlZddlZddlmZddlZddlmZddlm	Z	ddlm
Z
ddlmZddlm
Z
dd	lmZdd
lmZddlmZddlmZdd
lmZejZd'Zidd6dd6dd6Zd„Zd„Zd„Zdd„Zd„Z dd„Z!d„Z"dddd„Z#d„Z$d„Z%dddddd„Z&d„Z'dd „Z(d!„Z)d"„Z*d#„Z+de,d$„Z-de,d%„Z.d&„Z/dS((sä
Handling of block device information and mapping.

This module contains helper methods for interpreting the block
device information and determining the suitable mapping to
guest devices and libvirt XML.

Throughout these methods there are a number of standard
variables / types used

 * 'mapping': a dict contains the storage device mapping.

   For the default disk types it will contain the following
   keys & values:

      'disk' -> disk_info
      'disk.rescue' -> disk_info
      'disk.local' -> disk_info
      'disk.swap' -> disk_info
      'disk.config' -> disk_info

   If any of the default disks are overridden by the block
   device info mappings, the hash value will be None

   For any ephemeral device there will also be a dict entry

      'disk.eph$NUM' -> disk_info

   For any volume device there will also be a dict entry:

       $path -> disk_info

   Finally a special key will refer to the root device:

      'root' -> disk_info


 * 'disk_info': a dict specifying disk configuration

   It contains the following 3 required fields

      bus (disk_bus), dev (disk_dev), type (device_type)

   and possibly these optional fields: ('format', 'boot_index')

 * 'disk_bus': the guest bus type ('ide', 'virtio', 'scsi', etc)

 * 'disk_dev': the device name 'vda', 'hdc', 'sdf', 'xvde' etc

 * 'device_type': type of device eg 'disk', 'cdrom', 'floppy'

 * 'format': Which format to apply to the device if applicable

 * 'boot_index': Number designating the boot order of the device

iÿÿÿÿN(tcfg(tblock_device(tarch(tvm_mode(t	exception(t_(tbase(tconfigdrive(tdriver(tutils(tosinfotdisktcdromtfloppytlunthdtfdcCs3x,|D]$}||}|d|krtSqWtS(sòDetermine if a disk device name has already been used.

       Looks at all the keys in mapping to see if any
       corresponding disk_info tuple has a device name
       matching disk_dev

       Returns True if the disk_dev is in use.
    tdev(tTruetFalse(tmappingtdisk_devRtinfo((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pythas_disk_dev`s



cCsÃtjjrtjjS|dkr&dS|dkr6dS|dkrFdS|dkrVdS|d	krfdS|d
krvdS|dkr†d
S|dkr–dS|dkr¦dStjtdƒ|ƒ‚dS(s,Determine the dev prefix for a disk bus.

       Determine the dev prefix to be combined
       with a disk number to fix a disk_dev.
       eg 'hd' for 'ide' bus can be used to
       form a disk dev 'hda'

       Returns the dev prefix or raises an
       exception if the disk bus is unknown.
    tideRtvirtiotvdtxentxvdtscsitsdtusbtfdcRtumltubdtlxctsatas&Unable to determine disk prefix for %sN(tCONFtlibvirttdisk_prefixtNoneRt
NovaExceptionR(tdisk_bus((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytget_dev_prefix_for_disk_busqs.
	cCs|dkrdSdSdS(s¼Determine the number disks supported.

       Determine how many disks can be supported in
       a single VM for a particular disk bus.

       Returns the number of disks supported.
    RiiN((R*((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytget_dev_count_for_disk_bus—s	cCs³t|ƒ}|dkrdS|dkr1g}nt|ƒ}t|ƒ}xJ|D]B}|ttdƒ|ƒ}t||ƒsP||kr’|SqPqPWtjt	dƒ|ƒ‚dS(s<Identify a free disk dev name for a bus.

       Determines the possible disk dev names for
       the bus, and then checks them in order until
       it identifies one that is not yet used in the
       disk mapping.

       Returns the chosen disk_dev name, or raises an
       exception if none is available.
    tas)No free disk device names for prefix '%s'N(
R+R(R,trangetchrtordRRR)R(Rtbustassigned_devicest
dev_prefixtmax_devtdevstidxR((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytfind_disk_dev_for_disk_bus¦s
	
	cCs’idddddgd6dddddgd6ddgd6d	gd	6d
gd
6dddgd6}||kr„tjd
|ƒ‚n|||kS(NRRRRR tqemutkvmRR!R#R$t	parallelstvirt(RtUnsupportedVirtType(t	virt_typeR*t	valid_bus((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytis_disk_bus_valid_for_virtÈs


cCs¯|dkr!tj|ƒj}n d|d}|jj|ƒ}|dk	r{t||ƒswtjd|d|ƒ‚n|S|dkrš|dkr«dSn|dkrªdS|dkrßt	j
|ƒ}|t	jkrØd	SdSnÌ|dkrj|dkrGtj
|ƒ}|tjtjtjtjtjtjtjfkr@d
Sd	Sq«|dkrWdS|dkr«dSnA|dkr™|dkr†d	S|dkr«dSntjd|ƒ‚dS(sÃDetermine the best disk bus to use for a device type.

       Considering the currently configured virtualization
       type, return the optimal disk_bus to use for a given
       device type. For example, for a disk on KVM it will
       return 'virtio', while for a CDROM it will return 'ide'
       on x86_64 and 'scsi' on ppc64.

       Returns the disk_bus, or returns None if the device
       type is not supported for this virtualization
    Rthw_t_bustmodelR;R!R#RRR8R9RRRR
R R:R$N(sqemuskvm(R
tHardwarePropertiest
disk_modelt
propertiestgetR(R?RtUnsupportedHardwareRtget_from_instancetHVMt
libvirt_utilstget_archRtPPCtPPC64tPPCLEtPPC64LEtS390tS390XtAARCH64R<(tinstanceR=t
image_metatdevice_typeR*tkeyt
guest_vm_modet	guestarch((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytget_disk_bus_for_device_typeØsJcCs¶|jdƒrdS|jdƒrI|dkr2dS|dkrBdSdSni|jdƒr\d	S|jd
ƒrodS|jdƒr‚dS|jd
ƒr•dStjtdƒ|d ƒ‚dS(s<Determine the disk bus for a disk device.

       Given a disk device like 'hda', 'sdf', 'xvdb', etc
       guess what the most appropriate disk bus is for
       the currently configured virtualization technology

       Returns the disk bus, or raises an Exception if
       the disk device prefix is unknown.
    RRRRR:R$RRRRR RR"R!s%Unable to determine disk bus for '%s'iN(t
startswithRR)R(R=R((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytget_disk_bus_for_disk_devs&	cCs\t|||ƒ}i|d6|d6|d6}|dk	rX|dkrXt|ƒ|d<n|S(sDetermine the disk info for the next device on disk_bus.

       Considering the disks already listed in the disk mapping,
       determine the next available disk dev that can be assigned
       for the disk bus.

       Returns the disk_info for the next available disk.
    R1Rttypeit
boot_indexN(R7R(tstr(RR*RUR]R2RR((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytget_next_disk_info=s
	

cCsdt|ƒS(Nsdisk.eph(R^(tindex((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytget_eph_diskWscCsItjdkrd}n-tjdkr0d}ntjdtjƒ‚|S(sÔDetermine the type of config drive.

       If config_drive_format is set to iso9660 then the config drive will
       be 'cdrom', otherwise 'disk'.

       Returns a string indicating the config drive type.
    tiso9660RtvfatRtformat(R%tconfig_drive_formatRtConfigDriveUnknownFormat(tconfig_drive_type((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytget_config_drive_type[s				c		Csx|p	i}|pt}tjt|ƒƒ}	|jdƒp?|}
|
|krWd}
n|jdƒpi|}t||ƒs«|	r“t||	ƒ}q«t||||
ƒ}n|	sï|r×d„|Dƒ}|j|ƒn|}t	||ƒ}	ni|d6|	d6|
d6}
|jdƒ}|r6|
ji|d	6ƒn|jd
ƒ}|dk	rt|dkrtt|dƒ|
d
<n|
S(
NRURR*cSs i|]}i|d6|“qS(R((t.0R((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pys
<dictcomp>…s	R1RR\tguest_formatRdR]ii(tSUPPORTED_DEVICE_TYPESRt	strip_devtget_device_nameRFR?R[RYtupdateR7R(R^(RSR=RTtbdmRR*tdev_typet
allowed_typesR2tdevice_nametbdm_typetbdm_bustpadded_mappingtbdm_infot
bdm_formatR]((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytget_info_from_bdmos8		

cCs9t|tjƒr|jS|jdƒp4|jdƒSdS(s<Get the device name if present regardless of the bdm format.Rrtmount_deviceN(t
isinstancetobj_baset
NovaObjectRrRF(Ro((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pyRmœsc
Cs|p.|jdƒdko.|jdƒdk}|rÀ|jdƒrd|jdkrd|}d}	n|}d}	|rˆt||ƒ}nti|ƒ}i|d	6|	d
6tj|ƒd6dd
6St|ƒrì|rì|jƒ}||d<nt	||||i|ƒS(Ntsource_typetimagetdestination_typetlocaltdisk_formattisoRRR1R\Rt1R]Rr(
RFtobj_attr_is_setRR[R7RRlRmtcopyRx(
RSR=RTtroot_bdmR*t	cdrom_bustroot_device_nametno_root_bdmtroot_device_bustroot_device_type((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pyt
get_root_info¤s.	

cCs`t||||ƒxFtj|d|dr:|dgng|dƒD]}|jƒqHWdS(Nt
ephemeralstswaptblock_device_mapping(t
get_disk_infot	itertoolstchaintsave(R=tcontextRStblock_device_infoRTt
driver_bdm((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytdefault_device_namesÊs
cCsYtj|ƒ}|jdks$|r(dSt||ƒ}tj|d|ƒrQdS|SdS(NiR(Rt block_device_info_get_ephemeralstephemeral_gbR(R_Rtvolume_in_mapping(RSR*R•RRR((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytget_default_ephemeral_infoÕsc	Csnd|krdnd}|jtt|ddf|j|ƒpOtj|dƒ|d|dfƒƒƒdS(NRrRyR*RURR1R\(RntdicttzipRFRtprepend_dev(RoRtdevice_name_field((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pyt
update_bdmàs	cCs‰i}|ržt||ddƒ}||d<||d<t||ƒ}	|	|d<tj|ƒrštƒ}
t||||
ƒ}t|||
ƒ}||d<n|Sgtjtj|ƒtj	|ƒgtj
|ƒƒD]'}t|ƒrÒtj
t|ƒƒ^qÒ}
tjtj
|ƒƒ}tj
tj|ƒƒ}t|||||||ƒ}||d<|r‚tj|d|ƒr‚||d<n|r˜t||ƒnt||||ƒ}|rÀ||d<nxattj|ƒƒD]J\}}t||||||d	|
ƒ}||t|ƒ<t||ƒqÖWtj	|ƒ}|r†|jd
dƒdkr†t||||||ƒ}||d<t||ƒnQ|jƒd
dkr×t||d	|
ƒ}tj|d|ƒs×||d<q×ntj
|ƒ}xP|D]H}t|||||d	|
ƒ}||tj|dƒ<t||ƒqíWtj|ƒr…tƒ}
t||||
ƒ}t|||
ƒ}||d<n|S(s)Determine how to map default disks to the virtual machine.

       This is about figuring out whether the default 'disk',
       'disk.local', 'disk.swap' and 'disk.config' images have
       been overridden by the block device mapping.

       Returns the guest disk mapping for the devices.
    R]isdisk.rescuetrootRsdisk.config.rescueRs
disk.localR2t	swap_sizeis	disk.swapRŽsdisk.config(R_Rtrequired_byRhRYR‘R’RR˜tblock_device_info_get_swaptblock_device_info_get_mappingRmRRltget_root_bdmtblock_device_info_get_rootRŒRšR R›t	enumerateRxRaRFt
get_flavorRž(R=RSR*R‡RTR•trescueRtrescue_infotos_infoRUtconfig_infoRotpre_assigned_device_namesR†Rˆt	root_infotdefault_ephR6tephteph_infoRŽt	swap_infoRtvol_info((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytget_disk_mappingìs¢

	
			
	'


	
		
	
		
				
cCsat|||dƒ}t|||dƒ}t|||||||ƒ}i|d6|d6|d6S(sgDetermine guest disk mapping info.

       This is a wrapper around get_disk_mapping, which
       also returns the chosen disk_bus and cdrom_bus.
       The returned data is in a dict

            - disk_bus: the bus for harddisks
            - cdrom_bus: the bus for CDROMs
            - mapping: the disk mapping

       Returns the disk mapping disk.
    RRR*R‡R(RYRµ(R=RSRTR•RªR*R‡R((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pyRis				
cCsUd„tj|dƒDƒ}d„t|dtjdƒƒDƒ}d„}||ƒS(Ncss<|]2\}}|dkr|jdƒdk	r|VqdS(R¡R]N(RFR((RitnameR((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pys	<genexpr>ˆs	Rcss|]}t|dVqdS(R\N(tBOOT_DEV_FOR_TYPE(RiR((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pys	<genexpr>ŠsRVR]cSs<tƒ}g|D](}||kr|j|ƒr|^qS(N(tsettadd(tlsttstel((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytuniqŽs	(tsixt	iteritemstsortedtoperatort
itemgetter(t	disk_infotboot_mappingt
boot_devs_dupR½((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pytget_boot_order‡s		(sdiskscdromsfloppyslun(0t__doc__R‘RÁtoslo_configRR¾tnovaRtnova.computeRRRt	nova.i18nRtnova.objectsRR{t	nova.virtRRtnova.virt.libvirtR	RJR
R%RkR·RR+R,R(R7R?RYR[R_RaRhRxRmRŒR—R›R RRµRRÆ(((sP/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/blockinfo.pyt<module>FsR			&	!	=	&		*		%			z