WIP: Load keystone credentials from clouds.yaml

Change-Id: Ie8246aa18d90ba506fe708be13c9a5afa3e5d2fd
This commit is contained in:
Takashi Kajinami 2021-10-25 22:37:05 +09:00
parent 0027bf6893
commit 1775d2c952
4 changed files with 138 additions and 2 deletions

View File

@ -54,6 +54,10 @@ class Puppet::Provider::Openstack::Credentials
end
end
def scope_match?(target)
scope_set? and (scope == nil or scope == target)
end
def user_password_set?
return true if @username && @password && @project_name && @auth_url
end
@ -88,7 +92,9 @@ class Puppet::Provider::Openstack::CredentialsV3 < Puppet::Provider::Openstack::
:trust_id,
:user_domain_id,
:user_domain_name,
:user_id
:user_id,
:cloud,
:client_config_file,
]
KEYS.each { |var| attr_accessor var }
@ -113,12 +119,14 @@ class Puppet::Provider::Openstack::CredentialsV3 < Puppet::Provider::Openstack::
elsif @system_scope
return 'system'
else
# When OS_CLOUDS is used, parameters are not directly passed to puppet
# so the scope can't be detected.
return nil
end
end
def user_password_set?
return true if user_set? && @password && scope_set? && @auth_url
return true if (user_set? && @password && scope_set? && @auth_url) || @cloud
end
def initialize

84
manifests/clouds.pp Normal file
View File

@ -0,0 +1,84 @@
# == Class: openstacklib::clouds
#
# Generates clouds.yaml for openstack CLI
#
# == Parameters
#
# [*username*]
# (Required) The name of the keystone user.
#
# [*password*]
# (Required) Password of the keystone user.
#
# [*path*]
# (Optional) Path to the clouds.yaml file.
# Defaults to $name
#
# [*mode*]
# (Optional) Mode (permissions) of the clouds.yaml file.
# Defaults to 'root'
#
# [*owner*]
# (Optional) Owner of the clouds.yaml file.
# Defaults to 'root'
#
# [*group*]
# (Optional) Group of the clouds.yaml file.
# Defaults to 'root'
#
# [*cloudname*]
# (Optional) Name of the cloud.
# Defaults to 'openstack'
#
# [*user_domain_name*]
# (Optional) Name of domain for $username.
# Defaults to 'Default'
#
# [*project_name*]
# (Optional) The name of the keystone project.
# Defaults to undef
#
# [*project_domain_name*]
# (Optional) Name of domain for $project_name.
# Defaults to 'Default'
#
# [*system_scope*]
# (Optional) Scope for system operations.
# Defaults to undef
#
# [*identity_api_version*]
# (Optional) Version of identity API.
# Defaults to '3'
#
# [*interface*]
# (Optional) Determine the endpoint to be used.
# Defaults to undef
#
# [*region_name*]
# (Optional) The region in which the service can be found.
# Defaults to undef
#
define openstacklib::clouds(
$username,
$password,
$path = $name,
$mode = '0600',
$owner = 'root',
$group = 'root',
$cloudname = 'openstack',
$user_domain_name = 'Default',
$project_name = undef,
$project_domain_name = 'Default',
$system_scope = undef,
$identity_api_version = '3',
$interface = undef,
$region_name = undef,
) {
concat::fragment { $path:
content => template('openstacklib/clouds.yaml.erb'),
mode => $mode,
owner => $owner,
group => $group,
}
}

View File

@ -5,6 +5,10 @@
"name": "puppetlabs/apache",
"version_requirement": ">=5.0.0"
},
{
"name": "puppetlabs/concat",
"version_requirement": ">=1.0.0 <8.0.0"
},
{
"name": "puppetlabs/inifile",
"version_requirement": ">=2.0.0 <3.0.0"

40
templates/clouds.yaml.erb Normal file
View File

@ -0,0 +1,40 @@
clouds:
<% if @project_name -%>
project:
auth:
auth_url: <%= @auth_url %>
password: <%= @password %>
username: <%= @username %>
user_domain_name: <%= @user_domain_name %>
project_name: <%= @project_name %>
project_domain_name: <%= @project_domain_name %>
identity_api_version: <%= $identity_api_version %>
<% if @interface -%>
interface: <%= @interface %>
<% end -%>
<% if @region_name -%>
region_name: <%= @region_name %>
<% end -%>
<% if @cacert -%>
cacert: <%= @cacert %>
<% end -%>
<% end -%>
<% if @system_scope -%>
system:
auth:
auth_url: <%= @auth_url %>
password: <%= @password %>
username: <%= @username %>
user_domain_name: <%= @user_domain_name %>
system_scope: <%= @system_scope %>
identity_api_version: <%= $identity_api_version %>
<% if @interface -%>
interface: <%= @interface %>
<% end -%>
<% if @region_name -%>
region_name: <%= @region_name %>
<% end -%>
<% if @cacert -%>
cacert: <%= @cacert %>
<% end -%>
<% end -%>