1
0

libvirt.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. https://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 accepted 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. SSH Key Authentication
  73. ======================
  74. Instead of specifying a password, an authorized key can be used for the minion setup. Ensure that
  75. the ssh user of your base image has the public key you want to use in ~/.ssh/authorized_keys. If
  76. you want to use a non-root user you will likely want to configure salt-cloud to use sudo.
  77. An example using root:
  78. .. code-block:: yaml
  79. centos7:
  80. provider: local-kvm
  81. # the domain to clone
  82. base_domain: base-centos7-64
  83. ssh_username: root
  84. private_key: /path/to/private/key
  85. An example using a non-root user:
  86. .. code-block:: yaml
  87. centos7:
  88. provider: local-kvm
  89. # the domain to clone
  90. base_domain: base-centos7-64
  91. ssh_username: centos
  92. private_key: /path/to/private/key
  93. sudo: True
  94. sudo_password: "--redacted--"
  95. Optional Settings
  96. =================
  97. .. code-block:: yaml
  98. centos7:
  99. # ssh settings
  100. # use forwarded agent instead of a local key
  101. ssh_agent: True
  102. ssh_port: 4910
  103. # credentials
  104. ssh_username: root
  105. # password will be used for sudo if defined, use sudo_password if using ssh keys
  106. password: my-secret-password
  107. private_key: /path/to/private/key
  108. sudo: True
  109. sudo_password: "--redacted--"
  110. # bootstrap options
  111. deploy_command: sh /tmp/.saltcloud/deploy.sh
  112. script_args: -F
  113. # minion config
  114. grains:
  115. sushi: more tasty
  116. # point at the another master at another port
  117. minion:
  118. master: 192.168.16.1
  119. master_port: 5506
  120. # libvirt settings
  121. # clone_strategy: [ quick | full ] # default is full
  122. clone_strategy: quick
  123. # ip_source: [ ip-learning | qemu-agent ] # default is ip-learning
  124. ip_source: qemu-agent
  125. # validate_xml: [ false | true ] # default is true
  126. validate_xml: false
  127. The ``clone_strategy`` controls how the clone is done. In case of ``full`` the disks
  128. are copied creating a standalone clone. If ``quick`` is used the disks of the base domain
  129. are used as backing disks for the clone. This results in nearly instantaneous clones at
  130. the expense of slower write performance. The quick strategy has a number of requirements:
  131. * The disks must be of type qcow2
  132. * The base domain must be turned off
  133. * The base domain must not change after creating the clone
  134. The ``ip_source`` setting controls how the IP address of the cloned instance is determined.
  135. When using ``ip-learning`` the IP is requested from libvirt. This needs a recent libvirt
  136. version and may only work for NAT/routed networks where libvirt runs the dhcp server.
  137. Another option is to use ``qemu-agent`` this requires that the qemu-agent is installed and
  138. configured to run at startup in the base domain.
  139. The ``validate_xml`` setting is available to disable xml validation by libvirt when cloning.
  140. See also :mod:`salt.cloud.clouds.libvirt`