HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/vagrant.cpython-310.pyc
o

�N�go-�@s~dZddlZddlZddlmZmZdZdd�Zddd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)a�
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

�N)�CommandExecutionError�SaltInvocationErrorZvagrantcCsdtvrtSdS)z<
    Only if vagrant module is available.

    :return:
    zvagrant.version)Fz"vagrant module could not be loaded)�__salt__�__virtualname__�rr�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/vagrant.py�__virtual__<srcKsr|iddd�}g}t|t�r#ztd|�r|g}Wn	ty"Ynw|s0td�}t�||�}g}	g}
|D]b}|rYztd|�d}|d|krKWq6WntttfyXYnwz!td	|��|fi|��}t|t�rp|d
}|	�	d|||i�Wq6ttfy�}
z|
�	|t|
�d��WYd
}
~
q6d
}
~
ww|	s�d|d<d|d<|
r�d|
i|d<|S||	i|d<||d<|S)a
    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
    T���name�changes�result�comment�vagrant.get_vm_infozvagrant.list_domains�vagrant.vm_stater�statezvagrant.r�node)rZissueNr
zNo changes seenrZignoredr)
�
isinstance�strrr�fnmatch�filter�
IndexErrorr�dict�append)r�function�sectionrZstatus_when_done�kwargs�retZtargeted_nodesZall_domainsZ
changed_nodesZ
ignored_nodesZ
present_state�response�errrrr�
_vagrant_callGsV
��
��
 ���r c	Ks�d|vsd|vrt|dddd�S|id|�d�d	�}z(td
|�}|dddkr@td
|�d|d|<d|�d�|d<W|SW|Sttfyut||fi|��\}}d|d<td|fi|��d|d|<d|�d�|d<Y|Sw)a�
    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

    �*�?�startZ	restartedzMachine has been restarted�runningTz is already runningr
rrrz
vagrant.startzMachine startedr�Node z startedr�vagrant.initzNode defined and startedz defined and started)r rrr�_find_init_change)rrr�inforrrr$|s4%
��	���r$cKs�tjjjdi|��}d|vr|�|�d��|�dd�|d<ztd|�}WntyCi}|��D]
\}}d|d�|d|<q3Ynw|rq|D](}||pOd}|d	krp|�	|d�}||krp|d
krg|dkrgqH||d�|d|<qH||fS)zc
    look for changes from any previous init of machine.

    :return: modified ret and kwargs
    ZvmZ
vagrant_runasr	ZrunasrN)�old�newrr�machiner)
�salt�utils�argsZclean_kwargs�update�poprr�items�get)rrrZvm_�key�valuer*rrrr'�s.���r'cKsp|iddd�}t||fi|��\}}|dikr|Sd|d<td|fi|��d|d|<d	|�d
�|d<|S)a�
    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?
    Tz#The VM is already correctly definedr
rFr#r&zNode initializedr%z defined but not started.r)r'r)rrrrrr�initialized�s&�r5cC�t|dddd�S)z�
    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
    �shutdown�stoppedzMachine has been shut down�poweroff�r �rrrrr8s
�r8cCr6)ah
    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
    �stopZ	unpoweredzMachine has been powered offr9r:r;rrr�powered_off)s
�r=cC�t|ddd�S)a�
    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
    Zdestroy�	destroyedzMachine has been removedr:r;rrrr?=sr?cCr6)z�
    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
    �pause�pausedzMachine has been suspendedZsavedr:r;rrrrAOsrAcCr>)a
    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
    Zreboot�rebootedzMachine has been reloadedr:r;rrrrB^srB)N)�__doc__rZsalt.utils.argsr,Zsalt.exceptionsrrrrr r$r'r5r8r=r?rArBrrrr�<module>s3
5E: