Make Glance Image Cahe code idempotent

Instead of creating random 32 character user and project IDs
for cinder internal user and tenant, use keystone to create
them and then obtain the IDs using an exec call as there is
no keystone call to get this information.

Add custom facts to get keystone data for internal tenant
and user.

Add volume type for Pure volumes and set default volume type
to be Pure if multibackend.

Change-Id: I24906fafe5216b7153ef67c0c529663bb66db6aa
This commit is contained in:
Simon Dodsley 2016-05-28 13:51:17 -04:00
parent 2056e74df9
commit dd4f169c59
4 changed files with 42 additions and 37 deletions

View File

@ -20,7 +20,7 @@ $previous_backends = ''
class { 'plugin_purestorage_cinder::controller' :
backend_name => $backend_name,
backends => $previous_backends,
multibackends => $plugin_settings['multibackend'],
multibackend => $plugin_settings['multibackend'],
glance_image_cache => $plugin_settings['pure_glance_image_cache'],
glance_image_count => $plugin_settings["pure_glance_cache_count"],
glance_image_size => $plugin_settings["pure_glance_cache_size"],

View File

@ -0,0 +1,7 @@
require 'facter/util/resolution'
Facter.add("cinder_tenant") do
setcode do
tenant = Facter::Util::Resolution.exec("/usr/bin/openstack project show cinder_internal_tenant | grep id | awk \'{print $4}\'")
end
end

View File

@ -0,0 +1,7 @@
require 'facter/util/resolution'
Facter.add("cinder_user") do
setcode do
user = Facter::Util::Resolution.exec("/usr/bin/openstack user show cinder_internal_user | grep id | awk \'{print $4}\'")
end
end

View File

@ -16,7 +16,7 @@
class plugin_purestorage_cinder::controller (
$backend_name,
$backends,
$multibackends,
$multibackend,
$glance_image_cache,
$glance_image_count,
$glance_image_size,
@ -70,52 +70,43 @@ class plugin_purestorage_cinder::controller (
Package[$::cinder::params::volume_package] -> Cinder_config<||>
}
if $multibackend == 'true' {
if $multibackend{
$section = $backend_name
cinder_type {'pure_vol':
ensure => present,
properties => ['volume_backend_name=$section'],
}
cinder_config {
"DEFAULT/default_volume_type": value => 'pure_vol';
"DEFAULT/enabled_backends": value => "${backend_name}";
}
} else {
$section = 'DEFAULT'
}
# Insert Glance Image Cache for Cinder settings
# Until we can do this correctly with Keystone and get back the created IDs
# we will do this with the get_random_id below.
#
# if $glance_image_cache == 'true' {
# keystone_tenant { 'cinder_internal_tenant':
# ensure => present,
# description => 'Cinder Internal Tenant',
# enabled => True,
# }
# keystone_user { 'cinder_internal_user':
# ensure => present,
# description => 'Cinder Internal User',
# enabled => True,
# }
# keystone_role { 'admin':
# ensure => present,
# }
# keystone_user_role { 'cinder_internal_user@cinder_internal_tenant':
# roles => ['admin'],
# ensure => present
# }
#
# Currently there is no way to recover a user or tenant ID from keystone in puppet.
# Luckily the glance image cache doesn't actually use keystone to check the IDs so
# we can just, temporarily, assign a randon ID to the two fields.
# When keystone-puppet has the functionality we need we will fix this workaround
if $glance_image_cache{
keystone_tenant { 'cinder_internal_tenant':
ensure => present,
enabled => True,
}
keystone_user { 'cinder_internal_user':
ensure => present,
enabled => True,
}
keystone_role { 'admin':
ensure => present,
}
keystone_user_role { 'cinder_internal_user@cinder_internal_tenant':
roles => ['admin'],
ensure => present
}
if $glance_image_cache == 'true' {
$PROJECT_ID = get_random_id(32)
$USER_ID = get_random_id(32)
cinder_config {
"DEFAULT/cinder_internal_tenant_project_id": value => "$PROJECT_ID";
"DEFAULT/cinder_internal_tenant_user_id": value => "$USER_ID";
"DEFAULT/cinder_internal_tenant_project_id": value => $::cinder_tenant;
"DEFAULT/cinder_internal_tenant_user_id": value => $::cinder_user;
"$section/image_volume_cache_enabled": value => $glance_image_cache;
"$section/image_volume_cache_max_count": value => $glance_cache_count;
"$section/image_volume_cache_max_size_gb": value => $glance_cache_size;
"$section/image_volume_cache_max_count": value => $glance_image_count;
"$section/image_volume_cache_max_size_gb": value => $glance_image_size;
}
}