3 \�me� � @ sh d dl Z d dlmZmZmZmZmZ d dlmZ d dlm Z d dlmZ e j e�ZG dd� dej�ZdS )� N)�distros�helpers�net�subp�util)�PackageList)� rhel_util)�PER_INSTANCEc @ s� e Zd ZdZdZdZdZdeed�iZdZdd � Z d"d d�Z dd � Zd#dd�Ze d�dd�Zdd� Zdd� Zd$dd�Zdd� Zdd� Zd%dd�Zd d!� ZdS )&�Distroz /etc/hostnamez/etc/systemd/network/z/etc/locale.confz/etc/systemd/resolved.confZnetworkd)Zresolv_conf_fn�network_conf_dirTc C s0 t jj| |||� tj|�| _d| _dg| _d S )NZphoton� systemctl)r r �__init__r ZRunners�_runnerZosfamilyZinit_cmd)�self�nameZcfg�paths� r �/usr/lib/python3.6/photon.pyr s zDistro.__init__c C sn t jd|� y8tj||d�\}}|r<t jd||� d||fS d||fS tjk rh tjt d|� dS X d S )NzAttempting to run: %s)�capturez(Running %s resulted in stderr output: %sTFzCommand %s failed)TNN)�LOG�debugr �warningZProcessExecutionErrorr Zlogexc)r �cmdr �out�errr r r �exec_cmd( s zDistro.exec_cmdc C s: d}| j j|d�}tjd||� |s,tj� S tjd� d S )N�disable_fallback_netcfgTz%s value is: %szJSkipping generate_fallback_config. Rely on PhotonOS default network config)�_cfg�getr r r �generate_fallback_config�info)r �keyr r r r r 6 s zDistro.generate_fallback_configNc C s6 |s | j }d|i}tj||� dddg}| j|� d S )NZLANGr Zrestartzsystemd-localed)�systemd_locale_conf_fn�rhutilZupdate_sysconfig_filer )r ZlocaleZout_fnZ locale_cfgr r r r �apply_localeD s zDistro.apply_locale)�pkglistc C s | j d|d� d S )NZinstall)�pkgs)�package_command)r r% r r r �install_packagesV s zDistro.install_packagesc C s� |r|j d�rtj||� ndd }tj| jdd�}|rP| jddt|�g�\}}}n| jdddt|�g�\}}}|r�tjd||f� d S )Nz/previous-hostname�create_hostname_fileTZhostnamectlzset-hostnamez--transientz3Error while setting hostname: %s Given hostname: %s) �endswithr Z write_fileZget_cfg_option_boolr r �strr r )r �hostname�filename�retr) �_outr r r r �_write_hostnameZ s$ zDistro._write_hostnamec C s | j | j�}| j|fS )N)�_read_hostname�systemd_hostname_conf_fn)r Zsys_hostnamer r r �_read_system_hostnamex s zDistro._read_system_hostnamec C s@ |r|j d�rtj|�j� S | jddg�\}}}|r<|j� S |S )Nz/previous-hostnamer, z-f)r* r Z load_file�stripr )r r- �defaultZ_retr Z_errr r r r1 | s zDistro._read_hostnamec C s dS )Nz 127.0.1.1r )r r r r �_get_localhost_ip� s zDistro._get_localhost_ipc C s t j|| j|�d� d S )N)�tzZtz_file)r Zset_etc_timezoneZ _find_tz_file)r r7 r r r �set_timezone� s zDistro.set_timezonec C s� |sg }ddg}|r*t |t�r*|j|� n|rBt |t�rB|j|� |j|� tjd|�}|j|� | j|�\}}}|r�tj d|� d S )NZtdnfz-yz%s-%sz#Error while installing packages: %s) � isinstancer+ �append�list�extendr Zexpand_package_listr r �error) r Zcommand�argsr&