x[h"ddlZddlZddlZddlZddlmZmZmZddlm Z m Z eje Z GddZy)N)netsubputil)ipv4_mask_to_net_prefixipv6_mask_to_net_prefixcneZdZ ddZdZdZdZdZdZdZ dZ d Z d Z d Z d ZddZdZddZy )NicConfiguratorc||_||_||_i|_|r|j nB|jD]3}|j |j|j j<5|j|_ y)a Initialize the Nic Configurator @param nics (list) an array of nics to configure @param use_system_devices (Bool) Get the MAC names from the system if this is True. If False, then mac names will be retrieved from the specified nics. N) nics name_servers dns_suffixesmac2Name find_devicesnamemaclowerget_primary_nic _primaryNic)selfr r r use_system_devicesnics Q/usr/lib/python3/dist-packages/cloudinit/sources/helpers/vmware/imc/config_nic.py__init__zNicConfigurator.__init__ss ((     yy :14 cggmmo. : //1c|jDcgc]}|js|}}|syt|dkDr$td|Dcgc]}|jc}|dScc}wcc}w)z| Retrieve the primary nic if it exists @return (NicBase): the primary nic if exists, None otherwise Nz!There can only be one primary nicr)r primarylen RuntimeErrorr)rr primary_nicss rrzNicConfigurator.get_primary_nic1sm (,yy@CKK@ @   "3$01S1   ? "A 2sA!A!A& c>gd}tj|\}}tjdd|zdd}d}|D]^}tj||}|s|j dj }|jddd} | |j |<`y) zb Create the mac2Name dictionary The mac address(es) are in the lower case )ipaddrshowz\n\d+:  rNz3link/ether (([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})):r)rresplitsearchgrouprr) rcmdoutput_errsectionsmacPatsectionmatchrrs rrzNicConfigurator.find_devicesAs %yy~ 88Jv 6qr:G &GIIfg.E++a.&&(C==a(+D!%DMM#   &rc |jj}|jj|}|st d|jzi}|j ||j ||j||j||j||j||j||jg}|D]}|s|j|||iS)z Return the config dict needed to configure a nic @return (dict): the config dict to configure the nic @param nic (NicBase): the nic to configure zNo known device has MACADDR: %s)rrrget ValueError gen_match gen_set_name gen_wakeonlan gen_dhcp4 gen_dhcp6 gen_addresses gen_routesgen_nameserversupdate)rrrrnic_config_dict generatorsvalues rgen_one_nic_v2zNicConfigurator.gen_one_nic_v2Ss ggmmo}}  %>HI I NN3    d #   s # NN3  NN3    s # OOC  "    .E&&u- .o&&rcdd|iiS)Nr1 macaddress)rrs rr5zNicConfigurator.gen_matchos,,--rc d|iS)Nzset-namerD)rrs rr6zNicConfigurator.gen_set_namers D!!rcd|jiS)N wakeonlan)onboot)rrs rr7zNicConfigurator.gen_wakeonlanusSZZ((rc0i}|jj}|jjdk(rd}|dk7rB|jddi|js |j r|jdddii|S|jddi|S) Ndisabledmanualstaticdhcp4Tzdhcp4-overrideszuse-dnsF) bootProtor ipv4_moder=r r )rrrM bootprotos rr8zNicConfigurator.gen_dhcp4xsMM'') ==   J . I  LL'4 )  D$5$5 /)U1CDE  LL'5) * rcHi}|jr|jddi|S)Ndhcp6F) staticIpv6r=)rrrRs rr9zNicConfigurator.gen_dhcp6s& >> LL'5) * rcng}d}|j}|rR|d}|jrt|j}|jr |j |jd||j }|r<|D]7}t |j}|j |jd|9|rd|iSiS)N r/ addresses) staticIpv4netmaskrr"appendrSr) rr address_listv4_cidrv4_addrsv4v6_addrsv6v6_cidrs rr:zNicConfigurator.gen_addressess >> !Bzz1"**=uu##ruugQwi$89>>  :1"**=##ruugQwi$89 : . .Irc&g}d}|j}|r|d}|jr-|jr!|jd|jdd|jso|jrc|j rt |j }|jD]3}tj|d|d}|j||d5|j}|r|D]} t| j } |jr*| jr|jd| jd|jr[| jshtj| jd| d} |j| | jd|rd |iSiS) NrUrz 0.0.0.0/0)toviarVF)strictz::/0routes) rXrgatewaysrZrrYr ipaddress IPv4NetworkrSrgateway IPv6Network) rr route_listr\r]r^rj v4_subnetr_r`ra v6_subnets rr;zNicConfigurator.gen_routessp >> !B{{r{{!!R[[^"LM## ::5bjjAG!{{NG ) 5 5")1WI.u!I%% {G&LM N >>  1"**=;;2::%%VBJJ&GH''BJJ ) 5 5::,ay1%!I%%"+bjjA  j) )Irc*i}g}g}|jr"|jD]}|j||jr"|jD]}|j||r|jd|i|r|jd|i|rd|iSiS)Nr)rW nameservers)r rZr r=)rnameservers_dict search_listaddresses_list dns_suffix name_servers rr<zNicConfigurator.gen_nameserverss    "// / "":. /   #00 3 %%k2 3   # #X{$; <   # #[.$A B !#34 4IrNc|r&tjd|j|i}|jD]"}|j |j |$|S)z@Return the config elements that are needed to configure the nicszConfiguring the interfaces file)loggerinfo configurer r=rA)rryosfamilyethernets_dictrs rgeneratezNicConfigurator.generatesW  KK9 : NN8 $99 rs> %%   8 $yyr