
    }f/                     6   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZmZmZ dZ ej0                  e      ZdZdZd	Zd
ZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ' G d dejP                        Z)d Z*d Z+d Z,d Z-d Z.d Z/d Z0d Z1d Z2d Z3d  Z4d! Z5d" Z6d# Z7d$ Z8d% Z9d& Z:d' Z;e)ejx                  ffe)ejx                  ejz                  ffgZ>d( Z?d) Z@d4d*ZAd+ ZBd,eCd-eCfd.ZDd,eCd-eCfd/ZEd0 ZFd1 ZGd2 ZHed3k(  r eH        yy)5zCloud-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lognetnetinfosourcesutil)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                        e Zd ZdZdZddZdeddf fdZd Zd	 Z	d
 Z
d Zd Zed        Zd Zd Zd Zd Zd Zd Zd Z xZS )DataSourceVMwareav  
    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                     t         j                  j                  | ||||       i | _        d | _        d | _        d | _        t        | j                  dft        | j                  dft        | j                  dfg| _        y )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   zDataSourceVMware.__init___   sw    ##D'65'J"& '(?(?G)4+E+EtL#T%9%94@1
-    ci_pkl_versionreturnc           	      8   t         |   |       dD ]  }t        | |      rt        | |d         t        | d      st        | di        t        | d      sDt        | dt        | j
                  dft        | j                  dft        | j                  dfg       y y )N)r   r   r   r%   FT)
super	_unpicklehasattrsetattrr   r    r!   r"   r#   r$   )r&   r-   attr	__class__s      r+   r1   zDataSourceVMware._unpicklet   s    .)- 	*D4&dD)	* tU#D%$t?@2 2// 522
 ,T-A-A4H Ar,   c                 d    t         j                  j                  |       }|d| j                  dS )Nz [seed=])r   r   __str__r   )r&   roots     r+   r8   zDataSourceVMware.__str__   s)    !!))$/!%t'>'>??r,   c                    d\  }}}| j                   D ]-  \  }}}|rt               s |       \  }}}|s|s|s&|| _         n | j                  st        j	                  d       yt        j                  d| j                                t        t        |            | _	        || _
        || _        | j                          | j                  s| j                  s| j                  ryy)a  
        _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_datazDataSourceVMware._get_data   s    " &
B 22	
	 
#&/A/C&=LRRR2*<'
	 &&IIAB.0E0E0GH )):2)>?  ! 	 ==D--1D1Dr,   c                    t        | j                        }t        j                  d|       t	        || j
                  | j                         t        j                  | j                  |g      | _        | j                          y)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_networkrC   r=   r?   advertise_local_ip_addrsr   r   r	   mergemanydictpersist_instance_data)r&   is_new_instance	host_infos      r+   setupzDataSourceVMware.setup   sb     $DMM2	$i0 	!DLL$//J
 **DMM9+EF 	""$r,   c                     d }| j                   t        k(  rt        }nD| j                   t        k(  rt        }n*| j                   t
        k(  rt        }nt        j                  S | j                   d |d      dS )Nz (rC   ))	r   r   get_guestinfo_envvar_key_namer!   get_guestinfo_key_namer#   get_imc_key_namer   METADATA_UNKNOWN)r&   get_key_name_fns     r+   r@   z!DataSourceVMware._get_subplatform   sl    ""&??;O$$(DD4O$$(>>.O+++ ##J'
 	
r,   c                     | j                   S N)r   r&   s    r+   get_config_objzDataSourceVMware.get_config_obj   s    xxr,   c                     d| j                   v rt        j                  d       n>t        j                  d       d| j                  j	                         i| j                   d<   | j                   d   d   S )Nnetworkzusing metadata network configzusing fallback network configconfig)rC   r=   r>   r(   generate_fallback_configr^   s    r+   network_configzDataSourceVMware.network_config   s`    %II56II56$++>>@(DMM)$ }}Y'11r,   c                 B   | j                   rd| j                   v r| j                   d   S t        t        d      5 }t        |j	                               j                         j                         | j                   d<   | j                   d   cd d d        S # 1 sw Y   y xY w)Nzinstance-idr)rC   openPRODUCT_UUID_FILE_PATHstrreadrstriplower)r&   id_files     r+   get_instance_idz DataSourceVMware.get_instance_id  s~     ==]dmm;==//(#. 	0'+.w||~+>+E+E+G+M+M+ODMM-(==/	0 	0 	0s   ABBc                     | j                   rB| j                   t        k(  r/t               r%t        j	                  d| j                                yy)Nz"Cache fallback is allowed for : %sTF)r   r#   r<   r=   r>   r@   r^   s    r+   check_if_fallback_is_allowedz-DataSourceVMware.check_if_fallback_is_allowed  sB    ##''+AA"$II4d6K6K6M r,   c                 x    dD ]4  }|| j                   v st        j                  | j                   |         c S  g S )N)zpublic-keys-datapublic_keys_datazpublic-keyspublic_keys)rC   r   normalize_pubkey_data)r&   key_names     r+   get_public_ssh_keysz$DataSourceVMware.get_public_ssh_keys  sD    
 	NH 4==(44T]]85LMM	N 	r,   c                    d }t         | j                  v r| j                  t            }n%t        | j                  v r| j                  t           }| j                  t        k(  r"t        || j                  | j                         y y r]   )REDACTrC   CLEANUP_GUESTINFOr   r!   guestinfo_redact_keysr   r   )r&   keys_to_redacts     r+   rF   zDataSourceVMware.redact_keys(  sh    T]]"!]]62N$--/!]]+<=N""&BB!doo Cr,   c                     d\  }}}t         j                  j                  t        d      r!t	        d      }t	        d      }t	        d      }|||fS )z<
        check to see if there is data via env vars
        r;    rC   userdata
vendordata)osenvirongetr   guestinfo_envvar)r&   rG   rH   rI   s       r+   r    z#DataSourceVMware.get_envvar_data_fn6  sK     &
B::>>-,!*-B!*-B!,/BB|r,   c                 8   t        d      }t        d      }|r(|| _        t        | _        t        j                  d|       |r*|s|| _        t        | _        t        j                  d|       | j                  st        j                  d       yd }	  || j                  | j                        S # t        $ r}t        j                  t        d| j                  |       |r| j                  |k(  rY d	}~y|st        j                  d
       Y d	}~yt        j                  d       || _        t        | _        	  || j                  | j                        cY d	}~S # t        $ r- t        j                  t        d| j                  |       Y Y d	}~yw xY wd	}~ww xY w)zK
        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                     d\  }}}t         j                  d|        t        d| |      }t        d| |      }t        d| |      }|||fS )Nr;   zquery guestinfo with %srC   r~   r   )r=   r?   r   )r   r   rG   rH   rI   s        r+   query_guestinfoz?DataSourceVMware.get_guestinfo_data_fn.<locals>.query_guestinfo^  sR    )JBBHH.8:w
;B:w
;B<*=Br2:r,   z%Failed to query guestinfo with %s: %sNz$vmtoolsd fallback option not presentzfallback to vmtoolsd)r   r   exec_vmware_rpctoolr   r=   r>   exec_vmtoolsd	Exceptionr	   logexcr?   )r&   r   vmware_rpctoolr   errors        r+   r"   z&DataSourceVMware.get_guestinfo_data_fnB  sP   
 $/0 )DL1DOII5~F "'"/II/: ||II-.%	&	* #4<<AA "	*KK7	 DLLH4)?@)HH+,#DL+DO
*&t||T__EE *;LL	 **5"	*sH   B0 0	F97F5F'F9EF/F
FFFFc                    d\  }}}t        j                  | j                        }t        j                  | j                        }|s|st
        j                  d       |||fS t        j                         s|||fS t        j                  | j                        }||||fS t        j                  j                  |      }t        j                  |      }t        j                  |      \  }	}
|	rr|rpt
        j                  d       t        j                  | j                  j                   | j                  j#                  d      ||| j$                        \  }}}| _        nH|
r1|r/t
        j                  d       t        j(                  |      \  }}}nt
        j                  d       t+        j,                  |       |||fS )zN
        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_cfgr=   r>   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&   rG   rH   rI   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$   z DataSourceVMware.get_imc_data_fn  s    &
B +AA$,,O,EEKK
 !)<IIEFB< 668B< '88E B< ww}5!00? ,,X6	
  "3IIKL%3%N%N

$$

$$Y/&"RR "&9II. *MMLRR IIIJ 	\"B|r,   r]   )__name__
__module____qualname____doc__dsnamer   intr1   r8   rL   rT   r@   r_   propertyrd   rn   rp   rv   rF   r    r"   r$   __classcell__)r5   s   @r+   r   r   8   s|    "H F
*  4@7r%8
& 2 20
	
J*X7r,   r   c                      t        j                  d      } | t        j                  d       yd| j	                         vrt        j                  d       yy)Nzsystem-product-namezNo system-product-name foundFvmwarezNot a VMware platformT)r   read_dmi_datar=   r>   rl   )system_types    r+   r<   r<     sM    ##$9:K		01	**,	,		)*r,   c                 x   t         j                  d| |       d}|dv r@t         j                  d||        t        j                  t	        j
                  |            }nI|dv r-t         j                  d||        t	        j
                  |      }nt         j                  d|        |}t        j                  |      S )z
    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)r=   r>   r	   decomp_gzipr   b64ddecode_binary)keyenc_typedataraw_datas       r+   decoder     s    
 II7hGH,,		)8S9##M$6$6t$<=	&	&		)8S9 %%d+		&,h''r,   c                     t        j                  |       } | j                         } t        |       dk(  s	| t        k(  ry| S )a  
    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.
    r   N)r	   r   rk   lenGUESTINFO_EMPTY_YAML_VAL)vals    r+   get_none_if_empty_valr     s:     

S
!C
**,C
3x1}77Jr,   c                    | r|r|sy| j                  t              }|r(t        t        |||       t        j	                  d|       | j                  t
              }|r)t        t
        |||       t        j	                  d|       yy)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_valuer=   r?   
LOCAL_IPV6)rS   r   r   
local_ipv4
local_ipv6s        r+   rO   rO     sq     G: z*JJ
GZH@*Mz*JJ
GZH@*M r,   c                 N    t        |      }|r|S t        j                  d|        y)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   r=   r>   )r   r   s     r+   handle_returned_guestinfo_valr     s(      
$C

II)3/r,   c                      y)Nzvmware-tools r   s    r+   rY   rY     s    r,   c                     d| z   S )Nz
guestinfo.r   r   s    r+   rX   rX   !  s    #r,   c                 \    dt        |       z   j                         j                  ddd      S )Nzvmx.._)rX   upperreplacer   s    r+   rW   rW   %  s+    +C00779AA#sBOOr,   c                 f    t        |       }|sy t        | dz         }t        t        |       ||      S )N	.encoding)guestinfo_envvar_get_valuer   rW   )r   r   r   s      r+   r   r   )  s6    
$S
)C)#*;<H/4hDDr,   c                 l    t        |       }t        | t        j                  j	                  |d            S )Nr}   )rW   r   r   r   r   )r   env_keys     r+   r   r   1  s(    +C0G(bjjnnWb.IJJr,   c                 *    t        | |g      \  }}||fS r]   r   r   argstdoutstderrs       r+   r   r   6  s     WcN+VVFr,   c                 ,    t        | d|g      \  }}||fS )Nz--cmdr   r   s       r+   r   r   ;  s#    Wgs34VVFr,   c                 n    t        | ||      }|syt        | dz   ||      }t        t        |       ||      S )zj
    guestinfo returns the guestinfo value for the provided key, decoding
    the value when required
    Nr   )guestinfo_get_valuer   rX   )r   r   r   r   r   s        r+   r   r   @  s@    
 c7J
7C"3#4gzJH(-x==r,   c                    t         j                  d|        	  ||dt        |       z         \  }}|t        k(  rt         j                  d|        n|st         j	                  d|        t        | |      S # t        $ rR}|j                  t        k(  rt         j                  d|        nt        j                  t         d| |       |Y d}~yd}~wt        $ r#}t        j                  t         d| |       |d}~ww xY w)z:
    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)r=   r>   rX   NOVALr   r   r   r   r	   r   r   )r   r   r   r   r   r   s         r+   r   r   L  s     II2C8!%[#9##>>
 U?II137II@#F,S&99   <<5 II137
 KK>	 K 8,   -	
 s%   AA4 4	C9=AC

C9C44C9c                 $   |dk(  rd}t         j                  d| |       	  ||dt        |       d|       y# t        $ r'}t	        j
                  t         d| ||       Y d}~yd}~wt        $ r t	        j
                  t         d| |       Y yw xY w)	z|
    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)r=   r>   rX   r   r	   r   r   )r   valuer   r   r   s        r+   r   r   x  s     {II4c5A
)?)DeL	
   

 	<	
 	
    
+	
 
s   9 	BA$$(BBc                 Z   | syt        |       t        t        fvr| g} | D ]  }t        |      }t        j                  d|       t        |t        ||      st        j                  d|       t        j                  d|       t        |dz   d||      rtt        j                  d|        y)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tuplerX   r=   r?   r   r   r   )keysr   r   r   ru   s        r+   rz   rz     s     Dz$&v 	?)#.)")7J
 II*H5'2"3#4b':NII3X>	?r,   c                     | si S t        | t              r| S 	 t        j                  |       S # t        j
                  t        f$ r t        j                  |       cY S w xY w)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+   rB   rB     sX     	$$~~d##  ), $~~d##$s   - .AAc                    | si S d}d| v r| d   }| d= d}d| v r| d   }| d= |rt        |t        j                  j                        r-t        j                  d       dt        j                  |      i}n0t        j                  d|       t        d||      }dt        |      i}t        j                  d|       || d<   | S )	z_
    process_metadata processes metadata and loads the optional network
    configuration.
    Nra   znetwork.encodingz#network data copied to 'config' keyrb   znetwork data to be decoded %szmetadata.networkznetwork data %s)
r   collectionsabcMappingr=   r>   copydeepcopyr   rB   )r   ra   network_encdec_nets       r+   rA   rA     s    
 	GDy/OKT!-.#$g{667II;<w!78GII5w?/gFG+G4G 			#W-!YKr,   c                 6    t        j                  | t              S )zK
    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                     d} d}t        j                         }|d   D ]  }|d   dk(  s|d   }  n |d   D ]  }|d   dk(  s|d   } n d}d}t        j                         }| |v rK||    d   }t        |      dkD  rt        j                  d	| |       nt        |      dk(  rd
|d   v r|d   d
   }||v rK||   d   }t        |      dkD  rt        j                  d||       nt        |      dk(  rd
|d   v r|d   d
   }|C|A|D ]<  }||   d   D ]/  }	|	d
   |k(  st        ||   d         dk(  s!||   d   d   d
   } < > |C|A|D ]<  }||   d   D ]/  }	|	d
   |k(  st        ||   d         dk(  s!||   d   d   d
   } < > ||fS )aI  
    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_infor   r=   r>   )
ipv4_ifipv6_ifroutesrouter   r   netdevaddrsdev_nameaddrs
             r+   get_default_ip_addrsr    s2    GG!F 9,GnG  6)GnG DD  "F&w'u:>II> Z1_q!18D>D&w'u:>II> Z1_q!18D>D
 DL 	Hx(0 :%#fX.>v.F*G1*L!(+F3A6t<D	 |( 	Hx(0 :%#fX.>v.F*G1*L!(+F3A6t<D	 :r,   c                 &   | j                         } | r| dk(  rt        j                         } 	 t        j                  | ddt        j
                  dt        j                        }|D ]  }|d   s	|d   }  | S  | S # t        j                  $ r Y | S w xY w)zoGet 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AwAwK		 K <<  Ks   6A9 9BBc                     t        j                  t        j                  |       }|xr) |j                  xs |j
                  xs |j                   S )zn
    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_addrr#  S  sM    
   !5!5s;D Ed..E$2E2E r,   r  r.   c                     | j                  d      si S | j                  d      | j                  d      | j                  d      d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_formatr)  ^  sA    & 88D>	XXg&88F# r,   c                     | j                  d      si S t        j                  | j                  d            }|j                   d|j                  j
                   t        |j                        d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 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  /)r(  r  )r   r  IPv6Interfacer(  ra   	prefixlenri   r  )r  r   s     r+    convert_to_netifaces_ipv6_formatr.  z  s^      88D>	""488D>2Dll^1T\\%;%;$<=DGG r,   c                  V   ddt        j                         t        j                         t        j                         dii} t        t        j                               }|r|| d<   || d<   || d<   t               \  }}|r	|| t        <   |r	|| t        <   | d   d   d   }| d   d   d   }| d   d   d	   }t        j                         }|D ]\  }g }	g }
||   d
   D ]  }|	j                  t        |              ||   d   D ]  }|
j                  t        |              ||   j                  d      }|dk(  rp|rm|	s|
ri|}i }|	r.g }|	D ]"  }t        |d         s|j                  |       $ ||d
<   |
r.g }|
D ]"  }t        |d         s|j                  |       $ ||d<   |||<   |	r<|	D ]7  }|d   }t        |      st        j                   |      }|d= |r||d<   |||<   9 |
s!|
D ]7  }|d   }t        |      st        j                   |      }|d= |r||d<   |||<   9 _ | S )zP
    Returns host information such as the host name and network interfaces.
    ra   
interfaces)by-macby-ipv4by-ipv6hostnamezlocal-hostnamelocal_hostnamer1  r2  r3  r   r   hwaddrz00:00:00:00:00:00r  mac)r   OrderedDictr  r	   r  r  r   r   r   r  appendr)  r.  r   r#  r   r   )rS   r4  default_ipv4default_ipv6by_macby_ipv4by_ipv6ifacesr  af_inet4af_inet6r  r7  r   r   af_inet4_valsip_infoaf_inet6_valss                     r+   get_host_inforE    s   
 	%113&224&224
I t((*+H (	*&.	"#&.	"#!5!7L, ,	* ,	*y!,/9F	"<0;G	"<0;G  "F 5#8$V, 	DDOO<TBC	D8$V, 	DDOO<TBC	D X""8, %%HCC "' 2G+GFO< !((12 ,F "' 2G+GFO< !((12 ,FF3K# #fo',mmG,K!$CJ"# # #fo',mmG,K!$CJ"#[5#n r,   c                    d}d}t         | v r{| t            }t        |v r1|t           }t        |t              r|}nt	        j
                  |      }t        |v r1|t           }t        |t              r|}nt	        j
                  |      }d\  }}}|t               }|j                  d      xs i }	|	j                  d      xs i }
|
j                  d      xs i }|
j                  d      xs i }|r|rt        |      dkD  nd}|sd }|r|rt        |      dkD  nd}|sd }|.t        j                  d||||       t        j                  d	       |t        j                  d
       |S )NF)NFFra   r0  r2  r3  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_IPV6rE  r   r   r=   r>   timesleep)rC   wait_on_ipv4wait_on_ipv6rN   wait_on_ipv4_valwait_on_ipv6_valrS   
ipv4_ready
ipv6_readyra   r0  r=  r>  s                r+   rN   rN     sv   LL(""?3?2./CD*D1/#223CD?2./CD*D1/#223CD );%Iz:

 "O	--	*0b[[.4"
..+1r..+1r-4W)%J 	-4W)%J 	IIN JJqM; 
> II+,r,   c                      	 t        j                          t        t        dt
        diddddiii} t        |       }t        j                  | |g      } t        t        j                  |              y# t        $ r Y fw xY w)z7
    Executed when this file is used as a program.
    TFra   rb   dhcpN)r   setup_basic_loggingr   rG  rH  rK  rN   r	   rP   printr   
json_dumps)rC   rS   s     r+   mainrY  #  s    ! 	 $ %
 	Hvtn-H  )I!!8Y"78H	-
"
"8
,-  s   A1 1	A=<A=__main__)r}   )Ir   r   r   r  r   loggingr   r  rL  	cloudinitr   r   r   r   r   r   r	   $cloudinit.sources.helpers.vmware.imcr
   cloudinit.subpr   r   r   rh   	getLoggerr   r=   r   r   r!   r#   rx   ry   r   r   r   r   rG  rH  rK  r   r   r<   r   r   rO   r   rY   rX   rW   r   r   r   r   r   r   r   rz   rB   rA   DEP_FILESYSTEMDEP_NETWORKr   r   r  r  r#  r   r)  r.  rE  rN   rY  r   r,   r+   <module>rb     s        	   J J J ? = =9 g! % *  	'   

#  Mw)) M`(*$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,   