ó 'KXc@s°ddlmZddlmZddlZddlZddlZeZejdƒZ ejdƒZ ejdƒZ ejdƒZ ejdƒZ ejd ƒZejeƒZd „Zd „Zd „Zdd „Zed„Zd„Zed„Zd„Zd„Zdddedd„Zd„Zd„Z d„Z!d„Z"d„Z#d„Z$d„Z%d„Z&d„Z'd„Z(d„Z)d„Z*d „Z+d!„Z,d"„Z-dS(#iÿÿÿÿ(t PER_INSTANCE(tutilNtudevadmtsfdisktlsblktblkidtblockdevtwipefsc Csì|jdƒ}t|tƒrôt||jƒ|jdt|ƒƒx­|jƒD]œ\}}t|tƒsƒ|jd|ƒqQny@|jdƒt j dt jdd|dt d ||fƒWqQt k rì}t jt d |ƒqQXqQWn|jd ƒ} t| tƒrè|jd t| ƒƒt| |jƒx­| D]¢}t|tƒsk|jd |ƒq?nyL|jdƒ|jdƒ} t j dt jdd| dtd |fƒWq?t k rà}t jt d|ƒq?Xq?WndS(s[ See doc/examples/cloud-config_disk-setup.txt for documentation on the format. t disk_setupsPartitioning disks: %ssInvalid disk definition for %ss!Creating new partition table/disktlogfunctmsgsCreating partition on %stfunctargss Failed partitioning operation %stfs_setupssetting up filesystems: %ss"Invalid file system definition: %ssCreating new filesystem.tdevicesCreating fs for %ss%Failed during filesystem operation %sN(tgett isinstancetdicttupdate_disk_setup_devicestdevice_name_to_devicetdebugtstrtitemstwarnRtlog_timetLOGtmkpartt Exceptiontlogexctlisttupdate_fs_setup_devicestmkfs( t_nametcfgtcloudtlogt_argsRtdiskt definitionteR R((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pythandle&s>     cCs¤x|jƒD]}||ƒ}|dks ||kr=q n||krftjd||ƒ||=n||||<|||d<||=tjd||ƒq WdS(Ns0Replacing %s in disk_setup for translation of %st _orignames,updated disk_setup device entry '%s' to '%s'(tkeystNoneRtinfoR(Rttformertorignamet transformed((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pyROs      cCsèxá|D]Ù}t|tƒs2tjd|ƒqn|jdƒ}|dkrSqntj|ƒ\}}||ƒ}|dk r³|}tjd|||ƒ||d<||d: don't enumerate children devices Return a dict describing the disk: type: the entry type, i.e disk or part fstype: the filesystem type, if it exists label: file system label, if it exists name: the device name, i.e. sda s--pairss--outsNAME,TYPE,FSTYPE,LABELs--nodepss"Failed during disk check for %s %sitnamettypetfstypetlabelN( t LSBLK_CMDtappendR+RtsubpRtstript splitlinestlenR8R?tlower( Rtnodepst lsblk_cmdR,t_errR'R<tpartsR4tdR=R>((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pytenumerate_disk‹s$  =   cCs;x4t|dtƒD] }d|kr|djƒSqWdS(s@ Return the device type of the device by calling lsblk. RKRAN(RPtTrueRJR+(RRO((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pyt device_typeµs cCscd}yt|ƒ}Wntjd|ƒtSX|rH|dkrHtS| r_|dkr_tStS(s0 Check if the device is a valid device. tsQuery against device %s failedR4R%(RRRRtFalseRQ(R@R0td_type((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pytis_device_validÀsc Csd \}}}}tdd|g}y%tj|dddgƒ\}}Wn)tk rt}td||fƒ‚nX|r t|jƒƒdkr xtt|ddƒD]]\}} |jƒd krÍ| }q¦|jƒd krè| }q¦|jƒd kr¦| }q¦q¦Wq n|||fS(sÏ Check if the device has a filesystem on it Output of blkid is generally something like: /dev/sda: LABEL="Backup500G" UUID="..." TYPE="ext4" Return values are device, label, type, uuid s-cs /dev/nulltrcsiis"Failed during disk check for %s %siR:RCRAtuuidN(NNNN( R+t BLKID_CMDRRFRRIRHR?RJ( RtoutRCtfs_typeRXt blkid_cmdRMR'R=R>((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pytcheck_fsÒs %  cCst|ƒ\}}}|S(s7 Returns true if the device has a file system. (R](Rt_R[((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pyt is_filesystemðsc Cs@|d krd}n|s*ddg}nt}xæt|ƒD]Ø}|d|krq|tkrqd|dtfS|d|kr°|r—|d|ksž| r°d|dtfS|d|kr=|ddksÚ|drãt}n|ddkröq|dsd|dtfSq=q=W|s)|tfStjd ƒd tfS( s Find a device that is either matches the spec, or the first The return is value is (, ) where the device is the device to use and the bool is whether the device matches the fs_type and label. Note: This works with GPT partition tables! RSR%R4RBs/dev/%sR@RCRAs5Failed to find device during available device search.N(R+RTRPRQRR(RR[RCt valid_targetst label_matcht replace_fstraw_device_usedRO((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pytfind_device_nodeøs,      cCs^gt|ƒD] }|^q }t|jƒƒdkr;tSt|ƒ\}}}|rZtStS(s¥ Check if the device is currently used. Returns true if the device has either a file system or a partition entry is no filesystem found on the disk. i(RPRIRHRQR]RT(RR<t use_countR^t check_fstype((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pyt is_disk_used)s cCsjtd|g}d}ytj|ƒ\}}Wn)tk rY}td||fƒ‚nXt|jƒƒS(sW Returns the hard disk size. This works with any disk type, including GPT. s --show-sizesFailed to get %s size %sN(t SFDISK_CMDR+RRFRtintRG(Rtsize_cmdtsizeRMR'((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pyt get_hdd_size>scGs‹t|ƒdkr!tdƒ‚n|d|d}|d}y&|rWtƒ||ŒStƒ|SWn!tk r†td|ƒ‚nXdS(s- Call the appropriate function. The first value is the template for function name The second value is the template replacement The remain values are passed to the function For example: get_dyn_func("foo_%s", 'bar', 1, 2, 3,) would call "foo_bar" with args of 1, 2, 3 is*Unable to determine dynamic funcation nameiisNo such function %s to call!N(RIRtglobalstKeyError(R t func_namet func_args((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pyt get_dyn_funcNs   c Cst|ƒtd|g}y#tj|dd|ƒ\}}Wn)tk rg}td||fƒ‚nXg}xÔ|jƒD]Æ}|jƒ}t|ƒdkr¥q{n||dkr{|djƒd krÑq{nd } xWt t d t|ƒƒd t ƒD]4} || j ƒrù|| d krù|| } PqùqùW|j| ƒq{q{Wt|tƒrt|rpt|ƒd krpt StSt|ƒt|ƒkrtSxkt d t|ƒd ƒD]P} t|| d tƒrª|| \} } t|| ƒt| ƒkrútSqªqªWt StS(sÒ Returns true if the partition layout matches the one on the disk Layout should be a list of values. At this time, this only verifies that the number of partitions and their labels is correct. s-ltdatas%s s(Error running partition command on %s %siiÿÿÿÿtextendedtemptyitreverset/(RssemptyN(t read_parttblRhRRFRRHR8RIRJR+tsortedtrangeRQtisdigitRERtboolRTttupleRi( Rtlayouttprt_cmdRZRMR't found_layouttlinet_linet type_labelR<R^t part_type((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pytcheck_partition_mbr_layoutisD # (    cCstd|||ƒS(sÎ See if the partition lay out matches. This is future a future proofing function. In order to add support for other disk layout schemes, add a function called check_partition_%s_layout scheck_partition_%s_layout(Rq(t table_typeRR}((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pytcheck_partition_layout¤s c Cs“t|tƒ r#t|tƒr#dSt|ƒdkrDt|tƒsTt|tƒ rctdƒ‚nt|ƒ}|dkrŠtdƒ‚ng}d}xÂ|D]º}d}|}|d7}t|tƒrüt|ƒdkrítd |ƒ‚n|\}}ntt|ƒt|ƒd d ƒ}||kr@|jd |ƒq|jd ||fƒqWdj|ƒ} t|ƒdkrtd| ƒ‚n| S(s@ Calculate the layout of the partition table. Partition sizes are defined as percentage values or a tuple of percentage and partition type. For example: [ 33, [66: 82] ] Defines the first partition to be a size of 1/3 the disk, while the remaining 2/3's will be of type Linux Swap. s0,isPartition layout is invalidis$Only simply partitioning is allowed.iSiis%Partition was incorrectly defined: %sidis,,%ss,%s,%ss s-Calculated partition definition is too big %s( RRR{RIRRitfloatREtjoin( RkR}t last_part_numtpart_definitiontpart_numR4Rƒtpercentt part_sizetsfdisk_definition((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pytget_partition_mbr_layout°s6 !    $  cCsxd}d}d}t|dƒG}|j||ƒ|j| tjƒ|j||ƒ|jƒWdQXt|ƒdS(Ntisrb+ii(topentwritetseektostSEEK_ENDtflushRw(Rtnullt start_lentend_lentfp((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pytpurge_disk_ptableäscCsxŒt|ƒD]~}|dd kr tdd|dg}y&tjd|dƒtj|ƒWq‹tk r‡td|dƒ‚q‹Xq q Wt|ƒd S( s' Remove parition table entries RAR%tcrypts--alls/dev/%sR@sPurging filesystem on /dev/%ssFailed FS purge of /dev/%sN(sdiskRœ(RPt WIPEFS_CMDRR,RRFRR›(RROt wipefs_cmd((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pyt purge_diskós cCstd|||ƒS(sï Call the appropriate function for creating the table definition. Returns the table definition This is a future proofing function. To add support for other layouts, simply add a "get_partition_%s_layout" function. sget_partition_%s_layout(Rq(R…RkR}((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pytget_partition_layouts cCsttd|g}tdg}y+tj|ƒtj|ƒtj|ƒWn'tk ro}tjtd|ƒnXdS(sr Use partprobe instead of 'udevadm'. Partprobe is the only reliable way to probe the partition table. s --rereadpttsettles%Failed reading the partition table %sN(t BLKDEV_CMDt UDEVADM_CMDRRFRRR(Rt blkdev_cmdtudev_cmdR'((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pyRws   cCsgtdd|g}ytj|dd|ƒWn)tk rX}td||fƒ‚nXt|ƒdS(sV Break out of mbr partition to allow for future partition types, i.e. gpt s--Linuxs-uMRrs%s s Failed to partition device %s %sN(RhRRFRRw(RR}R~R'((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pytexec_mkpart_mbr s cCstd|||ƒS(s Fetches the function for creating the table type. This allows to dynamically find which function to call. Paramaters: table_type: type of partition table to use device: the device to work on layout: layout definition specific to partition table sexec_mkpart_%s(Rq(R…RR}((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pyt exec_mkpart/s c CsÚtjd|ƒ|jdtƒ}|jdtƒ}|jddƒ}tjdƒt|tƒrj| sq| r‚tjdƒdStjd |ƒt|ƒs°td |ƒ‚nt|tƒrì|j ƒd krìtjd ƒt |ƒdStjd ƒt |||ƒrtjdƒt Stjdƒ| r]t |ƒsHt|ƒr]tjd|ƒdStjdƒt|ƒ}tjdƒt|||ƒ}tjd|ƒtjd|ƒt|||ƒtjd|ƒdS(sñ Creates the partition table. Parameters: definition: dictionary describing how to create the partition. The following are supported values in the dict: overwrite: Should the partition table be created regardless of any pre-exisiting data? layout: the layout of the partition table table_type: Which partition table to use, defaults to MBR device: the device to work on. s!Checking values for %s definitiont overwriteR}R…tmbrs Checking against default devicess)Device is not to be partitioned, skippingNs'Checking if device %s is a valid devicesDevice %s is not a disk device!tremoves,Instructed to remove partition table entriess!Checking if device layout matchess"Device partitioning layout matchess'Checking if device is safe to partitions-Skipping partitioning on configured device %ssChecking for device sizesCalculating partition layouts Layout is: %ssCreating partition table on %ssPartition table created for %s(RRRRTRR{RVRRRJRŸR†RQRgR_RlR R§(RR&R¨R}R…t device_sizeRŠ((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pyR<s>   !        cCslidd6dd6dd6dd6}d|jƒkr=d}n|jƒ|krW||Stjd|ƒdS( s9 A force flag might be -F or -F, this look it up s-Ftexts-ftbtrfstxfstreiserfssForce flag for %s is unknown.RS(RJRR(tfstflags((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pytlookup_force_flagys   c CsY|jdƒ}|jdƒ}t|jddƒƒ}|jdƒ}|jdgƒ}|jdgƒ}|jdtƒ}|jd tƒ}tjd |ƒ| s°|jƒr…|jƒrâd ||f}tjd ||ƒntjd |ƒt|ƒ\} } } tjd|| | ƒ| |krr| |krrtjd|ƒ|s_tjd|ƒdStjd|ƒq¶tjd|ƒn1|rrt|ƒjƒd+krr|} tjd|ƒt } |jƒdkrÚt} nt |d|d|d| d|ƒ\}}tjd| |ƒ|r.tjdƒdS| rU|rU|rUtjd|ƒn|s¶tjd|ƒdSnD| s‘t|ƒjƒdkr¥tjd|ƒntjdƒdStjd||ƒ|sãtjd |ƒdS|pì|st d!|ƒ‚n|r-|di|d6|d6|d6}ntt j d"|ƒ}|s\t j d#|ƒ}n|sytjd$||ƒdS||g}|r¡|jd%|gƒn| rÖ|sÀt|ƒd&krÖ|jt|ƒƒn|rì|j|ƒntjd'||ƒtjd(d)j|ƒƒyt j|ƒWn)t k rT}t d*||fƒ‚nXdS(,s¦ Create a file system on the device. label: defines the label to use on the device fs_cfg: defines how the filesystem is to look The following values are required generally: device: which device or cloud defined default_device filesystem: which file system type overwrite: indiscriminately create the file system partition: when device does not define a partition, setting this to a number will mean device + partition. When set to 'auto', the first free device or the first device which matches both label and type will be used. 'any' means the first filesystem that matches on the device. When 'cmd' is provided then no other parameter is required. RCRR0tanyt filesystemtcmdt extra_optsRbR¨s#Checking %s against default devicess%s%ss%Manual request of partition %s for %ssChecking device %ssDevice %s has %s %ss Existing file system found at %ss"Device %s has required file systemNsDestroying filesystem on %ss"Device %s is cleared for formatingtautos,Identifying device to create %s filesytem onR[Ras(Automatic device for %s identified as %ss+Found filesystem match, skipping formating.s*Replacing file system on %s as instructed.sCNo device aviable that matches request. Skipping fs creation for %stnones.Using the raw device to place filesystem %s ons(Error in device identification handling.s$File system %s will be created on %ssDevice is not known: %ss@No way to create filesystem '%s'. fs_type or fs_cmd must be set.smkfs.%ssmk%ss.Cannot create fstype '%s'. No mkfs.%s commands-LR%sCreating file system %s on %ss Using cmd: %st sFailed to exec of '%s': %s(R·sany(RRRTRRRzR]RRJRQRdRRtwhichtextendRRRER²RˆRF(tfs_cfgRCRR0R[tfs_cmdtfs_optst fs_replaceR¨t check_labelRfR^todeviceRatreusetmkfs_cmdR'((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pyRsœ           (.tcloudinit.settingsRt cloudinitRtloggingR”R7t frequencyRºR£RhRDRYR¢Rt getLoggert__name__RR(RRR+R?RTRPRRRVR]R_RQRdRgRlRqR„R†RR›RŸR RwR¦R§RR²R(((sK/opt/freeware/lib/python2.7/site-packages/cloudinit/config/cc_disk_setup.pytsL    )   *    0    ; 4     =