3 cjZ @ s d Z ddlZddlZddlZddlZddlZddlmZ ddlm Z m Z mZ ddlm Z mZ ejeZdZdd Zeed d dZeje dd dZdd Zdd Zdd Zdd Zdd ZG dd de jZee j ffgZ!dd Z"dS )zr This file contains code used to gather the user data passed to an instance on rootbox / hyperone cloud platforms N)IPv4Address)sourcessubputil) EventScope EventTypez /etc/hostsc C s. t jtdd} | r tjd dS tjd dS )NT)quietz5/etc/hosts exists - setting manage_etc_hosts to FalseFz=/etc/hosts does not exists - setting manage_etc_hosts to True)r load_file ETC_HOSTSLOGdebug)Zhosts r (/usr/lib/python3.6/DataSourceRbxCloud.pyget_manage_etc_hosts s r )increturnc C s t ttt| | S )N)strr int)addrr r r r increment_ip# s r )r c C s | t | dt | dgS )zReturn a list of 3 IP addresses: [addr, addr + 2, addr + 3] @param addr: an object that is passed to IPvAddress @return: list of strings )r )r r r r get_three_ips' s r c C s t j dg| S )z Uses the preferred cloud-init subprocess def of subp.subp and runs arping. Breaking this to a separate function for later use in mocking and unittests Zarping)r )cmdr r r _sub_arp4 s r c C s d}|j d krd}xh| D ]`}ytdd ||d |d g W q tjk rv } ztjd|d |d | W Y d d }~X qX qW d S )Nz-S almalinuxfedoracentos cloudlinuxrhelz-sz-c2sourcedestinationz&Failed to arping from "%s" to "%s": %s)r r r r r )namer r ZProcessExecutionErrorr Zwarning)itemsdistroZsource_paramitemerrorr r r gratuitous_arp= s r( c C s t tjdtjd } | s dS x| D ]z}y"tj|tdddgd}|rJ|S W q& tk r| } z|jtjkrl W Y dd}~X q& tjk r tj t d | Y q&X