404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.139.87.39: ~ $
3

\�me7D�@s:dZddlZddlZddlZddlZddlZddlmZmZddl	m
Z
ddlmZm
Z
mZmZmZmZmZddlZddlmZddlmZddlmZdd	lmZmZmZmZmZdd
l m!Z!ej"e#�Z$dZ%dZ&d
Z'ddddddd�Z(e)d�dd�Z*d9eee)e
e)efd�dd�Z+Gdd�de�Z,Gdd�de�Z-Gdd�de�Z.e)e/d�dd �Z0Gd!d"�d"ej1�Z2e3d�d#d$�Z4d:ej5e)e3d&�d'd(�Z6d;ej5e)e3ej7d)�d*d+�Z8Gd,d-�d-e�Z9Gd.d/�d/�Z:e&e9j;fe)e9e/d0�d1d2�Z<e2ej=ffgZ>d3d4�Z?e#d5k�r6ddl@Z@d6ZAe@jBeAd7�ZCeCjD�eEejFe<e9j;d8���dS)<a�Datasource for LXD, reads /dev/lxd/sock representation of instance data.

Notes:
 * This datasource replaces previous NoCloud datasource for LXD.
 * Older LXD images may not have updates for cloud-init so NoCloud may
   still be detected on those images.
 * Detect LXD datasource when /dev/lxd/sock is an active socket file.
 * Info on dev-lxd API: https://documentation.ubuntu.com/lxd/en/latest/dev-lxd/
�N)�Flag�auto)�JSONDecodeError)�Any�Dict�List�Optional�Tuple�Union�cast)�HTTPAdapter)�HTTPConnection)�HTTPConnectionPool)�
atomic_helper�sources�subp�
url_helper�util)�find_fallback_nicz
/dev/lxd/sockz1.0z
http://lxdz	user-dataznetwork-configzvendor-data)zcloud-init.user-datazcloud-init.network-configzcloud-init.vendor-datazuser.user-datazuser.network-configzuser.vendor-data)�returncCs�d}tjd�r�ytjdg�\}}Wn.tjk
rP}ztjd|�|Sd}~XnX|j�d
kr�tj�dd}|dkrzd	S|d
kr�dSdS|S)NZeth0zsystemd-detect-virtzHUnable to run systemd-detect-virt: %s. Rendering default network config.�kvm�qemu�uname�Zppc64leZenp0s5Zs390xZenc9Zenp5s0)rr)rZwhichZProcessExecutionError�LOG�warning�striprZsystem_info)Zdefault_nameZ	virt_type�_�errZarch�r�#/usr/lib/python3.6/DataSourceLXD.py�_get_fallback_interface_name/s&
r!)�nicsrcCsFt�}|rtjd|�nt�}tjd|�dd|ddd�gd�gd	�S)
zCReturn network config V1 dict representing instance network config.zCLXD datasource generating network from discovered active device: %szVLXD datasource generating network from systemd-detect-virt platform default device: %s�ZphysicalZdhcpr)�typeZcontrol)r$�nameZsubnets)�version�config)rr�debugr!)r"Zprimary_nicrrr �generate_network_configIsr)cs$eZdZ�fdd�Zdd�Z�ZS)�SocketHTTPConnectioncst�jd�||_dS)N�	localhost)�super�__init__�socket_path)�selfr.)�	__class__rr r-pszSocketHTTPConnection.__init__cCs$tjtjtj�|_|jj|j�dS)N)�socketZAF_UNIXZSOCK_STREAMZsock�connectr.)r/rrr r2tszSocketHTTPConnection.connect)�__name__�
__module__�__qualname__r-r2�
__classcell__rr)r0r r*osr*cs$eZdZ�fdd�Zdd�Z�ZS)�SocketConnectionPoolcs||_t�jd�dS)Nr+)r.r,r-)r/r.)r0rr r-zszSocketConnectionPool.__init__cCs
t|j�S)N)r*r.)r/rrr �	_new_conn~szSocketConnectionPool._new_conn)r3r4r5r-r8r6rr)r0r r7ysr7c@seZdZddd�ZdS)�LXDSocketAdapterNcCstt�S)N)r7�LXD_SOCKET_PATH)r/�urlZproxiesrrr �get_connection�szLXDSocketAdapter.get_connection)N)r3r4r5r<rrrr r9�sr9)�
metadata_typercCs�t|t�r|S|dkriSytj|�}Wn8tk
r`}ztjdj||d��|�WYdd}~XnX|dkr~tjdj||d���|S)a6Convert raw instance data from str, bytes, YAML to dict

    :param metadata_type: string, one of as: meta-data, vendor-data, user-data
        network-config

    :param metadata_value: str, bytes or dict representing or instance-data.

    :raises: InvalidMetaDataError on invalid instance-data content.
    NzAInvalid {md_type}. Expected str, bytes or dict but found: {value})Zmd_type�valuez:Invalid {md_type} format. Expected YAML but found: {value})�
isinstance�dictr�	load_yaml�AttributeErrorr�InvalidMetaDataException�format)r=Zmetadata_valueZparsed_metadata�excrrr �_raw_instance_data_to_dict�s 


rFcs�eZdZUdZejZeee	fejZ
eee	f
ejjdZe
e	dfdZed	d
��fdd�Zeed
�dd��Zed
�dd�Ze	d
�dd�Ze	d
�dd�Zeed
�dd��Z�ZS)�
DataSourceLXDZLXD�user.meta-data�user.vendor-data�user.user-data�cloud-init.user-data�cloud-init.vendor-data.TN)�ci_pkl_versionrcst�j|�d|_dS)NT)r,�	_unpickle�skip_hotplug_detect)r/rM)r0rr rN�szDataSourceLXD._unpickle)rcCst�S)z@Check platform environment to report if this datasource may run.)�is_platform_viablerrrr �	ds_detect�szDataSourceLXD.ds_detectcCs�tjtjdtd�|_td|jjd��|_|jjdi�}|jdi�}|rPtd|�}t	|jt
�sttjtj|j�|g�|_d|jkr�|jd|_
d|jkr�td|jd�|_d|jkr�|jd|_d	S)
z=Crawl LXD socket API instance data and return True on successzCrawl of metadata service)Zlogfunc�msg�funcz	meta-datar'zuser.meta-dataz	user-dataznetwork-configzvendor-dataT)rZlog_timerr(�
read_metadata�_crawled_metadatarF�get�metadatar?r@Z
mergemanydictrAZuserdata_raw�_network_configZvendordata_raw)r/r'Z
user_metadatarrr �	_get_data�s,



zDataSourceLXD._get_datacCsdjttd�S)z.Return subplatform details for this datasourcez"LXD socket API v. {ver} ({socket}))Zverr1)rD�LXD_SOCKET_API_VERSIONr:)r/rrr �_get_subplatform�szDataSourceLXD._get_subplatformcCsBttjd�}|jdi�}t|t�s,tj|�}|jd�|jjd�kS)z%Return True if instance_id unchanged.)�
metadata_keysz	meta-datazinstance-id)	rT�MetaDataKeys�	META_DATArVr?r@rrArW)r/Zsys_cfg�response�mdrrr �check_instance_id�s


zDataSourceLXD.check_instance_idcCs�|jtjkr~|jtjkr |j�t|jt�r~|jjd�rPtj	d�|jd|_n.|jjd�r~dd�|jdj
�D�}t|�|_|jtjkr�tj	d�t�|_tt|j�S)z�Network config read from LXD socket config/user.network-config.

        If none is present, then we generate fallback configuration.
        znetwork-configz,LXD datasource using provided network config�devicescSs g|]\}}|ddkr|�qS)r$Znicr)�.0�k�vrrr �
<listcomp>�sz0DataSourceLXD.network_config.<locals>.<listcomp>z8LXD datasource generating network config using fallback.)
rXr�UNSETrUrYr?r@rVrr(�itemsr)r)r/rbrrr �network_config�s"


zDataSourceLXD.network_config)rHrIrJrKrL)r3r4r5ZdsnamerrgrXr
r�strrU�
DataSourceZsensitive_metadata_keysr	rO�intrN�staticmethod�boolrQrYr[ra�propertyr@rir6rr)r0r rG�s$
rGcCs"tjjt�rtjtjt�j�SdS)z=Return True when this platform appears to have an LXD socket.F)�os�path�existsr:�stat�S_ISSOCK�lstat�st_moderrrr rPsrPT)�sessionr;�do_raisecCsrt|||�}|js*tjd||j|j�iSy|j�Stk
rl}ztj	dj
||jd��|�WYdd}~XnXdS)NzSkipping %s on [HTTP:%d]:%szFUnable to process LXD config at {url}. Expected JSON but found: {resp})r;�resp)�_do_request�okrr(�status_code�textZjsonrrrCrD)rwr;rxZurl_responserErrr �_get_json_responsesr~)rwr;rxrcCs�xHtddd
�D]8}|j|�}d|jkrDtjd�tjd|j||�qPqWtjd|j|�|r�|jr�t	j
dj|j||jd	���|S)N�rr#i�g�������?z,[GET] [HTTP:%d] %s, retrying %d more time(s)z[GET] [HTTP:%d] %sz3Invalid HTTP response [{code}] from {route}: {resp})�codeZroutery���)
�rangerVr|�timeZsleeprrr(r{rrCrDr})rwr;rxZretriesr_rrr rz,s$


rzc@s0eZdZe�Ze�Ze�Ze�ZeeBeBZdS)r]N)	r3r4r5rZNONE�CONFIG�DEVICESr^�ALLrrrr r]Is
r]c@s@eZdZefed�dd�Zejed�dd�Z	e
ed�dd	�Zd
S)�_MetaDataReader)�api_versioncCs||_tjt|j�|_dS)N)r�r�combine_url�LXD_URL�_version_url)r/r�rrr r-Rsz_MetaDataReader.__init__)rwrc	Cs�dii}tj|jd�}t||�}x�t|�D]�}tjt|�}t||dd�}|jsdtj	d||j
|j�q*|jd�d
}|j|d|<|t
kr*t
||kr�|j|t
|<q*tjd||jdd	d��q*W|S)a�Iterate on LXD API config items. Promoting CONFIG_KEY_ALIASES

        Any CONFIG_KEY_ALIASES which affect cloud-init behavior are promoted
        as top-level configuration keys: user-data, network-data, vendor-data.

        LXD's cloud-init.* config keys override any user.* config keys.
        Log debug messages if any user.* keys are overridden by the related
        cloud-init.* key.
        r'F)rxzSkipping %s on [HTTP:%d]:%s�/r#z,Ignoring LXD config %s in favor of %s value.�userz
cloud-initr�)rr�r�r~�sortedr�rzr{rr(r|r}�
rpartition�CONFIG_KEY_ALIASESr�replace)	r/rwr'Z
config_urlZ
config_routesZconfig_routeZconfig_route_urlZconfig_route_responseZcfg_keyrrr �_process_configVs0

z_MetaDataReader._process_config)r\rcCs�tj���}|j|jt��d|ji}tj|krLtj	|jd�}t
||�j|d<tj|krf|j
|j|��tj|kr�tj	|jd�}t||dd�}|r�||d<|SQRXdS)NZ_metadata_api_versionz	meta-datarbF)rx)�requests�SessionZmountr�r9r�r]r^rr�rzr}r��updater�r�r~)r/r\rwr`Zmd_router;rbrrr �__call__�s





z_MetaDataReader.__call__N)r3r4r5rZrjr-r�r�r@r�r]r�rrrr r�Qs7r�)r�r\rcCst|d�|d�S)a8Fetch metadata from the /dev/lxd/socket routes.

    Perform a number of HTTP GETs on known routes on the devlxd socket API.
    Minimally all containers must respond to <LXD_SOCKET_API_VERSION>/meta-data
    when the LXD configuration setting `security.devlxd` is true.

    When `security.devlxd` is false, no /dev/lxd/socket file exists. This
    datasource will return False from `is_platform_viable` in that case.

    Perform a GET of <LXD_SOCKET_API_VERSION>/config` and walk all `user.*`
    configuration keys, storing all keys and values under a dict key
        LXD_SOCKET_API_VERSION: config {...}.

    In the presence of the following optional user config keys,
    create top level aliases:
      - user.user-data -> user-data
      - user.vendor-data -> vendor-data
      - user.network-config -> network-config

    :param api_version:
        LXD API version to operated with.
    :param metadata_keys:
        Instance of `MetaDataKeys` indicating what keys to fetch.
    :return:
        A dict with the following optional keys: meta-data, user-data,
        vendor-data, network-config, network_mode, devices.

        Below <LXD_SOCKET_API_VERSION> is a dict representation of all raw
        configuration keys and values provided to the container surfaced by
        the socket under the /1.0/config/ route.
    )r�)r\)r�)r�r\rrr rT�s#rTcCstj|t�S)N)rZlist_from_depends�datasources)Zdependsrrr �get_datasource_list�sr��__main__z*Query LXD metadata and emit a JSON object.)�description)r\)N)T)T)G�__doc__Zloggingrpr1rsr��enumrrZjson.decoderrZtypingrrrrr	r
rr�Zrequests.adaptersrZurllib3.connectionr
Zurllib3.connectionpoolrZ	cloudinitrrrrrZ
cloudinit.netrZ	getLoggerr3rr:rZr�r�rjr!r)r*r7r9r@rFrkrGrnrPr�r~ZResponserzr]r�r�rTZDEP_FILESYSTEMr�r��argparser��ArgumentParser�parser�
parse_args�printZ
json_dumpsrrrr �<module>	sd$
$
	j
Q
'


Filemanager

Name Type Size Permission Actions
DataSourceAkamai.cpython-36.opt-1.pyc File 8.18 KB 0644
DataSourceAkamai.cpython-36.pyc File 8.18 KB 0644
DataSourceAliYun.cpython-36.opt-1.pyc File 3.22 KB 0644
DataSourceAliYun.cpython-36.pyc File 3.22 KB 0644
DataSourceAltCloud.cpython-36.opt-1.pyc File 6.74 KB 0644
DataSourceAltCloud.cpython-36.pyc File 6.74 KB 0644
DataSourceAzure.cpython-36.opt-1.pyc File 47.95 KB 0644
DataSourceAzure.cpython-36.pyc File 47.95 KB 0644
DataSourceBigstep.cpython-36.opt-1.pyc File 1.84 KB 0644
DataSourceBigstep.cpython-36.pyc File 1.84 KB 0644
DataSourceCloudSigma.cpython-36.opt-1.pyc File 3.62 KB 0644
DataSourceCloudSigma.cpython-36.pyc File 3.62 KB 0644
DataSourceCloudStack.cpython-36.opt-1.pyc File 5.97 KB 0644
DataSourceCloudStack.cpython-36.pyc File 5.97 KB 0644
DataSourceConfigDrive.cpython-36.opt-1.pyc File 8.18 KB 0644
DataSourceConfigDrive.cpython-36.pyc File 8.18 KB 0644
DataSourceDigitalOcean.cpython-36.opt-1.pyc File 3.65 KB 0644
DataSourceDigitalOcean.cpython-36.pyc File 3.65 KB 0644
DataSourceEc2.cpython-36.opt-1.pyc File 23.49 KB 0644
DataSourceEc2.cpython-36.pyc File 23.49 KB 0644
DataSourceExoscale.cpython-36.opt-1.pyc File 5.92 KB 0644
DataSourceExoscale.cpython-36.pyc File 5.92 KB 0644
DataSourceGCE.cpython-36.opt-1.pyc File 9.83 KB 0644
DataSourceGCE.cpython-36.pyc File 9.93 KB 0644
DataSourceHetzner.cpython-36.opt-1.pyc File 3.78 KB 0644
DataSourceHetzner.cpython-36.pyc File 3.78 KB 0644
DataSourceIBMCloud.cpython-36.opt-1.pyc File 12.44 KB 0644
DataSourceIBMCloud.cpython-36.pyc File 12.44 KB 0644
DataSourceLXD.cpython-36.opt-1.pyc File 13.31 KB 0644
DataSourceLXD.cpython-36.pyc File 13.31 KB 0644
DataSourceMAAS.cpython-36.opt-1.pyc File 11.86 KB 0644
DataSourceMAAS.cpython-36.pyc File 11.86 KB 0644
DataSourceNWCS.cpython-36.opt-1.pyc File 3.77 KB 0644
DataSourceNWCS.cpython-36.pyc File 3.77 KB 0644
DataSourceNoCloud.cpython-36.opt-1.pyc File 7.97 KB 0644
DataSourceNoCloud.cpython-36.pyc File 7.97 KB 0644
DataSourceNone.cpython-36.opt-1.pyc File 1.47 KB 0644
DataSourceNone.cpython-36.pyc File 1.47 KB 0644
DataSourceOVF.cpython-36.opt-1.pyc File 9.15 KB 0644
DataSourceOVF.cpython-36.pyc File 9.15 KB 0644
DataSourceOpenNebula.cpython-36.opt-1.pyc File 11.75 KB 0644
DataSourceOpenNebula.cpython-36.pyc File 11.75 KB 0644
DataSourceOpenStack.cpython-36.opt-1.pyc File 7.91 KB 0644
DataSourceOpenStack.cpython-36.pyc File 7.91 KB 0644
DataSourceOracle.cpython-36.opt-1.pyc File 10.99 KB 0644
DataSourceOracle.cpython-36.pyc File 10.99 KB 0644
DataSourceRbxCloud.cpython-36.opt-1.pyc File 7.19 KB 0644
DataSourceRbxCloud.cpython-36.pyc File 7.19 KB 0644
DataSourceScaleway.cpython-36.opt-1.pyc File 10.84 KB 0644
DataSourceScaleway.cpython-36.pyc File 10.84 KB 0644
DataSourceSmartOS.cpython-36.opt-1.pyc File 24.51 KB 0644
DataSourceSmartOS.cpython-36.pyc File 24.51 KB 0644
DataSourceUpCloud.cpython-36.opt-1.pyc File 4.36 KB 0644
DataSourceUpCloud.cpython-36.pyc File 4.36 KB 0644
DataSourceVMware.cpython-36.opt-1.pyc File 23.66 KB 0644
DataSourceVMware.cpython-36.pyc File 23.66 KB 0644
DataSourceVultr.cpython-36.opt-1.pyc File 3.44 KB 0644
DataSourceVultr.cpython-36.pyc File 3.44 KB 0644
__init__.cpython-36.opt-1.pyc File 30.52 KB 0644
__init__.cpython-36.pyc File 30.52 KB 0644