CasperSecurity

Current Path : /lib/python3/dist-packages/cloudinit/sources/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceCloudStack.cpython-310.pyc

o

쑛hv3�@s4ddlZddlZddlZddlmZddlmZmZmZddl	m
Z
ddlmZm
Z
mZmZmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZe�e�ZdZGd
d�d�Z Gdd�dej!�Z"Gdd�de"�Z#dd�Z$dd�Z%dd�Z&de'fdd�Z(e#ej)ffe"ej)ej*ffgZ+dd�Z,dS)�N)�suppress)�gaierror�getaddrinfo�	inet_ntoa)�pack)�dmi�net�performance�sources�subp)�
url_helper)�util)�dhcp)�NoDHCPLeaseError)�EphemeralIPNetwork)�ec2�
CloudStackc@s6eZdZdZdd�Zdd�Zejddd�d	d
��ZdS)�CloudStackPasswordServerClienta�
    Implements password fetching from the CloudStack password server.

    http://cloudstack-administration.readthedocs.org/
       en/latest/templates.html#adding-password-management-to-your-templates
    has documentation about the system.  This implementation is following that
    found at
    https://github.com/shankerbalan/cloudstack-scripts/
       blob/master/cloud-set-guest-password-debian
    cCs
||_dS�N)�virtual_router_address)�selfr�r�H/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceCloudStack.py�__init__/�
z'CloudStackPasswordServerClient.__init__cCs:t�ddddddddd	d
�|�d�|j�g�\}}|��S)N�wgetz--quietz--tries�3z	--timeout�20z--output-document�-z--headerzDomU_Request: {0}z{0}:8080)r�formatr�strip)r�domu_request�output�_rrr�_do_request2s
��z*CloudStackPasswordServerClient._do_requestzGetting password�always��log_modecCs4|�d�}|dvrdS|dkrtd��|�d�|S)N�send_my_password)��saved_password�bad_requestz-Error when attempting to fetch root password.r*)r$�RuntimeError)r�passwordrrr�get_passwordGs

z+CloudStackPasswordServerClient.get_passwordN)	�__name__�
__module__�__qualname__�__doc__rr$r	�timedr.rrrrr#srcs�eZdZdZdZdZdZ�fdd�Zdd�Z			d�fd	d
�	Z	dd�Z
d
d�Zede
fdd��Zdd�Zejddd�dd��Zdd�Zedd��Z�ZS)�DataSourceCloudStackFr�x�2cs2t��|||�tj�|jd�|_d|_i|_dS)N�cs�latest)�superr�os�path�join�seed_dir�api_ver�cfg)r�sys_cfg�distro�paths��	__class__rrrZs
zDataSourceCloudStack.__init__cCs�t�d�t�d�}|r|St�d�ttj��t���|jd�}|r-|Wd�SWd�n1s7wYt�d|jj	j
�tt��|jj	�|jj
�}|�d�pYd}|Wd�S1sfwYt�d�dS)z�
        Try obtaining a "domain-name" DHCP lease parameter:
        - From systemd-networkd lease
        - From dhclient lease
        z.Try obtaining domain name from networkd leases�
DOMAINNAMEzHCould not obtain FQDN from networkd leases. Falling back to ISC dhclientzdomain-nameNzBCould not obtain FQDN from ISC dhclient leases. Falling back to %szNo dhcp leases found)�LOG�debugr�networkd_get_option_from_leasesr�NoDHCPLeaseMissingDhclientError�IscDhclient�get_key_from_latest_leaserA�dhcp_client�client_name�FileNotFoundError�get_newest_lease�fallback_interface�get)r�
domainname�domain_name�latest_leaserrr�_get_domainnamebs:

�����
� �
z$DataSourceCloudStack._get_domainnamecsnt��|||�}|r5d|jvr5t�d�|��}|r/|j�d|��}t�d|�t�||j�St�d|�|S)z�
        Returns instance's hostname / fqdn
        First probes the parent class method.

        If fqdn is requested, and the parent method didn't return it,
        then attach the domain-name from DHCP response.
        �.zFQDN requestedzObtained the following FQDN: %szNCould not determine domain name for FQDN. Fall back to hostname as an FQDN: %s)	r9�get_hostname�hostnamerFrGrUr
�DataSourceHostname�
is_default)r�fqdn�
resolve_ip�
metadata_onlyrXrRrCrrrW�s

�z!DataSourceCloudStack.get_hostnamecCs�|��}|jdkrdSt�|jd�g}t��}tj||j|jt	j
d�\}}|r1t	�d|�t|�St	�d|t
t��|��t|�S)NrFzlatest/meta-data/instance-id)�urls�max_wait�timeout�	status_cbzUsing metadata source: '%s'z>Giving up on waiting for the metadata from %s after %s seconds)�get_url_params�max_wait_seconds�uhelp�combine_url�metadata_address�time�	monotonic�wait_for_url�timeout_secondsrF�warningrG�critical�int�bool)r�
url_paramsr^�
start_time�url�	_responserrr�wait_for_metadata_service�s.
��
�	��z.DataSourceCloudStack.wait_for_metadata_servicecCs|jSr)r?�rrrr�get_config_obj�sz#DataSourceCloudStack.get_config_obj�returncCst�S)z#Check if running on this datasource)�is_platform_viablerrrr�	ds_detect�szDataSourceCloudStack.ds_detectc
CsVi}tj||jdd�r|d|_|d|_t�d|j�dS|jr3t�	�}t�d|�t
|j|�}nt��}zI|�<t
|j�}t|t�rJ|�d�n||_|jsTtd	��d
|j�d�|_|��sj	Wd�WdS|��Wd�WS1sywYWdSty�t�d|�YdSty�}zt�d
t|��WYd}~dSd}~ww)N�/)�basez	user-dataz	meta-dataz%Using seeded cloudstack data from: %sTzAttempting DHCP on: %s�dhcp-server-identifierzNo virtual router found!zhttp://Fz#Unable to obtain a DHCP lease on %sz$Failed fetching metadata service: %s)r
�read_optional_seedr=�userdata_raw�metadatarFrG�perform_dhcp_setupr�find_fallback_nicrrA�nullcontext�get_vr_address�
isinstance�dictrQ�vr_addrr,rfrs�_crawl_metadatarrk�	Exception�str)r�seed_ret�primary_nic�network_contextr��errr�	_get_data�sD


���(���zDataSourceCloudStack._get_datazCrawling metadatar%r&cCszt�|j|j�|_t�|j|j�|_t|j�}z|�	�}Wnt
y/t�t
d|j�YdSw|r;d|ddid�|_dS)Nz/Failed to fetch password from virtual router %sT�expireF)�
ssh_pwauthr-�chpasswd)r�get_instance_userdatar>rfr}�get_instance_metadatar~rr�r.r�r
�logexcrFr?)r�password_client�set_passwordrrrr��s0��
����z$DataSourceCloudStack._crawl_metadatacC�
|jdS)Nzinstance-id�r~rtrrr�get_instance_idrz$DataSourceCloudStack.get_instance_idcCr�)Nzavailability-zoner�rtrrr�availability_zones
z&DataSourceCloudStack.availability_zone)FFF)r/r0r1r�dsname�url_max_wait�url_timeoutrrUrWrsru�staticmethodrnrxr�r	r3r�r��propertyr��
__classcell__rrrCrr4Rs*,�$
r4c@seZdZdZdZdS)�DataSourceCloudStackLocalauRun in init-local using a dhcp discovery prior to metadata crawl.

    In init-local, no network is available. This subclass sets up minimal
    networking with dhclient on a viable nic so that it can talk to the
    metadata service. If the metadata service provides network configuration
    then render the network configuration for that instance based on metadata.
    TN)r/r0r1r2rrrrrr�sr�cCs>ztdd�}Wntyt�d�YdSw|dddS)Nzdata-server�PzDNS Entry data-server not foundr�)rrrFrG)�addrinforrr�get_data_server$s
�r�cCs^t�d���}|D]#}|�d�}|ddkr,ttdt|dd���}t�d|�|Sq	dS)	Nz/proc/net/route�	��00000000z<L��z"Found default route, gateway is %s)	r
�load_text_file�
splitlines�splitrrrmrFrG)�lines�line�items�gwrrr�get_default_gateway/s
�r�cCst�}|r
t�d|�|St�d�}|rt�d|�|Sttj��!t���|d�}|r;t�d|�|Wd�SWd�n1sEwYtt	��"|j
�|�}|rit�d||j
j�|Wd�SWd�n1sswYt�d�t
�S)Nz4Found metadata server '%s' via data-server DNS entry�SERVER_ADDRESSz-Found SERVER_ADDRESS '%s' via networkd_leasesr{z&Found SERVER_ADDRESS '%s' via dhclientz1Found SERVER_ADDRESS '%s' via ephemeral %s lease z$No DHCP found, using default gateway)r�rFrGrrHrrIrJrKrNrLrOrMr�)rA�latest_addressrTrrrr�<sJ�
����
���
r�rvcCs&t�d�}|st�d�dS|�t�S)Nzsystem-product-namez-system-product-name not available in dmi dataF)r�
read_dmi_datarFrG�
startswith�CLOUD_STACK_DMI_NAME)�product_namerrrrwls



rwcCst�|t�Sr)r
�list_from_depends�datasources)�dependsrrr�get_datasource_list|sr�)-�loggingr:rg�
contextlibr�socketrrr�structr�	cloudinitrrr	r
rrrdr
�
cloudinit.netr�cloudinit.net.dhcpr�cloudinit.net.ephemeralr�cloudinit.sources.helpersr�	getLoggerr/rFr�r�
DataSourcer4r�r�r�r�rnrw�DEP_FILESYSTEM�DEP_NETWORKr�r�rrrr�<module>s6
/G
0

�
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY