Implement custom function to generate keystone-like ID
Generate a random 32 charaqcter hex string to use as a keystone-like ID. This is required for the glance image-cache for cinder tenant and user IDs to be entered into cinder.conf Change-Id: I5e12eef26b6f9e2dba28be870bee38dbd6ebf2c9
This commit is contained in:
parent
a9387ba486
commit
afbe409075
|
@ -59,25 +59,36 @@ class plugin_purestorage_cinder::controller (
|
|||
}
|
||||
|
||||
# Insert Glance Image Cache for Cinder settings
|
||||
if $plugin_settings['image_volume_cache_enabled'] {
|
||||
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
|
||||
}
|
||||
# How do I get back the IDs.
|
||||
# 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 $plugin_settings['image_volume_cache_enabled'] {
|
||||
# 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
|
||||
|
||||
$PROJECT_ID" = get_random_id(32)
|
||||
$USER_ID" = get_random_id(32)
|
||||
|
||||
}
|
||||
cinder::backend::pure { DEFAULT :
|
||||
extra_options => { "DEFAULT/cinder_internal_tenant_project_id" => { value => "$PROJECT_ID"] },
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# Customm function to generate a random hex string of length arg[0].
|
||||
#
|
||||
# This is used to ensure we get unique tenant and user IDs that
|
||||
# are required for the glance image-cache for cinder
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:get_random_id, :type => :rvalue, :doc => "returns a random 32 character hex string") do |args|
|
||||
raise(Puppet::ParseError, "get_random_id(): Wrong number of arguments " +
|
||||
"given (#{args.size} for 1)") if args.size != 1
|
||||
numbers = (0..9).to_a
|
||||
alpha = ('a'..'z').to_a
|
||||
length = args[0]
|
||||
CHARS = (alpha + numbers)
|
||||
id = CHARS.sort_by { rand }.join[0...length]
|
||||
return id
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue