Current File : //lib/python2.7/site-packages/cloudinit/config/cc_chef.pyc
�
�jbc	@sdZddlZddlZddlZddlmZddlmZddlmZddlZdZ	e
ddd	d
ddg�Ze
dg�Zd
Z
dZdZdZidd6dd6dd6ed6dd6dd6ed6d
d6dd6dd6ed 6dd!6Zed g�Zedddddddd!g�Zeej��Zeje�eje�ejd"d#d$d%g�ee�Zd&Zd'Ze
d(d)d*d+d,g�Zd-�Zd.�Zd/�Z d0�Z!d1�Z"dddd2�Z#d3�Z$d4�Z%d5�Z&dS(6sD	
Chef
----
**Summary:** module that configures, starts and installs chef.

This module enables chef to be installed (from packages or
from gems, or from omnibus). Before this occurs chef configurations are
written to disk (validation.pem, client.pem, firstboot.json, client.rb),
and needed chef folders/directories are created (/etc/chef and /var/log/chef
and so-on). Then once installing proceeds correctly if configured chef will
be started (in daemon mode or in non-daemon mode) and then once that has
finished (if ran in non-daemon mode this will be when chef finishes
converging, if ran in daemon mode then no further actions are possible since
chef will have forked into its own process) then a post run function can
run that can do finishing activities (such as removing the validation pem
file).

**Internal name:** ``cc_chef``

**Module frequency:** per always

**Supported distros:** all

**Config keys**::

    chef:
       directories: (defaulting to /etc/chef, /var/log/chef, /var/lib/chef,
                     /var/cache/chef, /var/backups/chef, /run/chef)
       validation_cert: (optional string to be written to file validation_key)
                        special value 'system' means set use existing file
       validation_key: (optional the path for validation_cert. default
                        /etc/chef/validation.pem)
       firstboot_path: (path to write run_list and initial_attributes keys that
                        should also be present in this configuration, defaults
                        to /etc/chef/firstboot.json)
       exec: boolean to run or not run chef (defaults to false, unless
                                             a gem installed is requested
                                             where this will then default
                                             to true)

    chef.rb template keys (if falsey, then will be skipped and not
                           written to /etc/chef/client.rb)

    chef:
      client_key:
      encrypted_data_bag_secret:
      environment:
      file_backup_path:
      file_cache_path:
      json_attribs:
      log_level:
      log_location:
      node_name:
      omnibus_url:
      omnibus_url_retries:
      omnibus_version:
      pid_file:
      server_url:
      show_time:
      ssl_verify_mode:
      validation_cert:
      validation_key:
      validation_name:
i����N(t	templater(t
url_helper(tutils1.8s	/etc/chefs
/var/log/chefs
/var/lib/chefs/var/cache/chefs/var/backups/chefs	/run/chefs#https://www.chef.io/chef/install.shis/etc/chef/validation.pems/etc/chef/firstboot.jsons:verify_nonetssl_verify_modes:infot	log_levels/var/log/chef/client.logtlog_locationtvalidation_keytvalidation_certs/etc/chef/client.pemt
client_keytjson_attribstfile_cache_pathtfile_backup_paths/run/chef/client.pidtpid_filet	show_timetencrypted_data_bag_secrett
server_urlt	node_nametenvironmenttvalidation_names/etc/chef/client.rbs/usr/bin/chef-clients-ds-it1800s-st20cCs3tjjt�stStjttj�s/tStS(N(tostpathtisfiletCHEF_EXEC_PATHtFalsetaccesstX_OKtTrue(((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_chef.pytis_installed�s
cCsDtj|ddt�}|r@tjjt�r@tjt�ndS(Ntdelete_validation_post_exectdefault(Rtget_cfg_option_boolRRRRtCHEF_VALIDATION_PEM_PATHtunlink(tchef_cfgtlogt
delete_pem((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_chef.pyt
post_run_chef�s
		cCstj�}x�|j�D]�\}}|tkrG|jd|�qn|dkr`d||<q|tkr�tj||�||<qtj	||�||<qW|j
itj�d6tj	|dd|�d6tj	|ddd�d6|dd6|dd6�|S(	Ns'Skipping unknown chef template key '%s'tgenerated_byRRRt_defaultRR(tCHEF_RB_TPL_DEFAULTStcopytitemstCHEF_RB_TPL_KEYStdebugtNonetCHEF_RB_TPL_BOOL_KEYSRR tget_cfg_option_strtupdatetmake_header(tiidR#R$tparamstktv((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_chef.pytget_template_params�s&
	


cCs�d|kr |jd|�dS|d}tj|d�}|sQtt�}nx'tj|t�D]}tj|�qdW|j	dt
�}|j	d�}	|	r�|	dkr�tj||	�q�tj
j|�s�|jd|�q�n|jd	�}
|
r�t|jj��}t|||�}t�}
xH|j�D]:\}}|tkr;|r;|
jtj
j|��q;q;Wtj|
�tj|
t|�n|jd
t�tj|ddt�}|s�|j d
�n�i}d|kr�|d|d<nd|krA|d}x+t|j!��D]}||||<q&Wntj|t"j#|��tj$|ddt%�}t&�s�|r�t'|||�}n*t&�r�tj$|ddt%�}nt%}|r�t(||�t)||�ndS(s'Handler method activated by cloud-init.tchefs8Skipping module named %s, no 'chef' key in configurationNtdirectoriesRRtsystemsWchef validation_cert provided as 'system', but validation_key path '%s' does not exist.schef_client.rbs&No template found, not rendering to %stfirstboot_pathRs7First boot path empty, not writing first boot json filetrun_listtinitial_attributest
force_installtexec(*R-Rtget_cfg_option_listtlistt	CHEF_DIRSt	itertoolstchaintREQUIRED_CHEF_DIRSt
ensure_dirtgetR!t
write_fileRRRtwarningtget_template_filenametstrt
datasourcetget_instance_idR7tsetR+tCHEF_RB_TPL_PATH_KEYStaddtdirnametensure_dirsRtrender_to_filetCHEF_RB_PATHR0tCHEF_FB_PATHtinfotkeystjsontdumpsR RRtinstall_cheftrun_chefR&(tnametcfgtcloudR$t_argsR#t	chef_dirstdt	vkey_pathtvcertttemplate_fnR3R4tparam_pathsR5R6tfb_filenametinitial_jsonR=R>trun((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_chef.pythandle�sh	
	
	 
		
		
cCs�|jd�tg}d|kr�|d}t|ttf�rQ|j|�q�t|tj�rs|j|�q�|j	dt
|��|jt�n
|jt�tj
|dt�dS(NsRunning chef-clienttexec_argumentssRUnknown type %s provided for chef 'exec_arguments' expected list, tuple, or stringtcapture(R-Rt
isinstanceRAttupletextendtsixtstring_typestappendRIttypetCHEF_EXEC_DEF_ARGSRtsubpR(R#R$tcmdtcmd_args((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_chef.pyR[
s
	
	

c	Cs�|d	krt}n|d	kr*t}n|d	kr?g}nd|g}tjd|d|�j}tjd|d|dddt�S(
sgInstall an omnibus unified package from url.

    @param url: URL where blob of chef content may be downloaded. Defaults to
        OMNIBUS_URL.
    @param retries: Number of retries to perform when attempting to read url.
        Defaults to OMNIBUS_URL_RETRIES
    @param omnibus_version: Optional version string to require for omnibus
        install.
    s-vturltretriestblobtargstbasenameschef-omnibus-installRkN(	R.tOMNIBUS_URLtOMNIBUS_URL_RETRIESRtreadurltcontentsRtsubp_blob_in_tempfileR(RwRxtomnibus_versionRztcontent((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_chef.pytinstall_chef_from_omnibus s
				cCstj|dd�}tj|ddt�}|dkr�tj|dd�}tj|dt�}t|||j�tj|ddt�}n�|dkr�|jj	d�nh|d	krtj|d
�}t
dtj|d�d
tj|d�d
|�n|jd|�t}|S(Ntinstall_typetpackagesR?Rtgemstversiontruby_versionR8tomnibusR�Rwtomnibus_urlRxtomnibus_url_retriessUnknown chef install type '%s'(schef(
RR0R RR.tRUBY_VERSION_DEFAULTtinstall_chef_from_gemstdistroRtinstall_packagesR�tget_cfg_option_intRI(R^R#R$R�Rhtchef_versionR�R�((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_chef.pyRZ9s(		
cCs4d|d|g}|dkr0|jd�n|S(Nsruby%ss
ruby%s-devs1.8slibopenssl-ruby1.8srubygems1.8(slibopenssl-ruby1.8srubygems1.8(Rn(R�tpkgs((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_chef.pytget_ruby_packagesVsc
Cs�|jt|��tjjd�s<tjd|d�ntjjd�setjd|d�n|r�tjdddd|dd	d
ddg	d
t�n+tjddddd	d
ddgd
t�dS(Ns/usr/bin/gems/usr/bin/gem%ss
/usr/bin/rubys/usr/bin/ruby%stinstallR8s-v %ss--no-ris	--no-rdocs--bindirs/usr/bins-qRk(	R�R�RRtexistsRtsym_linkRtR(R�R�R�((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_chef.pyR�^s
	('t__doc__RCRXRt	cloudinitRRRRoR�RmRBRER|R}R!RUR.RR)t	frozensetR/RORARWR,RnRTRRsRR&R7RiR[R�RZR�R�(((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_chef.pyt<module>Hs�



				L