܍~c UdZddlmZddlmZddlmZmZmZddl m Z ddl m Z ddl mZmZddlmZdd lmZeZgd Zd Zd d deegeededgdgdZeed<eeZdede de dededdf dZdS)zPhone Home: Post data to url)Logger)dedent) templater url_helperutil)Cloud)Config) MetaSchema get_meta_doc) ALL_DISTROS) PER_INSTANCE) pub_key_dsa pub_key_rsa pub_key_ecdsapub_key_ed25519 instance_idhostnamefqdnajThis module can be used to post data to a remote host after boot is complete. If the post url contains the string ``$INSTANCE_ID`` it will be replaced with the id of the current instance. Either all data can be posted or a list of keys to post. Available keys are: - ``pub_key_dsa`` - ``pub_key_rsa`` - ``pub_key_ecdsa`` - ``pub_key_ed25519`` - ``instance_id`` - ``hostname`` - ``fdqn`` Data is sent as ``x-www-form-urlencoded`` arguments. **Example HTTP POST**: .. code-block:: http POST / HTTP/1.1 Content-Length: 1337 User-Agent: Cloud-Init/21.4 Accept-Encoding: gzip, deflate Accept: */* Content-Type: application/x-www-form-urlencoded pub_key_dsa=dsa_contents&pub_key_rsa=rsa_contents&pub_key_ecdsa=ecdsa_contents&pub_key_ed25519=ed25519_contents&instance_id=i-87018aed&hostname=myhost&fqdn=myhost.internal cc_phone_homez Phone HomezPost data to urlzt phone_home: url: http://example.com/$INSTANCE_ID/ post: all as phone_home: url: http://example.com/$INSTANCE_ID/ post: - pub_key_dsa - pub_key_rsa - pub_key_ecdsa - pub_key_ed25519 - instance_id - hostname - fqdn tries: 5 phone_home)idnametitle descriptiondistros frequencyexamplesactivate_by_schema_keysmetarcfgcloudlogargsreturnNc t|dkrtj|d}n$d|vr|d|dS|d}d|vr|d|dS|d}|dd}|d} t |}n/#ttf$rd }tj |d |YnwxYw|dkrt}| | j | d j d } ddddd} | D]C\} } tj| | | <#t $rtj |d| Y@wxYwi} |D]-}|| vr | || |<d| |<|d|.i}| D]\}}|d||< t#|||< d| di}t%j||} t)j|||dz dtj|jdS#t $rtj |d||YdSwxYw)Nrrz=Skipping module named %s, no 'phone_home' configuration foundurlzFSkipping module named %s, no 'url' found in 'phone_home' configurationpostalltries z?Configuration entry 'tries' is not an integer, using %s insteadT)r)rrrz/etc/ssh/ssh_host_dsa_key.pubz/etc/ssh/ssh_host_rsa_key.pubz/etc/ssh/ssh_host_ecdsa_key.pubz!/etc/ssh/ssh_host_ed25519_key.pub)rrrrz1%s: failed to open, can not phone home that data!z=Requested key %s from 'post' configuration list not availablezN/A INSTANCE_IDr)dataretries sec_between ssl_detailsz0Failed to post phone home data to %s in %s tries)lenr read_confdebugwarninggetint ValueError TypeErrorlogexc POST_LIST_ALLget_instance_id get_hostnameritems load_file Exceptionstrr render_stringrread_file_or_urlfetch_ssl_detailspaths)rr r!r"r#ph_cfgr& post_listr)all_keyspubkeysnpath submit_keyskreal_submit_keysv url_paramss @/usr/lib/python3/dist-packages/cloudinit/config/cc_phone_home.pyhandlerRosi 4yyA~~Q(( s " " II6    F\" F  ;     -C 65))I JJw  E E   "     M       E! ,,..&&((1"""--6H76:> G]]__ D ...HQKK    KH$       K    ==%a[KNN!KN KK4    ##%%))A 9"' Q  "%a&& Q   x .J  !#z 2 2C  # !AI.u{;;            CS%       s6#B33)CCE00 FF3I!I87I8)__doc__loggingrtextwrapr cloudinitrrrcloudinit.cloudrcloudinit.configr cloudinit.config.schemar r cloudinit.distrosr cloudinit.settingsr rr;MODULE_DESCRIPTIONr__annotations__rAlistrRrQras#""1111111111!!!!!!######<<<<<<<<))))))++++++   >   %}       0!-~?  j   D ,t  ` ` ` #(` /5` =A`  ` ` ` ` ` ` r`