mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #44037 from vernondcole/vagrant-cloud
Vagrant cloud and state modules
This commit is contained in:
commit
73c3581864
15 changed files with 1216 additions and 148 deletions
|
@ -34,6 +34,7 @@ Full list of Salt Cloud modules
|
|||
scaleway
|
||||
softlayer
|
||||
softlayer_hw
|
||||
vagrant
|
||||
virtualbox
|
||||
vmware
|
||||
vultrpy
|
||||
|
|
6
doc/ref/clouds/all/salt.cloud.clouds.vagrant.rst
Normal file
6
doc/ref/clouds/all/salt.cloud.clouds.vagrant.rst
Normal file
|
@ -0,0 +1,6 @@
|
|||
=========================
|
||||
salt.cloud.clouds.vagrant
|
||||
=========================
|
||||
|
||||
.. automodule:: salt.cloud.clouds.vagrant
|
||||
:members:
|
|
@ -267,6 +267,7 @@ state modules
|
|||
tuned
|
||||
uptime
|
||||
user
|
||||
vagrant
|
||||
vault
|
||||
vbox_guest
|
||||
victorops
|
||||
|
|
6
doc/ref/states/all/salt.states.vagrant.rst
Normal file
6
doc/ref/states/all/salt.states.vagrant.rst
Normal file
|
@ -0,0 +1,6 @@
|
|||
===================
|
||||
salt.states.vagrant
|
||||
===================
|
||||
|
||||
.. automodule:: salt.states.vagrant
|
||||
:members:
|
|
@ -540,6 +540,17 @@ machines which are already installed, but not Salted. For more information about
|
|||
this driver and for configuration examples, please see the
|
||||
:ref:`Gettting Started with Saltify <getting-started-with-saltify>` documentation.
|
||||
|
||||
.. _config_vagrant:
|
||||
|
||||
Vagrant
|
||||
-------
|
||||
|
||||
The Vagrant driver is a new, experimental driver for controlling a VagrantBox
|
||||
virtual machine, and installing Salt on it. The target host machine must be a
|
||||
working salt minion, which is controlled via the salt master using salt-api.
|
||||
For more information, see
|
||||
:ref:`Getting Started With Vagrant <getting-started-with-vagrant>`.
|
||||
|
||||
|
||||
Extending Profiles and Cloud Providers Configuration
|
||||
====================================================
|
||||
|
|
|
@ -38,26 +38,30 @@ These are features that are available for almost every cloud host.
|
|||
|
||||
.. container:: scrollable
|
||||
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
| |AWS |CloudStack|Digital|EC2|GoGrid|JoyEnt|Linode|OpenStack|Parallels|Rackspace|Saltify|Softlayer|Softlayer|Aliyun|
|
||||
| |(Legacy)| |Ocean | | | | | | |(Legacy) | | |Hardware | |
|
||||
+=======================+========+==========+=======+===+======+======+======+=========+=========+=========+=======+=========+=========+======+
|
||||
|Query |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes | |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|Full Query |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes | |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|Selective Query |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes | |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|List Sizes |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes | |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|List Images |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes | |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|List Locations |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes | |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|create |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|destroy |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes | |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+-------+---------+---------+------+
|
||||
| |AWS |CloudStack|Digital|EC2|GoGrid|JoyEnt|Linode|OpenStack|Parallels|Rackspace|Saltify|Vagrant|Softlayer|Softlayer|Aliyun|
|
||||
| |(Legacy)| |Ocean | | | | | | |(Legacy) | | | |Hardware | |
|
||||
+=======================+========+==========+=======+===+======+======+======+=========+=========+=========+=======+=======+=========+=========+======+
|
||||
|Query |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |[1] |[1] |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+-------+---------+---------+------+
|
||||
|Full Query |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |[1] |[1] |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+-------+---------+---------+------+
|
||||
|Selective Query |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |[1] |[1] |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+-------+---------+---------+------+
|
||||
|List Sizes |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |[2] |[2] |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+-------+---------+---------+------+
|
||||
|List Images |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+-------+---------+---------+------+
|
||||
|List Locations |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |[2] |[2] |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+-------+---------+---------+------+
|
||||
|create |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |Yes |[1] |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+-------+---------+---------+------+
|
||||
|destroy |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |[1] |[1] |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+-------+---------+---------+------+
|
||||
|
||||
[1] Yes, if salt-api is enabled.
|
||||
|
||||
[2] Always returns `{}`.
|
||||
|
||||
Actions
|
||||
=======
|
||||
|
@ -70,46 +74,46 @@ instance name to be passed in. For example:
|
|||
|
||||
.. container:: scrollable
|
||||
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|Actions |AWS |CloudStack|Digital|EC2|GoGrid|JoyEnt|Linode|OpenStack|Parallels|Rackspace|Saltify|Softlayer|Softlayer|Aliyun|
|
||||
| |(Legacy)| |Ocean | | | | | | |(Legacy) | | |Hardware | |
|
||||
+=======================+========+==========+=======+===+======+======+======+=========+=========+=========+=======+=========+=========+======+
|
||||
|attach_volume | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|create_attach_volumes |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|del_tags |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|delvol_on_destroy | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|detach_volume | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|disable_term_protect |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|enable_term_protect |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|get_tags |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|keepvol_on_destroy | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|list_keypairs | | |Yes | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|rename |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|set_tags |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|show_delvol_on_destroy | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|show_instance | | |Yes |Yes| | |Yes | |Yes | | |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|show_term_protect | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|start |Yes | | |Yes| |Yes |Yes | |Yes | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|stop |Yes | | |Yes| |Yes |Yes | |Yes | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|take_action | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|Actions |AWS |CloudStack|Digital|EC2|GoGrid|JoyEnt|Linode|OpenStack|Parallels|Rackspace|Saltify&|Softlayer|Softlayer|Aliyun|
|
||||
| |(Legacy)| |Ocean | | | | | | |(Legacy) | Vagrant| |Hardware | |
|
||||
+=======================+========+==========+=======+===+======+======+======+=========+=========+=========+========+=========+=========+======+
|
||||
|attach_volume | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|create_attach_volumes |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|del_tags |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|delvol_on_destroy | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|detach_volume | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|disable_term_protect |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|enable_term_protect |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|get_tags |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|keepvol_on_destroy | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|list_keypairs | | |Yes | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|rename |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|set_tags |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|show_delvol_on_destroy | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|show_instance | | |Yes |Yes| | |Yes | |Yes | | |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|show_term_protect | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|start |Yes | | |Yes| |Yes |Yes | |Yes | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|stop |Yes | | |Yes| |Yes |Yes | |Yes | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|take_action | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|
||||
Functions
|
||||
=========
|
||||
|
@ -122,81 +126,83 @@ require the name of the provider to be passed in. For example:
|
|||
|
||||
.. container:: scrollable
|
||||
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|Functions |AWS |CloudStack|Digital|EC2|GoGrid|JoyEnt|Linode|OpenStack|Parallels|Rackspace|Saltify|Softlayer|Softlayer|Aliyun|
|
||||
| |(Legacy)| |Ocean | | | | | | |(Legacy) | | |Hardware | |
|
||||
+=======================+========+==========+=======+===+======+======+======+=========+=========+=========+=======+=========+=========+======+
|
||||
|block_device_mappings |Yes | | | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|create_keypair | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|create_volume | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|delete_key | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|delete_keypair | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|delete_volume | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|get_image | | |Yes | | |Yes | | |Yes | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|get_ip | |Yes | | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|get_key | |Yes | | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|get_keyid | | |Yes | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|get_keypair | |Yes | | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|get_networkid | |Yes | | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|get_node | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|get_password | |Yes | | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|get_size | | |Yes | | |Yes | | | | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|get_spot_config | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|get_subnetid | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|iam_profile |Yes | | |Yes| | | | | | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|import_key | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|key_list | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|keyname |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|list_availability_zones| | | |Yes| | | | | | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|list_custom_images | | | | | | | | | | | |Yes | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|list_keys | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|list_nodes |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|list_nodes_full |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|list_nodes_select |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|list_vlans | | | | | | | | | | | |Yes |Yes | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|rackconnect | | | | | | | |Yes | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|reboot | | | |Yes| |Yes | | | | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|reformat_node | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|securitygroup |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|securitygroupid | | | |Yes| | | | | | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|show_image | | | |Yes| | | | |Yes | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|show_key | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|show_keypair | | |Yes |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
|show_volume | | | |Yes| | | | | | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+-------+---------+---------+------+
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|Functions |AWS |CloudStack|Digital|EC2|GoGrid|JoyEnt|Linode|OpenStack|Parallels|Rackspace|Saltify&|Softlayer|Softlayer|Aliyun|
|
||||
| |(Legacy)| |Ocean | | | | | | |(Legacy) | Vagrant| |Hardware | |
|
||||
+=======================+========+==========+=======+===+======+======+======+=========+=========+=========+========+=========+=========+======+
|
||||
|block_device_mappings |Yes | | | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|create_keypair | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|create_volume | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|delete_key | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|delete_keypair | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|delete_volume | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|get_image | | |Yes | | |Yes | | |Yes | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|get_ip | |Yes | | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|get_key | |Yes | | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|get_keyid | | |Yes | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|get_keypair | |Yes | | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|get_networkid | |Yes | | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|get_node | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|get_password | |Yes | | | | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|get_size | | |Yes | | |Yes | | | | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|get_spot_config | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|get_subnetid | | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|iam_profile |Yes | | |Yes| | | | | | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|import_key | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|key_list | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|keyname |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|list_availability_zones| | | |Yes| | | | | | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|list_custom_images | | | | | | | | | | | |Yes | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|list_keys | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|list_nodes |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|list_nodes_full |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|list_nodes_select |Yes |Yes |Yes |Yes|Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|list_vlans | | | | | | | | | | | |Yes |Yes | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|rackconnect | | | | | | | |Yes | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|reboot | | | |Yes| |Yes | | | | |[1] | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|reformat_node | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|securitygroup |Yes | | |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|securitygroupid | | | |Yes| | | | | | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|show_image | | | |Yes| | | | |Yes | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|show_key | | | | | |Yes | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|show_keypair | | |Yes |Yes| | | | | | | | | | |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|show_volume | | | |Yes| | | | | | | | | |Yes |
|
||||
+-----------------------+--------+----------+-------+---+------+------+------+---------+---------+---------+--------+---------+---------+------+
|
||||
|
||||
[1] Yes, if salt-api is enabled.
|
||||
|
|
|
@ -129,6 +129,7 @@ Cloud Provider Specifics
|
|||
Getting Started With Scaleway <scaleway>
|
||||
Getting Started With Saltify <saltify>
|
||||
Getting Started With SoftLayer <softlayer>
|
||||
Getting Started With Vagrant <vagrant>
|
||||
Getting Started With Vexxhost <vexxhost>
|
||||
Getting Started With Virtualbox <virtualbox>
|
||||
Getting Started With VMware <vmware>
|
||||
|
|
|
@ -183,6 +183,8 @@ simple installation.
|
|||
ssh_username: vagrant # a user name which has passwordless sudo
|
||||
password: vagrant # on your target machine
|
||||
provider: my_saltify_provider
|
||||
shutdown_on_destroy: true # halt the target on "salt-cloud -d" command
|
||||
|
||||
|
||||
|
||||
.. code-block:: yaml
|
||||
|
|
268
doc/topics/cloud/vagrant.rst
Normal file
268
doc/topics/cloud/vagrant.rst
Normal file
|
@ -0,0 +1,268 @@
|
|||
.. _getting-started-with-vagrant:
|
||||
|
||||
============================
|
||||
Getting Started With Vagrant
|
||||
============================
|
||||
|
||||
The Vagrant driver is a new, experimental driver for spinning up a VagrantBox
|
||||
virtual machine, and installing Salt on it.
|
||||
|
||||
Dependencies
|
||||
============
|
||||
The Vagrant driver itself has no external dependencies.
|
||||
|
||||
The machine which will host the VagrantBox must be an already existing minion
|
||||
of the cloud server's Salt master.
|
||||
It must have Vagrant_ installed, and a Vagrant-compatible virtual machine engine,
|
||||
such as VirtualBox_.
|
||||
(Note: The Vagrant driver does not depend on the salt-cloud VirtualBox driver in any way.)
|
||||
|
||||
.. _Vagrant: https://www.vagrantup.com/
|
||||
.. _VirtualBox: https://www.virtualbox.org/
|
||||
|
||||
\[Caution: The version of Vagrant packaged for ``apt install`` in Ubuntu 16.04 will not connect a bridged
|
||||
network adapter correctly. Use a version downloaded directly from the web site.\]
|
||||
|
||||
Include the Vagrant guest editions plugin:
|
||||
``vagrant plugin install vagrant-vbguest``.
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
Configuration of the client virtual machine (using VirtualBox, VMware, etc)
|
||||
will be done by Vagrant as specified in the Vagrantfile on the host machine.
|
||||
|
||||
Salt-cloud will push the commands to install and provision a salt minion on
|
||||
the virtual machine, so you need not (perhaps **should** not) provision salt
|
||||
in your Vagrantfile, in most cases.
|
||||
|
||||
If, however, your cloud master cannot open an SSH connection to the child VM,
|
||||
you may **need** to let Vagrant provision the VM with Salt, and use some other
|
||||
method (such as passing a pillar dictionary to the VM) to pass the master's
|
||||
IP address to the VM. The VM can then attempt to reach the salt master in the
|
||||
usual way for non-cloud minions. Specify the profile configuration argument
|
||||
as ``deploy: False`` to prevent the cloud master from trying.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
# Note: This example is for /etc/salt/cloud.providers file or any file in
|
||||
# the /etc/salt/cloud.providers.d/ directory.
|
||||
|
||||
my-vagrant-config:
|
||||
minion:
|
||||
master: 111.222.333.444
|
||||
provider: vagrant
|
||||
|
||||
|
||||
Because the Vagrant driver needs a place to store the mapping between the
|
||||
node name you use for Salt commands and the Vagrantfile which controls the VM,
|
||||
you must configure your salt minion as a Salt smb server.
|
||||
(See `host provisioning example`_ below.)
|
||||
|
||||
Profiles
|
||||
========
|
||||
|
||||
Vagrant requires a profile to be configured for each machine that needs Salt
|
||||
installed. The initial profile can be set up at ``/etc/salt/cloud.profiles``
|
||||
or in the ``/etc/salt/cloud.profiles.d/`` directory.
|
||||
|
||||
Each profile requires a ``vagrantfile`` parameter. If the Vagrantfile has
|
||||
definitions for `multiple machines`_ then you need a ``machine`` parameter,
|
||||
|
||||
.. _`multiple machines`: https://www.vagrantup.com/docs/multi-machine/
|
||||
|
||||
Salt-cloud uses SSH to provision the minion. There must be a routable path
|
||||
from the cloud master to the VM. Usually, you will want to use
|
||||
a bridged network adapter for SSH. The address may not be known until
|
||||
DHCP assigns it. If ``ssh_host`` is not defined, and ``target_network``
|
||||
is defined, the driver will attempt to read the address from the output
|
||||
of an ``ifconfig`` command. Lacking either setting,
|
||||
the driver will try to use the value Vagrant returns as its ``ssh_host``,
|
||||
which will work only if the cloud master is running somewhere on the same host.
|
||||
|
||||
The ``target_network`` setting should be used
|
||||
to identify the IP network your bridged adapter is expected to appear on.
|
||||
Use CIDR notation, like ``target_network: '2001:DB8::/32'``
|
||||
or ``target_network: '192.0.2.0/24'``.
|
||||
|
||||
Profile configuration example:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
# /etc/salt/cloud.profiles.d/vagrant.conf
|
||||
|
||||
vagrant-machine:
|
||||
host: my-vhost # the Salt id of the virtual machine's host computer.
|
||||
provider: my-vagrant-config
|
||||
cwd: /srv/machines # the path to your Virtualbox file.
|
||||
vagrant_runas: my-username # the username who defined the Vagrantbox on the host
|
||||
# vagrant_up_timeout: 300 # (seconds) timeout for cmd.run of the "vagrant up" command
|
||||
# vagrant_provider: '' # option for "vagrant up" like: "--provider vmware_fusion"
|
||||
# ssh_host: None # "None" means try to find the routable IP address from "ifconfig"
|
||||
# target_network: None # Expected CIDR address of your bridged network
|
||||
# force_minion_config: false # Set "true" to re-purpose an existing VM
|
||||
|
||||
The machine can now be created and configured with the following command:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt-cloud -p vagrant-machine my-id
|
||||
|
||||
This will create the machine specified by the cloud profile
|
||||
``vagrant-machine``, and will give the machine the minion id of
|
||||
``my-id``. If the cloud master is also the salt-master, its Salt
|
||||
key will automatically be accepted on the master.
|
||||
|
||||
Once a salt-minion has been successfully installed on the instance, connectivity
|
||||
to it can be verified with Salt:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt my-id test.ping
|
||||
|
||||
.. _host provisioning example:
|
||||
|
||||
Provisioning a Vagrant cloud host (example)
|
||||
===========================================
|
||||
|
||||
In order to query or control minions it created, each host
|
||||
minion needs to track the Salt node names associated with
|
||||
any guest virtual machines on it.
|
||||
It does that using a Salt sdb database.
|
||||
|
||||
The Salt sdb is not configured by default. The following example shows a
|
||||
simple installation.
|
||||
|
||||
This example assumes:
|
||||
|
||||
- you are on a large network using the 10.x.x.x IP address space
|
||||
- your Salt master's Salt id is "bevymaster"
|
||||
- it will also be your salt-cloud controller
|
||||
- it is at hardware address 10.124.30.7
|
||||
- it is running a recent Debian family Linux (raspbian)
|
||||
- your workstation is a Salt minion of bevymaster
|
||||
- your workstation's minion id is "my_laptop"
|
||||
- VirtualBox has been installed on "my_laptop" (apt install is okay)
|
||||
- Vagrant was installed from vagrantup.com. (not the 16.04 Ubuntu apt)
|
||||
- "my_laptop" has done "vagrant plugin install vagrant-vbguest"
|
||||
- the VM you want to start is on "my_laptop" at "/home/my_username/Vagrantfile"
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
# file /etc/salt/minion.d/vagrant_sdb.conf on host computer "my_laptop"
|
||||
# -- 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
|
||||
|
||||
Remember to re-start your minion after changing its configuration files...
|
||||
|
||||
``sudo systemctl restart salt-minion``
|
||||
|
||||
.. code-block:: ruby
|
||||
|
||||
# -*- mode: ruby -*-
|
||||
# file /home/my_username/Vagrantfile on host computer "my_laptop"
|
||||
BEVY = "bevy1"
|
||||
DOMAIN = BEVY + ".test" # .test is an ICANN reserved non-public TLD
|
||||
|
||||
# must supply a list of names to avoid Vagrant asking for interactive input
|
||||
def get_good_ifc() # try to find a working Ubuntu network adapter name
|
||||
addr_infos = Socket.getifaddrs
|
||||
addr_infos.each do |info|
|
||||
a = info.addr
|
||||
if a and a.ip? and not a.ip_address.start_with?("127.")
|
||||
return info.name
|
||||
end
|
||||
end
|
||||
return "eth0" # fall back to an old reliable name
|
||||
end
|
||||
|
||||
Vagrant.configure(2) do |config|
|
||||
config.ssh.forward_agent = true # so you can use git ssh://...
|
||||
|
||||
# add a bridged network interface. (try to detect name, then guess MacOS names, too)
|
||||
interface_guesses = [get_good_ifc(), 'en0: Ethernet', 'en1: Wi-Fi (AirPort)']
|
||||
config.vm.network "public_network", bridge: interface_guesses
|
||||
if ARGV[0] == "up"
|
||||
puts "Trying bridge network using interfaces: #{interface_guesses}"
|
||||
end
|
||||
config.vm.provision "shell", inline: "ip address", run: "always" # make user feel good
|
||||
|
||||
# . . . . . . . . . . . . Define machine QUAIL1 . . . . . . . . . . . . . .
|
||||
config.vm.define "quail1", primary: true do |quail_config|
|
||||
quail_config.vm.box = "boxesio/xenial64-standard" # a public VMware & Virtualbox box
|
||||
quail_config.vm.hostname = "quail1." + DOMAIN # supply a name in our bevy
|
||||
quail_config.vm.provider "virtualbox" do |v|
|
||||
v.memory = 1024 # limit memory for the virtual box
|
||||
v.cpus = 1
|
||||
v.linked_clone = true # make a soft copy of the base Vagrant box
|
||||
v.customize ["modifyvm", :id, "--natnet1", "192.168.128.0/24"] # do not use 10.x network for NAT
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
# file /etc/salt/cloud.profiles.d/my_vagrant_profiles.conf on bevymaster
|
||||
q1:
|
||||
host: my_laptop # the Salt id of your virtual machine host
|
||||
machine: quail1 # a machine name in the Vagrantfile (if not primary)
|
||||
vagrant_runas: my_username # owner of Vagrant box files on "my_laptop"
|
||||
cwd: '/home/my_username' # the path (on "my_laptop") of the Vagrantfile
|
||||
provider: my_vagrant_provider # name of entry in provider.conf file
|
||||
target_network: '10.0.0.0/8' # VM external address will be somewhere here
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
# file /etc/salt/cloud.providers.d/vagrant_provider.conf on bevymaster
|
||||
my_vagrant_provider:
|
||||
driver: vagrant
|
||||
minion:
|
||||
master: 10.124.30.7 # the hard address of the master
|
||||
|
||||
|
||||
Create and use your new Salt minion
|
||||
-----------------------------------
|
||||
|
||||
- Typing on the Salt master computer ``bevymaster``, tell it to create a new minion named ``v1`` using profile ``q1``...
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
sudo salt-cloud -p q1 v1
|
||||
sudo salt v1 network.ip_addrs
|
||||
[ you get a list of IP addresses, including the bridged one ]
|
||||
|
||||
- logged in to your laptop (or some other computer known to GitHub)...
|
||||
|
||||
\[NOTE:\] if you are using MacOS, you need to type ``ssh-add -K`` after each boot,
|
||||
unless you use one of the methods in `this gist`_.
|
||||
|
||||
.. _this gist: https://github.com/jirsbek/SSH-keys-in-macOS-Sierra-keychain
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
ssh -A vagrant@< the bridged network address >
|
||||
# [ or, if you are at /home/my_username/ on my_laptop ]
|
||||
vagrant ssh quail1
|
||||
|
||||
- then typing on your new node "v1" (a.k.a. quail1.bevy1.test)...
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
password: vagrant
|
||||
# [ stuff types out ... ]
|
||||
|
||||
ls -al /vagrant
|
||||
# [ should be shared /home/my_username from my_laptop ]
|
||||
|
||||
# you can access other network facilities using the ssh authorization
|
||||
# as recorded in your ~.ssh/ directory on my_laptop ...
|
||||
|
||||
sudo apt update
|
||||
sudo apt install git
|
||||
git clone ssh://git@github.com/yourID/your_project
|
||||
# etc...
|
||||
|
|
@ -138,6 +138,56 @@ file. For example:
|
|||
|
||||
These commands will run in sequence **before** the bootstrap script is executed.
|
||||
|
||||
New salt-cloud Grains
|
||||
=====================
|
||||
|
||||
When salt cloud creates a new minon, it will now add grain information
|
||||
to the minion configuration file, identifying the resources originally used
|
||||
to create it.
|
||||
|
||||
The generated grain information will appear similar to:
|
||||
|
||||
.. code-block:: yaml
|
||||
grains:
|
||||
salt-cloud:
|
||||
driver: ec2
|
||||
provider: my_ec2:ec2
|
||||
profile: ec2-web
|
||||
The generation of salt-cloud grains can be surpressed by the
|
||||
option ``enable_cloud_grains: 'False'`` in the cloud configuration file.
|
||||
|
||||
Upgraded Saltify Driver
|
||||
=======================
|
||||
|
||||
The salt-cloud Saltify driver is used to provision machines which
|
||||
are not controlled by a dedicated cloud supervisor (such as typical hardware
|
||||
machines) by pushing a salt-bootstrap command to them and accepting them on
|
||||
the salt master. Creation of a node has been its only function and no other
|
||||
salt-cloud commands were implemented.
|
||||
|
||||
With this upgrade, it can use the salt-api to provide advanced control,
|
||||
such as rebooting a machine, querying it along with conventional cloud minions,
|
||||
and, ultimately, disconnecting it from its master.
|
||||
|
||||
After disconnection from ("destroying" on) one master, a machine can be
|
||||
re-purposed by connecting to ("creating" on) a subsequent master.
|
||||
|
||||
New Vagrant Driver
|
||||
==================
|
||||
|
||||
The salt-cloud Vagrant driver brings virtual machines running in a limited
|
||||
environment, such as a programmer's workstation, under salt-cloud control.
|
||||
This can be useful for experimentation, instruction, or testing salt configurations.
|
||||
|
||||
Using salt-api on the master, and a salt-minion running on the host computer,
|
||||
the Vagrant driver can create (``vagrant up``), restart (``vagrant reload``),
|
||||
and destroy (``vagrant destroy``) VMs, as controlled by salt-cloud profiles
|
||||
which designate a ``Vagrantfile`` on the host machine.
|
||||
|
||||
The master can be a very limited machine, such as a Raspberry Pi, or a small
|
||||
VagrantBox VM.
|
||||
|
||||
|
||||
New pillar/master_tops module called saltclass
|
||||
----------------------------------------------
|
||||
|
||||
|
|
|
@ -1417,7 +1417,7 @@ class Cloud(object):
|
|||
if name in vms:
|
||||
prov = vms[name]['provider']
|
||||
driv = vms[name]['driver']
|
||||
msg = six.u('{0} already exists under {1}:{2}').format(
|
||||
msg = u'{0} already exists under {1}:{2}'.format(
|
||||
name, prov, driv
|
||||
)
|
||||
log.error(msg)
|
||||
|
|
338
salt/cloud/clouds/vagrant.py
Normal file
338
salt/cloud/clouds/vagrant.py
Normal file
|
@ -0,0 +1,338 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Vagrant Cloud Driver
|
||||
====================
|
||||
|
||||
The Vagrant cloud is designed to "vagrant up" a virtual machine as a
|
||||
Salt minion.
|
||||
|
||||
Use of this module requires some configuration in cloud profile and provider
|
||||
files as described in the
|
||||
:ref:`Gettting Started with Vagrant <getting-started-with-vagrant>` documentation.
|
||||
|
||||
.. versionadded:: Oxygen
|
||||
|
||||
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
import salt.config as config
|
||||
import salt.client
|
||||
import salt.ext.six as six
|
||||
if six.PY3:
|
||||
import ipaddress
|
||||
else:
|
||||
import salt.ext.ipaddress as ipaddress
|
||||
from salt.exceptions import SaltCloudException, SaltCloudSystemExit
|
||||
|
||||
# Get logging started
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Needs no special configuration
|
||||
'''
|
||||
return True
|
||||
|
||||
|
||||
def avail_locations(call=None):
|
||||
r'''
|
||||
This function returns a list of locations available.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt-cloud --list-locations my-cloud-provider
|
||||
|
||||
# \[ vagrant will always returns an empty dictionary \]
|
||||
|
||||
'''
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
def avail_images(call=None):
|
||||
'''This function returns a list of images available for this cloud provider.
|
||||
vagrant will return a list of profiles.
|
||||
salt-cloud --list-images my-cloud-provider
|
||||
'''
|
||||
vm_ = get_configured_provider()
|
||||
return {'Profiles': [profile for profile in vm_['profiles']]}
|
||||
|
||||
|
||||
def avail_sizes(call=None):
|
||||
r'''
|
||||
This function returns a list of sizes available for this cloud provider.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt-cloud --list-sizes my-cloud-provider
|
||||
|
||||
# \[ vagrant always returns an empty dictionary \]
|
||||
|
||||
'''
|
||||
return {}
|
||||
|
||||
|
||||
def list_nodes(call=None):
|
||||
'''
|
||||
List the nodes which have salt-cloud:driver:vagrant grains.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt-cloud -Q
|
||||
'''
|
||||
nodes = _list_nodes(call)
|
||||
return _build_required_items(nodes)
|
||||
|
||||
|
||||
def _build_required_items(nodes):
|
||||
ret = {}
|
||||
for name, grains in nodes.items():
|
||||
if grains:
|
||||
private_ips = []
|
||||
public_ips = []
|
||||
ips = grains['ipv4'] + grains['ipv6']
|
||||
for adrs in ips:
|
||||
ip_ = ipaddress.ip_address(adrs)
|
||||
if not ip_.is_loopback:
|
||||
if ip_.is_private:
|
||||
private_ips.append(adrs)
|
||||
else:
|
||||
public_ips.append(adrs)
|
||||
|
||||
ret[name] = {
|
||||
'id': grains['id'],
|
||||
'image': grains['salt-cloud']['profile'],
|
||||
'private_ips': private_ips,
|
||||
'public_ips': public_ips,
|
||||
'size': '',
|
||||
'state': 'running'
|
||||
}
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def list_nodes_full(call=None):
|
||||
'''
|
||||
List the nodes, ask all 'vagrant' minions, return dict of grains (enhanced).
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt-call -F
|
||||
'''
|
||||
ret = _list_nodes(call)
|
||||
|
||||
for key, grains in ret.items(): # clean up some hyperverbose grains -- everything is too much
|
||||
try:
|
||||
del grains['cpu_flags'], grains['disks'], grains['pythonpath'], grains['dns'], grains['gpus']
|
||||
except KeyError:
|
||||
pass # ignore absence of things we are eliminating
|
||||
except TypeError:
|
||||
del ret[key] # eliminate all reference to unexpected (None) values.
|
||||
|
||||
reqs = _build_required_items(ret)
|
||||
for name in ret:
|
||||
ret[name].update(reqs[name])
|
||||
return ret
|
||||
|
||||
|
||||
def _list_nodes(call=None):
|
||||
'''
|
||||
List the nodes, ask all 'vagrant' minions, return dict of grains.
|
||||
'''
|
||||
local = salt.client.LocalClient()
|
||||
ret = local.cmd('salt-cloud:driver:vagrant', 'grains.items', '', tgt_type='grain')
|
||||
return ret
|
||||
|
||||
|
||||
def list_nodes_select(call=None):
|
||||
'''
|
||||
Return a list of the minions that have salt-cloud grains, with
|
||||
select fields.
|
||||
'''
|
||||
return salt.utils.cloud.list_nodes_select(
|
||||
list_nodes_full('function'), __opts__['query.selection'], call,
|
||||
)
|
||||
|
||||
|
||||
def show_instance(name, call=None):
|
||||
'''
|
||||
List the a single node, return dict of grains.
|
||||
'''
|
||||
local = salt.client.LocalClient()
|
||||
ret = local.cmd(name, 'grains.items', '')
|
||||
reqs = _build_required_items(ret)
|
||||
ret[name].update(reqs[name])
|
||||
return ret
|
||||
|
||||
|
||||
def _get_my_info(name):
|
||||
local = salt.client.LocalClient()
|
||||
return local.cmd(name, 'grains.get', ['salt-cloud'])
|
||||
|
||||
|
||||
def create(vm_):
|
||||
'''
|
||||
Provision a single machine
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
salt-cloud -p my_profile new_node_1
|
||||
|
||||
'''
|
||||
name = vm_['name']
|
||||
machine = config.get_cloud_config_value(
|
||||
'machine', vm_, __opts__, default='')
|
||||
vm_['machine'] = machine
|
||||
host = config.get_cloud_config_value(
|
||||
'host', vm_, __opts__, default=NotImplemented)
|
||||
vm_['cwd'] = config.get_cloud_config_value(
|
||||
'cwd', vm_, __opts__, default='/')
|
||||
vm_['runas'] = config.get_cloud_config_value(
|
||||
'vagrant_runas', vm_, __opts__, default=os.getenv('SUDO_USER'))
|
||||
vm_['timeout'] = config.get_cloud_config_value(
|
||||
'vagrant_up_timeout', vm_, __opts__, default=300)
|
||||
vm_['vagrant_provider'] = config.get_cloud_config_value(
|
||||
'vagrant_provider', vm_, __opts__, default='')
|
||||
vm_['grains'] = {'salt-cloud:vagrant': {'host': host, 'machine': machine}}
|
||||
|
||||
log.info('sending \'vagrant.init %s machine=%s\' command to %s', name, machine, host)
|
||||
|
||||
local = salt.client.LocalClient()
|
||||
ret = local.cmd(host, 'vagrant.init', [name], kwarg={'vm': vm_, 'start': True})
|
||||
log.info('response ==> %s', ret[host])
|
||||
|
||||
network_mask = config.get_cloud_config_value(
|
||||
'network_mask', vm_, __opts__, default='')
|
||||
if 'ssh_host' not in vm_:
|
||||
ret = local.cmd(host,
|
||||
'vagrant.get_ssh_config',
|
||||
[name],
|
||||
kwarg={'network_mask': network_mask,
|
||||
'get_private_key': True})[host]
|
||||
with tempfile.NamedTemporaryFile() as pks:
|
||||
if 'private_key' not in vm_ and ret.get('private_key', False):
|
||||
pks.write(ret['private_key'])
|
||||
pks.flush()
|
||||
log.debug('wrote private key to %s', pks.name)
|
||||
vm_['key_filename'] = pks.name
|
||||
if 'ssh_host' not in vm_:
|
||||
vm_.setdefault('ssh_username', ret['ssh_username'])
|
||||
if ret.get('ip_address'):
|
||||
vm_['ssh_host'] = ret['ip_address']
|
||||
else: # if probe failed or not used, use Vagrant's reported ssh info
|
||||
vm_['ssh_host'] = ret['ssh_host']
|
||||
vm_.setdefault('ssh_port', ret['ssh_port'])
|
||||
|
||||
log.info('Provisioning machine %s as node %s using ssh %s',
|
||||
machine, name, vm_['ssh_host'])
|
||||
ret = __utils__['cloud.bootstrap'](vm_, __opts__)
|
||||
return ret
|
||||
|
||||
|
||||
def get_configured_provider():
|
||||
'''
|
||||
Return the first configured instance.
|
||||
'''
|
||||
ret = config.is_provider_configured(
|
||||
__opts__,
|
||||
__active_provider_name__ or 'vagrant',
|
||||
''
|
||||
)
|
||||
return ret
|
||||
|
||||
|
||||
# noinspection PyTypeChecker
|
||||
def destroy(name, call=None):
|
||||
'''
|
||||
Destroy a node.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt-cloud --destroy mymachine
|
||||
'''
|
||||
if call == 'function':
|
||||
raise SaltCloudSystemExit(
|
||||
'The destroy action must be called with -d, --destroy, '
|
||||
'-a, or --action.'
|
||||
)
|
||||
|
||||
opts = __opts__
|
||||
|
||||
__utils__['cloud.fire_event'](
|
||||
'event',
|
||||
'destroying instance',
|
||||
'salt/cloud/{0}/destroying'.format(name),
|
||||
args={'name': name},
|
||||
sock_dir=opts['sock_dir'],
|
||||
transport=opts['transport']
|
||||
)
|
||||
my_info = _get_my_info(name)
|
||||
profile_name = my_info[name]['profile']
|
||||
profile = opts['profiles'][profile_name]
|
||||
host = profile['host']
|
||||
local = salt.client.LocalClient()
|
||||
ret = local.cmd(host, 'vagrant.destroy', [name])
|
||||
|
||||
if ret[host]:
|
||||
__utils__['cloud.fire_event'](
|
||||
'event',
|
||||
'destroyed instance',
|
||||
'salt/cloud/{0}/destroyed'.format(name),
|
||||
args={'name': name},
|
||||
sock_dir=opts['sock_dir'],
|
||||
transport=opts['transport']
|
||||
)
|
||||
|
||||
if opts.get('update_cachedir', False) is True:
|
||||
__utils__['cloud.delete_minion_cachedir'](
|
||||
name, __active_provider_name__.split(':')[0], opts)
|
||||
|
||||
return {'Destroyed': '{0} was destroyed.'.format(name)}
|
||||
else:
|
||||
return {'Error': 'Error destroying {}'.format(name)}
|
||||
|
||||
|
||||
# noinspection PyTypeChecker
|
||||
def reboot(name, call=None):
|
||||
'''
|
||||
Reboot a vagrant minion.
|
||||
|
||||
name
|
||||
The name of the VM to reboot.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt-cloud -a reboot vm_name
|
||||
'''
|
||||
if call != 'action':
|
||||
raise SaltCloudException(
|
||||
'The reboot action must be called with -a or --action.'
|
||||
)
|
||||
my_info = _get_my_info(name)
|
||||
profile_name = my_info[name]['profile']
|
||||
profile = __opts__['profiles'][profile_name]
|
||||
host = profile['host']
|
||||
local = salt.client.LocalClient()
|
||||
return local.cmd(host, 'vagrant.reboot', [name])
|
|
@ -55,7 +55,6 @@ def __virtual__():
|
|||
'''
|
||||
run Vagrant commands if possible
|
||||
'''
|
||||
# noinspection PyUnresolvedReferences
|
||||
if salt.utils.path.which('vagrant') is None:
|
||||
return False, 'The vagrant module could not be loaded: vagrant command not found'
|
||||
return __virtualname__
|
||||
|
@ -298,6 +297,11 @@ def vm_state(name='', cwd=None):
|
|||
'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.
|
||||
|
||||
'''
|
||||
|
||||
if name:
|
||||
|
@ -321,7 +325,7 @@ def vm_state(name='', cwd=None):
|
|||
datum = {'machine': tokens[0],
|
||||
'state': ' '.join(tokens[1:-1]),
|
||||
'provider': tokens[-1].lstrip('(').rstrip(')'),
|
||||
'name': name or get_machine_id(tokens[0], cwd)
|
||||
'name': get_machine_id(tokens[0], cwd)
|
||||
}
|
||||
info.append(datum)
|
||||
except IndexError:
|
||||
|
@ -365,7 +369,7 @@ def init(name, # Salt_id for created VM
|
|||
# passed-in keyword arguments overwrite vm dictionary values
|
||||
vm_['cwd'] = cwd or vm_.get('cwd')
|
||||
if not vm_['cwd']:
|
||||
raise SaltInvocationError('Path to Vagrantfile must be defined by \'cwd\' argument')
|
||||
raise SaltInvocationError('Path to Vagrantfile must be defined by "cwd" argument')
|
||||
vm_['machine'] = machine or vm_.get('machine', machine)
|
||||
vm_['runas'] = runas or vm_.get('runas', runas)
|
||||
vm_['vagrant_provider'] = vagrant_provider or vm_.get('vagrant_provider', '')
|
||||
|
@ -423,7 +427,7 @@ def shutdown(name):
|
|||
'''
|
||||
Send a soft shutdown (vagrant halt) signal to the named vm.
|
||||
|
||||
This does the same thing as vagrant.stop. Other VM control
|
||||
This does the same thing as vagrant.stop. Other-VM control
|
||||
modules use "stop" and "shutdown" to differentiate between
|
||||
hard and soft shutdowns.
|
||||
|
||||
|
@ -476,7 +480,7 @@ def pause(name):
|
|||
return ret == 0
|
||||
|
||||
|
||||
def reboot(name):
|
||||
def reboot(name, provision=False):
|
||||
'''
|
||||
Reboot a VM. (vagrant reload)
|
||||
|
||||
|
@ -484,12 +488,16 @@ def reboot(name):
|
|||
|
||||
.. code-block:: bash
|
||||
|
||||
salt <host> vagrant.reboot <salt_id>
|
||||
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.
|
||||
'''
|
||||
vm_ = get_vm_info(name)
|
||||
machine = vm_['machine']
|
||||
prov = '--provision' if provision else ''
|
||||
|
||||
cmd = 'vagrant reload {}'.format(machine)
|
||||
cmd = 'vagrant reload {} {}'.format(machine, prov)
|
||||
ret = __salt__['cmd.retcode'](cmd,
|
||||
runas=vm_.get('runas'),
|
||||
cwd=vm_.get('cwd'))
|
||||
|
|
369
salt/states/vagrant.py
Normal file
369
salt/states/vagrant.py
Normal file
|
@ -0,0 +1,369 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
r'''
|
||||
.. index:: Vagrant state function
|
||||
|
||||
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:: Oxygen
|
||||
|
||||
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
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Python libs
|
||||
import fnmatch
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils.args
|
||||
from salt.exceptions import CommandExecutionError, SaltInvocationError
|
||||
import salt.ext.six as six
|
||||
|
||||
__virtualname__ = 'vagrant'
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Only if vagrant module is available.
|
||||
|
||||
:return:
|
||||
'''
|
||||
|
||||
if 'vagrant.version' in __salt__:
|
||||
return __virtualname__
|
||||
return False
|
||||
|
||||
|
||||
def _vagrant_call(node, function, section, comment, status_when_done=None, **kwargs):
|
||||
'''
|
||||
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
|
||||
'''
|
||||
ret = {'name': node, 'changes': {}, 'result': True, 'comment': ''}
|
||||
|
||||
targeted_nodes = []
|
||||
if isinstance(node, six.string_types):
|
||||
try: # use shortcut if a single node name
|
||||
if __salt__['vagrant.get_vm_info'](node):
|
||||
targeted_nodes = [node]
|
||||
except SaltInvocationError:
|
||||
pass
|
||||
|
||||
if not targeted_nodes: # the shortcut failed, do this the hard way
|
||||
all_domains = __salt__['vagrant.list_domains']()
|
||||
targeted_nodes = fnmatch.filter(all_domains, node)
|
||||
changed_nodes = []
|
||||
ignored_nodes = []
|
||||
for node in targeted_nodes:
|
||||
if status_when_done:
|
||||
try:
|
||||
present_state = __salt__['vagrant.vm_state'](node)[0]
|
||||
if present_state['state'] == status_when_done:
|
||||
continue # no change is needed
|
||||
except (IndexError, SaltInvocationError, CommandExecutionError):
|
||||
pass
|
||||
try:
|
||||
response = __salt__['vagrant.{0}'.format(function)](node, **kwargs)
|
||||
if isinstance(response, dict):
|
||||
response = response['name']
|
||||
changed_nodes.append({'node': node, function: response})
|
||||
except (SaltInvocationError, CommandExecutionError) as err:
|
||||
ignored_nodes.append({'node': node, 'issue': str(err)})
|
||||
if not changed_nodes:
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'No changes seen'
|
||||
if ignored_nodes:
|
||||
ret['changes'] = {'ignored': ignored_nodes}
|
||||
else:
|
||||
ret['changes'] = {section: changed_nodes}
|
||||
ret['comment'] = comment
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def running(name, **kwargs):
|
||||
r'''
|
||||
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
|
||||
|
||||
'''
|
||||
if '*' in name or '?' in name:
|
||||
|
||||
return _vagrant_call(name, 'start', 'restarted',
|
||||
"Machine has been restarted", "running")
|
||||
|
||||
else:
|
||||
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': '{0} is already running'.format(name)
|
||||
}
|
||||
|
||||
try:
|
||||
info = __salt__['vagrant.vm_state'](name)
|
||||
if info[0]['state'] != 'running':
|
||||
__salt__['vagrant.start'](name)
|
||||
ret['changes'][name] = 'Machine started'
|
||||
ret['comment'] = 'Node {0} started'.format(name)
|
||||
except (SaltInvocationError, CommandExecutionError):
|
||||
# there was no viable existing machine to start
|
||||
ret, kwargs = _find_init_change(name, ret, **kwargs)
|
||||
kwargs['start'] = True
|
||||
__salt__['vagrant.init'](name, **kwargs)
|
||||
ret['changes'][name] = 'Node defined and started'
|
||||
ret['comment'] = 'Node {0} defined and started'.format(name)
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def _find_init_change(name, ret, **kwargs):
|
||||
'''
|
||||
look for changes from any previous init of machine.
|
||||
|
||||
:return: modified ret and kwargs
|
||||
'''
|
||||
kwargs = salt.utils.args.clean_kwargs(**kwargs)
|
||||
if 'vm' in kwargs:
|
||||
kwargs.update(kwargs.pop('vm'))
|
||||
# the state processing eats 'runas' so we rename
|
||||
kwargs['runas'] = kwargs.pop('vagrant_runas', '')
|
||||
try:
|
||||
vm_ = __salt__['vagrant.get_vm_info'](name)
|
||||
except SaltInvocationError:
|
||||
vm_ = {}
|
||||
for key, value in kwargs.items():
|
||||
ret['changes'][key] = {'old': None, 'new': value}
|
||||
if vm_: # test for changed values
|
||||
for key in vm_:
|
||||
value = vm_[key] or '' # supply a blank if value is None
|
||||
if key != 'name': # will be missing in kwargs
|
||||
new = kwargs.get(key, '')
|
||||
if new != value:
|
||||
if key == 'machine' and new == '':
|
||||
continue # we don't know the default machine name
|
||||
ret['changes'][key] = {'old': value, 'new': new}
|
||||
return ret, kwargs
|
||||
|
||||
|
||||
def initialized(name, **kwargs):
|
||||
r'''
|
||||
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?
|
||||
'''
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'The VM is already correctly defined'
|
||||
}
|
||||
|
||||
# define a machine to start later
|
||||
ret, kwargs = _find_init_change(name, ret, **kwargs)
|
||||
|
||||
if ret['changes'] == {}:
|
||||
return ret
|
||||
|
||||
kwargs['start'] = False
|
||||
__salt__['vagrant.init'](name, **kwargs)
|
||||
ret['changes'][name] = 'Node initialized'
|
||||
ret['comment'] = 'Node {0} defined but not started.'.format(name)
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def stopped(name):
|
||||
'''
|
||||
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
|
||||
'''
|
||||
|
||||
return _vagrant_call(name, 'shutdown', 'stopped',
|
||||
'Machine has been shut down', 'poweroff')
|
||||
|
||||
|
||||
def powered_off(name):
|
||||
'''
|
||||
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
|
||||
'''
|
||||
|
||||
return _vagrant_call(name, 'stop', 'unpowered',
|
||||
'Machine has been powered off', 'poweroff')
|
||||
|
||||
|
||||
def destroyed(name):
|
||||
'''
|
||||
Stops a VM (or VMs) and removes all refences 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
|
||||
'''
|
||||
|
||||
return _vagrant_call(name, 'destroy', 'destroyed',
|
||||
'Machine has been removed')
|
||||
|
||||
|
||||
def paused(name):
|
||||
'''
|
||||
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
|
||||
'''
|
||||
|
||||
return _vagrant_call(name, 'pause', 'paused',
|
||||
'Machine has been suspended', 'saved')
|
||||
|
||||
|
||||
def rebooted(name):
|
||||
'''
|
||||
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
|
||||
'''
|
||||
|
||||
return _vagrant_call(name, 'reboot', 'rebooted', 'Machine has been reloaded')
|
|
@ -398,13 +398,14 @@ def bootstrap(vm_, opts=None):
|
|||
|
||||
# NOTE: deploy_kwargs is also used to pass inline_script variable content
|
||||
# to run_inline_script function
|
||||
host = salt.config.get_cloud_config_value('ssh_host', vm_, opts)
|
||||
deploy_kwargs = {
|
||||
'opts': opts,
|
||||
'host': vm_['ssh_host'],
|
||||
'host': host,
|
||||
'port': salt.config.get_cloud_config_value(
|
||||
'ssh_port', vm_, opts, default=22
|
||||
),
|
||||
'salt_host': vm_.get('salt_host', vm_['ssh_host']),
|
||||
'salt_host': vm_.get('salt_host', host),
|
||||
'username': ssh_username,
|
||||
'script': deploy_script_code,
|
||||
'inline_script': inline_script_config,
|
||||
|
|
Loading…
Add table
Reference in a new issue