+
    i$n                        ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtHtH	t	H
t
Ht ^ RIHt ^ RIHt ]P                   ! ]4      tRRR R3R	R
]P&                  / 3RRR R3/tR#tRtRtRtRtRtRtRtRtRt]]]]]]]]3tR$t  ! R R]!4      t" ! R R4      t# ! R R] PH                  R7      t% ! R R]%4      t& ! R  R!]%4      t'R%R" lt(R# )&    N)netsourcessubp
url_helperutil)BrokenMetadata)ec2zetc/network/interfacesnetwork_configc                     V # N xs   &E/usr/lib/python3/dist-packages/cloudinit/sources/helpers/openstack.py<lambda>r      s    1     zmeta.jsmeta_jszroot/.ssh/authorized_keysauthorized_keysc                     V # r   r   r   s   &r   r   r      s    qr   latestz
2012-08-10z
2013-04-04z
2013-10-17z
2015-10-15z
2016-06-30z
2016-10-06z
2017-02-22z
2018-08-27c                       ] tR t^QtRtR# )NonReadabler   N)__name__
__module____qualname____firstlineno____static_attributes__r   r   r   r   r   Q   s    r   r   c                   >   a  ] tR t^Ut o R tR tR tR tR tRt	V t
R# )SourceMixinc                    V P                   '       g   R # V P                   P                  R/ 4      pVP                  4        F  w  r4W8X  g   K  Vu # 	  R # )Nzblock-device-mapping)ec2_metadatagetitems)selfnamebdment_namedevices   &&   r   _ec2_name_to_deviceSourceMixin._ec2_name_to_deviceV   sM       ##$:B? #		H !, r   c                    R pV P                   ^8X  d   Rp\        P                  ! V P                  P	                  V4      4      # )public_keyspublic-keys)versionr   normalize_pubkey_datametadatar#   )r%   r&   s   & r   get_public_ssh_keysSourceMixin.get_public_ssh_keys_   s8    <<1 D,,T]]->->t-DEEr   c                    R p RV,          pVR8X  d
   RV,          p\         P                  ! V4      pV'       d
   V^ ,          pV#   \        P                   d     T# i ; i)NzLABEL=%sswapzTYPE=%s)r   find_devs_withr   ProcessExecutionError)r%   r&   r)   criteriadev_entriess   &&   r   _os_name_to_deviceSourceMixin._os_name_to_devicee   si    	!T*Hv~$---h7K$Q  )) 		s   6A 	A AAc                D   V'       g   R # VP                  R4      '       g
   RV,          p\        P                  P                  V4      '       d   V# V P	                  \        P                  P                  V4      4      pV'       d   \        P                  RW4       V# R # )N/z/dev/%szRemapped device name %s => %s)
startswithospathexists_remap_devicebasenameLOGdebug)r%   r)   remappeds   && r   _validate_device_name!SourceMixin._validate_device_namer   st      %%'F77>>&!!M%%bgg&6&6v&>?II5vHOr   c                   V'       g   R # V.pVR8X  d   VP                  ^ R4       VR8X  d   VP                  R4       R p\        P                  RV4       V F/  pV P	                  V4      pV P                  V4      pV'       g   K/   M	  V'       gL   \        P                  RV4       V F/  pV P                  V4      pV P                  V4      pV'       g   K/   M	  V'       g   R # \        P                  RW4       V# )Nrootamiz(Using ec2 style lookup to find device %sz.Using openstack style lookup to find device %szMapped %s to device %s)insertappendrD   rE   r*   rG   r:   )r%   r&   namesr)   ns   &&   r   device_name_to_device!SourceMixin.device_name_to_device   s    6>LLE"5=LL 		<eDA--a0F//7Fv	  IIFN00333F;6	  II.=Mr   r   N)r   r   r   r   r*   r2   r:   rG   rP   r   __classdictcell____classdict__s   @r   r    r    U   s$     F r   r    c                      a  ] tR t^t o R t]P                  R 4       t]P                  RR l4       t]P                  R 4       t	]P                  R 4       t
R tRR ltR tR	tV tR
# )
BaseReaderc                    Wn         R # r   	base_path)r%   rY   s   &&r   __init__BaseReader.__init__   s    "r   c                    R # r   r   r%   baseadd_onss   &&*r   
_path_joinBaseReader._path_join       r   c                    R # r   r   r%   r@   decodes   &&&r   
_path_readBaseReader._path_read   rb   r   c                    R # r   r   r%   s   &r   _fetch_available_versions$BaseReader._fetch_available_versions   rb   r   c                    R # r   r   ri   s   &r   _read_ec2_metadataBaseReader._read_ec2_metadata   rb   r   c                T    V P                  4       p\        \        \        4      4       Uu. uF  q3NK  	  pp\        pV F  pWa9  d   K  Tp M	  \        P                  RVV4       V#   \         d.   p\        P                  R T P                  T4       . p Rp?LRp?ii ; iu upi )z4Unable to read openstack versions from %s due to: %sNzSelected version '%s' from %s)	rj   	ExceptionrD   rE   rY   reversedlistOS_VERSIONS	OS_LATEST)r%   versions_availableev	supportedselected_versionpotential_versions   &      r   _find_working_version BaseReader._find_working_version   s    	$!%!?!?!A !)k): ;< ;1Q ;	<$!* :0	 "+ 			+	

  1  	$IIF
 "$	$ =s   A* 
B%*B"5#BB"c                N   VP                  R R4      P                  R4      pVP                  R4      pV Uu. uF  p\        V4      '       g   K  VNK  	  ppV'       g   \	        RV,          4      hV P
                  ! V P                  R.VO5!  pV P                  W2R7      # u upi )content_pathr   r=   z!Item %s has no valid content path	openstackre   )r#   lstripsplitlenr   r`   rY   rf   )r%   itemre   r@   path_piecespvalid_piecess   &&&    r   _read_content_pathBaseReader._read_content_path   s    xx+2237jjo#.9;a#a&;9 !D!MNNt~~{I[It33	 :s   B"B"c                >  a a \         P                  ! \        P                  \        \
        \        3R7      oVV 3R lpRRR^/pV! S P                  4       4      pVP                  4        F  w  pw  rVpS P                  S P                  V4      pRpRp S P                  V4      pRpV'       d   V'       g   \        RV,          4      hV'       d   V'       d
    V! V4      pV'       g   K  W2V&   K  	  VR,          p
RV
9   d$   V
R,          p \$        P&                  ! V4      V
R&   / pV
P-                  R. 4      pV F)  pRV9  d   K  VR,          p S P/                  V4      W&   K+  	  WR&   V
P-                  RR4      pV'       d    S P/                  VRR7      pVVR&    V
R,          R,          VR&   S P3                  4       VR&   \4         FE  w  pppV'       d   VV
9  d   \#        RV,          4      hVV
9   g   K1  V
P-                  V4      V
V&   KG  	  V#   \         dF   p	T'       g   \        P                  R	YY4        Rp	?	EL\        P                  R
YY4        Rp	?	ELRp	?	ii ; i  \          d   p	\#        RT: RT	: 24      T	hRp	?	ii ; i  \(        \*        3 d   p	\#        RT	,          4      T	hRp	?	ii ; i  \          d   p	\#        RT: RT	: 24      T	hRp	?	ii ; i  \         d   p	\#        RT	,          4      T	hRp	?	ii ; i  \0         d     ELei ; i)zReads a version 2 formatted location.

Return a dict with metadata, userdata, ec2-metadata, dsmode,
network_config, files and version (2).

If not a valid location, raise a NonReadable exception.
)
root_typesc                 $  < / pSP                  R V R4      R\        P                  3VR&   SP                  R V R4      RR 3VR&   SP                  R V R4      RS3VR	&   SP                  R V R
4      RS3VR&   SP                  R V R4      RS3VR&   V# )r   zmeta_data.jsonTr1   	user_dataFc                     V # r   r   r   s   &r   r   7BaseReader.read_v2.<locals>.datafiles.<locals>.<lambda>   s    !r   userdatazvendor_data.json
vendordatazvendor_data2.jsonvendordata2znetwork_data.jsonnetworkdata)r`   r   	load_json)r/   filesload_json_anytyper%   s   & r   	datafiles%BaseReader.read_v2.<locals>.datafiles   s    E W6FG!E* WkB!E* W6HI!#E, W6IJ!$E-  W6IJ!$E- 
 Lr   r   r   r/   NFTz*Failed reading optional path %s due to: %sz+Failed reading mandatory path %s due to: %szMissing mandatory path: %sFailed to process path : r1   random_seedz.Badly formatted metadata random_seed entry: %sr   r@   zFailed to read provided file r
   r   z(Failed to read network configuration: %smetadsmodezec2-metadatazNo '%s' entry in metadata)	functoolspartialr   r   dictrr   strr{   r$   r`   rY   rf   IOErrorrD   rE   r   rp   r   base64	b64decode
ValueError	TypeErrorr#   r   KeyErrorrm   
KEY_COPIES)r%   r   resultsdatar&   r@   required
translatorfoundrv   r1   r   r   metadata_filesr   net_itemcontent
target_key
source_keyis_requiredr   s   f                   @r   read_v2BaseReader.read_v2   s%    &--NNdC'8
	B q
 335626**,.D.4:??4>>48DDEt, !">"EFF%d+D
 u $7 3?: :&H$"=1K*0*:*:;*G' !gr2"DT!<D"55d; # !
 << 0$711(41H,3()	 ( 0 :GH
 #'"9"9"; 4>/J
Kz9$%@:%MNNX%'/||J'?$	 4>
 _  IIDd  IIEt   ! (;?C 	* $DqH  $=A1E  $>!D  		s   HI-J K 
K' #L I*%I%	I%%I*-J8JJJ=%J88J= K$KK$'L
2LL
LLrX   NF)r   r   r   r   rZ   abcabstractmethodr`   rf   rj   rm   r{   r   r   r   rR   rS   s   @r   rV   rV      s     # 	  	  	  	  :4G Gr   rV   )	metaclassc                   T   a a ] tR tRt oV 3R ltR tR	R ltR tR tR t	Rt
VtV ;t# )
ConfigDriveReaderie  c                <   < \         \        V `  V4       R V n        R # r   )superr   rZ   	_versions)r%   rY   	__class__s   &&r   rZ   ConfigDriveReader.__init__f  s    /	:r   c                d    V.\        V4      ,           p\        P                  P                  ! V!  # r   )rr   r?   r@   join)r%   r^   r_   
componentss   &&* r   r`   ConfigDriveReader._path_joinj  s%    Vd7m+
ww||Z((r   c                j    V'       d   \         P                  ! V4      # \         P                  ! V4      # r   )r   load_text_fileload_binary_filerd   s   &&&r   rf   ConfigDriveReader._path_readn  s1      %	
 &&t,	
r   c                j   V P                   f   V P                  V P                  R4      p\        P                  ! V4       Uu. uFI  p\        P
                  P                  \        P
                  P                  V4      4      '       g   KG  VNKK  	  pp\        V4      V n         V P                   # u upi )Nr   )	r   r`   rY   r?   listdirr@   isdirr   sorted)r%   r@   dr   s   &   r   rj   +ConfigDriveReader._fetch_available_versionsu  s    >>!??4>>;?D D))A77==d!34 )  
 $E]DN~~s   AB0B0c                &   V P                  V P                  R RR4      p\        P                  P	                  V4      '       g   / #  \
        P                  ! V P                  V4      4      #   \         d   p\        RT: RT: 24      ThRp?ii ; i)r	   r   zmeta-data.jsonr   r   N)
r`   rY   r?   r@   rA   r   r   rf   rp   r   )r%   r@   rv   s   &  r   rm   $ConfigDriveReader._read_ec2_metadata  s}    NNE8-=
 ww~~d##I~~dood&;<< $7;Q?s   $A, ,B7BBc                   / p\         P                  4        FJ  pV P                  V P                  V4      p\        P
                  P                  V4      '       g   KF  W1V&   KL  	  V'       g   \        RV P                  ,          4      h/ p\         P                  4        FN  w  pw  rVpW!9   d(   W,          p V P                  V4      p T! T4      YE&   K6  \        P                  ! V4      WE&   KP  	  VR,          p
VR,          pVP                  RV
4      p
V
'       dR   V
P!                  4       pV Uu. uF1  p\#        V4      '       g   K  VP%                  R	4      '       d   K/  VNK3  	  upVR&   R
V9   d   VR
,          VR
&   R^RV/pRV9   d   VR,          VR&   VP                  RR4      VR&   / VR&   V#   \         d   p	\        RT,          4      T	hRp	?	ii ; i  \         d   p	\        RT: RT	: 24      T	hRp	?	ii ; iu upi )zReads a version 1 formatted location.

Return a dict with metadata, userdata, dsmode, files and version (1).

If not a valid path, raise a NonReadable exception.
z%s: no files foundzFailed to read: %sNr   r   r   r   r.   #instance-idr/   r1   r   z	user-datar   r   r   )FILES_V1keysr`   rY   r?   r@   rA   r   r$   rf   r   r   rp   copydeepcopyr#   
splitlinesr   r>   )r%   r   r&   r@   mdkeyr   defaultcontentsrv   keydatar   linesliner   s   &              r   read_v1ConfigDriveReader.read_v1  s     MMOD??4>>48Dww~~d##"d $ 2dnnEFF080@,D,3G}{M#t4H )2BG --0# 1A& &'Y- ++mW5&&(E "!!Dt9 %)__S%9 !!B} G# ' 6B} q
 w ' 1GH &kk+r:
 c  M()=)DE1LM ! (;?C!sB   7F6	
G1H	H"H6GGGH 'G;;H )r   r   )r   r   r   r   rZ   r`   rf   rj   rm   r   r   rR   __classcell__r   rT   s   @@r   r   r   e  s*     )
	G Gr   r   c                   R   a a ] tR tRt oRV 3R lltR tR	R ltR tR tRt	Vt
V ;t# )
MetadataReaderi  c                   < \         \        V `  V4       W n        \	        V4      V n        \        V4      V n        R V n        R # r   )	r   r   rZ   ssl_detailsfloattimeoutintretriesr   )r%   base_urlr   r   r   r   s   &&&&&r   rZ   MetadataReader.__init__  s5    nd,X6&W~7|r   c                @   V P                   e   V P                   # . pV P                  V P                  R4      pV P                  VRR7      pVP	                  4        F.  pVP                  4       pV'       g   K  VP                  V4       K0  	  Wn         V P                   # )Nr   Tr   )r   r`   rY   rf   r   striprM   )r%   r   version_pathr   r   s   &    r   rj   (MetadataReader._fetch_available_versions  s    >>%>>!t~~{C//,t/<&&(D::<DLL	 )
 ~~r   c                    R  p\         P                  ! VV P                  V P                  V P                  VR7      pV'       d   VP
                  P                  4       # VP
                  # )c                      \        V P                  4      pVR 8  d
   VR9  d   R# R#   \        \        3 d     R# i ; i)i  FT)i  i  i  i  i  i  )r   coder   r   )causer   s   & r   should_retry_cb2MetadataReader._path_read.<locals>.should_retry_cb  sG    5::3;4/M#M   z* s   #) >>)r   r   r   exception_cb)r   readurlr   r   r   r   re   )r%   r@   re   r   responses   &&&  r   rf   MetadataReader._path_read  s\    	 %%LL((LL(
 $$++--$$$r   c                2    \         P                  ! V.VO5!  # r   )r   combine_urlr]   s   &&*r   r`   MetadataReader._path_join  s    %%d5W55r   c                p    \         P                  ! V P                  V P                  V P                  R 7      # ))r   r   r   )r	   get_instance_metadatar   r   r   ri   s   &r   rm   !MetadataReader._read_ec2_metadata	  s,    ((((LLLL
 	
r   )r   r   r   r   )N   r  r   )r   r   r   r   rZ   rj   rf   r`   rm   r   rR   r   r   s   @@r   r   r     s#     %.6
 
r   r   c           
     z  a& V f   R# R. R6OR. R7OR. R8O/o&V P                  R. 4      pV P                  R. 4      pV P                  R. 4      p. p/ pRp^ p. p	V EF{  p
. p\        V&3R lV
P                  4        4       4      pRV
9   d   V
R,          VR&   RpV
P                  R4      '       d+   V
P                  R4      P                  4       pWV
R,          &   RVP                  R4      RVRV
R,          RV
R,          /pV Uu. uF  qR,          V
R,          8X  g   K  VNK  	  up EF  p\        V&3R lVP                  4        4       4      pVP                  R. 4       Uu. uF&  p\        V&3R lVP                  4        4       4      NK(  	  ppV'       d   VP	                  RV/4       VR,          R8X  d   VP	                  RR/4       MVR,          R8X  d   VP	                  RR/4       MVR,          R99   d   VP	                  RVR,          /4       MxVR,          R:9   d&   VP	                  RRR	VP                  R4      /4       MEVR,          R;9   d8   VP	                  R R!/4       VP	                  RRR	VP                  R4      /4       VP                  R. 4       UUu. uF=  pVP                  R. 4       F$  pVP                  R4      R"8X  g   K  VR	,          NK&  	  K?  	  pppVP                  R. 4       FC  pVP                  R4      R"8w  d   K  VR	,          V9   d   K+  VP                  VR	,          4       KE  	  V'       d   VVR
&   VR,          R<9   d   VP	                  R R#/4       VR,          R8X  d   R#VR&   VR,          R8X  d   R#VR&   VP                  V4       EK  	  VP	                  RV/4       V
R,          R=9   d   / pV'       d   VP	                  RV/4       V
P                  4        Fc  w  ppVR%8X  d   K  VP                  R$4      '       g   K(  R&P                  VP                  R'^4      R>,          4      pVP	                  VV/4       Ke  	  VVR&   VP                  R4      f   Wx,          pVVR&   VVR&   V^,          pVP                  VR(R)\        P                  ! V
R%,          4      34       MV
R,          R?9   d   V
R*,          : R+V
R,,          : 2pVP	                  RVR,V
R,,          RV
R-,          /4       VP                  VR*R)V
R*,          34       VP                  VRR.V
R,,          ,          V
R*,          34       VP	                  RV
R-,          RV/4       MDV
R,          \        9  d   \        P                  R/V
R,          4       VP	                  RRRV/4       V	P                  V4       WVR,          &   EK~  	  V	 Uu. uF&  pVP                  R4      R8X  g   K  RV9  g   K$  VNK(  	  ppV'       g
   V'       Edr   Vf   \        P                  ! 4       pVP                  4        FJ  w  ppVP                  R4      '       d   K  VP                  R4      V9   g   K7  VVR,          ,          VR&   KL  	  V F  pVP                  R4      p V '       g   \!        R0V,          4      hV V9  dD   \"        P$                  ! 4        \        P                  ! 4       pV V9  d   \!        R1V,          4      hVV ,          VR&   K  	  V Fj  w  pp!p"p#\'        V#\(        \*        34      '       d-   V# U$u. uF  p$V"VV$,          R,          ,          NK  	  up$VV!&   KP  V"VV#,          R,          ,          VV!&   Kl  	  \        P,                  ! 4       p%V%'       d2   V	 F+  pVR,          V%9   g   K  V%VR,          ,          VR&   R2VR&   K-  	  V F=  p\        P                  ! V4      pVP	                  RR3/4       V	P                  V4       K?  	  R4^R5V	/# u upi u upi u uppi u upi u up$i )@a  Return a dictionary of network_config by parsing provided
   OpenStack ConfigDrive NetworkData json format

OpenStack network_data.json provides a 3 element dictionary
  - "links" (links are network devices, physical or virtual)
  - "networks" (networks are ip network configurations for one or more
                links)
  -  services (non-ip services, like dns)

networks and links are combined via network items referencing specific
links via a 'link_id' which maps to a links 'id' field.

To convert this format to network_config yaml, we first iterate over the
links and then walk the network list to determine if any of the networks
utilize the current link; if so we generate a subnet entry for the device

We also need to map network_data.json fields to network_config fields. For
example, the network_data links 'id' field is equivalent to network_config
'name' field for devices.  We apply more of this mapping to the various
link types that we encounter.

There are additional fields that are populated in the network_data.json
from OpenStack that are not relevant to network_config yaml, so we
enumerate a dictionary of valid keys for network_yaml and apply filtering
to drop these superfluous keys from the network_config yaml.
Nphysicalr&   typemac_addresssubnetsparamssubnetaddressdns_nameserversrouteslinksnetworksserviceszbond%dc              3   N   <"   T F  w  rVSR ,          9   g   K  W3x  K  	  R# 5i)r  Nr   .0krw   
valid_keyss   &  r   	<genexpr>#convert_net_json.<locals>.<genexpr>T  s&      
+tqqJz4J/JFQF|   %%ethernet_mac_addressidmaclinkc              3   N   <"   T F  w  rVSR ,          9   g   K  W3x  K  	  R# 5i)r	  Nr   r  s   &  r   r  r  k  s&      #241a:h;O6O?r  c              3   N   <"   T F  w  rVSR ,          9   g   K  W3x  K  	  R# 5i)r  Nr   r  s   &  r   r  r  r  s+       -Jx00 QF -r  	ipv4_dhcpdhcp4	ipv6_dhcpdhcp6ipv4static
ip_addressipv6static6z	accept-raFdnsTbond
bond_linkszbond-{}bond_bond_interfacesz%s	vlan_link.vlan_idvlan_mac_addressz%%s.%sz9Unknown network_data link type (%s); treating as physicalz#No mac_address or name entry for %sz"Unable to find a system nic for %s
infiniband
nameserverr/   config)r&   r  r  r  r  mtu)
r  r
  netmask	broadcastmetricgatewaypointopointscoper  
dns_search)networkdestinationr4  r7  r6  )
ipv6_slaaczipv6_dhcpv6-statelessipv6_dhcpv6-stateful)r"  r#  )r%  r&  )r>  r   )r(  )vlan)r#   r   r$   lowerupdaterM   r>   formatr   r   r   KNOWN_PHYSICAL_TYPESrD   warningr   get_interfaces_by_macr   r   udevadm_settle
isinstancerr   tupleget_ib_hwaddrs_by_interface)'network_json
known_macsr  r  r  link_updateslink_id_infobond_name_fmtbond_numberr2  r  r  cfglink_mac_addrcurinforO   r;  r	  router  servicer  r  r  rw   translated_key	link_namer&   r   
need_names_link_idinfor  r   fmttargetstargetib_known_hwaddrsr  s'   &&                                    @r   convert_net_jsonr_    s   6  	 
 	 
 	L+J0 Wb)E
B/H
B/HLLMKF 
#zz|
 
 T>v,CK88*++ HH%;<BBDM'4d$ CGGFO=$t*DL	
 $,G8ayDJ/F8GG #*==? F %[[26 7E   % 
 7   x01v+-vw/0K/vw/0 % 
 vwv78$66!7;;|#< $77

K/0	!7;;|#< %[[266E$yyR8G;;v&%/ #	""8 #6   #;;z26;;v&%/9%8&&wy'9: 7 ,;() v"GG

K./v&(!%vv&(!%vNN6"Q HR 	

Iw'(<8#F

M=9:

1$\\&)) &/%5%5agggq6I"6M%NNMM>1"56 % #CM
 wwv&)7	'F"+1K
 %MM$|"45	 &\X%";//iADJJDtI!4(:#; k4k9J KLfhi8${:KL NNE4(:#;VTJKF|#77 L
 JJ
M=IJc&-WT]#A F aQUU6]j8V1_6   \\224J +002NHdxxxx*,)$u+6V	 3 A%%&C !F!JKK*$##% 668
j($%IA%MNN"3AfI  '3"Cc7'D%=11ELEL6C,v.v666WC g!6v!>>C '3 668C6{..%5c&k%BM"*F 
 mmG$

FL)*c 
 q(F++{ HRt:s6   `#`#!,`($-`-
`-
`39`3`3 `8))zlocal-hostnamehostnameF)r   uuidT)Nbgpovsbridge	cascadingdvsethernethw_vebhypervovsphytap	vhostuservif)NN))r   r   r   r   loggingr?   	cloudinitr   r   r   r   r   cloudinit.sourcesr   cloudinit.sources.helpersr	   	getLoggerr   rD   r   r   r   rt   	OS_FOLSOM
OS_GRIZZLY	OS_HAVANA
OS_LIBERTYOS_NEWTON_ONEOS_NEWTON_TWOOS_OCATAOS_ROCKYrs   rD  r   r   r    ABCMetarV   r   r   r_  r   r   r   <module>r|     s        	 : : , ) ! /bA	4>>2."3["!E	
 		
	

 	 "	' 	I IXA3;; AHp
 pf6
Z 6
tU,r   