try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / cinder / manifests / type.pp
1 # ==Define: cinder::type
2 #
3 # Creates cinder type and assigns backends.
4 #
5 # === Parameters
6 #
7 # [*os_password*]
8 #   (required) The keystone tenant:username password.
9 #
10 # [*set_key*]
11 #   (optional) Must be used with set_value. Accepts a single string be used
12 #     as the key in type_set
13 #
14 # [*set_value*]
15 #   (optional) Accepts list of strings or singular string. A list of values
16 #     passed to type_set
17 #
18 # [*os_tenant_name*]
19 #   (optional) The keystone tenant name. Defaults to 'admin'.
20 #
21 # [*os_username*]
22 #   (optional) The keystone user name. Defaults to 'admin.
23 #
24 # [*os_auth_url*]
25 #   (optional) The keystone auth url. Defaults to 'http://127.0.0.1:5000/v2.0/'.
26 #
27 # [*os_region_name*]
28 #   (optional) The keystone region name. Default is unset.
29 #
30 # Author: Andrew Woodward <awoodward@mirantis.com>
31
32 define cinder::type (
33   $os_password,
34   $set_key        = undef,
35   $set_value      = undef,
36   $os_tenant_name = 'admin',
37   $os_username    = 'admin',
38   $os_auth_url    = 'http://127.0.0.1:5000/v2.0/',
39   $os_region_name = undef,
40   ) {
41
42   $volume_name = $name
43
44 # TODO: (xarses) This should be moved to a ruby provider so that among other
45 #   reasons, the credential discovery magic can occur like in neutron.
46
47   $cinder_env = [
48     "OS_TENANT_NAME=${os_tenant_name}",
49     "OS_USERNAME=${os_username}",
50     "OS_PASSWORD=${os_password}",
51     "OS_AUTH_URL=${os_auth_url}",
52   ]
53
54   if $os_region_name {
55     $region_env = ["OS_REGION_NAME=${os_region_name}"]
56   }
57   else {
58     $region_env = []
59   }
60
61   exec {"cinder type-create ${volume_name}":
62     command     => "cinder type-create ${volume_name}",
63     unless      => "cinder type-list | grep -qP '\\b${volume_name}\\b'",
64     environment => concat($cinder_env, $region_env),
65     require     => Package['python-cinderclient'],
66     path        => ['/usr/bin', '/bin'],
67   }
68
69   if ($set_value and $set_key) {
70     Exec["cinder type-create ${volume_name}"] ->
71     cinder::type_set { $set_value:
72       type            => $volume_name,
73       key             => $set_key,
74       os_password     => $os_password,
75       os_tenant_name  => $os_tenant_name,
76       os_username     => $os_username,
77       os_auth_url     => $os_auth_url,
78       os_region_name  => $os_region_name,
79     }
80   }
81 }