
    x[h;                     F   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
JrJrJrJrJr  SSKJr  SSKJr  SSKJrJrJr  Sr\R2                  " \5      rSrS	rS
rSrSr Sr!Sr"Sr#Sr$Sr%Sr&Sr'Sr( " S S\RR                  5      r*S r+S r,S r-S r.S r/S r0S r1S r2S r3S  r4S! r5S" r6S# r7S$ r8S% r9S& r:S' r;S( r<\*\Rz                  44\*\Rz                  \R|                  44/r?S) r@S* rAS5S+ jrBS, rCS-\DS.\D4S/ jrES-\DS.\D4S0 jrFS1 rGS2 rHS3 rI\S4:X  a  \I" 5         gg)6zCloud-Init DataSource for VMware

This module provides a cloud-init datasource for VMware systems and supports
multiple transports types, including:

    * EnvVars
    * GuestInfo
    * IMC (Guest Customization)
    N)atomic_helperdminetnetinfosourcesutil)loggers)guestcust_util)ProcessExecutionErrorsubpwhichz/sys/class/dmi/id/product_uuidzNo value foundenvvar	guestinfoimcredactzcleanup-guestinfoVMX_GUESTINFOz---z
local-ipv4z
local-ipv6zwait-on-networkipv4ipv6c                      ^  \ rS rSrSrSrSS jrS\SS4U 4S jjrS	 r	S
 r
S rS rS r\S 5       rS rS rS rS rS rS rS rSrU =r$ )DataSourceVMware9   a  
Setting the hostname:
    The hostname is set by way of the metadata key "local-hostname".

Setting the instance ID:
    The instance ID may be set by way of the metadata key "instance-id".
    However, if this value is absent then the instance ID is read
    from the file /sys/class/dmi/id/product_uuid.

Configuring the network:
    The network is configured by setting the metadata key "network"
    with a value consistent with Network Config Versions 1 or 2,
    depending on the Linux distro's version of cloud-init:

        Network Config Version 1 - http://bit.ly/cloudinit-net-conf-v1
        Network Config Version 2 - http://bit.ly/cloudinit-net-conf-v2

    For example, CentOS 7's official cloud-init package is version
    0.7.9 and does not support Network Config Version 2.

    imc transport:
        Either Network Config Version 1 or Network Config Version 2 is
        supported which depends on the customization type.
        For LinuxPrep customization, Network config Version 1 data is
        parsed from the customization specification.
        For CloudinitPrep customization, Network config Version 2 data
        is parsed from the customization specification.

    envvar and guestinfo transports:
        Network Config Version 2 data is supported as long as the Linux
        distro's cloud-init package is new enough to parse the data.
        The metadata key "network.encoding" may be used to indicate the
        format of the metadata key "network". Valid encodings are base64
        and gzip+base64.
VMwareNc                     [         R                  R                  XX#U5        0 U l        S U l        S U l        S U l        [        U R                  S4[        U R                  S4[        U R                  S4/U l        g )NFT)r   
DataSource__init__cfgdata_access_methodrpctool
rpctool_fnDATA_ACCESS_METHOD_ENVVARget_envvar_data_fnDATA_ACCESS_METHOD_GUESTINFOget_guestinfo_data_fnDATA_ACCESS_METHOD_IMCget_imc_data_fn possible_data_access_method_list)selfsys_cfgdistropathsud_procs        D/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceVMware.pyr   DataSourceVMware.__init__`   ss    ##D6'J"& '(?(?G)4+E+EtL#T%9%94@1
-    ci_pkl_versionreturnc           	      X  > [         TU ]  U5        S H!  n[        X5      (       a  M  [        XS 5        M#     [        U S5      (       d  [        U S0 5        [        U S5      (       dD  [        U S[        U R
                  S4[        U R                  S4[        U R                  S4/5        g g )N)r   r   r   r&   FT)
super	_unpicklehasattrsetattrr    r!   r"   r#   r$   r%   )r'   r/   attr	__class__s      r,   r3   DataSourceVMware._unpickleu   s    .)-D4&&D) . tU##D%$t?@@2 2// 522
 ,T-A-A4H Ar.   c                 h    [         R                  R                  U 5      nU< SU R                  < S3$ )Nz [seed=])r   r   __str__r   )r'   roots     r,   r;   DataSourceVMware.__str__   s)    !!))$/!%t'>'>??r.   c                 "   Su  pnU R                    HF  u  nnnU(       a  [        5       (       d  M  U" 5       u  pnU(       d  U(       d	  U(       d  M@  X@l          O   U R                  (       d  [        R	                  S5        g[        R                  SU R                  5       5        [        [        U5      5      U l	        X l
        X0l        U R                  5         U R                  (       d"  U R                  (       d  U R                  (       a  gg)aC  
_get_data loads the metadata, userdata, and vendordata from one of
the following locations in the given order:

    * envvars
    * guestinfo
    * imc

Please note when updating this function with support for new data
transports, the order should match the order in the dscheck_VMware
function from the file ds-identify.
NNNz)failed to find a valid data access methodFzusing data access method %sT)r&   is_vmware_platformr   LOGdebuginfo_get_subplatformprocess_metadataload_json_or_yamlmetadatauserdata_rawvendordata_rawredact_keys)r'   mdudvdr   get_data_fnrequire_vmware_platforms          r,   	_get_dataDataSourceVMware._get_data   s    " &
 22	
#&/A/C/C&=LRRR22*<' 3 &&IIAB.0E0E0GH )):2)>?  ! 	 ==D--1D1Dr.   c                    [        U R                  5      n[        R                  SU5        [	        X R
                  U R                  5        [        R                  " U R                  U/5      U l        U R                  5         g)a   setup(is_new_instance)

This is called before user-data and vendor-data have been processed.

Unless the datasource has set mode to 'local', then networking
per 'fallback' or per 'network_config' will have been written and
brought up the OS at this point.
zgot host-info: %sN)
wait_on_networkrG   rA   rC   advertise_local_ip_addrsr   r   r   mergemanydictpersist_instance_data)r'   is_new_instance	host_infos      r,   setupDataSourceVMware.setup   s`     $DMM2	$i0 	!LL$//J
 **DMM9+EF 	""$r.   c                     S nU R                   [        :X  a  [        nOFU R                   [        :X  a  [        nO+U R                   [
        :X  a  [        nO[        R                  $ U R                   < SU" S5      < S3$ )Nz (rG   ))	r   r    get_guestinfo_envvar_key_namer"   get_guestinfo_key_namer$   get_imc_key_namer   METADATA_UNKNOWN)r'   get_key_name_fns     r,   rD   !DataSourceVMware._get_subplatform   sl    ""&??;O$$(DD4O$$(>>.O+++ ##J'
 	
r.   c                     U R                   $ N)r   r'   s    r,   get_config_objDataSourceVMware.get_config_obj   s    xxr.   c                     SU R                   ;   a  [        R                  S5        O>[        R                  S5        SU R                  R	                  5       0U R                   S'   U R                   S   S   $ )Nnetworkzusing metadata network configzusing fallback network configconfig)rG   rA   rB   r)   generate_fallback_configre   s    r,   network_configDataSourceVMware.network_config   s`    %II56II56$++>>@(DMM)$ }}Y'11r.   c                    U R                   (       a  SU R                   ;   a  U R                   S   $ [        R                  " [        5      R	                  5       R                  5       U R                   S'   U R                   S   $ )Nzinstance-id)rG   r   load_text_filePRODUCT_UUID_FILE_PATHrstriplowerre   s    r,   get_instance_id DataSourceVMware.get_instance_id	  se     ==]dmm;==// 67>>@FFH 	m$ }}]++r.   c                     U R                   (       aH  U R                   [        :X  a4  [        5       (       a%  [        R	                  SU R                  5       5        gg)Nz"Cache fallback is allowed for : %sTF)r   r$   r@   rA   rB   rD   re   s    r,   check_if_fallback_is_allowed-DataSourceVMware.check_if_fallback_is_allowed  sE    ##''+AA"$$II4d6K6K6M r.   c                     S H7  nXR                   ;   d  M  [        R                  " U R                   U   5      s  $    / $ )N)zpublic-keys-datapublic_keys_datazpublic-keyspublic_keys)rG   r   normalize_pubkey_data)r'   key_names     r,   get_public_ssh_keys$DataSourceVMware.get_public_ssh_keys  s;    
H ==(44T]]85LMM
 	r.   c                    S n[         U R                  ;   a  U R                  [            nO'[        U R                  ;   a  U R                  [           nU R                  [        :X  a!  [        XR                  U R                  5        g g rd   )REDACTrG   CLEANUP_GUESTINFOr   r"   guestinfo_redact_keysr   r   )r'   keys_to_redacts     r,   rJ   DataSourceVMware.redact_keys*  sf    T]]"!]]62N$--/!]]+<=N""&BB!doo Cr.   c                     Su  pn[         R                  R                  [        S5      (       a!  [	        S5      n[	        S5      n[	        S5      nXU4$ )z,
check to see if there is data via env vars
r?    rG   userdata
vendordata)osenvirongetr   guestinfo_envvar)r'   rK   rL   rM   s       r,   r!   #DataSourceVMware.get_envvar_data_fn8  sJ     &
::>>-,,!*-B!*-B!,/B|r.   c                 x   [        S5      n[        S5      nU(       a'  X l        [        U l        [        R                  SU5        U(       a.  U(       d  Xl        [        U l        [        R                  SU5        U R                  (       d  [        R                  S5        gS n U" U R                  U R                  5      $ ! [         a  n[        R                  " [        SU R                  U5        U(       a  U R                  U:X  a   S	nAgU(       d  [        R                  S
5         S	nAg[        R                  S5        Xl        [        U l         U" U R                  U R                  5      s S	nA$ ! [         a.    [        R                  " [        SU R                  U5          S	nAgf = fS	nAff = f)z;
check to see if there is data via the guestinfo transport
vmtoolsdzvmware-rpctoolzdiscovered vmware-rpctool: %szdiscovered vmtoolsd: %szno rpctool discoveredr?   c                     Su  p#n[         R                  SU 5        [        SX5      n[        SX5      n[        SX5      nX#U4$ )Nr?   zquery guestinfo with %srG   r   r   )rA   rC   r   )r   r   rK   rL   rM   s        r,   query_guestinfo?DataSourceVMware.get_guestinfo_data_fn.<locals>.query_guestinfo`  sH    )JBBHH.8:w;B:w;B<=B2:r.   z%Failed to query guestinfo with %s: %sNz$vmtoolsd fallback option not presentzfallback to vmtoolsd)r   r   exec_vmware_rpctoolr   rA   rB   exec_vmtoolsd	Exceptionr   logexcrC   )r'   r   vmware_rpctoolr   errors        r,   r#   &DataSourceVMware.get_guestinfo_data_fnD  sJ   
 $/0 )L1DOII5~F "'"/II/: ||II-.%	&	* #4<<AA "	*KK7	 DLLH4)?@)HH+,#L+DO
*&t||T__EE *;LL	 **5"	*sH   %C 
F9>F4F40&F4E93F991F1*F40F11F44F9c                    Su  pn[         R                  " U R                  5      n[         R                  " U R                  5      nU(       d   U(       d  [
        R                  S5        XU4$ [         R                  " 5       (       d  XU4$ [         R                  " U R                  5      nUc  XU4$ [        R                  R                  U5      n[         R                  " U5      n[         R                  " U5      u  n	n
U	(       av  U(       ao  [
        R                  S5        [         R                  " U R                  R                   U R                  R#                  S5      UUU R$                  5      u  po0l        ORU
(       a6  U(       a/  [
        R                  S5        [         R(                  " U5      u  pnO[
        R                  S5        [*        R,                  " U5        XU4$ )z>
check to see if there is data via vmware guest customization
r?   z-Customization for VMware platform is disabledz3Getting data via VMware customization configurationscriptszFGetting data via VMware raw cloudinit data customization configurationz1No allowed customization configuration data found)r
   is_vmware_cust_enabledr(   is_raw_data_cust_enabledds_cfgrA   rB   is_cust_plugin_availableget_cust_cfg_filer   pathdirnameparse_cust_cfgget_cust_cfg_typeget_data_from_imc_cust_cfgr*   	cloud_dir	get_cpathr)   r   #get_data_from_imc_raw_data_cust_cfgr   del_dir)r'   rK   rL   rM   allow_vmware_custallow_raw_data_custcust_cfg_filecust_cfg_dircust_cfgis_vmware_cust_cfgis_raw_data_cust_cfgs              r,   r%    DataSourceVMware.get_imc_data_fn  s    &
 +AA$,,O,EEKK
 !)<IIEFB< 6688B< '88E B< ww}5!00? ,,X6	
  "3IIKL%3%N%N

$$

$$Y/&"RR "&9II. *MMLRR IIIJ 	\"|r.   )r   r   rG   r&   r   r   rH   rI   rd   )__name__
__module____qualname____firstlineno____doc__dsnamer   intr3   r;   rP   rY   rD   rf   propertyrl   rs   rv   r}   rJ   r!   r#   r%   __static_attributes____classcell__)r7   s   @r,   r   r   9   s    "H F
*  4@7r%8
& 2 2,
	
J*X7 7r.   r   c                      [         R                  " S5      n U c  [        R                  S5        gSU R	                  5       ;  a  [        R                  S5        gg)Nzsystem-product-namezNo system-product-name foundFvmwarezNot a VMware platformT)r   read_dmi_datarA   rB   rr   )system_types    r,   r@   r@     sM    ##$9:K		01	**,	,		)*r.   c                    [         R                  SX5        SnUS;   aA  [         R                  SX5        [        R                  " [        R
                  " U5      5      nOKUS;   a-  [         R                  SX5        [        R
                  " U5      nO[         R                  SU 5        Un[        R                  " U5      $ )zy
decode returns the decoded string value of data
key is a string used to identify the data being decoded in log messages
z'Getting encoded data for key=%s, enc=%sN)zgzip+base64zgz+b64zDecoding %s format %s)base64b64zPlain-text data %s)rA   rB   r   decomp_gzipr   b64ddecode_binary)keyenc_typedataraw_datas       r,   decoder     s    
 II7GH,,		)89##M$6$6t$<=	&	&		)89 %%d+		&,h''r.   c                 v    [         R                  " U 5      n U R                  5       n U (       a
  U [        :X  a  gU $ )z
get_none_if_empty_val returns None if the provided value, once stripped
of its trailing whitespace, is empty or equal to GUESTINFO_EMPTY_YAML_VAL.

The return value is always a string, regardless of whether the input is
a bytes class or a string.
N)r   r   rq   GUESTINFO_EMPTY_YAML_VAL)vals    r,   get_none_if_empty_valr     s2     

S
!C
**,CS44Jr.   c                 >   U (       a  U(       a  U(       d  gU R                  [        5      nU(       a'  [        [        X1U5        [        R	                  SU5        U R                  [
        5      nU(       a(  [        [
        XAU5        [        R	                  SU5        gg)z
advertise_local_ip_addrs gets the local IP address information from
the provided host_info map and sets the addresses in the guestinfo
namespace
Nz-advertised local ipv4 address %s in guestinfoz-advertised local ipv6 address %s in guestinfo)r   
LOCAL_IPV4guestinfo_set_valuerA   rC   
LOCAL_IPV6)rX   r   r   
local_ipv4
local_ipv6s        r,   rT   rT     sm     G: z*JJ
ZH@*Mz*JJ
ZH@*M r.   c                 X    [        U5      nU(       a  U$ [        R                  SU 5        g)z
handle_returned_guestinfo_val returns the provided value if it is
not empty or set to GUESTINFO_EMPTY_YAML_VAL, otherwise None is
returned
No value found for key %sN)r   rA   rB   )r   r   s     r,   handle_returned_guestinfo_valr     s(      
$C

II)3/r.   c                     g)Nzvmware-tools r   s    r,   r_   r_     s    r.   c                     SU -   $ )Nz
guestinfo.r   r   s    r,   r^   r^   #  s    #r.   c                 \    S[        U 5      -   R                  5       R                  SSS5      $ )Nzvmx.._)r^   upperreplacer   s    r,   r]   r]   '  s+    +C00779AA#sBOOr.   c                 n    [        U 5      nU(       d  g [        U S-   5      n[        [        U 5      X!5      $ )N	.encoding)guestinfo_envvar_get_valuer   r]   )r   r   r   s      r,   r   r   +  s4    
$S
)C)#*;<H/4hDDr.   c                 l    [        U 5      n[        U [        R                  R	                  US5      5      $ )Nr   )r]   r   r   r   r   )r   env_keys     r,   r   r   3  s(    +C0G(bjjnnWb.IJJr.   c                 $    [        X/5      u  p#X#4$ rd   r   r   argstdoutstderrs       r,   r   r   8  s    WN+Vr.   c                 (    [        U SU/5      u  p#X#4$ )Nz--cmdr   r   s       r,   r   r   =  s    Wgs34Vr.   c                 r    [        XU5      nU(       d  g[        U S-   X5      n[        [        U 5      XC5      $ )z^
guestinfo returns the guestinfo value for the provided key, decoding
the value when required
Nr   )guestinfo_get_valuer   r^   )r   r   r   r   r   s        r,   r   r   B  s:    
 cJ
7C"3#4gJH(-x==r.   c                    [         R                  SU 5         U" US[        U 5      -   5      u  p4U[        :X  a  [         R                  SU 5        OU(       d  [         R	                  SU 5        [        X5      $ ! [         aS  nUR                  [        :X  a  [         R                  SU 5         SnAg[        R                  " [         SU U5        UeSnAf[         a$  n[        R                  " [         SU U5        UeSnAff = f)z2
Returns a guestinfo value for the specified key.
z"Getting guestinfo value for key %sz	info-get r   z(Failed to get guestinfo value for key %sz,Failed to get guestinfo value for key %s: %sNzCUnexpected error while trying to get guestinfo value for key %s: %s)rA   rB   r^   NOVALr   r   r   r   r   r   r   )r   r   r   r   r   r   s         r,   r   r   N  s     II2C8!%[#9##>>
 U?II137II@#F,S99   <<5 II1377, # KK>	 K -	
 s*   AA8 8
D*C1CDC<<Dc                 0   US:X  a  Sn[         R                  SX5         U" US[        U 5      < SU< 35        g! [         a(  n[        R
                  " [         SU UU5         SnAgSnAf[         a     [        R
                  " [         SU U5         gf = f)	zp
Sets a guestinfo value for the specified key. Set value to an empty string
to clear an existing guestinfo key.
r    z$Setting guestinfo key=%s to value=%sz	info-set Tz.Failed to set guestinfo key=%s to value=%s: %sNzAUnexpected error while trying to set guestinfo key=%s to value=%s)rA   rB   r^   r   r   r   r   )r   valuer   r   r   s        r,   r   r   z  s     {II4cA
)?)DeL	
   

 	<	
 	
    
+	
 
s   ; 
BA((*BBc                 ~   U (       d  g[        U 5      [        [        4;  a  U /n U  H  n[        U5      n[        R                  SU5        [        U[        X5      (       d  [        R                  SU5        [        R                  SU5        [        US-   SX5      (       a  M}  [        R                  SU5        M     g)z
guestinfo_redact_keys redacts guestinfo of all of the keys in the given
list. each key will have its value set to "---". Since the value is valid
YAML, cloud-init can still read it if it tries.
Nzclearing %szfailed to clear %szclearing %s.encodingr   r   zfailed to clear %s.encoding)	typelisttupler^   rA   rC   r   r   r   )keysr   r   r   r|   s        r,   r   r     s     Dz$&v)#.)")7
 
 II*H5'2"3#4b'NNII3X> r.   c                     U (       d  0 $ [        U [        5      (       a  U $  [        R                  " U 5      $ ! [        R
                  [        4 a    [        R                  " U 5      s $ f = f)z
load first attempts to unmarshal the provided data as JSON, and if
that fails then attempts to unmarshal the data as YAML. If data is
None then a new dictionary is returned.
)
isinstancedictr   	load_jsonjsonJSONDecodeError	TypeError	load_yaml)r   s    r,   rF   rF     s[     	$$~~d##  ), $~~d##$s   8 0A+*A+c                    U (       d  0 $ SnSU ;   a  U S   nU S	 SnSU ;   a  U S   nU S	 U(       a  [        U[        R                  R                  5      (       a.  [        R                  S5        S[        R                  " U5      0nO/[        R                  SU5        [        SX!5      nS[        U5      0n[        R                  SU5        XS'   U $ )	zS
process_metadata processes metadata and loads the optional network
configuration.
Nri   znetwork.encodingz#network data copied to 'config' keyrj   znetwork data to be decoded %szmetadata.networkznetwork data %s)
r   collectionsabcMappingrA   rB   copydeepcopyr   rF   )r   ri   network_encdec_nets       r,   rE   rE     s    
 	GDy/OKT!-.#$g{6677II;<w!78GII5w?/FG+G4G 			#W-!YKr.   c                 8    [         R                  " U [        5      $ )zC
Return a list of data sources that match this set of dependencies
)r   list_from_dependsdatasources)dependss    r,   get_datasource_listr    s     $$Wk::r.   c                  T   Sn Sn[         R                  " 5       nUS    H  nUS   S:X  d  M  US   n   O   US    H  nUS   S:X  d  M  US   n  O   SnSn[         R                  " 5       nX;   aM  X`   S   n[        U5      S:  a  [        R                  S	X5        O [        U5      S:X  a  S
US   ;   a  US   S
   nX;   aM  Xa   S   n[        U5      S:  a  [        R                  SX5        O [        U5      S:X  a  S
US   ;   a  US   S
   nUbI  UcF  U H@  nXh   S    H2  n	U	S
   U:X  d  M  [        Xh   S   5      S:X  d  M$  Xh   S   S   S
   n  M>     MB     UcI  UbF  U H@  nXh   S    H2  n	U	S
   U:X  d  M  [        Xh   S   5      S:X  d  M$  Xh   S   S   S
   n  M>     MB     XE4$ )a1  
Returns the default IPv4 and IPv6 addresses based on the device(s) used for
the default route. Please note that None may be returned for either address
family if that family has no default route or if there are multiple
addresses associated with the device used by the default route for a given
address.
Nr   destination0.0.0.0ifacer   z::/0   z,device %s has more than one ipv4 address: %sipr   z,device %s has more than one ipv6 address: %s)r   
route_infonetdev_infolenrA   rB   )
ipv4_ifipv6_ifroutesrouter   r   netdevaddrsdev_nameaddrs
             r,   get_default_ip_addrsr     s    GG!F9,GnG   6)GnG   DD  "F'u:>II> Z1_q!18D>D'u:>II> Z1_q!18D>D
 DLH(0:%#f.>v.F*G1*L!+F3A6t<D 1  |(H(0:%#f.>v.F*G1*L!+F3A6t<D 1  :r.   c                 H   U R                  5       n U (       a  U S:X  a  [        R                  " 5       n  [        R                  " U SS[        R
                  S[        R                  5      nU H  nUS   (       d  M  US   n   U $     U $ ! [        R                   a     U $ f = f)zgGet fully qualified domain name from name.
An empty argument is interpreted as meaning the local host.
r  Nr      )stripr   get_hostnamesocketgetaddrinfo
SOCK_DGRAMAI_CANONNAMEr   )namer  r  s      r,   getfqdnr*  >  s     ::<D49$  "
""$6,,a1D1D
 DAwwAwK	  K <<  Ks   7B	 	B! B!c                     [         R                  " [        R                  U 5      nU=(       a7    UR                  =(       d    UR
                  =(       d    UR                  (       + $ )zb
Returns false if the address is loopback, link local or unspecified;
otherwise true is returned.
)r   maybe_get_address	ipaddress
ip_addressis_link_localis_loopbackis_unspecified)r   r  s     r,   is_valid_ip_addrr2  U  sM    
   !5!5s;D Ed..E$2E2E r.   r  r0   c                     U R                  S5      (       d  0 $ U R                  S5      U R                  S5      U R                  S5      S.$ )a  
Takes a cloudinit.netinfo formatted address and converts to netifaces
format, since this module was originally written with netifaces as the
network introspection module.
netifaces ipv4 format:
{
  "broadcast": "10.15.255.255",
  "netmask": "255.240.0.0",
  "addr": "10.0.1.4"
}
cloudinit.netinfo ipv4 format:
{
  "ip": "10.0.1.4",
  "mask": "255.240.0.0",
  "bcast": "10.15.255.255",
  "scope": "global",
}
r  bcastmask)	broadcastnetmaskr  )r   )r  s    r,    convert_to_netifaces_ipv4_formatr8  `  sC    & 88D>>	XXg&88F# r.   c                     U R                  S5      (       d  0 $ [        R                  " U R                  S5      5      nUR                   SUR                  R
                   3[        UR                  5      S.$ )ao  
Takes a cloudinit.netinfo formatted address and converts to netifaces
format, since this module was originally written with netifaces as the
network introspection module.
netifaces ipv6 format:
{
  "netmask": "ffff:ffff:ffff:ffff::/64",
  "addr": "2001:db8:abcd:1234::1"
}
cloudinit.netinfo ipv6 format:
{
  "ip": "2001:db8:abcd:1234::1/64",
  "scope6": "global",
}
r  /)r7  r  )r   r-  IPv6Interfacer7  ri   	prefixlenstrr  )r  r   s     r,    convert_to_netifaces_ipv6_formatr>  |  s`      88D>>	""488D>2Dll^1T\\%;%;$<=DGG r.   c                     SS[         R                  " 5       [         R                  " 5       [         R                  " 5       S.00n [        [        R                  " 5       5      nU(       a  XS'   XS'   XS'   [        5       u  p#U(       a  X [        '   U(       a  X0[        '   U S   S   S   nU S   S   S   nU S   S   S	   n[        R                  " 5       nU GH  n/ n	/ n
Xx   S
    H  nU	R                  [        U5      5        M     Xx   S    H  nU
R                  [        U5      5        M     Xx   R                  S5      nUS:X  a  Ms  U(       a  U	(       d  U
(       a  Un0 nU	(       a5  / nU	 H)  n[        US   5      (       d  M  UR                  U5        M+     XS
'   U
(       a6  / nU
 H)  n[        US   5      (       d  M  UR                  U5        M+     UUS'   XU'   U	(       aH  U	 HB  nUS   n[        U5      (       d  M  [        R                   " U5      nUS	 U(       a  XS'   XU'   MD     U
(       d  GMb  U
 HB  nUS   n[        U5      (       d  M  [        R                   " U5      nUS	 U(       a  XS'   XU'   MD     GM     U $ )zH
Returns host information such as the host name and network interfaces.
ri   
interfaces)by-macby-ipv4by-ipv6hostnamezlocal-hostnamelocal_hostnamerA  rB  rC  r   r   hwaddrz00:00:00:00:00:00r  mac)r  OrderedDictr*  r   r$  r   r   r   r   r  appendr8  r>  r   r2  r  r  )rX   rD  default_ipv4default_ipv6by_macby_ipv4by_ipv6ifacesr  af_inet4af_inet6r  rG  r   r   af_inet4_valsip_infoaf_inet6_valss                     r,   get_host_inforU    s   
 	%113&224&224
I t((*+H (*&."#&."#!5!7L ,* ,*y!,/9F	"<0;G	"<0;G  "F$V,DOO<TBC -$V,DOO<TBC - ""8, %%HCC "'G+GFO<< !((1  ( ,F "'G+GFO<< !((1  ( ,F3K#fo',,mmG,K!$J" $ 8#fo',,mmG,K!$J" $[ n r.   c                 `   SnSn[         U ;   a  U [            n[        U;   a7  U[           n[        U[        5      (       a  UnO[        R
                  " U5      n[        U;   a7  U[           n[        U[        5      (       a  UnO[        R
                  " U5      nSu  pgnUc  [        5       nUR                  S5      =(       d    0 n	U	R                  S5      =(       d    0 n
U
R                  S5      =(       d    0 nU
R                  S5      =(       d    0 nU(       a   U(       a  [        U5      S:  OSnU(       d  S nU(       a   U(       a  [        U5      S:  OSnU(       d  S nUc/  [        R                  SUUUU5        [        R                  " S	5        Uc  M  [        R                  S
5        U$ )NF)NFFri   r@  rB  rC  r   z<waiting on network: wait4=%s, ready4=%s, wait6=%s, ready6=%sr  zwaiting on network complete)WAIT_ON_NETWORKWAIT_ON_NETWORK_IPV4r   boolr   translate_boolWAIT_ON_NETWORK_IPV6rU  r   r  rA   rB   timesleep)rG   wait_on_ipv4wait_on_ipv6rS   wait_on_ipv4_valwait_on_ipv6_valrX   
ipv4_ready
ipv6_readyri   r@  rM  rN  s                r,   rS   rS     sz   LL(""?3?2./CD*D11/#223CD?2./CD*D11/#223CD );%I:

 "O	--	*0b[[.4"
..+1r..+1r-4W)%J 	-4W)%J 	IIN JJqM; 
> II+,r.   c                      [         R                  " 5         [        [        S[
        S0SSSS000n [        U 5      n[        R                  " X/5      n [        [        R                  " U 5      5        g! [         a     Nhf = f)z/
Executed when this file is used as a program.
TFri   rj   dhcpN)r	   setup_basic_loggingr   rW  rX  r[  rS   r   rU   printr   
json_dumps)rG   rX   s     r,   mainri  %  s    ##% 	 $ %
 	Hvtn-H  )I!!8"78H	-
"
"8
,-  s   A3 3
B ?B __main__)r   )Jr   r  r  r-  r   loggingr   r%  r\  	cloudinitr   r   r   r   r   r   cloudinit.logr	   $cloudinit.sources.helpers.vmware.imcr
   cloudinit.subpr   r   r   rp   	getLoggerr   rA   r   r    r"   r$   r   r   r   r   r   r   rW  rX  r[  r   r   r@   r   r   rT   r   r_   r^   r]   r   r   r   r   r   r   r   r   rF   rE   DEP_FILESYSTEMDEP_NETWORKr  r  r   r*  r2  r   r8  r>  rU  rS   ri  r   r.   r,   <module>rs     s        	   E E ! ? = =9 ! % *  	'   

#  Nw)) Nb(*$N,
PEK


	>)X(V?,$"H ..01..0C0CDE;?D.4 D 84 D 2Up5p.( zF r.   