%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/vagrant.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddl	Zddl
ZddlmZm
Z
ddljjZddlmZeje�ZdZdZd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Z d�Z!dd�Z#dd�Z$ddd�Z%ddde&ddd�Z'd�Z(d�Z)d�Z*d�Z+d�Z,e&d�Z-d�Z.de&d�Z/dS(ub
Work with virtual machines managed by Vagrant.

.. versionadded:: 2018.3.0

Mapping between a Salt node id and the Vagrant machine name
(and the path to the Vagrantfile where it is defined)
is stored in a Salt sdb database on the Vagrant host (minion) machine.
In order to use this module, sdb must be configured. An SQLite
database is the recommended storage method.  The URI used for
the sdb lookup is "sdb://vagrant_sdb_data".

requirements:
   - the VM host machine must have salt-minion, Vagrant and a vm provider installed.
   - the VM host must have a valid definition for `sdb://vagrant_sdb_data`

    Configuration example:

    .. code-block:: yaml

        # file /etc/salt/minion.d/vagrant_sdb.conf
        vagrant_sdb_data:
          driver: sqlite3
          database: /var/cache/salt/vagrant.sqlite
          table: sdb
          create_table: True

i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionErrortSaltInvocationError(t	ipaddressuvagrantusdb://vagrant_sdb_data/cC@s)tjjjd�dkr%tdfStS(u*
    run Vagrant commands if possible
    uvagrantuAThe vagrant module could not be loaded: vagrant command not foundN(tsalttutilstpathtwhichtNonetFalset__virtualname__(((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pyt__virtual__3s
cC@sdjt|�S(u�
    returns string used to fetch data for "key" from the sdb store.

    Salt node id's are used as the key for vm_ dicts.

    u{}{}(tformattVAGRANT_SDB_URL(tkey((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pyt_build_sdb_uri<scC@s(dj|tjj|��}t|�S(u�
    returns string used to fetch id names from the sdb store.

    the cwd and machine name are concatenated with '?' which should
    never collide with a Salt node id -- which is important since we
    will be storing both in the same table.
    u{}?{}(RtosRtabspathR(tmachinetcwdR((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pyt_build_machine_uriFscC@sXtdt|�|t�|drTtdt|d|jdd��|t�ndS(u) store the vm_ information keyed by name usdb.sdb_setumachineucwdu.N(t	__utils__Rt__opts__Rtget(tnametvm_((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pyt_update_vm_infoRs
cC@sqytdt|�t�}Wntk
r<td��nX|dksUd|krmtdj|���n|S(u�
    get the information for a VM.

    :param name: salt_id name
    :return: dictionary of {'machine': x, 'cwd': y, ...}.
    usdb.sdb_getu8Probable sdb driver not found. Check your configuration.umachineu)No Vagrant machine defined for Salt_id {}N(RRRtKeyErrorRR
R(RR((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pytget_vm_info^s

cC@s tdt||�t�}|S(u�
    returns the salt_id name of the Vagrant VM

    :param machine: the Vagrant machine name
    :param cwd: the path to Vagrantfile
    :return: salt_id name
    usdb.sdb_get(RRR(RRR((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pytget_machine_idpscC@s�yyt|�}|drxt|d|jdd��}ytd|t�Wqxtk
rttd|dt�qxXnWntk
r�nXt|�}ytd|t�Wn5tk
r�td|it�ntk
r�nXdS(u�
    erase the information for a VM the we are destroying.

    some sdb drivers (such as the SQLite driver we expect to use)
    do not have a `delete` method, so if the delete fails, we have
    to replace the with a blank entry.
    umachineucwdu.usdb.sdb_deleteusdb.sdb_setN(	RRRRRRR
t	ExceptionR(RRRturi((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pyt_erase_vm_info|s"




c	C@s�|d}tjd|pd�dj|�}td|d|jd�d|jd	�d
t�}i}xP|jd�D]?}|j�j�}t|�dkry|d
||d<qyqyWtj	dt
|��|S(u�
    get the information for ssh communication from the new VM

    :param vm_: the VM's info as we have it now
    :return: dictionary of ssh stuff
    umachineu'requesting vagrant ssh-config for VM %su	(default)uvagrant ssh-config {}u	cmd.shelltrunasurunasRucwdtignore_retcodeu
iiiu
ssh_config=%s(tlogtinfoRt__salt__RtTruetsplittstriptlentdebugtrepr(RRtcmdtreplyt
ssh_configtlinettokens((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pyt_vagrant_ssh_config�s

	cC@sd}td|�S(u�
    Return the version of Vagrant on the minion

    CLI Example:

    .. code-block:: bash

        salt '*' vagrant.version
    u
vagrant -vu	cmd.shell(R'(R.((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pytversion�s
c	C@s�g}d}td|�}tjd|�x�|jd�D]�}|j�j�}yt|dd�}Wnttfk
r�q=nX|d}|d}t||�}|r=|j	|�q=q=W|S(	u�
    Return a list of the salt_id names of all available Vagrant VMs on
    this host without regard to the path where they are defined.

    CLI Example:

    .. code-block:: bash

        salt '*' vagrant.list_domains --log-level=info

    The log shows information about all known Vagrant environments
    on this machine. This data is cached and may not be completely
    up-to-date.
    uvagrant global-statusu	cmd.shellu--->
u
iiii����(
R'R%R&R)R*tintt
ValueErrort
IndexErrorRtappend(	tvmsR.R/R1R2t_RRR((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pytlist_domains�s 

cC@s�g}d}td|d|�}tjd|�xb|jd�D]Q}|j�j�}t|�dkrC|ddkr�|j|d�q�qCqCW|S(	u�
    Return a list of machine names for active virtual machine on the host,
    which are defined in the Vagrantfile at the indicated path.

    CLI Example:

    .. code-block:: bash

        salt '*' vagrant.list_active_vms  cwd=/projects/project_1
    uvagrant statusu	cmd.shellRu--->
u
iurunningi(R'R%R&R)R*R+R8(RR9R.R/R1R2((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pytlist_active_vms�scC@s�g}d}td|d|�}tjd|�xu|jd�D]d}|j�j�}t|�dkrC|djd�rC|dd	kr�|j|d
�q�qCqCW|S(u
    Return a list of machine names for inactive virtual machine on the host,
    which are defined in the Vagrantfile at the indicated path.


    CLI Example:

    .. code-block:: bash

        salt '*' virt.list_inactive_vms cwd=/projects/project_1
    uvagrant statusu	cmd.shellRu--->
u
ii����u)urunningi(R'R%R&R)R*R+tendswithR8(RR9R.R/R1R2((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pytlist_inactive_vms�s%uc
C@sb|r/t|�}|d}|dp)|}n$|sMtdj|���nd}g}dj|�}td||�}tjd|�x�|jd�D]�}|j�j�}t|�d	kr�|d
j	d�r�yji|dd6d
j
|d	d
!�d6|d
jd�jd�d6t
|d|�d6}	|j|	�WqZtk
rVqZXq�q�W|S(u
    Return list of information for all the vms indicating their state.

    If you pass a VM name in as an argument then it will return info
    for just the named VM, otherwise it will return all VMs defined by
    the Vagrantfile in the `cwd` directory.

    CLI Example:

    .. code-block:: bash

        salt '*' vagrant.vm_state <name>  cwd=/projects/project_1

    returns a list of dictionaries with machine name, state, provider,
    and salt_id name.

    .. code-block:: python

        datum = {'machine': _, # Vagrant machine name,
                 'state': _, # string indicating machine state, like 'running'
                 'provider': _, # the Vagrant VM provider
                 'name': _} # salt_id name

    Known bug: if there are multiple machines in your Vagrantfile, and you request
    the status of the ``primary`` machine, which you defined by leaving the ``machine``
    parameter blank, then you may receive the status of all of them.
    Please specify the actual machine name for each VM if there are more than one.

    umachineucwdu.Path to Vagranfile must be defined, but cwd={}uuvagrant status {}u	cmd.shellu--->
u
ii����u)iu ustateu(uprovideruname(RRRR'R%R&R)R*R+R=tjointlstriptrstripRR8R7(
RRRRR&R.R/R1R2tdatum((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pytvm_states0
%
c	C@s|dkrin	|j�}||d<|p:|jd�|d<|dsZtd��n|po|jd|�|d<|p�|jd|�|d<|p�|jdd�|d<t||�|r�tjd|�t||�}nd	j||dp�d
�}|S(u`
    Initialize a new Vagrant VM.

    This inputs all the information needed to start a Vagrant VM.  These settings are stored in
    a Salt sdb database on the Vagrant host minion and used to start, control, and query the
    guest VMs. The salt_id assigned here is the key field for that database and must be unique.

    :param name: The salt_id name you will use to control this VM
    :param cwd: The path to the directory where the Vagrantfile is located
    :param machine: The machine name in the Vagrantfile. If blank, the primary machine will be used.
    :param runas: The username on the host who owns the Vagrant work files.
    :param start: (default: False) Start the virtual machine now.
    :param vagrant_provider: The name of a Vagrant VM provider (if not the default).
    :param vm: Optionally, all the above information may be supplied in this dictionary.
    :return: A string indicating success, or False.

    CLI Example:

    .. code-block:: bash

        salt <host> vagrant.init <salt_id> /path/to/Vagrantfile
        salt my_laptop vagrant.init x1 /projects/bevy_master machine=quail1
    unameucwdu5Path to Vagrantfile must be defined by "cwd" argumentumachineurunasuvagrant_provideruuStarting VM %suName {} defined using VM {}u	(default)N(	R
tcopyRRRR%R,t_startR(	RRRR#tstarttvagrant_providertvmRtret((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pytinitMs


cC@st|�}t||�S(u�
    Start (vagrant up) a virtual machine defined by salt_id name.
    The machine must have been previously defined using "vagrant.init".

    CLI Example:

    .. code-block:: bash

        salt <host> vagrant.start <salt_id>
    (RRE(RR((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pyRFscC@s>y|d}Wn&tk
r6tdj|���nX|jdd�}|r^dj|�nd}dj||�}td|d|jd	�d
|jd�dd
�}|dkrxa|djd�D]I}|jd�r�|j�djd�}||d<t||�Pq�q�Wn|ddkr:dj||�St	S(Numachineu)No Vagrant machine defined for Salt_id {}uvagrant_provideruu
--provider={}uvagrant up {} {}ucmd.run_allR#urunasRucwdtoutput_logleveluinfoustdoutu
u==>iu:uretcodeiu(Started "{}" using Vagrant machine "{}".(
RRRRR'R)t
startswithRARR(RRRRGt	provider_R.RIR1((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pyRE�s$
4

cC@s
t|�S(u=
    Send a soft shutdown (vagrant halt) signal to the named vm.

    This does the same thing as vagrant.stop. Other-VM control
    modules use "stop" and "shutdown" to differentiate between
    hard and soft shutdowns.

    CLI Example:

    .. code-block:: bash

        salt <host> vagrant.shutdown <salt_id>
    (tstop(R((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pytshutdown�scC@s]t|�}|d}dj|�}td|d|jd�d|jd��}|dkS(	u�
    Hard shutdown the virtual machine. (vagrant halt)

    CLI Example:

    .. code-block:: bash

        salt <host> vagrant.stop <salt_id>
    umachineuvagrant halt {}ucmd.retcodeR#urunasRucwdi(RRR'R(RRRR.RI((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pyRN�s


cC@s]t|�}|d}dj|�}td|d|jd�d|jd��}|dkS(	u�
    Pause (vagrant suspend) the named VM.

    CLI Example:

    .. code-block:: bash

        salt <host> vagrant.pause <salt_id>
    umachineuvagrant suspend {}ucmd.retcodeR#urunasRucwdi(RRR'R(RRRR.RI((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pytpause�s


cC@srt|�}|d}|r"dnd}dj||�}td|d|jd�d|jd	��}|d
kS(u
    Reboot a VM. (vagrant reload)

    CLI Example:

    .. code-block:: bash

        salt <host> vagrant.reboot <salt_id> provision=True

    :param name: The salt_id name you will use to control this VM
    :param provision: (False) also re-run the Vagrant provisioning scripts.
    umachineu--provisionuuvagrant reload {} {}ucmd.retcodeR#urunasRucwdi(RRR'R(Rt	provisionRRtprovR.RI((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pytreboot�s


cC@s�t|�}|d}dj|�}td|d|jd�d|jd�dd	�}|d
dkr�t|�dj|�StS(
u�
    Destroy and delete a virtual machine. (vagrant destroy -f)

    This also removes the salt_id name defined by vagrant.init.

    CLI Example:

    .. code-block:: bash

        salt <host> vagrant.destroy <salt_id>
    umachineuvagrant destroy -f {}ucmd.run_allR#urunasRucwdRKuinfouretcodeiuDestroyed VM {0}(RRR'RR"R(RRRR.RI((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pytdestroy�s

	

cC@st|�}t|�}y6i|dd6|dd6|dd6|dd6}Wn2tk
r�td	j|jd
d����nX|r�dj|�}tjd
j|��td|�}tjd|�t	j
|dt�}x�|jd�D]�}	y�|	j
ddd�j�}
d}d|
krS|
jd�d}t	j|
|�}nBd|
kr�|
jd�d}t	j|
|jd�d�}n||kr�tj|�|d<PnWq�tttfk
r�q�Xq�Wtjd||jdd��n|r{yEtjjj|d��&}
tjjj|
j��|d<WdQXWq{ttfk
rw}tdj|���q{Xn|S(u�
    Retrieve hints of how you might connect to a Vagrant VM.

    :param name: the salt_id of the machine
    :param network_mask: a CIDR mask to search for the VM's address
    :param get_private_key: (default: False) return the key used for ssh login
    :return: a dict of ssh login information for the VM

    CLI Example:

    .. code-block:: bash

        salt <host> vagrant.get_ssh_config <salt_id>
        salt my_laptop vagrant.get_ssh_config quail1 network_mask=10.0.0.0/8 get_private_key=True

    The returned dictionary contains:

    - key_filename:  the name of the private key file on the VM host computer
    - ssh_username:  the username to be used to log in to the VM
    - ssh_host:  the IP address used to log in to the VM.  (This will usually be `127.0.0.1`)
    - ssh_port:  the TCP port used to log in to the VM.  (This will often be `2222`)
    - \[ip_address:\]  (if `network_mask` is defined. see below)
    - \[private_key:\]  (if `get_private_key` is True) the private key for ssh_username

    About `network_mask`:

    Vagrant usually uses a redirected TCP port on its host computer to log in to a VM using ssh.
    This redirected port and its IP address are "ssh_port" and "ssh_host".  The ssh_host is
    usually the localhost (127.0.0.1).
    This makes it impossible for a third machine (such as a salt-cloud master) to contact the VM
    unless the VM has another network interface defined.  You will usually want a bridged network
    defined by having a `config.vm.network "public_network"` statement in your `Vagrantfile`.

    The IP address of the bridged adapter will typically be assigned by DHCP and unknown to you,
    but you should be able to determine what IP network the address will be chosen from.
    If you enter a CIDR network mask, Salt will attempt to find the VM's address for you.
    The host machine will send an "ifconfig" command to the VM (using ssh to `ssh_host`:`ssh_port`)
    and return the IP address of the first interface it can find which matches your mask.
    uIdentityFileukey_filenameuUserussh_usernameuHostNameussh_hostuPortussh_portu=Insufficient SSH information to contact VM {}. Is it running?umachineu	(default)u�ssh -i {IdentityFile} -p {Port} -oStrictHostKeyChecking={StrictHostKeyChecking} -oUserKnownHostsFile={UserKnownHostsFile} -oControlPath=none {User}@{HostName} ifconfigu/Trying ssh -p {Port} {User}@{HostName} ifconfigu	cmd.shellu--->
tstrictu
uaddr:uiuinetuinet6u/iu
ip_addressu(Network IP address in %s detected as: %su(not found)uprivate_keyNu-Error processing Vagrant private key file: {}(RR3RRRRR%R&R'Rt
ip_networkRR)treplaceR
tindext
ip_addresstsixt	text_typeR7tAttributeErrort	TypeErrorRRtfilestfopentstringutilst
to_unicodetreadtOSErrortIOError(Rtnetwork_masktget_private_keyRR0tanstcommandR/ttarget_network_rangeR1R2t
found_addresstnxttpkste((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pytget_ssh_configsT(
	#	)(0t__doc__t
__future__RRRtloggingRtsalt.utils.filesRtsalt.utils.pathtsalt.utils.stringutilstsalt.exceptionsRRtsalt.ext.sixtextRZtsalt._compatRt	getLoggert__name__R%RRR
RRRRRR"R3R4R;R
R<R>RCRRJRFRERORNRPRSRTRn(((s8/usr/lib/python2.7/site-packages/salt/modules/vagrant.pyt<module>sN			
					 			!=,						

Zerion Mini Shell 1.0