a '¡Dg«§ã @s6ddlZddlZddlZddlZddlZddlZddlmZmZm Z m Z m Z ddl m Z mZddlmZe e¡ZdZdZgd¢Zgd¢Ze d ¡fd d „Zd d „Zd¡dd„Zd¢dd„Zd£dd„Zdd„Zdd„Zdd„Z dd„Z!dd„Z"dd „Z#d!d"„Z$d#d$„Z%ej&dd%�e'd&œd'd(„ƒZ(ej&dd%�e)d&œd)d*„ƒZ*e+e'd+œd,d-„Z,d¤d.d/„Z-d0d1„Z.d2d3„Z/d¥e'd&œd4d5„Z0d¦d6d7„Z1d§d8d9„Z2d:d;„Z3dd?„Z5d@dA„Z6dBdC„Z7GdDdE„dEe8ƒZ9dFdG„Z:e e+d&œdHdI„Z;e e+d&œdJdK„Ze e+d&œdPdQ„Z?e e+d&œdRdS„Z@e e+d&œdTdU„ZAe e+d&œdVdW„ZBd¨e eCd&œdXdY„ZDdZd[„ZEd©d]d^„ZFdªd`da„ZGd«dbdc„ZHddde„ZIdfdg„ZJeCd&œdhdi„ZKe+e e+djœdkdl„ZLeCd&œdmdn„ZMeCd&œdodp„ZNeCd&œdqdr„ZOeCd&œdsdt„ZPd¬e'e'e'e'e'e'e'e)duœdvdw„ZQedxe e e+e+e+e+fddyœdzd{„ZRd|d}„ZSee+d~œdd€„ZTe+e'd�œd‚dƒ„ZUe+e'd�œd„d…„ZVe+e'd�œd†d‡„ZWe+e'd�œdˆd‰„ZXe+e'd�œdŠd‹„ZYe+e'd�œdŒd�„ZZe+e+e'dŽœd�d�„Z[e+e+e'd‘œd’d“„Z\e'd&œd”d•„Z]e+d&œd–d—„Z^e_d&œd˜d™„Z`e_d&œdšd›„Zae+e+e+dœœd�dž„ZbGdŸd „d ecƒZddS)­éN)ÚCallableÚDictÚListÚOptionalÚTuple)ÚsubpÚutil)ÚIproute2z/sys/class/net/Zeth0)Údhcp6Z ipv6_slaaczipv6_dhcpv6-statelesszipv6_dhcpv6-stateful) ú ovs-vsctlz--formatZcsvz --no-headingsz --timeoutZ10z --columnsÚnameÚfindÚ interfacez type=internalz([0-9]+)cCsdd„t ||¡DƒS)aDSorting for Humans: natural sort order. Can be use as the key to sort functions. This will sort ['eth0', 'ens3', 'ens10', 'ens12', 'ens8', 'ens0'] as ['ens0', 'ens3', 'ens8', 'ens10', 'ens12', 'eth0'] instead of the simple python way which will produce ['ens0', 'ens10', 'ens12', 'ens3', 'ens8', 'eth0'].cSs$g|]}| ¡rt|ƒn| ¡‘qS©)ÚisdigitÚintÚlower)Ú.0Útextrrú:/usr/lib/python3.9/site-packages/cloudinit/net/__init__.pyÚ 2sÿz$natural_sort_key..)ÚreÚsplit)ÚsZ_nsrerrrÚnatural_sort_key+s þrcCstS)z3Simple function to return the global SYS_CLASS_NET.)Ú SYS_CLASS_NETrrrrÚget_sys_class_path8srÚcCstƒ|d|S)Nú/)r©ÚdevnameÚpathrrrÚ sys_dev_path=sr"c Cst||ƒ}zt |¡}WnŠttfy¢}znt|ddƒ} | tjtjfvrd|durd||ƒWYd}~S| tj fvrŒ|durŒ||ƒWYd}~S‚WYd}~n d}~00|  ¡}|dur¸|Sz ||WSt �y}z8|durð||ƒWYd}~St   d||¡‚WYd}~n d}~00dS)NÚerrnoz5Found unexpected (not translatable) value '%s' in '%s)r"rZload_text_fileÚOSErrorÚIOErrorÚgetattrr#ÚENOENTÚENOTDIRÚEINVALÚstripÚKeyErrorÚLOGÚdebug) r r!Ú translateÚ on_enoentÚ on_keyerrorÚ on_einvalZdev_pathÚcontentsÚeZe_errnorrrÚ read_sys_netAs4    ýr4cCsdd„}t||||||d�S)NcSsdS©NFr)r3rrrÚ on_excp_falsegsz(read_sys_net_safe..on_excp_false)r0r/r1r.)r4)ÚifaceÚfieldr.r6rrrÚread_sys_net_safefsúr9cCs:t||ƒ}|durdSz t|ƒWSty4YdS0dSr5)r9rÚ ValueError)r7r8ÚvalrrrÚread_sys_net_intts   r<cCsddddœ}t|d|d�S)NTF)ÚupÚunknownÚdownÚ operstate)r.©r9)r r.rrrÚis_up~s rBcCstj t|dƒ¡S)NÚbridge©Úosr!Úexistsr"©r rrrÚ is_bridge†srHcCstj t|dƒ¡S)NÚbondingrDrGrrrÚis_bondŠsrJcCs t|dd�}tj |¡r|SdS)z8Return the master path for devname, or None if no masterÚmaster©r!N)r"rEr!rFrrrrÚ get_masterŽs  rMcCsHt|ƒ}|durdStj |d¡}tj |d¡}tj |¡pFtj |¡S)z@Return a bool indicating if devname's master is a bridge or bondNFrIrC)rMrEr!ÚjoinrF)r Ú master_pathZ bonding_pathZ bridge_pathrrrÚmaster_is_bridge_or_bond–s rPcCs,t|ƒ}|durdSt|dd�}tj |¡S)z;Return a bool indicating if devname's master is openvswitchNFzupper_ovs-systemrL)rMr"rEr!rF)r rOZovs_pathrrrÚmaster_is_openvswitch s  rQcCst|dƒdkS)NÚtypeÚ32rArGrrrÚis_ib_interface©srT)Úmaxsize)ÚreturncCs tt d¡ƒ}|st d¡|S)zDReturn a bool indicating if Open vSwitch is installed in the system.r z/device/features.rzdevice/features)r4Ú Exception©r ZfeaturesrrrÚget_dev_featuresés  rlcCs(t|ƒ}|rt|ƒdkrdS|ddkS)zÄReturn True if VIRTIO_NET_F_STANDBY bit (62) is set. https://github.com/torvalds/linux/blob/ 089cf7f6ecb266b6a4164919a2e69bd2f938374a/ include/uapi/linux/virtio_net.h#L60 é@Fé>Ú1)rlÚlenrkrrrÚhas_netfail_standby_featureósrqcCs<t|ƒdurdS|dur t|ƒ}|dkr,dSt|ƒs8dSdS)zòA device is a "netfail master" device if: - The device does NOT have the 'master' sysfs attribute - The device driver is 'virtio_net' - The device has the standby feature bit set Return True if all of the above is True. NFÚ virtio_netT©rMrdrqrgrrrÚis_netfail_masters rtcCstt|dd�}tj |¡sdS|dur,t|ƒ}|dkr8dStj tj |¡¡}t|ƒ}|dkr`dSt|ƒ}|spdSdS)a7A device is a "netfail primary" device if: - the device has a 'master' sysfs file - the device driver is not 'virtio_net' - the 'master' sysfs file points to device with virtio_net driver - the 'master' device has the 'standby' feature bit set Return True if all of the above is True. rKrLFNrrT)r"rEr!rFrdÚbasenameÚrealpathrq)r rhZmaster_sysfs_pathZmaster_devnameZ master_driverZmaster_has_standbyrrrres  recCs<t|ƒdurdS|dur t|ƒ}|dkr,dSt|ƒs8dSdS)zçA device is a "netfail standby" device if: - The device has a 'master' sysfs attribute - The device driver is 'virtio_net' - The device has the standby feature bit set Return True if all of the above is True. NFrrTrsrgrrrrf9s rfcCst|dƒ}|r|dvrdSdS)a° /* interface name assignment types (sysfs name_assign_type attribute) */ #define NET_NAME_UNKNOWN 0 /* unknown origin (not exposed to user) */ #define NET_NAME_ENUM 1 /* enumerated by kernel */ #define NET_NAME_PREDICTABLE 2 /* predictably named by the kernel */ #define NET_NAME_USER 3 /* provided by user-space */ #define NET_NAME_RENAMED 4 /* renamed by user-space */ Úname_assign_type)Ú3Ú4TFrA)r rwrrrÚ is_renamedQs  rzcCstt|dƒƒ}d| ¡vS)NÚueventz DEVTYPE=vlan)Ústrr9r^)r r{rrrÚis_vlan`sr}cCs0d}t|dƒ}tj |¡r,tj t |¡¡}|S)z8Return the device driver for net device named 'devname'.Nz device/driver)r"rEr!ÚislinkruÚreadlink)r rhZ driver_pathrrrrdes   rdcCst|dƒ}|durdS|S)z;Return the device id string for net device named 'devname'.z device/deviceFNrA)r Zdev_idrrrÚ device_devidps r€c Cslt ¡st ¡rttƒ ¡ƒSzt tƒ¡}Wn8t yf}z |j t j krPg}n‚WYd}~n d}~00|S©N) rÚ is_FreeBSDÚis_DragonFlyBSDÚlistÚget_interfaces_by_macÚvaluesrEÚlistdirrr$r#r')Údevsr3rrrÚget_devicelistys r‰c@seZdZdZdS)Ú ParserErrorz6Raised when a parser has issue parsing a file/content.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrЇsrŠcCs |rt|tƒsdS| d¡dkS)NFÚconfigZdisabled)Ú isinstanceÚdictÚget)ÚcfgrrrÚis_disabled_cfg‹sr”cCs6t ¡st ¡rtƒSt ¡s&t ¡r,tƒStƒSdS)zqGet the list of network interfaces viable for networking. @return List of interfaces, sorted naturally. N)rr‚rƒÚfind_candidate_nics_on_freebsdÚ is_NetBSDÚ is_OpenBSDÚ(find_candidate_nics_on_netbsd_or_openbsdÚfind_candidate_nics_on_linuxrrrrÚfind_candidate_nics‘s ršcCs6t ¡st ¡rtƒSt ¡s&t ¡r,tƒStƒSdS)z.Get the name of the 'fallback' network device.N)rr‚rƒÚfind_fallback_nic_on_freebsdr–r—Ú&find_fallback_nic_on_netbsd_or_openbsdÚfind_fallback_nic_on_linuxrrrrÚfind_fallback_nicžs ržcCsttƒ ¡td�S)zmGet the names of the candidate network devices on NetBSD/OpenBSD. @return list of sorted interfaces ©Úkey)Úsortedr…r†rrrrrr˜¨sr˜cCstƒ}|r|dSdS)zfGet the 'fallback' network device name on NetBSD/OpenBSD. @return default interface, or None rN)r˜©Únamesrrrrœ°srœcCs4t gd¢¡\}}| ¡}|r"|Sttƒ ¡td�S)zgGet the names of the candidate network devices on FreeBSD. @return List of sorted interfaces. )Úifconfigz-lz-uÚetherrŸ)rrr¡r…r†r)ÚstdoutÚ_stderrr†rrrr•¼s r•cCstƒ}|r|dSdS)z_Get the 'fallback' network device name on FreeBSD. @return List of sorted interfaces. rN)r•r¢rrrr›Ësr›c CsFdt ¡vrt d¡n,dd„tƒDƒ}t|ƒrDt d|¡t ¡g}g}tddddddd�D]˜\}}}}|d krvq`| d ¡rŽt d |¡q`t |d ƒ}|r¨|  |¡q`t d |¡t |dƒ}|rÎ|  |¡q`t |dƒ}|dvrì|  |¡q`t d|¡q`g}||fD]:} t | t d�} t| v�r6|  t¡|  dt¡|| 7}�q|S)zeGet the names of the candidate network devices on Linux. @return List of sorted interfaces. z net.ifnames=0z9Stable ifnames disabled by net.ifnames=0 in /proc/cmdlinecSs g|]}|dkrt|ƒs|‘qS)Úlo)rz)rZdevicerrrrßsþz0find_candidate_nics_on_linux..z4Found unstable nic names: %s; calling udevadm settleFT)Úfilter_openvswitch_internalÚ2filter_slave_if_master_not_bridge_bond_openvswitchÚ filter_vlanÚfilter_without_own_macÚfilter_zero_macÚlog_filtered_reasonsr¨ZvethzIgnoring veth interface: %sÚcarrierzInterface has no carrier: %sÚdormantr@)r°r?Zlowerlayerdownr>zInterface ignored: %srŸr)rZ get_cmdliner,r-r‰rpZudevadm_settleÚget_interfacesÚ startswithr<Úappendr9r¡rÚDEFAULT_PRIMARY_INTERFACEÚremoveÚinsert) ZunstableZ connectedZpossibly_connectedrÚ_r¯r°r@Zsorted_interfacesÚ interfacesrrrr™×s`  þþú               r™cCstƒ}|r|dSdS)z]Get the 'fallback' network device name on Linux. @return List of sorted interfaces. rN)r™r¢rrrr�sr�cCsjtƒ}|sdSt|ƒr d|i}ndt|dƒ ¡i}|rJt|ƒ}|rJ||d<dd||dœ}||idd œ}|S) zBGenerate network cfg v2 for dhcp on the NIC most likely connected.Nr Ú macaddressÚaddressrhT)Zdhcp4r úset-nameÚmatché)Ú ethernetsÚversion)ržrtr9rrd)Z config_driverZ target_namer¼rhr“ZnconfrrrÚgenerate_fallback_config+s$ ÿürÀcCsJdd„}dd„}| d¡}|dkr*||ƒS|dkr:||ƒStd|ƒ‚dS) NcSs’g}| di¡D]|}| d¡dkr$q| d¡}|s4q| d¡}| di¡ d¡}| di¡ d¡}|snt|ƒ}|szt|ƒ}| ||||g¡q|S) Nr�rRZphysicalZ mac_addressr ÚparamsrhÚ device_id)r’rdr€r³)ÚnetcfgÚphysdevsÚentÚmacr rhrÂrrrÚ _version_1Is   z$extract_physdevs.._version_1cSs”g}| di¡ ¡D]z}| d¡}|s(q| di¡ d¡}|s@q| di¡ d¡}| di¡ d¡}|spt|ƒ}|s|t|ƒ}| ||||g¡q|S)Nr¾r»r¼r¹rhrÂ)r’r†rdr€r³)rÃrÄrÅr rÆrhrÂrrrÚ _version_2[s  z$extract_physdevs.._version_2r¿ér½z"Unknown network config version: %s)r’Ú RuntimeError)rÃrÇrÈr¿rrrÚextract_physdevsHs rËFcCs*t|dƒ}|dur"|rtdƒ‚dS|dvS)ašreturn True if the provided interface has its own address. Based on addr_assign_type in /sys. Return true for any interface that does not have a 'stolen' address. Examples of such devices are bonds or vlans that inherit their mac from another device. Possible values are: 0: permanent address 2: stolen from another device 1: randomly generated 3: set using dev_set_mac_addressZaddr_assign_typeNz%s had no addr_assign_type.T)rrÉé)r<r:)ÚifnameÚstrictZ assign_typerrrÚinterface_has_own_macxs rÏTc CsÂi}tƒD]*\}}}}d||| ¡|t|ƒdœ||<q |r¾t d¡}tjgd¢dd�\}}tjgd¢dd�\} }tƒ} || fD]} |  | | ¡¡q~|  ¡D] } | dd up¶| d | v| d <qœ|S) aàCollect information necessary for rename_interfaces. returns a dictionary by mac address like: {name: { 'downable': None or boolean indicating that the device has only automatically assigned ip addrs. 'device_id': Device id value (if it has one) 'driver': Device driver (if it has one) 'mac': mac address (in lower case) 'name': name 'up': boolean: is_up(name) }} N)ÚdownablerÂrhrÆr r=z[0-9]+:\s+(\w+)[@:])Úipz-6ÚaddrÚshowZ permanentZscopeÚglobalT)Zcapture)rÑz-4rÒrÓr=Fr rÐ) r±rrBrÚcompilerÚsetÚupdateÚfindallr†) Zcheck_downableÚcur_infor rÆrhrÂZnmatchZipv6r`Zipv4Znics_with_addressesZ bytes_outÚdrrrÚ_get_current_rename_infoŒs.ú  þ   ÿrÛc svt|ƒst d¡dS|dur$tƒ}i‰| ¡D]:\}}| ¡}| d¡rZ|d ¡|d<||d<|ˆ|<q0t dˆ¡dd„}g}g} g} |ˆƒ} d} d} d d „‰‡‡fd d „}|D�]Ö\}}}}|rÐ| ¡}g}||||ƒ}|sü|r¶|  d ||f¡q¶| d¡}||k�rq¶|�s0|r¶|  d ||f¡q¶|d�r’d}|d�sb|r¶|  ||||f¡q¶d|d<| d|||ff¡|  d|||ff¡|| v�r\| |}|d�rìd}|d�sØ|r¶|  ||||f¡q¶n| d|||ff¡d}|du�s|| v�r| d7} | | }�qð| d||||ff¡||d<|ˆƒ} |d�r\|  d|||ff¡| d|||d|ff¡||d<|ˆƒ} ||7}q¶t j t j t j dœ}t|ƒt| ƒdk�ràt| ƒ�rÒt  d|| ¡n t d|¡nzt d||| ¡|| D]^\}}}}z|||ŽWn>t�yT}z$|  d|||||f¡WYd}~n d}~00�qút| ƒ�rrtd | ¡ƒ‚dS)Nzno interfaces to renamerÆr zDetected interfaces %scSstdd„| ¡DƒƒS)Ncss|]}|d|fVqdS)r Nr©rÚdatarrrÚ Ðóz<_rename_interfaces..update_byname..)r‘r†)ZbymacrrrÚ update_bynameÏsz)_rename_interfaces..update_bynamez cirename%déÿÿÿÿcSsd|r0|r0|r0|d|ko.|d|ko.|d|kS|rP|rP|d|koN|d|kS|r`|d|kSdS)zmatch if set and in datarÆrhrÂFr)rÝrÆrhrÂrrrÚ entry_matchÙs   ÿ ý z'_rename_interfaces..entry_matchcsT‡‡‡‡fdd„ˆ ¡Dƒ}t|ƒrPt|ƒdkrHd|ˆˆˆf}t|ƒ‚|dSdS)Ncsg|]}ˆ|ˆˆˆƒr|‘qSrrrÜ)rÂrhrârÆrrrésþz:_rename_interfaces..find_entry..rÉzjFailed to match a single device. Matched devices "%s" with search values "(mac:%s driver:%s device_id:%s)"r)r†rpr:)rÆrhrÂr¼Úmsg©rÙrâ)rÂrhrÆrÚ find_entryèsþ  þÿz&_rename_interfaces..find_entryz<[nic not present] Cannot rename mac=%s to %s, not available.r=z*[busy] Error renaming mac=%s from %s to %srÐFr?z2[busy-target] Error renaming mac=%s from %s to %s.rÉÚrename)rær?r=rz1Unable to rename interfaces: %s due to errors: %sz$no work necessary for renaming of %szRenamed %s with ops %sz.[unknown] Error performing %s%s for %s, %s: %sÚ )rpr,r-rÛÚitemsÚcopyr’rr³r Z link_renameZ link_downZlink_upÚwarningrjrÊrN)ÚrenamesZstrict_presentZ strict_busyZ current_infor rÝZcurràÚopsÚerrorsZupsZ cur_bynameZ tmpname_fmtZtmpirårÆÚnew_namerhrÂZcur_opsZcur_namerãÚtargetZtmp_nameZopmapÚoprÁr3rrärÚ_rename_interfacesºsÊ     ÿÿ  ÿÿ        ý ý ÿÿ rñcCs$d}tj t|dƒ¡rd}t||ƒS)z6Returns the string value of an interface's MAC AddressrºZ bonding_slavezbonding_slave/perm_hwaddr)rEr!Úisdirr"r9)rÍr!rrrÚget_interface_macXsrócCs>t|dƒdkr:t|ƒ}|r6|r6|dd…|dd…}|SdS)z½Returns the string value of an Infiniband interface's hardware address. If ethernet_format is True, an Ethernet MAC-style 6 byte representation of the address will be returned. rRrSé$iòÿÿÿé3N)r9ró)rÍZethernet_formatrÆrrrÚget_ib_interface_hwaddrbs röcCs<t ¡st ¡rtƒSt ¡r$tƒSt ¡r2tƒStƒSdSr�) rr‚rƒÚ get_interfaces_by_mac_on_freebsdr–Úget_interfaces_by_mac_on_netbsdr—Ú get_interfaces_by_mac_on_openbsdÚget_interfaces_by_mac_on_linuxrrrrr…psr…)rÆrVcCs0tƒ ¡D] \}}| ¡| ¡kr |Sq dSr�)r…rèr)rÆZ interface_macZinterface_namerrrÚfind_interface_name_from_mac{s rûcCs<t gd¢¡\}}dd„}dd„}dd„|||ƒƒDƒ}|S)N)r¤ú-ar¥css@d}| d¡D]&}| d¡r&||7}q|r0|V|}q|VdS)Nrrçú )rr²)r_Z curr_blockÚlinerrrÚflatten†s  z1get_interfaces_by_mac_on_freebsd..flattencss4|D]*}t d|¡}|r| d¡| d¡fVqdS)Nz2^(?P\S*): .*ether\s(?P[\da-f:]{17}).*rÆrÍ)rÚsearchÚgroup)Z flat_listÚblockÚmrrrÚfind_mac’s ÿz2get_interfaces_by_mac_on_freebsd..find_maccSsi|]\}}||“qSrr)rrÆrÍrrrÚ šrßz4get_interfaces_by_mac_on_freebsd..)r)r_r·rÿrÚresultsrrrr÷‚s  r÷cCsbi}d}t ddg¡\}}t dd|¡ ¡}|D],}t ||¡}|r0| ¡}|d||d<q0|S)NzE(?P\w+).*address:\s(?P([\da-f]{2}[:-]){5}([\da-f]{2})).*r¤rüú\n\s+ú rÍrÆ©rrÚsubr^r¼Ú groupdict©rYZre_field_matchr_r·Zif_linesrþrÚfieldsrrrrøžsÿ røcCsbi}d}t ddg¡\}}t dd|¡ ¡}|D],}t ||¡}|r0| ¡}|d||d<q0|S)NzC(?P\w+).*lladdr\s(?P([\da-f]{2}[:-]){5}([\da-f]{2})).*r¤rürrrÍrÆr r rrrrù®sÿ rùcCs˜i}tƒD]ˆ\}}}}||vrV|dvrIgnoring duplicate macs from '%s' and '%s' due to driver '%s'.z6duplicate mac found! both '%s' and '%s' have mac '%s'.Tz^Ethernet and InfiniBand interfaces have the same address both '%s' and '%s' have address '%s'.)r±r,r-rÊrörê)rYr rÆrhZ_devidrãÚib_macrrrrú¾s:ûý  ûrú)Úfilter_hyperv_vf_with_syntheticr©rªr«r¬r­r®rVcCs$|r tjndd„}g}tƒ} d d¡} | D]ä} |rrßz get_interfaces..ú:)Ú00rrrrrrrrrrrrrrrzIgnoring bridge interface: %szIgnoring bond interface: %sNzIgnoring failover interface: %sz"Ignoring interface without mac: %sr¨)r,r-r‰rNrÏrHr}rJrMrPrQrirórprcrdr³r€Ú)filter_hyperv_vf_with_synthetic_interface)rr©rªr«r¬r­r®Úfiltered_loggerrYrˆZzero_macr rÆrhrrrr±sT      ÿ þýü   ÿ r±).N)rr¸rVcsXdd„|Dƒ‰‡fdd„|Dƒ}|D].}|\}}}}|d||ˆ||ƒ| |¡q$dS)a�Filter Hyper-V SR-IOV/VFs when used with synthetic hv_netvsc. Hyper-V's netvsc driver may register an SR-IOV/VF interface with a mac that matches the synthetic (hv_netvsc) interface. This VF will be enslaved to the synthetic interface, but cloud-init may be racing this process. The [perhaps-yet-to-be-enslaved] VF should never be directly configured, so we filter interfaces that duplicate any hv_netvsc mac address, as this the most reliable indicator that it is meant to be subordinate to the synthetic interface. VF drivers will be mlx4_core, mlx5_core, or mana. However, given that this list of drivers has changed over time and mana's dependency on hv_netvsc is expected to be removed in the future, we no longer rely on these names. Note that this will not affect mlx4/5 instances outside of Hyper-V, as it only affects environments where hv_netvsc is present. cSs&i|]}|ddkr|d|d“qS)r½Ú hv_netvscrÉrr©rÚirrrrUsz=filter_hyperv_vf_with_synthetic_interface..cs(g|] }|dˆvr|ddkr|‘qS)rÉr½rrr©Zhv_netvsc_mac_to_namerrrXsþz=filter_hyperv_vf_with_synthetic_interface..zdIgnoring %r VF interface with driver %r due to synthetic hv_netvsc interface %r with mac address %r.N)rµ)rr¸Zinterfaces_to_removerr rÆrhr·rrrrAs ÿ þ úrcCsPi}tƒD]@\}}}}t|dƒ}|r ||vrBtd||||fƒ‚|||<q |S)zTBuild a dictionary mapping Infiniband interface names to their hardware address.Fz5duplicate mac found! both '%s' and '%s' have mac '%s')r±rörÊ)rYr r·rrrrÚget_ib_hwaddrs_by_interfaceks  ÿÿ r)Úconvert_to_addressrºcKs,z||fi|¤ŽWSty&YdS0dS)aUse a function to return an address. If conversion throws a ValueError exception return False. :param check_cb: Test function, must return a truthy value :param address: The string to test. :return: Address or False FN)r:)rrºÚkwargsrrrÚmaybe_get_address{s  r)rºrVcCstttj|ƒƒS)z¹Returns a bool indicating if ``s`` is an IP address. :param address: The string to test. :return: A bool indicating if the string is an IP address or not. )rWrÚ ipaddressÚ ip_address©rºrrrÚ is_ip_addressŽs r!cCstttj|ƒƒS)z½Returns a bool indicating if ``s`` is an IPv4 address. :param address: The string to test. :return: A bool indicating if the string is an IPv4 address or not. )rWrrÚ IPv4Addressr rrrÚis_ipv4_addressšs r#cCstttj|ƒƒS)z½Returns a bool indicating if ``s`` is an IPv6 address. :param address: The string to test. :return: A bool indicating if the string is an IPv4 address or not. )rWrrÚ IPv6Addressr rrrÚis_ipv6_address¦s r%cCstttj|dd�ƒS)zÅReturns a bool indicating if ``s`` is an IPv4 or IPv6 network. :param address: The string to test. :return: A bool indicating if the string is an IPv4 address or not. F©rÎ)rWrrÚ ip_networkr rrrÚ is_ip_network²s r(cCstttj|dd�ƒS)z½Returns a bool indicating if ``s`` is an IPv4 network. :param address: The string to test. :return: A bool indicating if the string is an IPv4 address or not. Fr&)rWrrÚ IPv4Networkr rrrÚis_ipv4_network¾s ÿr*cCstttj|dd�ƒS)z½Returns a bool indicating if ``s`` is an IPv6 network. :param address: The string to test. :return: A bool indicating if the string is an IPv4 address or not. Fr&)rWrrÚ IPv6Networkr rrrÚis_ipv6_networkÌs ÿr,)rºÚsubnetrVcCs t |¡}tj|dd�}||vS)zâReturns a bool indicating if ``s`` is in subnet. :param address: The string of IP address. :param subnet: The string of subnet. :return: A bool indicating if the string is in subnet. Fr&)rrr')rºr-rZsubnet_networkrrrÚis_ip_in_subnetÚs r.)Úgatewayr-rVc CsJzt||ƒ WStyD}zt d|||¡WYd}~dSd}~00dS)zóReturns a bool indicating if should add gateway onlink flag. :param gateway: The string of gateway address. :param subnet: The string of subnet. :return: A bool indicating if the string is in subnet. zDFailed to check whether gateway %s is contained within subnet %s: %sNF)r.r:r,rê)r/r-r3rrrÚshould_add_gateway_onlink_flagës ûr0cCs@|d d¡s|dtvrdS|ddkr "255.255.255.0" Also supports input as a string.ú0.0.0.0/)r|rr)Únetmask)ÚprefixrrrÚnet_prefix_to_ipv4_masksr8cCst d|›�¡jS)aConvert an ipv4 netmask into a network prefix length. If the input is already an integer or a string representation of an integer, then int(mask) will be returned. "255.255.255.0" => 24 str(24) => 24 "24" => 24 r5)rr'Ú prefixlen)ÚmaskrrrÚipv4_mask_to_net_prefixs r;cCsšzt d|›�¡j}|WSty*Yn0t |¡}t|ƒ}|dkrJ|Sttj||d@ ¡ƒ}||?}tj|}d|>d}||kr–td|ƒ‚|S)zÿConvert an ipv6 netmask (very uncommon) or prefix (64) to prefix. If the input is already an integer or a string representation of an integer, then int(mask) will be returned. "ffff:ffff:ffff::" => 48 "48" => 48 z::/rrÉzInvalid network mask '%s') rr'r9r:rrÚminÚ IPV6LENGTHÚ bit_length)r:r9r6Zmask_intÚtrailing_zeroesÚ leading_onesÚall_onesrrrÚipv6_mask_to_net_prefix's$  ÿ   rB)r:rÑrVcCsttj|›d|›�dd�jƒS)zCGet string representation of broadcast address from an ip/mask pairrFr&)r|rr)Úbroadcast_address)r:rÑrrrÚmask_and_ipv4_to_bcast_addrJsÿrDc@s eZdZdS)ÚRendererNotFoundErrorN)r‹rŒr�rrrrrEQsrE)r)NNNN)N)N)N)N)N)N)F)T)TTN)TTTTTTF)er#Ú functoolsrZloggingrErÚtypingrrrrrZ cloudinitrrZcloudinit.net.netops.iproute2r Z getLoggerr‹r,rr´r3r[rÕrrr"r4r9r<rBrHrJrMrPrQrTÚ lru_cacherWrZr„rbr|rcrirlrqrtrerfrzr}rdr€r‰rjrŠr”ršržr˜rœr•r›r™r�r‘rÀrËrÏrÛrñrórör…rûr÷rørùrúr±rrrr!r#r%r(r*r,r.r0r4r8rr;rBrDrÊrErrrrÚsØ    ú %          !       H 0  /ÿ   Hùø =ý *      #