9bb0dceaf167816a87ff8cb60a3883d0092d3127
[mirror/dsa-puppet.git] / 3rdparty / modules / nova / manifests / compute / rbd.pp
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
19 # == Class: nova::compute::rbd
20 #
21 # Configure nova-compute to store virtual machines on RBD
22 #
23 # === Parameters
24 #
25 # [*libvirt_images_rbd_pool*]
26 #   (optional) The RADOS pool in which rbd volumes are stored.
27 #   Defaults to 'rbd'.
28 #
29 # [*libvirt_images_rbd_ceph_conf*]
30 #   (optional) The path to the ceph configuration file to use.
31 #   Defaults to '/etc/ceph/ceph.conf'.
32 #
33 # [*libvirt_rbd_user*]
34 #   (Required) The RADOS client name for accessing rbd volumes.
35 #
36 # [*libvirt_rbd_secret_uuid*]
37 #   (optional) The libvirt uuid of the secret for the rbd_user.
38 #   Required to use cephx.
39 #   Default to false.
40 #
41 # [*libvirt_rbd_secret_key*]
42 #   (optional) The cephx key to use as key for the libvirt secret,
43 #   it must be base64 encoded; when not provided this key will be
44 #   requested to the ceph cluster, which assumes the node is
45 #   provided of the client.admin keyring as well.
46 #   Default to undef.
47 #
48 # [*rbd_keyring*]
49 #   (optional) The keyring name to use when retrieving the RBD secret
50 #   Default to 'client.nova'
51 #
52
53 class nova::compute::rbd (
54   $libvirt_rbd_user,
55   $libvirt_rbd_secret_uuid      = false,
56   $libvirt_rbd_secret_key       = undef,
57   $libvirt_images_rbd_pool      = 'rbd',
58   $libvirt_images_rbd_ceph_conf = '/etc/ceph/ceph.conf',
59   $rbd_keyring                  = 'client.nova',
60 ) {
61
62   include nova::params
63
64   nova_config {
65     'libvirt/images_type':          value => 'rbd';
66     'libvirt/images_rbd_pool':      value => $libvirt_images_rbd_pool;
67     'libvirt/images_rbd_ceph_conf': value => $libvirt_images_rbd_ceph_conf;
68     'libvirt/rbd_user':             value => $libvirt_rbd_user;
69   }
70
71   if $libvirt_rbd_secret_uuid {
72     nova_config {
73       'libvirt/rbd_secret_uuid': value => $libvirt_rbd_secret_uuid;
74     }
75
76     file { '/etc/nova/secret.xml':
77       content => template('nova/secret.xml-compute.erb')
78     }
79
80     exec { 'get-or-set virsh secret':
81       command => '/usr/bin/virsh secret-define --file /etc/nova/secret.xml | /usr/bin/awk \'{print $2}\' | sed \'/^$/d\' > /etc/nova/virsh.secret',
82       creates => '/etc/nova/virsh.secret',
83       require => File['/etc/nova/secret.xml']
84     }
85
86     if $libvirt_rbd_secret_key {
87       $libvirt_key = $libvirt_rbd_secret_key
88     } else {
89       $libvirt_key = "$(ceph auth get-key ${rbd_keyring})"
90     }
91     exec { 'set-secret-value virsh':
92       command => "/usr/bin/virsh secret-set-value --secret ${libvirt_rbd_secret_uuid} --base64 ${libvirt_key}",
93       unless  => "/usr/bin/virsh secret-get-value ${libvirt_rbd_secret_uuid}",
94       require => Exec['get-or-set virsh secret']
95     }
96
97   }
98
99 }