3 \�me�+ � @ s� d dl Z d dlZd dlmZmZmZ d dlmZmZ d dl m Z d dlmZ d dl mZ e je�ZdZdZd eiZd!Zd"Zd#Zedd� eD ��ZG dd� dejej�Zdd� Zdd� Zd$dd�Zdd� Z d%dd�Z!eZ"eej#ffgZ$dd � Z%dS )&� N)�sources�subp�util)� EventScope� EventType)�eni)�get_ibm_platform)� openstackziid-dsconfigdrive�passzinstance-id�vfat�iso9660�config-2�CONFIG-2�sr�cdc c s* | ]"}t d d�D ]}d||f V qqdS )r � z /dev/%s%sN)�range)�.0�z�i� r �+/usr/lib/python3.6/DataSourceConfigDrive.py� <genexpr> s r c sr e Zd ZdZejejejej ej hiZ� fdd�Zdd� Z dd� Zdd � Zed d� �Zedd � �Zdd� Z� ZS )�DataSourceConfigDriveZConfigDrivec s\ t t| �j|||� d | _tjj|jd�| _d | _d | _ d | _ tj| _ d | _d | _i | _d S )NZconfig_drive)�superr �__init__�source�os�path�join�seed_dir�version�ec2_metadata�_network_configr �UNSET�network_json�network_eni� known_macs�files)�self�sys_cfg�distro�paths)� __class__r r r / s zDataSourceConfigDrive.__init__c C s0 t jj| �}d|| j| jf }|d| j 7 }|S )Nz%s [%s,ver=%s]z[source=%s])r � DataSource�__str__�dsmoder! r )r) �rootZmstrr r r r/ ; s zDataSourceConfigDrive.__str__c C s� d }i }i }xX| j dfD ]J}tjj|�s*qyt|�}|}P W q tjk r` tjt d|� Y qX qW |�s| j jd�}x�t|d�D ]�}d }tj � r�|jd�r�d}ytj|t|d�}|}W nN tjk r� Y n: tjk r� Y n& tjk �r tjt d|� Y nX |r�P q�W |�sd S |jd i �}tj|tg�}| j|jd�| jjd�|d d k�rbtjnd g�| _| jtjk�r~d S t| j�}|d } || k�r�t|| j| jtjkd� | jtjk�r�t jd| | j� d S || _|| _ |jd�| _!|jd�| _"|d | _#| j$j%|jdi �� |jd�} | | _&ytj'| �| _(W n6 t)k �rl } zt j*d|� d | _(W Y d d }~X nX |jd�}|| _+ytj'|�| _,W n6 t)k �r� } zt j*d|� d | _,W Y d d }~X nX |jd�| _-|jd�| _.dS )Nz /config-drivez#Failed reading config drive from %sZdatasource_list)�dslistz/dev/cdZcd9660)�mtypezBroken config drive: %sF�metadatar0 r! � zinstance-id)r+ �networkz&%s: not claiming datasource, dsmode=%szec2-metadataZuserdatar( Z vendordataz"Invalid content in vendor-data: %sZvendordata2z#Invalid content in vendor-data2: %s�network_configZnetworkdataT)/r r r �isdir�read_config_driver �NonReadabler �logexc�LOGr* �get�find_candidate_devsZis_BSD� startswithZmount_cbZMountFailedErrorZBrokenMetadataZ mergemanydict�DEFAULT_METADATAZ_determine_dsmodeZds_cfgr ZDSMODE_PASSr0 ZDSMODE_DISABLED�get_previous_iidr, � on_first_bootr+ �debugr r4 r"