oB]c@sddlmZmZddlZddlmZddlmZddlmZddl m Z ej Z igd6gd6d d 6e d 6Zd Zd Zd dZdZdZdZdZdZddZdS(i(tcopytdeepcopyN(tlog(tnet_prefix_to_ipv4_mask(tutil(t SimpleTabletipv4tipv6tthwaddrtupc Csri}d}x_t|jD]K\}}tjd|}|r|jdjjdd}|jdjd}igd6gd6d d 6td |kod |kd 6||[^:]+):\s+<(?P\S+)>\s+.*tdevt@itflagst,RRRR tUPtLOWER_UPR tinet6s/\s+inet6\s(?P\S+)\sscope\s(?P\S+).*s*Could not parse ip addr show: (line:%d) %stinetsH\s+inet\s(?P\S+)(\sbrd\s(?P\S+))?\sscope\s(?P\S+).*tcidr4t/t32tiptbcasttmasktscopetlinks-\s+link/(?P\S+)\s(?P\S+).*t link_typetetherN(tNonet enumeratet splitlinestretmatchtgrouptlowertsplittbooltLOGtwarningtappendt groupdicttpopt partitionR( t ipaddr_outtdevstdev_nametnumtlinetmR R!Rtaddrt_tprefix((s5/usr/lib/python2.7/site-packages/cloudinit/netinfo.pyt_netdev_info_iproutes` ")            cCsi}x|jD]}t|dkr1qn|ddkr|jd}|jdrm|d }n||krtt||(s R6(RtlenR$tendswithRtDEFAULT_NETDEV_INFOR#tstriptTrueR tsearchtrangeR(tlstript startswithR!R"(t ifconfig_dataR-R0tcurdevttokstitaddr6tres((s5/usr/lib/python2.7/site-packages/cloudinit/netinfo.pyt_netdev_info_ifconfig^sZ  "&!&! ''&&")csi}tjdrBtjdddg\}}t|}nRtjdrtjddgdddg\}}t|}n tjd |d kr|Sttt fd d fd |d ||S(NRR2tshowtifconfigs-atrcsiis>Could not print networks: missing 'ip' and 'ifconfig' commandsRcst|tr|j}n0t|ttfrBt|}n tdxL|D]D\}}||krz|||R tsub( t route_dataRxRyR0RHR{t route_data6R~R((s5/usr/lib/python2.7/site-packages/cloudinit/netinfo.pyt_netdev_route_info_netstatsp     "            .   "        cCsi}tjdrEtjddddg\}}t|}nXtjdrtjddddgd d d g\}}t|}n tjd |S( NRs-oRnRTRs--routes --numerics--extendROiis;Could not print routes: missing 'ip' and 'netstat' commands(RR^R_RRR&R'(Rxt iproute_outRat route_out((s5/usr/lib/python2.7/site-packages/cloudinit/netinfo.pyt route_infoXs!'c Csg}d}ytd|}WnAtk rb}|jtjdjdt|ddnX|smdSdd d d d d g}t|}xt|j D] \}}xR|j dD]A}|j ||d|d|d|j d||dfqWxN|j dD]=}|j ||d|d||j d||dfqWt |j dt |j ddkr|j ||d||||dfqqW|j } t t| jdt } tjdd| } |j| | gdj|dS(Nt.R`s Net device info failed ({error})terrort!iPs tDevicetUptAddresstMasktScopes Hw-AddressRR RRRR RR;iRZsNet device infot+(Rct ExceptionR(RtcentertformattstrRtsortedRRtgettadd_rowR=t get_stringtmaxRtextendRu( tlinesR`tnetdevRstfieldsttblR RVR2tnetdev_stmax_lentheader((s5/usr/lib/python2.7/site-packages/cloudinit/netinfo.pytnetdev_pformatis< !!. c Csbg}y t}WnUtk rj}|jtjdjdt|ddtjtd|nX|j drXddd d d d g}t |}xbt |j dD]K\}}t|}|j ||d |d|d|d|dgqW|j }tt|jdt} tjdd| } |j| |gn|j drQddd d d g} t | } xqt |j dD]Z\}}t|}|ddkrqn| j ||d |d|d|dgqW| j }tt|jdt} tjdd| } |j| |gndj|dS(NsRoute info failed ({error})RRiPsRoute info failed: %sRtRouteRtGatewaytGenmaskt InterfacetFlagsRdReRfRgR RZsRoute IPv4 infoRRRsRoute IPv6 infos (RRR(RRRRtlogexcR&RRRRRR=RRRRu( RRxRst fields_v4ttbl_v4tntrtroute_idtroute_sRRt fields_v6ttbl_v6((s5/usr/lib/python2.7/site-packages/cloudinit/netinfo.pyt route_pformatsJ    "     "   s ci-info: cCsg}tj}|rFx5|D]}|jd||fq"Wn |j|tj}|rx5|D]}|jd||fqoWn |j|dj|S(Ns%s%ss (RRR(RRRu(R4Rt netdev_linesR0t route_lines((s5/usr/lib/python2.7/site-packages/cloudinit/netinfo.pyt debug_infos    (RRR t cloudinitRtloggingtcloudinit.net.network_stateRRtcloudinit.simpletableRt getLoggerR&tFalseR?R5RLRcRRRRRR(((s5/usr/lib/python2.7/site-packages/cloudinit/netinfo.pyt s(    ? 8 ' R I  " )