File manager - Edit - /usr/lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceCloudStack.cpython-310.pyc
Back
o o@�d� � @ s� d dl Z d dlZd dlmZmZmZ d dlmZ d dlm Z d dlmZmZ d dlm Z d dlmZ d dlmZ d d lmZ e �e�ZG d d� d�ZG dd � d ej�Zdd� Zdd� Zdd� ZeejejffgZdd� Z dS )� N)�gaierror�getaddrinfo� inet_ntoa)�pack)�log)�sources�subp)� url_helper)�util)�dhcp)�ec2c @ s( e Zd ZdZdd� Zdd� Zdd� 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 c C s || _ d S �N)�virtual_router_address)�selfr � r �H/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceCloudStack.py�__init__* � z'CloudStackPasswordServerClient.__init__c C s: 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�_r r r �_do_request- s ��z*CloudStackPasswordServerClient._do_requestc C s4 | � d�}|dv rd S |dkrtd��| � d� |S )N�send_my_password)� �saved_password�bad_requestz-Error when attempting to fetch root password.r! )r �RuntimeError)r �passwordr r r �get_passwordB s z+CloudStackPasswordServerClient.get_passwordN)�__name__� __module__�__qualname__�__doc__r r r% r r r r r s r c @ sL e Zd ZdZdZdZdd� Zdd� Zdd � Zd d� Z dd � Z edd� �ZdS )�DataSourceCloudStack� CloudStack�x �2 c C sX t j�| |||� tj�|jd�| _d| _t� | _ | j s t d��d| j f | _i | _d S )N�cs�latestzNo virtual router found!z http://%s/) r � DataSourcer �os�path�join�seed_dir�api_ver�get_vr_address�vr_addrr# �metadata_address�cfg)r �sys_cfg�distro�pathsr r r r T s zDataSourceCloudStack.__init__c C s� | � � }|jdkrdS t�| jd�g}t�� }tj||j|jtj d�\}}|r1t� d|� t |�S t�d|tt�� | �� t |�S )Nr Fzlatest/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_urlr8 �time�wait_for_url�timeout_seconds�LOG�warning�debug�critical�int�bool)r � url_paramsr= � start_time�url� _responser r r �wait_for_metadata_service` s. �� � ��z.DataSourceCloudStack.wait_for_metadata_servicec C s | j S r )r9 �r r r r �get_config_obj s z#DataSourceCloudStack.get_config_objc C s i }t j|| jd d�r|d | _|d | _t�d| j� dS zV| �� s'W dS t�� }t � | j| j�| _t � | j| j�| _t�dtt�� | �� t| j�}z|�� }W n tyg t �td | j� Y W dS w |rsd|d did�| _W dS ty� t �td| j� Y dS w ) N�/)�basez user-dataz meta-dataz%Using seeded cloudstack data from: %sTFz)Crawl of metadata service took %s secondsz/Failed to fetch password from virtual router %s�expire)� ssh_pwauthr$ �chpasswdz(Failed fetching from metadata service %s)r �read_optional_seedr4 �userdata_raw�metadatarH rJ rR rE r �get_instance_userdatar5 r8 �get_instance_metadatarL r r7 r% � Exception�logexcr9 )r �seed_retrO �password_client�set_passwordr r r � _get_data� s\ ��� ������zDataSourceCloudStack._get_datac C � | j d S )Nzinstance-id�r\ rS r r r �get_instance_id� r z$DataSourceCloudStack.get_instance_idc C re )Nzavailability-zonerf rS r r r �availability_zone� s z&DataSourceCloudStack.availability_zoneN) r&