403Webshell
Server IP : 23.254.227.96  /  Your IP : 216.73.216.7
Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k
System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64
User : viralblo ( 1001)
PHP Version : 8.1.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3.6/site-packages/cloudinit/config/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.6/site-packages/cloudinit/config/__pycache__/cc_disk_setup.cpython-36.pyc
3

��b��@s�UdZddlZddlZddlZddlmZddlmZmZddl	m
Z
mZddlm
Z
ddlmZejd�Zejd	�Zejd
�Zejd�Zejd�Zejd
�Zejd�ZddiZeje�ZdZdddee
geed�gd�Ze
ee�Zdd�Zdd�Zdd�Z dSdd�Z!dTd d!�Z"d"d#�Z#dUd$d%�Z$d&d'�Z%d(d)�Z&dVd+d,�Z'd-d.�Z(d/d0�Z)d1d2�Z*d3d4�Z+d5d6�Z,d7d8�Z-d9d:�Z.d;d<�Z/d=d>�Z0d?d@�Z1dAdB�Z2dCdD�Z3dEdF�Z4dGdH�Z5dIdJ�Z6dKdL�Z7dMdN�Z8dOdP�Z9dQdR�Z:dS)Wz1Disk Setup: Configure partitions and filesystems.�N)�dedent)�subp�util)�
MetaSchema�get_meta_doc)�ALL_DISTROS)�PER_INSTANCEZsfdiskZsgdiskZlsblkZblkidZblockdevZ	partprobeZwipefsZLANG�Ca�This module is able to configure simple partition tables and filesystems.

.. note::
    for more detail about configuration options for disk setup, see the disk
    setup example

For convenience, aliases can be specified for disks using the
``device_aliases`` config key, which takes a dictionary of alias: path
mappings. There are automatic aliases for ``swap`` and ``ephemeral<X>``, where
``swap`` will always refer to the active swap partition and ``ephemeral<X>``
will refer to the block device of the ephemeral image.

Disk partitioning is done using the ``disk_setup`` directive. This config
directive accepts a dictionary where each key is either a path to a block
device or an alias specified in ``device_aliases``, and each value is the
configuration options for the device. File system configuration is done using
the ``fs_setup`` directive. This config directive accepts a list of
filesystem configs.
Z
cc_disk_setupz
Disk Setupz$Configure partitions and filesystemsaD            device_aliases:
              my_alias: /dev/sdb
            disk_setup:
              my_alias:
                table_type: gpt
                layout: [50, 50]
                overwrite: true
            fs_setup:
            - label: fs1
              filesystem: ext4
              device: my_alias.1
              cmd: mkfs -t %(filesystem)s -L %(label)s %(device)s
            - label: fs2
              device: my_alias.2
              filesystem: ext4
            mounts:
            - ["my_alias.1", "/mnt1"]
            - ["my_alias.2", "/mnt2"]
            )�id�name�title�descriptionZdistrosZ	frequencyZexamplescs�|jdi����fdd�}|jd�}t|t�r�t||�|jdt|��x�|j�D]�\}}t|t�st|jd|�qRy*|jd�tj	t
jd|t||fd	�WqRtk
r�}	ztj
t
d
|	�WYdd}	~	XqRXqRW|jd�}
t|
t��r�|jd
t|
��t|
|�x�|
D]�}t|t��s.|jd|��qy2|jd�|jd�}tj	t
jd|t|fd	�Wn4tk
�r�}	ztj
t
d|	�WYdd}	~	XnX�qWdS)z[
    See doc/examples/cloud-config-disk-setup.txt for documentation on the
    format.
    �device_aliasescs�j|�}�j|p|�p|S)N)�getZdevice_name_to_device)Zcandr)�cloudr��#/usr/lib/python3.6/cc_disk_setup.py�alias_to_device`s
zhandle.<locals>.alias_to_device�
disk_setupzPartitioning disks: %szInvalid disk definition for %sz!Creating new partition table/diskzCreating partition on %s)Zlogfunc�msg�func�argsz Failed partitioning operation
%sN�fs_setupzsetting up filesystems: %sz"Invalid file system definition: %szCreating new filesystem.�devicezCreating fs for %sz%Failed during filesystem operation
%s)r�
isinstance�dict�update_disk_setup_devices�debug�str�items�warningrZlog_time�LOG�mkpart�	Exception�logexc�list�update_fs_setup_devices�mkfs)�_nameZcfgr�logZ_argsrr�disk�
definition�errr)rrr�handleYsJ




&




r-cCs�x�t|�D]t}||�}|dks
||kr(q
||krDtjd||�||=||||<t||t�rj|||d<||=tjd||�q
WdS)Nz0Replacing %s in disk_setup for translation of %s�	_orignamez,updated disk_setup device entry '%s' to '%s')r%r!�inforrr)r�tformer�orignameZtransformedrrrr�s$rcCs�x�|D]�}t|t�s"tjd|�q|jd�}|dkr6qtj|�\}}||�}|dk	rx|}tjd|||�||d<||d<|rd|kr�tjd|||�|d|d<||d<qWdS)Nz"entry in disk_setup not a dict: %srz%s is mapped to disk=%s part=%sr.�	partitionzKPartition '%s' from dotted device name '%s' overrides 'partition' key in %sZ
_partition)rrr!r rrZexpand_dotted_devnamer)rr0r+r1Zdev�partZtformedrrrr&�s0


r&ccsDtj|�}|r||d�}x$dd�|D�D]\}}||fVq*WdS)zd
    Returns the key/value pairs of output sent as string
    like:  FOO='BAR' HOME='127.0.0.1'
    NcSsg|]}|jd��qS)�=)�split)�.0�xrrr�
<listcomp>�sz"value_splitter.<locals>.<listcomp>)�shlexr5)�values�startZ_values�key�valuerrr�value_splitter�s

r>Fccs�tddd|g}|r|jd�d}ytj|�\}}Wn4tk
rf}ztd||f�|�WYdd}~XnXdd�|j�j�D�}xB|D]:}ddddd	�}x t|�D]\}	}
|
||	j�<q�W|Vq�WdS)
a�
    Enumerate the elements of a child device.

    Parameters:
        device: the kernel device name
        nodeps <BOOL>: 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
    z--pairsz--outputzNAME,TYPE,FSTYPE,LABELz--nodepsNz"Failed during disk check for %s
%scSs g|]}t|j��dkr|�qS)r)�lenr5)r6r7rrrr8�sz"enumerate_disk.<locals>.<listcomp>)r�type�fstype�label)�	LSBLK_CMD�appendrr#�strip�
splitlinesr>�lower)r�nodepsZ	lsblk_cmdr/�_errr,�partsr3�dr<r=rrr�enumerate_disk�s.

rLcCs.x(t|dd�D]}d|kr|dj�SqWdS)z@
    Return the device type of the device by calling lsblk.
    T)rHr@N)rLrG)rrKrrr�device_type
srMcCsXd}yt|�}Wn tk
r0tjd|�dSX|rB|dkrBdS|rT|dkrTdSdS)z0
    Check if the device is a valid device.
    �zQuery against device %s failedFr3Tr*)rMr#r!r )rr2Zd_typerrr�is_device_validsrOc
Cs�d
\}}}}tdd|g}ytj|ddgd�\}}Wn4tk
rf}ztd||f�|�WYdd}~XnX|r�t|j��dkr�xLt|dd	�D]<\}}	|j�d
kr�|	}q�|j�dkr�|	}q�|j�dkr�|	}q�W|||fS)z�
    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
    Nz-cz	/dev/nullr�)�rcsz"Failed during disk check for %s
%s�)r;rBr@�uuid)NNNN)�	BLKID_CMDrr#r?rFr>rG)
r�outrB�fs_typerSZ	blkid_cmdrIr,r<r=rrr�check_fs*s$	rWcCst|�\}}}|S)z7
    Returns true if the device has a file system.
    )rW)r�_rVrrr�
is_filesystemJsrYTcCs�|dkrd}|sddg}d}x�t|�D]�}|d|krN|dkrNd|ddfS|d|kr�|rj|d	|ksp|r�d|dd
fS|d|kr&|ddks�|dr�d
}|ddkr�q&|ds&d|ddfSq&W|s�|dfStjd�d
S)a
    Find a device that is either matches the spec, or the first

    The return is value is (<device>, <bool>) 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!
    NrNr*r3FrAz/dev/%srrBTr@z5Failed to find device during available device search.)NF)rLr!r )rrVrBZ
valid_targets�label_match�
replace_fsZraw_device_usedrKrrr�find_device_nodeRs,
r\cCs2ttt|���dkrdSt|�\}}}|r.dSdS)z�
    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.
    rRTF)r?r%rLrW)rrX�check_fstyperrr�is_disk_used�s	r^cGs�t|�dkrtd��|d|d}|dd�}y |rDt�||�St�|SWn0tk
r�}ztd|�|�WYdd}~XnXdS)a-
    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
    rPz*Unable to determine dynamic funcation namerrRNzNo such function %s to call!)r?r#�globals�KeyError)rZ	func_nameZ	func_argsr,rrr�get_dyn_func�sracCsry,tjtd|g�\}}tjtd|g�\}}Wn4tk
r`}ztd||f�|�WYdd}~XnXt|�t|�S)Nz--getsize64z--getsszFailed to get %s size
%s)r�
BLKDEV_CMDr#�int)rZ
size_in_bytesrXZsector_sizer,rrr�get_hdd_size�s$rdcCst|�td|g}ytj|d|d�\}}Wn4tk
r`}ztd||f�|�WYdd}~XnXg}x�|j�D]�}|j�}t|�dkr�qp||dkrp|d
j�dkr�qpd}	x@tt	dt|��d
d�D]&}
||
j
�r�||
dkr�||
}	Pq�W|j|	�qpW|S)z�
    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.
    z-lz%s
)�dataz(Error running partition command on %s
%sNrrR�extended�emptyT)�reverse�/���)rfrg)�read_parttbl�
SFDISK_CMDrr#rFr5r?rG�sorted�range�isdigitrD)r�layout�prt_cmdrUrIr,�found_layout�line�_lineZ
type_labelr7rrr�check_partition_mbr_layout�s.
rucCs�td|g}ytj|td�\}}Wn4tk
rT}ztd||f�|�WYdd}~XnXt|j��}x|D]}|j�jd�rhPqhWdd�|D�}g}	x8|D]0}
t|
�dkr�|
j	d�r�|
d	d
�}
|	j
|
�q�W|	S)Nz-p)Z
update_envz(Error running partition command on %s
%s�NumbercSsg|]}|j�j�d�qS)�)rEr5)r6rsrrrr8sz.check_partition_gpt_layout.<locals>.<listcomp>�Z00rrP)�
SGDISK_CMDr�
LANG_C_ENVr#�iterrFrE�
startswithr?�endswithrD)rrprqrUrIr,Z	out_linesrsZcodesZcleaned�coderrr�check_partition_gpt_layout�s$


rcCs�td|||�}tjd||||�t|t�rB|r>t|�dkr>dSdSt|�t|�kr�dd�|D�}tjd||�x2t||�D]$\}}|d	k	rzt|�t|�krzdSqzWdSdS)
z�
    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
    zcheck_partition_%s_layoutz6called check_partition_%s_layout(%s, %s), returned: %srRTFcSs*g|]"}t|ttf�r"t|d�nd�qS)rRN)r�tupler%r)r6r7rrrr81sz*check_partition_layout.<locals>.<listcomp>zLayout types=%s. Found types=%sN)rar!rr�boolr?�zipr)�
table_typerrprrZlayout_typesZitypeZftyperrr�check_partition_layouts*

r�c
Cst|t�rt|t�rdSt|�dkr0t|t�s<t|t�rDtd��t|�}|dkr\td��g}d}x�|D]�}d}|}|d7}t|t�r�t|�dkr�td	|��|\}}tt|�t|�d
�}||kr�|jd|�qj|jd||f�qjWd
j|�}	t|�dk�rtd|	��|	S)a@
    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.
    z0,rzPartition layout is invalidrxz$Only simply partitioning is allowed.�SrRrPz%Partition was incorrectly defined: %s�dz,,%sz,%s,%s�
z-Calculated partition definition is too big
%s)	rr%r�r?r#rc�floatrD�join)
�sizerpZ
last_part_num�part_definitionZpart_numr3Z	part_type�percent�	part_sizeZsfdisk_definitionrrr�get_partition_mbr_layout>s8




r�cCs�t|t�rdddgfgSg}xp|D]h}t|t�rRt|�dkrHtd|��|\}}n|}d}tt|�t|�d�}|j|ddj|�gf�q"Wd|ddd	<|S)
NrrPz%Partition was incorrectly defined: %sr�z+{}rRrjrjrj)	rr�r%r?r#rcr�rD�format)r�rpZpartition_specsr2r��partition_typer�rrr�get_partition_gpt_layoutus




r�c
Csbd}d}d}t|d��:}|j||�|j|tj�|j||�|j�WdQRXt|�dS)N�izrb+ii)�open�write�seek�os�SEEK_END�flushrk)rZnullZ	start_lenZend_len�fprrr�purge_disk_ptable�sr�cCs�x�t|�D]v}|dd
kr
tdd|dg}ytjd|d�tj|�Wq
tk
r~}ztd|d�|�WYd	d	}~Xq
Xq
Wt|�d	S)z'
    Remove parition table entries
    r@r*�cryptz--allz/dev/%srzPurging filesystem on /dev/%szFailed FS purge of /dev/%sN)r*r�)rL�
WIPEFS_CMDr!r/rr#r�)rrKZ
wipefs_cmdr,rrr�
purge_disk�sr�cCstd|||�S)z�
    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.
    zget_partition_%s_layout)ra)r�r�rprrr�get_partition_layout�s	r�cCsrtdk	rt|g}n
td|g}tj�ytj|�Wn2tk
rd}ztjtd|�WYdd}~XnXtj�dS)zq
    `Partprobe` is preferred over `blkdev` since it is more reliably
    able to probe the partition table.
    Nz
--rereadptz%Failed reading the partition table %s)�
PARTPROBE_CMDrbr�udevadm_settlerr#r$r!)rZ	probe_cmdr,rrrrk�s

"rkcCsftddd|g}ytj|d|d�Wn4tk
rX}ztd||f�|�WYdd}~XnXt|�dS)zV
    Break out of mbr partition to allow for future partition
    types, i.e. gpt
    z--Linuxz--unit=Sz--forcez%s
)rez Failed to partition device %s
%sN)rlrr#rk)rrprqr,rrr�exec_mkpart_mbr�sr�cCs�y�tjtd|g�xrt|�D]f\}\}\}}|d7}tjtddj|||�|g�|dk	rt|�jdd�}tjtddj||�|g�qWWn"tk
r�tjd	|��YnXt	|�dS)
Nz-ZrRz-nz{}:{}:{}rx�0z-tz{}:{}zFailed to partition device %s)
rry�	enumerater�r�ljustr#r!r rk)rrp�indexr�r;�endZpinputrrr�exec_mkpart_gpt�s"r�cCstd|||�S)a
    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
    zexec_mkpart_%s)ra)r�rrprrr�exec_mkpart�s
r�cCs8tjj|�s,tj�tjj|�s,td|��tj�dS)z?Assert that device exists and settle so it is fully recognized.zBDevice %s did not exist and was not created with a udevadm settle.N)r��path�existsrr��RuntimeError)rrrr�assert_and_settle_devicesr�cCszt|�tjj|�}tjd|�|jdd�}|jdd�}|jdd�}tjd�t|t�r^|sd|rrtjd�d	Stjd
|�t	|�s�t
dj|d���t|t�r�|j
�d
kr�tjd�t|�d	Stjd�t|||�r�tjd�dStjd�|�rt|��st|��rtjd|�d	Stjd|�t|�}tjd�t|||�}tjd|�tjd|�t|||�tjd|�d	S)a�
    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.
    z!Checking values for %s definition�	overwriteFrpr�Zmbrz Checking against default devicesz)Device is not to be partitioned, skippingNz'Checking if device %s is a valid devicez%Device {device} is not a disk device!)r�removez,Instructed to remove partition table entriesz!Checking if device layout matchesz"Device partitioning layout matchesTz'Checking if device is safe to partitionz-Skipping partitioning on configured device %szChecking for device size of %szCalculating partition layoutz   Layout is: %szCreating partition table on %szPartition table created for %s)r�r�r��realpathr!rrrr�rOr#r�rrGr�r�r^rYrdr�r�)rr+r�rpr�Zdevice_sizer�rrrr"sD






r"cCsDdddddd�}d|j�kr d}|j�|kr4||Stjd|�dS)z9
    A force flag might be -F or -F, this look it up
    z-Fz-f)�extZbtrfsZxfsZreiserfsZswapr�zForce flag for %s is unknown.rN)rGr!r )Zfs�flagsrrr�lookup_force_flagYsr�cCs�|jd�}|jd�}t|jdd��}|jd�}|jdg�}|jdg�}|jdd	�}|jd
d	�}t|�tjj|�}tjd|�|s�|j��r*|j�r�d||f}tjd
||�tjd|�t	|�\}	}
}tjd||	|
�|	|ko�|
|k�rtjd|�|�stjd|�dStj
d|�ntjd|�n�|�r�t|�j�d0k�r�|}tjd|�d}
|j�dk�rhd	}
t||||
|d�\}}tjd||�|�r�tjd�dS|�r�|�r�|�r�tjd|�|�stjd|�dSn6|�s�t|�j�dk�rtjd|�ntjd�dStjd |||�|�s4tj
d!|�dS|�p<|�sPt
d"j|d#���d	}|�r�|d|||d$�}d}|�r�tj
d%|�|�r*tj
d&|�n�tjd'|�}|�s�tjd(|�}|�s�tj
d)||�dS||g}|�r�|jd*|g�|�st|�d+k�rt|�}|�r|j|�|�r*|j|�tjd,||�tjd-t|��ytj||d.�Wn6t
k
�r�}zt
d/||f�|�WYdd}~XnXdS)1a�
    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.
    rBrr2�any�
filesystem�cmdZ
extra_optsr[Fr�z#Checking %s against default devicesz%s%sz%Manual request of partition %s for %szChecking device %sz0Device '%s' has check_label='%s' check_fstype=%sz Existing file system found at %sz"Device %s has required file systemNzDestroying filesystem on %sz"Device %s is cleared for formating�autoz,Identifying device to create %s filesytem onT)rVrBrZr[z(Automatic device for %s identified as %sz+Found filesystem match, skipping formating.z*Replacing file system on %s as instructed.zENo device available that matches request. Skipping fs creation for %sZnonez.Using the raw device to place filesystem %s onz(Error in device identification handling.z;File system type '%s' with label '%s' will be created on %szDevice is not known: %szENo way to create filesystem '{label}'. fs_type or fs_cmd must be set.)rB)rBr�rz8fs_setup:overwrite ignored because cmd was specified: %sz9fs_setup:extra_opts ignored because cmd was specified: %szmkfs.%szmk%sz.Cannot create fstype '%s'.  No mkfs.%s commandz-Lr*zCreating file system %s on %sz     Using cmd: %s)�shellzFailed to exec of '%s':
%s)r�r�)rrr�r�r�r�r!rrorWr rGr\r#r�r�which�extendrMr�rD)Zfs_cfgrBrr2rVZfs_cmdZfs_optsZ
fs_replacer�Zcheck_labelr]rXZodevicerZZreuser�Zmkfs_cmdZ
force_flagr,rrrr'os�









r')N)F)F)NNNTN);�__doc__Zloggingr�r9�textwraprZ	cloudinitrrZcloudinit.config.schemarrZcloudinit.distrosrZcloudinit.settingsrr�rlryrCrTrbr�r�rzZ	getLogger�__name__r!ZMODULE_DESCRIPTION�metar-rr&r>rLrMrOrWrYr\r^rardrurr�r�r�r�r�r�rkr�r�r�r�r"r�r'rrrr�<module>sx







5&

2
 

2
')+7
B

Youez - 2016 - github.com/yon3zu
LinuXploit