+
    im2                        ^ RI t ^ RIt^ RIt^ RIHt ^ RIHtHtHt ^ RI	H
t
 ^ RIHtHtHtHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ] P6                  ! ]4      tRt ! R R4      t ! R R]P@                  4      t! ! R R]!4      t"R t#R t$R t%R R lt&]"]PN                  33]!]PN                  ]PP                  33.t)R t*R# )    N)suppress)gaierrorgetaddrinfo	inet_ntoa)pack)dminetperformancesources)
url_helper)util)dhcp)NoDHCPLeaseError)EphemeralIPNetwork)ec2
CloudStackc                   d   a  ] tR t^#t o RtR tR t]P                  ! RRR7      R 4       t	Rt
V tR	# )
CloudStackPasswordServerClientav  
Implements password fetching from the CloudStack password server.

http://cloudstack-administration.readthedocs.org/
   en/latest/templates.html#adding-password-management-to-your-templates
has documentation about the system.  This implementation is following that
found at
https://github.com/shankerbalan/cloudstack-scripts/
   blob/master/cloud-set-guest-password-debian
c                    Wn         R # Nvirtual_router_address)selfr   s   &&H/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceCloudStack.py__init__'CloudStackPasswordServerClient.__init__/   s    &<#    c                    R V P                    R2pRV/p\        P                  ! W#^^R7      pVP                  4       '       g   \	        R4      hVP
                  P                  R4      P                  4       # )http://z:8080DomU_Request)headerstimeoutretriesz+Failed to fetch VM password from CloudStackzutf-8)r   uhelpreadurlokRuntimeErrorcontentsdecodestrip)r   domu_requesturlr!   resps   &&   r   _do_request*CloudStackPasswordServerClient._do_request2   sh    334E:!<0}}S2qIwwyyLMM}}##G,2244r   zGetting passwordalwayslog_modec                    V P                  R 4      pVR9   d   R# VR8X  d   \        R4      hV P                  R4       V# )send_my_passwordsaved_passwordNbad_requestz-Error when attempting to fetch root password.) r5   )r.   r'   )r   passwords   & r   get_password+CloudStackPasswordServerClient.get_password=   sG    ##$67--}$NOO)*r   r   N)__name__
__module____qualname____firstlineno____doc__r   r.   r
   timedr9   __static_attributes____classdictcell__)__classdict__s   @r   r   r   #   s6     	=	5 )H= >r   r   c                      a a ] tR t^Ht oRtRt^xt^2tV 3R ltR t	RV 3R llt
R tR t]V3R lR	 l4       tR
 t]P"                  ! RRR7      R 4       tR t]R 4       tRtVtV ;t# )DataSourceCloudStackFr   c                   < \         SV `  WV4       \        P                  P	                  VP
                  R 4      V n        RV n        / V n        RV n        R# )cslatestN)	superr   ospathjoinseed_dirapi_vercfgvr_addr)r   sys_cfgdistropaths	__class__s   &&&&r   r   DataSourceCloudStack.__init__P   sC    %0U^^T:  r   c                |   \         P                  R4       R F3  p\        P                  ! V4      pV'       g   K#  VP	                  4       u # 	  \         P                  R4       \        \        P                  4      ;_uu_ 4        \        P                  ! 4       P                  V P                  R4      pV'       d   VP	                  4       uuRRR4       #  RRR4       \         P                  RV P                  P                  P                  4        V P                  P                  P                  V P                  P                  4      pVP                  R4      pV'       d   VP	                  4       #  \         P                  R4       R#   + '       g   i     L; i  \        \         \"        3 d     LBi ; i)	zTry obtaining a "domain-name" DHCP lease parameter:
- From systemd-networkd lease (case-insensitive)
- From ISC dhclient
- From dhcpcd (ephemeral)
- Return empty string if not found (non-fatal)
z.Try obtaining domain name from networkd leasesdomain-namezHCould not obtain FQDN from networkd leases. Falling back to ISC dhclientNzBCould not obtain FQDN from ISC dhclient leases. Falling back to %sz7No domain name found in any DHCP lease; returning emptyr7   )
DOMAINNAMEDomainrW   )LOGdebugr   networkd_get_option_from_leasesr*   r   NoDHCPLeaseMissingDhclientErrorIscDhclientget_key_from_latest_leaserR   dhcp_clientclient_nameget_newest_leasefallback_interfacegetr   FileNotFoundErrorAttributeError)r   key
domainnamedomain_namelatest_leases   &    r   _get_domainname$DataSourceCloudStack._get_domainnameY   s[    			BC:C==cBJz!'')) ;
 				
 d::;;**,FF]K "((* <; 	 < 			KK##//	

	;;22CC..L '**=9K"((** 
 			KL/ <;& !"3^D 		s&   AFAF" 'F" F	"F;:F;c                n  < \         SV `  WV4      pV'       d   RVP                  9  d   \        P	                  R4       V P                  4       pV'       dH   VP                   RV 2p\        P	                  RV4       \        P                  ! WP                  4      # \        P	                  RV4       V# )z
Returns instance's hostname / fqdn
First probes the parent class method.

If fqdn is requested, and the parent method didn't return it,
then attach the domain-name from DHCP response.
.zFQDN requestedzObtained the following FQDN: %szNCould not determine domain name for FQDN. Fall back to hostname as an FQDN: %s)	rI   get_hostnamehostnamerZ   r[   rk   r   DataSourceHostname
is_default)r   fqdn
resolve_ipmetadata_onlyrp   rh   rT   s   &&&&  r   ro   !DataSourceCloudStack.get_hostname   s     7'-HCx000II&'--/J"++,Aj\:		;TB11$8K8KLLII7
 r   c                   V P                  4       pVP                  ^ 8:  d   R# \        P                  ! V P                  R4      .p\
        P                  ! 4       p\        P                  ! VVP                  VP                  \        P                  R7      w  rEV'       d   \        P                  RV4       M:\        P                  RV\        \
        P                  ! 4       V,
          4      4       \        V4      # )r   Fzlatest/meta-data/instance-id)urlsmax_waitr"   	status_cbzUsing metadata source: '%s'z>Giving up on waiting for the metadata from %s after %s seconds)get_url_paramsmax_wait_secondsr$   combine_urlmetadata_addresstime	monotonicwait_for_urltimeout_secondsrZ   warningr[   criticalintbool)r   
url_paramsrx   
start_timer,   	_responses   &     r   wait_for_metadata_service.DataSourceCloudStack.wait_for_metadata_service   s    ((*
&&!+ %%'E

 ^^%
++00..kk	
 II3S9LL$DNN$z12	 Cyr   c                    V P                   # r   )rO   r   s   &r   get_config_obj#DataSourceCloudStack.get_config_obj   s    xxr   c                    < V ^8  d   QhRS[ /#    returnr   )formatrC   s   "r   __annotate__!DataSourceCloudStack.__annotate__   s     $ $t $r   c                     \        4       # )z#Check if running on this datasource)is_platform_viable r   r   	ds_detectDataSourceCloudStack.ds_detect   s     "##r   c                   / p\         P                  ! WP                  R ,           R7      '       d?   VR,          V n        VR,          V n        \
        P                  RV P                  4       R# V P                  '       dC   \        P                  ! 4       p\
        P                  RV4       \        V P                  V4      pM\         P                  ! 4       p T;_uu_ 4        \        V P                  4      p\        V\        4      '       d   VP!                  R4      MTV n        V P"                  '       g   \%        R4      hR	V P"                   R 2V n        V P)                  4       '       g    R
R
R
4       R# V P+                  4       uuR
R
R
4       #   + '       g   i     R
# ; i  \,         d    \
        P/                  RX4        R# \0         d+   p\
        P/                  R\3        T4      4        R
p?R# R
p?ii ; i)/)basez	user-dataz	meta-dataz%Using seeded cloudstack data from: %sTzAttempting DHCP on: %sdhcp-server-identifierzNo virtual router found!r   NFz#Unable to obtain a DHCP lease on %sz$Failed fetching metadata service: %s)r   read_optional_seedrM   userdata_rawmetadatarZ   r[   perform_dhcp_setupr	   find_fallback_nicr   rR   nullcontextget_vr_address
isinstancedictrd   rP   r'   r~   r   _crawl_metadatar   r   	Exceptionstr)r   seed_retprimary_nicnetwork_contextrP   es   &     r   	_get_dataDataSourceCloudStack._get_data   sw   ""8==33FHH ( 5D$[1DMII=t}}M"""//1KII.<0kJO"..0O	 (5 "'400 KK 89  
 |||&'ABB*1$,,q(A%5577  ! ++- !   	KK={K 	KK>AG	s[   
F( #AF95F/F0F( :F	
F( F%	F( %F( (!H H H G;;H zCrawling metadatar0   r1   c                   \         P                  ! V P                  V P                  4      V n        \         P
                  ! V P                  V P                  4      V n        \        V P                  4      p VP                  4       pV'       d   R RRVRRR//V n
        R#   \         d+    \        P                  ! \        RT P                  4        R# i ; i)
ssh_pwauthTr8   chpasswdexpireFz/Failed to fetch password from virtual router %s)r   get_instance_userdatarN   r~   r   get_instance_metadatar   r   rP   r9   rO   r   r   logexcrZ   )r   password_clientset_passwords   &  r   r   $DataSourceCloudStack._crawl_metadata   s    55LL$//
 11LL$//
 9F	*779L  $ %!   	KKA 	s   7B   1CCc                (    V P                   R ,          # )zinstance-idr   r   s   &r   get_instance_id$DataSourceCloudStack.get_instance_id  s    }}]++r   c                (    V P                   R ,          # )zavailability-zoner   r   s   &r   availability_zone&DataSourceCloudStack.availability_zone  s    }}011r   )rN   rO   r   r~   rM   r   rP   )FFF)r;   r<   r=   r>   r   dsnameurl_max_waiturl_timeoutr   rk   ro   r   r   staticmethodr   r   r
   r@   r   r   propertyr   rA   rB   __classcell__)rT   rC   s   @@r   rE   rE   H   s     F LK)V8> $ $"H *X> ?8, 2 2 2r   rE   c                       ] tR tRtRtRtRtR# )DataSourceCloudStackLocali  aa  Run in init-local using a dhcp discovery prior to metadata crawl.

In init-local, no network is available. This subclass sets up minimal
networking with dhclient on a viable nic so that it can talk to the
metadata service. If the metadata service provides network configuration
then render the network configuration for that instance based on metadata.
Tr   N)r;   r<   r=   r>   r?   r   rA   r   r   r   r   r     s     r   r   c                       \        R ^P4      p V ^ ,          ^,          ^ ,          #   \         d    \        P                  R4        R# i ; i)zdata-serverzDNS Entry data-server not foundN)r   r   rZ   r[   )addrinfos    r   get_data_serverr     sI    !}b1
 {1~a  	  		34s   %  A	A	c            
         \         P                  ! R 4      P                  4       p V  Fb  pVP                  R4      pV^,          R8X  g   K$  \	        \        R\        V^,          ^4      4      4      p\        P                  RV4       Vu # 	  R# )z/proc/net/route	00000000z<Lz"Found default route, gateway is %sN)	r   load_text_file
splitlinessplitr   r   r   rZ   r[   )lineslineitemsgws       r   get_default_gatewayr   '  su     12==?E

4 8z!4c%(B&789BII:B?I  r   c                 J   \        4       pV'       d   \        P                  R V4       V# \        P                  ! R4      pV'       d   \        P                  RV4       V# \        \        P                  4      ;_uu_ 4        \        P                  ! 4       P                  V R4      pV'       d#   \        P                  RV4       VuuRRR4       #  RRR4       \        \        4      ;_uu_ 4        V P                  P                  V P                  4      pV'       d8   \        P                  RVV P                  P                  4       VuuRRR4       #  RRR4       \        P                  R4       \        4       #   + '       g   i     L; i  + '       g   i     LB; i)z4Found metadata server '%s' via data-server DNS entrySERVER_ADDRESSz-Found SERVER_ADDRESS '%s' via networkd_leasesr   z&Found SERVER_ADDRESS '%s' via dhclientNz1Found SERVER_ADDRESS '%s' via ephemeral %s lease z$No DHCP found, using default gateway)r   rZ   r[   r   r\   r   r]   r^   r_   re   r`   rb   rc   ra   r   )rR   latest_addressrj   s   &  r   r   r   4  sG    %&N		B	
  99:JKN		;^	
 
 
$66	7	7))+EE,
 II>O! 
8	7 	 
8 
#	$	$))::%%
 IIC""..
   
%	$ 	 
% II45  - 
8	7 
%	$s   AE?2AF?F	F"	c                $    V ^8  d   QhR\         /# r   r   )r   s   "r   r   r   f  s     9 9D 9r   c                      \         P                  ! R 4      p V '       g   \        P                  R4       R# V P	                  \
        4      # )zsystem-product-namez-system-product-name not available in dmi dataF)r   read_dmi_datarZ   r[   
startswithCLOUD_STACK_DMI_NAME)product_names    r   r   r   f  s8    $$%:;L		AB""#788r   c                 8    \         P                  ! V \        4      # r   )r   list_from_dependsdatasources)dependss   &r   get_datasource_listr   v  s    $$Wk::r   )+loggingrJ   r   
contextlibr   socketr   r   r   structr   	cloudinitr   r	   r
   r   r   r$   r   cloudinit.netr   cloudinit.net.dhcpr   cloudinit.net.ephemeralr   cloudinit.sources.helpersr   	getLoggerr;   rZ   r   r   
DataSourcerE   r   r   r   r   r   DEP_FILESYSTEMDEP_NETWORKr   r   r   r   r   <module>r      s     	   3 3  4 4 )   / 6 )!# " "JE27-- E2P	 4 	!
/!d9 !7!7 9:G22G4G4GHI;r   