%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s�dZddlmZmZmZddlZddlZddlm	Z	m
Z
ddljj
Z
dZd�Zdd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�ZdS(u�
Manage Vagrant VMs
==================

Manange execution of Vagrant virtual machines on Salt minions.

Vagrant_ is a tool for building and managing virtual machine environments.
It can use various providers, such as VirtualBox_, Docker_, or VMware_, to run its VMs.
Vagrant provides some of the functionality of a light-weight hypervisor.
The combination of Salt modules, Vagrant running on the host, and a
virtual machine provider, gives hypervisor-like functionality for
developers who use Vagrant to quickly define their virtual environments.

.. _Vagrant: http://www.vagrantup.com/
.. _VirtualBox: https://www.virtualbox.org/
.. _Docker: https://www.docker.io/
.. _VMWare: https://www.vmware.com/

    .. versionadded:: 2018.3.0

The configuration of each virtual machine is defined in a file named
``Vagrantfile`` which must exist on the VM host machine.
The essential parameters which must be defined to start a Vagrant VM
are the directory where the ``Vagrantfile`` is located \(argument ``cwd:``\),
and the username which will own the ``Vagrant box`` created for the VM \(
argument ``vagrant_runas:``\).

A single ``Vagrantfile`` may define one or more virtual machines.
Use the ``machine`` argument to chose among them. The default (blank)
value will select the ``primary`` (or only) machine in the Vagrantfile.

\[NOTE:\] Each virtual machine host must have the following:

- a working salt-minion
- a Salt sdb database configured for ``vagrant_sdb_data``.
- Vagrant installed and the ``vagrant`` command working
- a suitable VM provider

.. code-block:: yaml

    # EXAMPLE:
    # file /etc/salt/minion.d/vagrant_sdb.conf on the host computer
    #  -- this sdb database is required by the Vagrant module --
    vagrant_sdb_data:  # The sdb database must have this name.
      driver: sqlite3  # Let's use SQLite to store the data ...
      database: /var/cache/salt/vagrant.sqlite  # ... in this file ...
      table: sdb  # ... using this table name.
      create_table: True  # if not present

i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionErrortSaltInvocationErroruvagrantcC@sdtkrtStS(u<
    Only if vagrant module is available.

    :return:
    uvagrant.version(t__salt__t__virtualname__tFalse(((s7/usr/lib/python2.7/site-packages/salt/states/vagrant.pyt__virtual__AscK@s�i|d6id6td6dd6}g}t|tj�rqy td|�rY|g}nWqqtk
rmqqXn|s�td�}tj||�}ng}	g}
x�|D]�}|ry.td|�d	}|d
|kr�w�nWqttt	fk
rqXnyWtdj
|�||�}t|t�rA|d}n|	ji|d6||6�Wq�tt	fk
r�}
|
ji|d6tj
|
�d
6�q�Xq�W|	s�t|d<d|d<|
r�i|
d6|d<q�ni|	|6|d<||d<|S(u
    Helper to call the vagrant functions. Wildcards supported.

    :param node: The Salt-id or wildcard
    :param function: the vagrant submodule to call
    :param section: the name for the state call.
    :param comment: what the state reply should say
    :param status_when_done: the Vagrant status expected for this state
    :return:  the dictionary for the state reply
    unameuchangesuresultuucommentuvagrant.get_vm_infouvagrant.list_domainsuvagrant.vm_stateiustateuvagrant.{0}unodeuissueuNo changes seenuignored(tTruet
isinstancetsixtstring_typesRRtfnmatchtfiltert
IndexErrorRtformattdicttappendt	text_type(tnodetfunctiontsectiontcommenttstatus_when_donetkwargstretttargeted_nodestall_domainst
changed_nodest
ignored_nodest
present_statetresponseterr((s7/usr/lib/python2.7/site-packages/salt/states/vagrant.pyt
_vagrant_callMsH"




,


cK@s)d|ksd|kr.t|dddd�Si|d6id6td	6d
j|�d6}yZtd|�}|d
ddkr�td|�d|d|<dj|�|d<nWnkttfk
r t|||�\}}t|d<td||�d|d|<dj|�|d<nX|SdS(u�
    Defines and starts a new VM with specified arguments, or restart a
    VM (or group of VMs). (Runs ``vagrant up``.)

    :param name: the Salt_id node name you wish your VM to have.

    If ``name`` contains a "?" or "*"  then it will re-start a group of VMs
    which have been paused or stopped.

    Each machine must be initially started individually using this function
    or the vagrant.init execution module call.

    \[NOTE:\] Keyword arguments are silently ignored when re-starting an existing VM.

    Possible keyword arguments:

    - cwd: The directory (path) containing the Vagrantfile
    - machine: ('') the name of the machine (in the Vagrantfile) if not default
    - vagrant_runas: ('root') the username who owns the vagrantbox file
    - vagrant_provider: the provider to run the VM (usually 'virtualbox')
    - vm: ({}) a dictionary containing these or other keyword arguments

    .. code-block:: yaml

        node_name:
          vagrant.running

    .. code-block:: yaml

        node_name:
          vagrant.running:
            - cwd: /projects/my_project
            - vagrant_runas: my_username
            - machine: machine1

    u*u?ustartu	restarteduMachine has been restartedurunningunameuchangesuresultu{0} is already runningucommentuvagrant.vm_stateiustateu
vagrant.startuMachine starteduNode {0} starteduvagrant.inituNode defined and starteduNode {0} defined and startedN(R"R	RRRRt_find_init_change(tnameRRtinfo((s7/usr/lib/python2.7/site-packages/salt/states/vagrant.pytrunning�s(%


cK@sUtjjj|�}d|kr:|j|jd��n|jdd�|d<ytd|�}WnPtk
r�i}x:|j�D](\}}idd6|d6|d|<q�WnX|rKx�|D]�}||p�d}|d	kr�|j
|d�}||krD|d
kr"|dkr"q�ni|d6|d6|d|<qDq�q�Wn||fS(uc
    look for changes from any previous init of machine.

    :return: modified ret and kwargs
    uvmu
vagrant_runasuurunasuvagrant.get_vm_infouoldunewuchangesunameumachineN(tsalttutilstargstclean_kwargstupdatetpopRRtitemstNonetget(R$RRtvm_tkeytvaluetnew((s7/usr/lib/python2.7/site-packages/salt/states/vagrant.pyR#�s(
$
)cK@s�i|d6id6td6dd6}t|||�\}}|dikrN|St|d<td||�d|d|<d	j|�|d<|S(
u�
    Defines a new VM with specified arguments, but does not start it.

    :param name: the Salt_id node name you wish your VM to have.

    Each machine must be initialized individually using this function
    or the "vagrant.running" function, or the vagrant.init execution module call.

    This command will not change the state of a running or paused machine.

    Possible keyword arguments:

    - cwd: The directory (path) containing the Vagrantfile
    - machine: ('') the name of the machine (in the Vagrantfile) if not default
    - vagrant_runas: ('root') the username who owns the vagrantbox file
    - vagrant_provider: the provider to run the VM (usually 'virtualbox')
    - vm: ({}) a dictionary containing these or other keyword arguments

    .. code-block:: yaml

        node_name1:
          vagrant.initialized
            - cwd: /projects/my_project
            - vagrant_runas: my_username
            - machine: machine1

        node_name2:
          vagrant.initialized
            - cwd: /projects/my_project
            - vagrant_runas: my_username
            - machine: machine2

        start_nodes:
          vagrant.start:
            - name: node_name?
    unameuchangesuresultu#The VM is already correctly defineducommentustartuvagrant.inituNode initializedu!Node {0} defined but not started.(R	R#RRR(R$RR((s7/usr/lib/python2.7/site-packages/salt/states/vagrant.pytinitialized�s%


cC@st|dddd�S(u�
    Stops a VM (or VMs) by shutting it (them) down nicely. (Runs ``vagrant halt``)

    :param name: May be a Salt_id node, or a POSIX-style wildcard string.

    .. code-block:: yaml

        node_name:
          vagrant.stopped
    ushutdownustoppeduMachine has been shut downupoweroff(R"(R$((s7/usr/lib/python2.7/site-packages/salt/states/vagrant.pytstoppedscC@st|dddd�S(uh
    Stops a VM (or VMs) by power off.  (Runs ``vagrant halt``.)

    This method is provided for compatibility with other VM-control
    state modules. For Vagrant, the action is identical with ``stopped``.

    :param name: May be a Salt_id node or a POSIX-style wildcard string.

    .. code-block:: yaml

        node_name:
          vagrant.unpowered
    ustopu	unpowereduMachine has been powered offupoweroff(R"(R$((s7/usr/lib/python2.7/site-packages/salt/states/vagrant.pytpowered_off+scC@st|ddd�S(u�
    Stops a VM (or VMs) and removes all references to it (them). (Runs ``vagrant destroy``.)

    Subsequent re-use of the same machine will requere another operation of ``vagrant.running``
    or a call to the ``vagrant.init`` execution module.

    :param name: May be a Salt_id node or a POSIX-style wildcard string.

    .. code-block:: yaml

        node_name:
          vagrant.destroyed
    udestroyu	destroyeduMachine has been removed(R"(R$((s7/usr/lib/python2.7/site-packages/salt/states/vagrant.pyt	destroyed>scC@st|dddd�S(u�
    Stores the state of a VM (or VMs) for fast restart. (Runs ``vagrant suspend``.)

    :param name: May be a Salt_id node or a POSIX-style wildcard string.

    .. code-block:: yaml

        node_name:
          vagrant.paused
    upauseupauseduMachine has been suspendedusaved(R"(R$((s7/usr/lib/python2.7/site-packages/salt/states/vagrant.pytpausedQscC@st|ddd�S(u
    Reboots a running, paused, or stopped VM (or VMs). (Runs ``vagrant reload``.)

    The  will re-run the provisioning

    :param name: May be a Salt_id node or a POSIX-style wildcard string.

    .. code-block:: yaml

        node_name:
          vagrant.reloaded
    urebooturebooteduMachine has been reloaded(R"(R$((s7/usr/lib/python2.7/site-packages/salt/states/vagrant.pytrebootedas(t__doc__t
__future__RRRR
tsalt.utils.argsR'tsalt.exceptionsRRtsalt.ext.sixtextRRRR.R"R&R#R4R5R6R7R8R9(((s7/usr/lib/python2.7/site-packages/salt/states/vagrant.pyt<module>3s 	5	C		9				

Zerion Mini Shell 1.0