libvirt.rst 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ============================
  2. Getting Started With Libvirt
  3. ============================
  4. Libvirt is a toolkit to interact with the virtualization capabilities of recent versions
  5. of Linux (and other OSes). This driver Salt cloud provider is currently geared towards
  6. libvirt with qemu-kvm.
  7. http://www.libvirt.org/
  8. Host Dependencies
  9. =================
  10. * libvirt >= 1.2.18 (older might work)
  11. Salt-Cloud Dependencies
  12. =======================
  13. * libvirt-python
  14. Provider Configuration
  15. ======================
  16. For every KVM host a provider needs to be set up. The provider currently maps to one libvirt daemon (e.g. one KVM host).
  17. Set up the provider cloud configuration file at ``/etc/salt/cloud.providers`` or
  18. ``/etc/salt/cloud.providers.d/*.conf``.
  19. .. code-block:: yaml
  20. # Set up a provider with qemu+ssh protocol
  21. kvm-via-ssh:
  22. driver: libvirt
  23. url: qemu+ssh://user@kvm.company.com/system?socket=/var/run/libvirt/libvirt-sock
  24. # Or connect to a local libvirt instance
  25. local-kvm:
  26. driver: libvirt
  27. url: qemu:///system
  28. # work around flag for XML validation errors while cloning
  29. validate_xml: no
  30. Cloud Profiles
  31. ==============
  32. Virtual machines get cloned from so called Cloud Profiles. Profiles can be set up at ``/etc/salt/cloud.profiles`` or
  33. ``/etc/salt/cloud.profiles.d/*.conf``:
  34. * Configure a profile to be used:
  35. .. code-block:: yaml
  36. centos7:
  37. # points back at provider configuration
  38. provider: local-kvm
  39. base_domain: base-centos7-64
  40. ip_source: ip-learning
  41. ssh_username: root
  42. password: my-very-secret-password
  43. # /tmp is mounted noexec.. do workaround
  44. deploy_command: sh /tmp/.saltcloud/deploy.sh
  45. script_args: -F
  46. # grains to add to the minion
  47. grains:
  48. clones-are-awesome: true
  49. # override minion settings
  50. minion:
  51. master: 192.168.16.1
  52. master_port: 5506
  53. The profile can be realized now with a salt command:
  54. .. code-block:: bash
  55. # salt-cloud -p centos7 my-centos7-clone
  56. This will create an instance named ``my-centos7-clone`` on the cloud host. Also
  57. the minion id will be set to ``my-centos7-clone``.
  58. If the command was executed on the salt-master, its Salt key will automatically
  59. be signed on the master.
  60. Once the instance has been created with salt-minion installed, connectivity to
  61. it can be verified with Salt:
  62. .. code-block:: bash
  63. # salt my-centos7-clone test.version
  64. Required Settings
  65. =================
  66. The following settings are always required for libvirt:
  67. .. code-block:: yaml
  68. centos7:
  69. provider: local-kvm
  70. # the domain to clone
  71. base_domain: base-centos7-64
  72. # how to obtain the IP address of the cloned instance
  73. # ip-learning or qemu-agent
  74. ip_source: ip-learning
  75. The ``ip_source`` setting controls how the IP address of the cloned instance is determined.
  76. When using ``ip-learning`` the IP is requested from libvirt. This needs a recent libvirt
  77. version and may only work for NAT networks. Another option is to use ``qemu-agent`` this requires
  78. that the qemu-agent is installed and configured to run at startup in the base domain.
  79. Optional Settings
  80. =================
  81. .. code-block:: yaml
  82. # Username and password
  83. ssh_username: root
  84. password: my-secret-password
  85. # Cloning strategy: full or quick
  86. clone_strategy: quick
  87. The ``clone_strategy`` controls how the clone is done. In case of ``full`` the disks
  88. are copied creating a standalone clone. If ``quick`` is used the disks of the base domain
  89. are used as backing disks for the clone. This results in nearly instantaneous clones at
  90. the expense of slower write performance. The quick strategy has a number of requirements:
  91. * The disks must be of type qcow2
  92. * The base domain must be turned off
  93. * The base domain must not change after creating the clone