3 \�me? � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZm Z m Z mZmZ ej e�ZdZdZdgZG dd� de j�ZG dd � d e�ZG d d� de�ZG dd � d �Zdd� Zdd� Zddd�Zddd�Zdd� ZeZee jffgZ dd� Z!dS )� N)� atomic_helper�net�sources�subp�utilziid-dsopennebulaZnobodyz context.shc @ sF e Zd ZdZdd� Zdd� Zdd� Zdd � Zed d� �Z dd d�Z dS )�DataSourceOpenNebulaZ OpenNebulac C s. t jj| |||� d | _tjj|jd�| _d S )NZ opennebula)r � DataSource�__init__�seed�os�path�join�seed_dir)�selfZsys_cfg�distro�paths� r �*/usr/lib/python3.6/DataSourceOpenNebula.pyr $ s zDataSourceOpenNebula.__init__c C s t jj| �}d|| j| jf S )Nz%s [seed=%s][dsmode=%s])r r �__str__r �dsmode)r �rootr r r r ) s zDataSourceOpenNebula.__str__c C s� dt i}d }d }t}d| jkr*| jjd�}| jg}|jt� � x�|D ]�}yLtjj | j�rjt || j|d�}n(|jd�r�t jt || jd�}tj||�}W nZ tk r� wDY nF tk r� } z |�W Y d d }~X n" tjk r� tjd|� Y nX |rD|}tjd|� P qDW |�sdS |d } tj| |g�} | j|jd �| jjd�g�| _| jtjk�rZdS || _|jd�| _| | _|jd �| _dS )Nzinstance-id� parseuser)�asuserz/dev)r r z%s was not mountablezfound datasource in %sF�metadataZDSMODEr znetwork-interfaces�userdataT) �DEFAULT_IID�DEFAULT_PARSEUSERZds_cfg�getr �extend�find_candidate_devsr r �isdir�read_context_disk_dirr � startswith� functools�partialr Zmount_cb�NonContextDiskDir�BrokenContextDiskDirZMountFailedError�LOG�warning�debugZ mergemanydictZ_determine_dsmoder r ZDSMODE_DISABLEDr �networkr Zuserdata_raw) r Zdefaults�resultsr r Z candidatesZcdevZpartially_applied_func�excZmdr r r � _get_data- sT zDataSourceOpenNebula._get_datac C s$ | j | jkrd}nd}d|| jf S )z/Return the subplatform metadata source details.zseed-dirzconfig-diskz%s (%s))r r )r Zsubplatform_typer r r �_get_subplatformj s z%DataSourceOpenNebula._get_subplatformc C s | j d k r| j S d S d S )N)r* )r r r r �network_configr s z#DataSourceOpenNebula.network_configFc C s. |d kr| j tjkrd}nd}tjj| ||�S )NTF)r r ZDSMODE_NETWORKr �get_hostname)r ZfqdnZ resolve_ipZ metadata_onlyr r r r0 y s z!DataSourceOpenNebula.get_hostnameN)FFF)�__name__� __module__�__qualname__Zdsnamer r r- r. �propertyr/ r0 r r r r r s =r c @ s e Zd ZdS )r% N)r1 r2 r3 r r r r r% � s r% c @ s e Zd ZdS )r&