8889841có ƒjbc@sMddlZddlZddlZddlZddlZddlZddlmZmZm Z m Z ddl m Z ddlmZddlmZddlmZejeƒZdZdefd „ƒYZd efd „ƒYZd efd „ƒYZdd„Zd„Zd„Zd„Z dd„Z!dd„Z"d„Z#dS(iÿÿÿÿN(tEphemeralIPv4Networktfind_fallback_nictget_devicelistthas_url_connectivity(tmask_and_ipv4_to_bcast_addr(t temp_utils(tutil(tStringIOs/run/systemd/netif/leasestInvalidDHCPLeaseFileErrorcBseZdZRS(s¤Raised when parsing an empty or invalid dhcp.leases file. Current uses are DataSourceAzure and DataSourceEc2 during ephemeral boot to scrape metadata. (t__name__t __module__t__doc__(((s6/usr/lib/python2.7/site-packages/cloudinit/net/dhcp.pyRstNoDHCPLeaseErrorcBseZdZRS(s'Raised when unable to get a DHCP lease.(R R R (((s6/usr/lib/python2.7/site-packages/cloudinit/net/dhcp.pyR $stEphemeralDHCPv4cBsMeZddd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(cCs(||_d|_d|_||_dS(N(tifacetNonet_ephipv4tleasetconnectivity_url(tselfRR((s6/usr/lib/python2.7/site-packages/cloudinit/net/dhcp.pyt__init__*s   cCs<|jr2t|jƒr2tjd|jƒdSn|jƒS(sUSetup sandboxed dhcp context, unless connectivity_url can already be reached.s:Skip ephemeral DHCP setup, instance has connectivity to %sN(RRtLOGtdebugt obtain_lease(R((s6/usr/lib/python2.7/site-packages/cloudinit/net/dhcp.pyt __enter__0s  cCs|jƒdS(s Teardown sandboxed dhcp context.N(t clean_network(Rt excp_typet excp_valuetexcp_traceback((s6/usr/lib/python2.7/site-packages/cloudinit/net/dhcp.pyt__exit__;scCs<|jrd|_n|js"dS|jjdddƒdS(s@Exit _ephipv4 context to teardown of ip configuration performed.N(RRRR(R((s6/usr/lib/python2.7/site-packages/cloudinit/net/dhcp.pyR?s    cCsW|jr|jSyt|jƒ}Wntk r?tƒ‚nX|sRtƒ‚n|d|_tjd|jd|jd|jdƒidd6dd6dd6dd 6d d gd 6d d6}|j|ƒ}|d s÷t|d|dƒ|d [^}]*)}\nis&Cannot parse empty dhcp lease file {0}t;t"tsoption t is1Cannot parse dhcp lease file {0}. No leases found( tretcompileRt load_filetlenRtformattfindalltsplittstriptreplacetappendtdict(t lease_filet lease_regext dhcp_leasest lease_contentRt lease_optionstline((s6/usr/lib/python2.7/site-packages/cloudinit/net/dhcp.pytparse_dhcp_lease_file¤s& $c Csõtjd|ƒtjj|dƒ}tj||ƒtjj|dƒ}tjj|dƒ}tj|tjƒs}|}ntj dddd|d gd t ƒ|d d d |d||ddg }tj |d t ƒtj ||gddddƒ}|r'tj ddjd„|DƒƒƒgSd}x¥t ddƒD]”} tj|ƒjƒ} yt| ƒ} Wntk r{nIXtj| ƒ}|dkrÄtjd| ƒtj| tjƒt|ƒStjdƒq=Wtjd| |dƒt|ƒS(s­Run dhclient on the interface without scripts or filesystem artifacts. @param dhclient_cmd_path: Full path to the dhclient used. @param interface: Name of the network inteface on which to dhclient. @param cleandir: The directory from which to run dhclient as well as store dhcp leases. @return: A list of dicts of representing the dhcp leases parsed from the dhcp.leases file or empty list. s!Performing a dhcp discovery on %sR7s dhclient.pids dhcp.leasesRtlinktsettdevtuptcaptures-1s-vs-lfs-pfs-sfs /bin/truetmaxwaititnapleng{®Gáz„?s+dhclient did not produce expected files: %ss, css!|]}tjj|ƒVqdS(N(tostpathtbasename(t.0tf((s6/usr/lib/python2.7/site-packages/cloudinit/net/dhcp.pys ôstunknowniièiskilling dhclient with pid=%ssCdhclient(pid=%s, parentpid=%s) failed to daemonize after %s secondsg$@(RRR_R`tjoinRtcopytaccesstX_OKtsubpR=twait_for_filestwarningtrangeRHRMtintt ValueErrort get_proc_ppidtkilltsignaltSIGKILLRWttimetsleepterror( tdhclient_cmd_pathRtcleandirtsandbox_dhclient_cmdtpid_fileRQtcmdtmissingtppidt_t pid_contenttpid((s6/usr/lib/python2.7/site-packages/cloudinit/net/dhcp.pyR>ÃsD  %      cCsttjt|ƒdtƒƒS(sÛParse a systemd lease file content as in /run/systemd/netif/leases/ Parse this (almost) ini style file even though it says: # This is private data. Do not parse. Simply return a dictionary of key/values.t list_values(RPt configobjt ConfigObjRtFalse(tcontent((s6/usr/lib/python2.7/site-packages/cloudinit/net/dhcp.pytnetworkd_parse_lease scCsw|dkrt}ni}tjj|ƒs1|Sx?tj|ƒD].}ttjtjj ||ƒƒƒ||R…RŒR‘R((((s6/usr/lib/python2.7/site-packages/cloudinit/net/dhcp.pyts,      " \   J