ó ô‰Yc@siddlZddlZddlZddlZddlZddlmZddlmZ ddlm Z e j e ƒZ d„Zd„Zd„Zd„Zd „Zd „Zd „Zd „Zd „Zd„Zd„Zd„Zd„Zed„Zdd„Zdeded„Z d„Z!ej"d„ƒZ#d„Z$d„Z%d„Z&d„Z'd„Z(dS(iÿÿÿÿN(t ResolvConf(tlog(tutilcCs6tjdƒ}|j|ƒr.|jddƒS|SdS(Ns eth[0-9]+tthtn(tretcompiletmatchtreplace(tdevnametdevice((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pyttranslate_devnamescCs6tjdƒ}|j|ƒr.|jddƒS|SdS(Nsen[0-9]+Rtnt(RRRR(R R ((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pytlogical_adpt_name'scCs£t||ƒdddg}|rs|dkrI|jdd|gƒqs|dkrs|jdd |gƒqsntj|d td d d gƒtjdƒdS(Ns/usr/sbin/chdevs-ltinet0tipv4s-aroute=snet,-hopcount,0,,0,tipv6s-arout6=snet,-hopcount,0,,,::,tcapturetrcsiii(t del_routetextendRtsubptFalsettimetsleep(tnetworktroutetcmd((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pyt add_route/s   cCsòt|ƒ}|dk rîdddg}|dkrd||jdƒdkrd|jd|dƒn=|d kr¡||jdƒd kr¡|jd |dƒnt|ƒd krîtj|d ttj dƒdtj ƒt j dƒqîndS(Ns/usr/sbin/chdevs-lRRt,is -adelroute="s"Ris -adelrout6="itstdouttwtstderri( t get_routetNonetsplittappendtlent subprocesstcalltopentostdevnulltSTDOUTRR(RRt route_outR((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pyRAs  %%(cCsš|dkr*dddddddg}n*|d krTddddd ddg}ntj|ƒ\}}tjd ƒ|jƒ}t|ƒr’|SdSdS( NRs/usr/sbin/lsattrs-ElRs-aRs-FtvalueRtrout6i(RRRRtstripR%R"(RRtoutterr((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pyR!Qs     cCs:ddddd|g}tj|dtƒt|ƒdS(Ns/usr/sbin/chrctcps-ct autoconf6s-fs interface=R(RRRtstart_autoconf6(t device_nameR((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pytenable_autoconf6ascCs&dddg}tj|dtƒdS(Ns/usr/sbin/chrctcps-dR2R(RRR(R((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pytdisable_autoconf6hscCsA|dkrddg}ndd|g}tj|dtƒdS(Ntanys/usr/sbin/autoconf6s-As-iR(RRR(R4R((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pyR3ns cCs)ddddg}tj|dtƒdS(Ns/usr/sbin/chrctcps-Ss-as ndpd-hostR(RRR(R((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pytenable_ndpd_hostwscCs)ddddg}tj|dtƒdS(Ns/usr/sbin/chrctcps-Ss-ds ndpd-hostR(RRR(R((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pytdisable_ndpd_host}scCs)ddddg}tj|dtƒdS(Ns/usr/sbin/chrctcps-Ss-atdhcpcdR(RRR(R((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pyt enable_dhcpcdƒscCs)ddddg}tj|dtƒdS(Ns/usr/sbin/chrctcps-Ss-dR:R(RRR(R((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pytdisable_dhcpcd‰scCsätj|d|ƒtj|dƒ|jdƒrStj|d|jdƒƒn|dkr‘|jdƒr¡tj|d|jdƒƒq¡ntj|dƒ|jd ƒrÐtj|d |jd ƒƒntj|d ƒdS( Ns interface %s s{ tnetmasks option 1 %s ten0tgateways option 3 %s s reject 3 taddresss option 50 %s s} (Rt append_filetget(ttmpft interfacetinfo((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pyt update_dhcp–s  # c Cs‹d}d}d}|dk r‡t|dƒU}tjƒ@}d|}xÞ|jƒD]Ð} |tkr{tj|| ƒqV|dkrª| jdƒ rªtj|| ƒqV|dkrÎ| jdƒrÎd}qV|dkrûtj d| j ƒƒrûd}qV|dkrVt |||ƒd}d }qVqVW|tkrIt |||ƒn|dkrht |||ƒntj ||ƒWdQXWdQXndS( Ns/etc/dhcpcd.iniisr+s %s/dhcpcd.inis interface it{ii( R"R(Rttempdirt readlinesRRAt startswithRRR/RFtcopy( RDREtcreatetinfileteattupdatedtfttmpdRCtline((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pyt config_dhcp¬s2    $     cCsždg}g}|r2|jdƒ|j|ƒn||}tj|ƒ\}}g}x@|jƒD]2}|jƒjƒd}|rd|j|ƒqdqdW|S(s: find devices matching given criteria (via lsdev) s/usr/sbin/lsdevs-Cli(R$RRt splitlinesR/R#(tpatht lsdev_cmdtoptionsRR0t_errtentriesRR((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pytfind_devs_withÌs   c Csêtƒ}tjƒÏ}t}d|} ||krE||d} n>| |krb|| d} n!yédg} g} |rŠ| jdƒn | jdƒ|r­| jdƒn| rÒ| jddj| ƒgƒn|rî| jd |gƒnd | kr| jd ƒ| j| ƒn | j|ƒ| j|ƒtj| ƒ|}|} Wn5tt fk r‚} tj d ||| fƒ‚nX| j d ƒsŸ| d 7} nt |ƒ3|dkrÇ|| ƒ}n|| |ƒ}|SWdQXWdQXdS(sË Mount the device, call method 'callback' passing the directory in which it was mounted, then unmount. Return whatever 'callback' returned. If data != None, also pass data to callback. s/dev/t mountpoints/usr/sbin/mounttrwtrotsyncs-oRs-ts/cds-vcdrfss#Failed mounting %s to %s due to: %st/N(tmountsRRHRR$RtjoinRtIOErrortOSErrortMountFailedErrortendswitht unmounterR"(R tcallbacktdataR\tmtypeR^tmountedRQtumountR R[tmountcmdt mountoptstexctret((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pytmount_cbàsJ                c Cs!i}yøtjdƒ\}}|jƒ}d}xÁ|D]¹}yntj||ƒ}|jdƒ}|jdƒ}|jdƒ} |jdƒ} |jdƒjdƒd } Wn q7nX|jd d ƒ}i| d 6|d 6| d6| d6||}y|j|ƒWqjtk r§tj td|ƒqjXqjWn|rxI|D]>}y|j |ƒWq¼tk rùtj td|ƒq¼Xq¼Wnt ||ƒdS(Ns/Failed at parsing %s creating an empty instancetsFailed at adding nameserver %ss!Failed at adding search domain %s( RRt load_filetparseRbtLOGREtadd_nameservert ValueErrortlogexctadd_search_domainRƒ(Rt dns_serverstsearch_serversR‚ts((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pytupdate_resolve_conf_fileHs(      cCstj|ƒdS(N(Rtdel_file(R((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pytremove_resolve_conf_filebscCs't|dƒ}|dkrdS|SdS(NR=t-(t get_if_attrR"(RDR=((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pytget_maskfs cCs_tjdd|d|ddgdddgƒ\}}| sM|dd krQdS|jƒSdS( Ns/usr/sbin/lsattrs-Els-as-FR-Riiÿs (RRR"R/(RDtattrt lsattr_outRX((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pyR“rs6()R)Rt contextlibR&Rt%cloudinit.distros.parsers.resolv_confRt cloudinitRtloggingRt getLoggert__name__R‡R R RRR!R5R6R3R8R9R;R<RFtTrueRSR"RZRRpR`tcontextmanagerRfRƒRR‘R”R“(((sG/opt/freeware/lib/python2.7/site-packages/cloudinit/distros/aix_util.pyts>                 7 !