rbd.pp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #
  2. # Copyright (C) 2014 OpenStack Fondation
  3. #
  4. # Author: Emilien Macchi <emilien.macchi@enovance.com>
  5. # Donald Talton <dotalton@cisco.com>
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. # not use this file except in compliance with the License. You may obtain
  9. # a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. # License for the specific language governing permissions and limitations
  17. # under the License.
  18. # == Class: nova::compute::rbd
  19. #
  20. # Configure nova-compute to store virtual machines on RBD
  21. #
  22. # === Parameters
  23. #
  24. # [*libvirt_images_rbd_pool*]
  25. # (optional) The RADOS pool in which rbd volumes are stored.
  26. # Defaults to 'rbd'.
  27. #
  28. # [*libvirt_images_rbd_ceph_conf*]
  29. # (optional) The path to the ceph configuration file to use.
  30. # Defaults to '/etc/ceph/ceph.conf'.
  31. #
  32. # [*libvirt_rbd_user*]
  33. # (Required) The RADOS client name for accessing rbd volumes.
  34. #
  35. # [*libvirt_rbd_secret_uuid*]
  36. # (optional) The libvirt uuid of the secret for the rbd_user.
  37. # Required to use cephx.
  38. # Default to false.
  39. #
  40. # [*libvirt_rbd_secret_key*]
  41. # (optional) The cephx key to use as key for the libvirt secret,
  42. # it must be base64 encoded; when not provided this key will be
  43. # requested to the ceph cluster, which assumes the node is
  44. # provided of the client.admin keyring as well.
  45. # Default to undef.
  46. #
  47. # [*rbd_keyring*]
  48. # (optional) The keyring name to use when retrieving the RBD secret
  49. # Default to 'client.nova'
  50. #
  51. # [*ephemeral_storage*]
  52. # (optional) Wether or not to use the rbd driver for the nova
  53. # ephemeral storage or for the cinder volumes only.
  54. # Defaults to true.
  55. #
  56. # [*manage_ceph_client*]
  57. # (optional) Whether to manage the ceph client package.
  58. # Defaults to true.
  59. #
  60. # [*ceph_client_ensure*]
  61. # (optional) Ensure value for ceph client package.
  62. # Defaults to 'present'.
  63. class nova::compute::rbd (
  64. $libvirt_rbd_user,
  65. $libvirt_rbd_secret_uuid = false,
  66. $libvirt_rbd_secret_key = undef,
  67. $libvirt_images_rbd_pool = 'rbd',
  68. $libvirt_images_rbd_ceph_conf = '/etc/ceph/ceph.conf',
  69. $rbd_keyring = 'client.nova',
  70. $ephemeral_storage = true,
  71. $manage_ceph_client = true,
  72. $ceph_client_ensure = 'present',
  73. ) {
  74. include ::nova::deps
  75. include ::nova::params
  76. if $manage_ceph_client {
  77. # Install ceph client libraries
  78. package { 'ceph-client-package':
  79. ensure => $ceph_client_ensure,
  80. name => $nova::params::ceph_client_package_name,
  81. tag => ['openstack'],
  82. }
  83. }
  84. nova_config {
  85. 'libvirt/rbd_user': value => $libvirt_rbd_user;
  86. }
  87. if $libvirt_rbd_secret_uuid {
  88. nova_config {
  89. 'libvirt/rbd_secret_uuid': value => $libvirt_rbd_secret_uuid;
  90. }
  91. file { '/etc/nova/secret.xml':
  92. content => template('nova/secret.xml-compute.erb'),
  93. require => Anchor['nova::config::begin'],
  94. }
  95. #Variable name shrinked in favor of removing
  96. #the more than 140 chars puppet-lint warning.
  97. #variable used in the get-or-set virsh secret
  98. #resource.
  99. $cm = '/usr/bin/virsh secret-define --file /etc/nova/secret.xml | /usr/bin/awk \'{print $2}\' | sed \'/^$/d\' > /etc/nova/virsh.secret'
  100. exec { 'get-or-set virsh secret':
  101. command => $cm,
  102. unless => "/usr/bin/virsh secret-list | grep ${libvirt_rbd_secret_uuid}",
  103. require => [File['/etc/nova/secret.xml'], Service['libvirt']],
  104. }
  105. if $libvirt_rbd_secret_key {
  106. $libvirt_key = $libvirt_rbd_secret_key
  107. } else {
  108. $libvirt_key = "$(ceph auth get-key ${rbd_keyring})"
  109. }
  110. exec { 'set-secret-value virsh':
  111. command => "/usr/bin/virsh secret-set-value --secret ${libvirt_rbd_secret_uuid} --base64 ${libvirt_key}",
  112. unless => "/usr/bin/virsh secret-get-value ${libvirt_rbd_secret_uuid} | grep ${libvirt_key}",
  113. require => Exec['get-or-set virsh secret'],
  114. before => Anchor['nova::config::end'],
  115. }
  116. }
  117. if $ephemeral_storage {
  118. nova_config {
  119. 'libvirt/images_type': value => 'rbd';
  120. 'libvirt/images_rbd_pool': value => $libvirt_images_rbd_pool;
  121. 'libvirt/images_rbd_ceph_conf': value => $libvirt_images_rbd_ceph_conf;
  122. }
  123. } else {
  124. nova_config {
  125. 'libvirt/images_rbd_pool': ensure => absent;
  126. 'libvirt/images_rbd_ceph_conf': ensure => absent;
  127. }
  128. }
  129. }