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ùdZddlZddlZddlZejdkrHddlZnddlmZddlm	Z
ddlmZddl
mZddlZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZdd
lmZddlmZddlm Z e
j!e"ƒZ#ej$j%Z%iZ&dZ(dZ)dZ*dZ+dZ,dZ-dZ.e)e*e+fZ/e.Z0ie+d6e-d6Z1xQe%j2D]FZ3e3j4ddƒ\Z5Z6e5rÓe6e&e5<ne5dkr¢e6Z(q¢q¢Wd„Z7dd„Z8e9dd„Z:e;e;d„Z<d„Z=d „Z>d!„Z?d"„Z@d#eAfd$„ƒYZBddddddd3d%„ZCd&„ZDdd'„ZEd(„ZFd4d)„ZGd*„ZHe;d+„ZId,„ZJd-„ZKd.„ZLd/„ZMd0„ZNd1„ZOd2„ZPdS(5s
Utility methods to resize, repartition, and modify disk images.

Includes injection of SSH PGP keys into authorized_keys file.

iÿÿÿÿNtnt(tprocessutils(tlog(t	jsonutils(tunits(t	exception(t_(t_LE(t_LW(tutils(tapi(tmodel(timagestext2text3text4txfstntfstvfattlinuxtwindowst=itdefaultcCstj|ƒr|SdS(NR(t
_MKFS_COMMANDtget(tos_type((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pytget_fs_type_for_os_typeSscCsetj|tƒ}|r!|}n3|sNtj}|sNtj|tƒ}qNn|}tj|ƒd S(Ni(	RRt_DEFAULT_MKFS_COMMANDtCONFtdefault_ephemeral_formatt_DEFAULT_FS_BY_OSTYPEt_DEFAULT_FILE_SYSTEMR	tget_hash_str(Rtspecified_fstmkfs_commandt	extension((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pytget_file_extension_for_os_typeWs			cCs–tj|tƒpdi|d6|d6}|rLtjd||jƒŒnF|sytj}|sytj|t	ƒ}qyntj
|||d|ƒdS(sFormat a file or block device using
       a user provided command for each os type.
       If user has not provided any configuration,
       format type will be used according to a
       default_ephemeral_format configuration
       or a system defaults.
    ttfs_labelttargettrun_as_rootN(RRRR	texecutetsplitRRRRtmkfs(RR&R'R(R!R"((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyR+es			cCsuy,tjdd|ddddgd|ƒWn&tjk
rT}tjd|ƒnXtjd	|d|d|ƒdS(
Nte2fscks-fptcheck_exit_codeiiiR(sQChecking the file system with e2fsck has failed, the resize will be aborted. (%s)t	resize2fs(R	R)RtProcessExecutionErrortLOGtdebug(timageR-R(texc((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyR.|s			cCstj|ƒjS(sÂGet the (virtual) size of a disk image

    :param path: Path to the disk image
    :returns: Size (in bytes) of the given disk image as it would be seen
              by a virtual machine.
    (Rt
qemu_img_infotvirtual_size(tpath((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyt
get_disk_sizesc
CsOt|tjƒsdS|jtjkrut|j|ƒs>dStjdddd|t	j
dd|jdtƒdSt|j|ƒs‹dStjd	d|j|ƒ|jtjkrÄt
jrÄdSt|ƒsÔdStd
„d„}|jtjkr>tjj|ddƒ}|jƒrK||jdtd|jƒqKn
||jƒdS(
s|Increase image to size.

    :param image: instance of nova.virt.image.model.Image
    :param size: image size in bytes
    Nt
prl_disk_tooltresizes--sizes%dMs--resize_partitions--hddR(sqemu-imgcSsdS(N(tNone(((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyt<lambda>¹scSsYzJyt|d|ddgƒWn&tjk
rH}tjd|ƒnXWd|ƒXdS(NR(R-isAResizing the file system with resize2fs has failed with error: %s(R.RR/R0R1(tdevR(tfinally_callR3((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pytsafe_resize2fs¹s	R=(t
isinstancetimgmodelt
LocalImagetformattFORMAT_PLOOPtcan_resize_imageR6R	R)RtMitTruet
FORMAT_RAWRtresize_fs_using_block_devicetis_image_extendabletFalsetmounttMounttinstance_for_formatR:tget_devtdevicet	unget_dev(R2tsizeR>tmounter((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pytextend—s6

	cCsNtjdi|d6|d6ƒt|ƒ}||krJtjd|ƒtStS(sŽCheck whether we can resize the container image file.
    :param image: path to local image file
    :param size: the image size in bytes
    s8Checking if we can resize image %(image)s. size=%(size)sR2RQs)Cannot resize image %s to a smaller size.(R0R1R7RJRF(R2RQt	virt_size((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyRDÐs		cCs6tjdi|d6ƒt|tjƒs<|jtjkrãd}z€y?tj	j
|dƒ}|jdtƒ|j
ƒtkrƒtSWn:tjk
rÀ}tjtdƒi|d6|d6ƒnXWd|dk	rÞ|jƒnXtSytjd|jƒWn5tjk
r1}tjdi|d6|d6ƒtSXtS(	s&Check whether we can extend the image.s6Checking if we can extend filesystem inside %(image)s.R2RKsDUnable to mount image %(image)s with error %(error)s. Cannot resize.terrorNte2labelsRUnable to determine label for image %(image)s with error %(error)s. Cannot resize.(R0R1R?R@RARBRGR:tvfstVFStinstance_for_imagetsetupRJtget_image_fstSUPPORTED_FS_TO_EXTENDRFRt
NovaExceptiontwarningRtteardownR	R)R6RR/(R2tfste((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyRIás2		
t
_DiskImagecBseeZdZdZd	d	d„Zed„ƒZd„Ze	d„ƒZ
d„Zd„Zd„Z
RS(
s(Provide operations on a disk image file.sopenstack-disk-mount-tmpcCsx||_||_||_t|_d|_g|_|rt|j|ƒ}|ra|j	|ƒqtt
jd|ƒndS(síCreate a new _DiskImage object instance

        :param image: instance of nova.virt.image.model.Image
        :param partition: the partition number within the image
        :param mount_dir: the directory to mount the image on
        sNo device found for path: %sN(t	partitiont	mount_dirR2RJt_mkdirR:t_mountert_errorst_device_for_patht_resetR0R1(tselfR2RcRdRO((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyt__init__s							cCsod}tjj|ƒ}tddƒB}x8|D]0}|jƒ}|d|kr1|d}Pq1q1WWdQX|S(Ns/proc/mountstrii(R:tosR6trealpathtopenR*(R6ROtifptlinetfields((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyRh*s

cCs[tjj|j|j|j|ƒ|_tjj	|jp<dƒ}|j
|jƒ|_dS(s8Reset internal state for a previously mounted directory.R%N(
RKRLtinstance_for_deviceR2RdRcRfRmR6tbasenamet
startswitht
tmp_prefixRe(RjROt
mount_name((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyRi6scCsdjdg|jƒS(s/Return the collated errors from all operations.s
--
R%(tjoinRg(Rj((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyterrors@scCs¹|jr!tjtdƒƒ‚n|jsNtjd|jƒ|_t|_	nt
jj|j
|j|jƒ}|jƒrŽ||_|jjStj|jƒ|jj|jƒdSdS(säMount a disk image, using the object attributes.

        The first supported means provided by the mount classes is used.

        True, or False is returned and the 'errors' attribute
        contains any diagnostics.
        simage already mountedtprefixN(RfRR]RRdttempfiletmkdtempRvRFReRKRLRMR2Rctdo_mountROR0R1RURgtappendR:(RjRR((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyRKEs			
cCs&|jr"|jjƒd|_ndS(s)Umount a mount point from the filesystem.N(Rft	do_umountR:(Rj((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pytumount`s	
cCsJz&|jr%|jjƒd|_nWd|jrEtj|jƒnXdS(s)Remove a disk image from the file system.N(Rftdo_teardownR:ReRmtrmdirRd(Rj((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyR_fs	
	N(t__name__t
__module__t__doc__RvR:RktstaticmethodRhRitpropertyRyRKR€R_(((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyRbs	
		c
Cs÷i|d6|d6|d6|d6|d6|d6}tjd|ƒy#tjj||ƒ}	|	jƒWn_tk
rÄ}
x$|D]}||}|r|‚q|q|Wtjtdƒi|d6|
d	6ƒt	SXz t
|	||||||ƒSWd
|	jƒXd
S(sÓInject the specified items into a disk image.

    :param image: instance of nova.virt.image.model.Image
    :param key: the SSH public key to inject
    :param net: the network configuration to inject
    :param metadata: the user metadata to inject
    :param admin_password: the root password to set
    :param files: the files to copy into the image
    :param partition: the partition number to access
    :param mandatory: the list of parameters which must not fail to inject

    If an item name is not specified in the MANDATORY iterable, then a warning
    is logged on failure to inject that item, rather than raising an exception.

    it will mount the image as a fully partitioned disk and attempt to inject
    into the specified partition number.

    If PARTITION is not specified the image is mounted as a single partition.

    Returns True if all requested operations completed without issue.
    Raises an exception if a mandatory item can't be injected.
    R2tkeytnettmetadatatfilesRcsŒInject data image=%(image)s key=%(key)s net=%(net)s metadata=%(metadata)s admin_password=<SANITIZED> files=%(files)s partition=%(partition)ss:Ignoring error injecting data into image %(image)s (%(e)s)RaN(R0R1RWRXRYRZt	ExceptionR^RRJtinject_data_into_fsR_(
R2RˆR‰RŠtadmin_passwordR‹Rct	mandatorytitemsR`Ratinjectt
inject_val((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pytinject_datass&	


cCsttd|d|ƒ}|jƒ}|dkrptjtdƒi|d6|d6|jd6ƒtj|jƒ‚n|S(s`Setup the LXC container.

    :param image: instance of nova.virt.image.model.Image
    :param container_dir: directory to mount the image at

    It will mount the loopback image to the container directory in order
    to create the root filesystem for the container.

    Returns path of image device which is mounted to the container directory.
    R2RdsLFailed to mount container filesystem '%(image)s' on '%(target)s': %(errors)sR'RyN(	RbRKR:R0RURRyRR](R2t
container_dirtimgR<((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pytsetup_container¥scCsÞy³tddd|ƒ}|jƒ|r²d|krftjd|ƒtjdd|dtdd	ƒq²d
|kržtjd|ƒtjdd
|dtƒq²tjd|ƒnWn$tk
rÙtj	t
dƒƒnXdS(s•Teardown the container rootfs mounting once it is spawned.

    It will umount the container that is mounted,
    and delete any linked devices.
    R2RdtloopsRelease loop device %stlosetups--detachR(tattemptsitnbdsRelease nbd device %ssqemu-nbds-ds(No release necessary for block device %ss'Failed to teardown container filesystemN(RbR:R_R0R1R	R)RFRŒRR(R”tcontainer_root_deviceR•((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pytteardown_container¼s 

	
cCsNy#tddd|ƒ}|jƒWn$tk
rItjtdƒƒnXdS(s¡Clean up the container namespace rootfs mounting one spawned.

    It will umount the mounted names that are mounted
    but leave the linked devices alone.
    R2Rds%Failed to umount container filesystemN(RbR:R€RŒR0RR(R”R•((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pytclean_lxc_namespace×s

cCsïi|d6|d6|d6|d6|d6}itd6td6td6td6td6}t}	x|jƒD]‚\}
}|rey||
}|||ƒWqçtk
rã}
|
|kr¶‚ntj	t
dƒi|
d6|
d6ƒt}	qçXqeqeW|	S(	sÒInjects data into a filesystem already mounted by the caller.
    Virt connections can call this directly if they mount their fs
    in a different way to inject_data.

    If an item name is not specified in the MANDATORY iterable, then a warning
    is logged on failure to inject that item, rather than raising an exception.

    Returns True if all requested operations completed without issue.
    Raises an exception if a mandatory item can't be injected.
    RˆR‰RŠRŽR‹s6Ignoring error injecting %(inject)s into image (%(e)s)R‘Ra(t_inject_key_into_fst_inject_net_into_fst_inject_metadata_into_fst_inject_admin_password_into_fst_inject_files_into_fsRFRRŒR0R^RRJ(R`RˆR‰RŠRŽR‹RRt	functionststatusR‘R’tinject_funcRa((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyRäs*

cCsžx—|D]\}}tjj|ƒ}t|ƒdkr†|dkr†|j|ƒr†|j|ƒ|j|ddƒ|j|dƒnt|||ƒqWdS(Nit/trootiä(	RmR6tdirnametlenthas_filet	make_patht
set_ownershiptset_permissionst_inject_file_into_fs(R‹R`R6tcontentst
parent_dir((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyR¢s
cCsRtjdi|d6|d6|d6ƒ|r>|j||ƒn|j||ƒdS(Ns5Inject file fs=%(fs)s path=%(path)s append=%(append)sR`R6R~(R0R1tappend_filetreplace_file(R`R6R¯R~((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyR®s
	cCs;tjdi|d6|d6ƒt|dtj|ƒƒdS(Ns/Inject metadata fs=%(fs)s metadata=%(metadata)sR`RŠsmeta.js(R0R1R®Rtdumps(RŠR`((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyR s	cCsë|jtjjddƒƒs"dStjjddƒ}tjjddƒ}|j|ƒrƒ|j|ƒrƒtjj|dƒ}nddd|g}|j|ƒs¸|jd	d
ƒnt||dj|ƒdtƒ|j|d
ƒdS(s>Get selinux guests to ensure correct context on injected keys.tetctselinuxNsrc.localsrc.ds
sC# Added by Nova to ensure injected ssh keys have the right context
s#restorecon -RF %s 2>/dev/null || :
is	#!/bin/shR%R~iÀ(RªRmR6RxtinsertR®RFR­(R`tsshdirtrclocaltrc_dt
restorecon((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyt_setup_selinux_for_keys#s
cCsÓtjdi|d6|d6ƒtjjddƒ}|j|ƒ|j|ddƒ|j|dƒtjj|dƒ}djd	d
d	|jƒd	gƒ}t	|||dt
ƒ|j|dƒt||ƒd
S(sªAdd the given public ssh key to root's authorized_keys.

    key is an ssh key string.
    fs is the path to the base of the filesystem into which to inject the key.
    s Inject key fs=%(fs)s key=%(key)sR`RˆR§s.sshiÀtauthorized_keysR%s
s,# The following ssh key was injected by NovaR~i€N(R0R1RmR6RxR«R¬R­tstripR®RFR»(RˆR`R·tkeyfiletkey_data((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyRž?s
	cCstjdi|d6|d6ƒtjjddƒ}|j|ƒ|j|ddƒ|j|dƒtjjdddƒ}t|||ƒd	S(
szInject /etc/network/interfaces into the filesystem rooted at fs.

    net is the contents of /etc/network/interfaces.
    s Inject key fs=%(fs)s net=%(net)sR`R‰R´tnetworkR§iät
interfacesN(	R0R1RmR6RxR«R¬R­R®(R‰R`tnetdirtnetfile((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyRŸ\s
cCsŽtjdi|d6ƒd}tjjddƒ}tjjddƒ}|j|ƒ}|j|ƒ}t||||ƒ}|j||ƒdS(s!Set the root password to admin_passwd

    admin_password is a root password
    fs is the path to the base of the filesystem into which to inject
    the key.

    This method modifies the instance filesystem directly,
    and does not require a guest agent running in the instance.

    s8Inject admin password fs=%(fs)s admin_passwd=<SANITIZED>R`R§R´tpasswdtshadowN(R0R1RmR6Rxt	read_filet_set_passwdR²(tadmin_passwdR`t
admin_usertpasswd_pathtshadow_pathtpasswd_datatshadow_datatnew_shadow_data((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyR¡ls		cCs5d}d}djg|D]}tj|ƒ^qƒS(Ns@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./it R%s                (Rxtrandomtchoice(tsalt_settsalttc((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyt_generate_salt‹scCs¯tjdkr'tjtdƒƒ‚nidd6dd6dd6d	d
6}tƒ}tj||d|ƒ}t|ƒdkr›tj||d
|ƒ}n|jdƒ}|jdƒ}xP|D])}	|	jd
ƒ}
|
d|krÀPqÀqÀWtdƒ}tj||ƒ‚t	ƒ}t
}
x\|D]T}	|	jd
ƒ}
|
d|krZ||
d<t}
nd
j|
ƒ}|j
|ƒq"W|
s¢tdƒ}tj||ƒ‚ndj|ƒS(s¾set the password for username to admin_passwd

    The passwd_file is not modified.  The shadow_file is updated.
    if the username is not found in both files, an exception is raised.

    :param username: the username
    :param admin_passwd: the admin password
    :param passwd_data: path to the passwd file
    :param shadow_data: path to the shadow password file
    :returns: nothing
    :raises: exception.NovaException(), IOError()

    RsNot implemented on Windowss$6$sSHA-512s$5$sSHA-256s$1$tMD5R%tDESi
s
t:is-User %(username)s not found in password file.is+User %(username)s not found in shadow file.(RmtnameRR]RRÕtcryptR©R*tlistRJRFRxR~(tusernameRÈRÌRÍtalgosRÓtencrypted_passwdtp_filets_filetentrytsplit_entrytmsgt
new_shadowtfoundt	new_entry((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyRǓs8"		
	

	(((QR…RmRÐR{RÙRÚtoslo_concurrencyRtoslo_logRtloggingtoslo_serializationRt
oslo_utilsRt	nova.conftnovaRt	nova.i18nRRRR	tnova.virt.disk.mountR
RKtnova.virt.disk.vfsRWtnova.virt.imageRR@t	nova.virtRt	getLoggerRƒR0tconfRRR:RtFS_FORMAT_EXT2tFS_FORMAT_EXT3tFS_FORMAT_EXT4t
FS_FORMAT_XFStFS_FORMAT_NTFStFS_FORMAT_VFATR\RRt	virt_mkfstsR*RR"RR$RFR+RJR.R7RSRDRItobjectRbR“R–RœRRR¢R®R R»RžRŸR¡RÕRÇ(((sG/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/disk/api.pyt<module>s‚	



		
	9		+g1		#