%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/roster/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/roster/terraform.pyc

�
���^c@@s�dZddlmZmZddlZddlZddlZddl	Zej
e�ZdZ
idd6dd6dd6d	d
6dd6dd
6dd6dd6d	d6dd6dd6d	d6ZdZd�Zd�Zd�Zdd�Zdd�ZdS(u�
Dynamic roster from terraform current state
===========================================

This roster module allows you dynamically generate the roster from the terraform
resources defined with the `Terraform Salt`_ provider.

It exposes all salt_host resources with the same attributes to the salt-ssh
roster, making it completely independent of the type of terraform resource, and
providing the integration using terraform constructs with interpolation.

Basic Example
-------------

Given a simple salt-ssh tree with a Saltfile:

.. code-block:: yaml

    salt-ssh:
      config_dir: etc/salt
      max_procs: 30
      wipe_ssh: True

and ``etc/salt/master``:

.. code-block:: yaml

    root_dir: .
      file_roots:
        base:
          - srv/salt
      pillar_roots:
        base:
          - srv/pillar
      roster: terraform

In the same folder as your ``Saltfile``, create terraform file with resources
like cloud instances, virtual machines, etc. For every single one of those that
you want to manage with Salt, create a ``salt_host`` resource:

.. code-block:: text

    resource "salt_host" "dbminion" {
      salt_id = "dbserver"
      host = "${libvirt_domain.vm-db.network_interface.0.addresses.0}"
      user = "root"
      passwd = "linux"
    }

You can use the count attribute to create multiple roster entries with a single
definition. Please refer to the `Terraform Salt`_ provider for more detailed
examples.

.. _Terraform Salt: https://github.com/dmacvicar/terraform-provider-salt
i(tabsolute_importtunicode_literalsNusalt.roster.usuhostuuserupasswduiuportubusudou	sudo_useruttyuprivutimeoutumuminion_optsuthin_diru	cmd_umaskusalt_idcC@s�i}|jdi�jdi�}|jt�|t<t|j��jtj��}x3|D]+}t|j|�tj|��||<q_W|S(u�
    Handles salt_host resources.
    See https://github.com/dmacvicar/terraform-provider-salt

    Returns roster attributes for the resource or None
    uprimaryu
attributes(tgett	MINION_IDtsettkeystintersectiontTF_ROSTER_ATTRSt_cast_output_to_type(tresourcetrettattrstvalid_attrstattr((s9/usr/lib/python2.7/site-packages/salt/roster/terraform.pyt_handle_salt_host_resourceSs!
)cC@s�d}tjd�rHtjjtjjd��rHtjjd�}n4tjdtjjtjjtddd���}|r�tjj|�r�||d<ndS(	uM
    Setups the salt-ssh minion to be accessed with salt-ssh default key
    ussh_use_home_keyu
~/.ssh/id_rsaussh_privupki_dirusshusalt-ssh.rsauprivN(	tNonet__opts__Rtostpathtisfilet
expandusertabspathtjoin(R
tpriv((s9/usr/lib/python2.7/site-packages/salt/roster/terraform.pyt_add_ssh_keycs-cC@s0|dkrt|�S|dkr,t|�S|S(u.cast the value depending on the terraform typeubui(tbooltint(tvaluettyp((s9/usr/lib/python2.7/site-packages/salt/roster/terraform.pyRws


uterraform.tfstatecC@s1i}tjjj|d��}tjjj|�}WdQX|jd�}|sbtjd�|Sx�|D]�}|jdg�}x�tj	j
j|�D]�\}}d}	|ddkr�t
|�}	n|	s�q�n|	jt|jd��}
|
s�q�nt|	kr|	t=nt|	�|	||
<q�WqiW|S(	u_
    Parses the terraform state file passing different resource types to the right handler
    urNumodulesu(Malformed tfstate file. No modules foundu	resourcesutypeu	salt_hostuid(tsalttutilstfilestfopentjsontloadRtlogterrortexttsixt	iteritemsRRRR(tstate_file_pathR
tfh_ttfstatetmodulestmodulet	resourcest
resource_nameR	troster_entryt	minion_id((s9/usr/lib/python2.7/site-packages/salt/roster/terraform.pyt_parse_state_file�s.

"

uglobcK@s�tjjd�}tjd�r:tjjtd�}ntjj|�s`tjd|�iStjd|�|j	d�s�tjd�iSt
|�}tjdt|��td|||d	�S(
uw
    Returns the roster from the terraform state file, checks opts for location, but defaults to terraform.tfstate
    uterraform.tfstateuroster_fileu$Can't find terraform state file '%s'u%terraform roster: using %s state fileu.tfstateu<Terraform roster can only be used with terraform state filesu %s hosts in terraform state fileuroster_matcher.targetsuipv4(
RRRRRRR#R$tdebugtendswithR1tlent	__utils__(ttgtttgt_typetkwargstroster_filetraw((s9/usr/lib/python2.7/site-packages/salt/roster/terraform.pyttargets�s
(t__doc__t
__future__RRtloggingtos.pathRtsalt.utils.filesRtsalt.utils.jsont	getLoggert__name__R#tTF_OUTPUT_PREFIXRRRRRR1R;(((s9/usr/lib/python2.7/site-packages/salt/roster/terraform.pyt<module>8s0

				"

Zerion Mini Shell 1.0