403Webshell
Server IP : 3.96.16.70  /  Your IP : 216.73.216.15
Web Server : Apache
System : Linux ip-172-31-26-103.ca-central-1.compute.internal 6.1.163-186.299.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Feb 24 16:35:42 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3.9/site-packages/cloudinit/sources/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.9/site-packages/cloudinit/sources/__pycache__/DataSourceLXD.cpython-39.pyc
a

ꬊh�5�@s�dZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZmZm
Z
ddlZddlmZddlmZddlmZddlmZdd	lmZmZmZe�e�Zd
ZdZdd
ddd
dd�Z e!d�dd�Z"Gdd�de�Z#Gdd�de�Z$Gdd�de�Z%e&e!d�dd�Z'Gdd�dej(�Z)e*d�dd�Z+ed fe&e*e!d!�d"d#�Z,e)ej-ffgZ.d$d%�Z/ed&k�r�ddl0Z0d'Z1e0j2e1d(�Z3e3�4�e5e�6e,���dS))a�Datasource for LXD, reads /dev/lxd/sock representaton 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://linuxcontainers.org/lxd/docs/master/dev-lxd
 * TODO( Hotplug support using websockets API 1.0/events )
�N)�JSONDecodeError)�Any�Dict�List�Optional�Tuple�Union�cast)�HTTPAdapter)�HTTPConnection)�HTTPConnectionPool)�log)�sources�subp�utilz
/dev/lxd/sockz1.0�	user-data�network-config�vendor-data)�cloud-init.user-datazcloud-init.network-config�cloud-init.vendor-data�user.user-datazuser.network-config�user.vendor-data��returnc
Cs�dddddd�gd�gd�}t�d	�r�zt�d	g�\}}Wn6tjyp}zt�d
|�|WYd}~Sd}~00|��dvr�t��d
d}|dkr�d|ddd<n*|dkr�d|ddd<nd|ddd<|S)zCReturn network config V1 dict representing instance network config.�ZphysicalZeth0Zdhcp�auto)�typeZcontrol)r�name�subnets)�version�configzsystemd-detect-virtzHUnable to run systemd-detect-virt: %s. Rendering default network config.N)ZkvmZqemu�uname�Zppc64leZenp0s5r rrZs390xZenc9Zenp5s0)rZwhichZProcessExecutionError�LOG�warning�striprZsystem_info)Z
network_v1Z	virt_type�_�errZarch�r(�C/usr/lib/python3.9/site-packages/cloudinit/sources/DataSourceLXD.py� generate_fallback_network_config5s0
���

�r*cs$eZdZ�fdd�Zdd�Z�ZS)�SocketHTTPConnectioncst��d�||_dS�NZ	localhost)�super�__init__�socket_path��selfr/��	__class__r(r)r.ZszSocketHTTPConnection.__init__cCs$t�tjtj�|_|j�|j�dS�N)�socketZAF_UNIXZSOCK_STREAMZsock�connectr/�r1r(r(r)r6^szSocketHTTPConnection.connect)�__name__�
__module__�__qualname__r.r6�
__classcell__r(r(r2r)r+Ysr+cs$eZdZ�fdd�Zdd�Z�ZS)�SocketConnectionPoolcs||_t��d�dSr,)r/r-r.r0r2r(r)r.dszSocketConnectionPool.__init__cCs
t|j�Sr4)r+r/r7r(r(r)�	_new_connhszSocketConnectionPool._new_conn)r8r9r:r.r=r;r(r(r2r)r<csr<c@seZdZddd�ZdS)�LXDSocketAdapterNcCstt�Sr4)r<�LXD_SOCKET_PATH)r1�urlZproxiesr(r(r)�get_connectionmszLXDSocketAdapter.get_connection)N)r8r9r:rAr(r(r(r)r>lsr>)�
metadata_typerc
Cs�t|t�r|S|duriSzt�|�}Wn:tyb}z"t�dj||d��|�WYd}~n
d}~00|dur�t�dj||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)rBZmetadata_valueZparsed_metadata�excr(r(r)�_raw_instance_data_to_dictqs*

�����rKc@s�eZdZUdZejZejZejj	dZ	e
edfed<e
d�dd�Ze
d�dd	�Zed�d
d�Zed�dd
�Zeed�dd��ZdS)�
DataSourceLXDZLXD)�user.meta-datarrrr.�sensitive_metadata_keysrcCst�S)z@Check platform environment to report if this datasource may run.)�is_platform_viabler7r(r(r)�_is_platform_viable�sz!DataSourceLXD._is_platform_viablecCs�|��st�d�dStjtjdtd�|_td|j�d��|_	|j�di�}|�di�}|rftd|�}t
|j	t�s�t�t�
|j	�|g�|_	d|jvr�|jd|_d	|jvr�td	|jd	�|_d
|jvr�|jd
|_dS)z=Crawl LXD socket API instance data and return True on successz+Not an LXD datasource: No LXD socket found.FzCrawl of metadata service)Zlogfunc�msg�func�	meta-datar rMrrrT)rPr#�debugrZlog_time�
read_metadata�_crawled_metadatarK�get�metadatarDrEZ
mergemanydictrFZuserdata_raw�_network_configZvendordata_raw)r1r Z
user_metadatar(r(r)�	_get_data�s<
����


�
zDataSourceLXD._get_datacCsdjttd�S)z.Return subplatform details for this datasourcez"LXD socket API v. {ver} ({socket}))Zverr5)rI�LXD_SOCKET_API_VERSIONr?r7r(r(r)�_get_subplatform�s�zDataSourceLXD._get_subplatformcCs@tdd�}|�di�}t|t�s*t�|�}|�d�|j�d�kS)z%Return True if instance_id unchanged.T)�
metadata_onlyrSzinstance-id)rUrWrDrErrFrX)r1Zsys_cfg�response�mdr(r(r)�check_instance_id�s



zDataSourceLXD.check_instance_idcCs6|jtjkr0|j�d�r(|j�d�|_nt�|_|jS)z�Network config read from LXD socket config/user.network-config.

        If none is present, then we generate fallback configuration.
        r)rYr�UNSETrVrWr*r7r(r(r)�network_config�s�zDataSourceLXD.network_configN)r8r9r:ZdsnamerrarYrV�
DataSourcerNr�str�__annotations__�boolrPrZr\r`�propertyrErbr(r(r(r)rL�s

��
"rLcCs"tj�t�rt�t�t�j�SdS)z=Return True when this platform appears to have an LXD socket.F)�os�path�existsr?�stat�S_ISSOCK�lstat�st_moder(r(r(r)rO�srOF)�api_versionr]rcCs
i}d}|d|d}t�����}|�|t��dj|d�}|�|�}t�d|j|�|j	sxt
�dj|j||jd���|j|d<|r�|Wd	�S|i|dd
�}|d}|�|�}t�d|j|�|j	s�t
�dj|j||jd���z|�
�}	Wn>t�y4}
z$t
�dj||jd
��|
�WYd	}
~
n
d	}
~
00t|	�D]�}dj|d�}|�|�}t�d|j|�|j	�r�|�d�d}
|j|d|
<|
tv�r�t|
|v�r�|j|t|
<nt�d|
|
�ddd��nt�d||j|j��q>Wd	�n1�s�0Y|S)a�Fetch 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 http://lxd/1.0/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

    :return:
        A dict with the following mandatory key: meta-data.
        Optional keys: user-data, vendor-data, network-config, network_mode

        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.
    z
http://lxd�/z{route}meta-data)�routez[GET] [HTTP:%d] %sz3Invalid HTTP response [{code}] from {route}: {resp})�coderq�resprSN)Z_metadata_api_versionr rSr zSUnable to determine cloud-init config from {route}. Expected JSON but found: {resp})rqrszhttp://lxd{route}���z,Ignoring LXD config %s in favor of %s value.�userz
cloud-initrzSkipping %s on [HTTP:%d]:%s)�requestsZSessionZmountr>rIrWr#rTZstatus_code�okrrH�textZjsonr�sorted�
rpartition�CONFIG_KEY_ALIASESr$�replace)ror]r_Zlxd_urlZversion_urlZsessionZmd_router^Z
config_urlZ
config_routesrJZconfig_router@Zcfg_keyr(r(r)rU�s�
��
�
�����


��(rUcCst�|t�Sr4)rZlist_from_depends�datasources)Zdependsr(r(r)�get_datasource_listesr~�__main__z*Query LXD metadata and emit a JSON object.)�description)7�__doc__rhr5rkZjson.decoderr�typingrrrrrrr	rvZrequests.adaptersr
Z$requests.packages.urllib3.connectionrZ(requests.packages.urllib3.connectionpoolrZ	cloudinitr
ZloggingrrrZ	getLoggerr8r#r?r[r{rEr*r+r<r>rdrKrcrLrfrOrUZDEP_FILESYSTEMr}r~�argparser��ArgumentParser�parser�
parse_args�printZ
json_dumpsr(r(r(r)�<module>sT$
�
$
	T��w
�


Youez - 2016 - github.com/yon3zu
LinuXploit