module to set quotas per volume type

This will set the quotas per volume type passed in

Change-Id: I6af7347cbf8d907a7cc004a594aafdb2745c280f
This commit is contained in:
cdelatte 2015-07-01 09:06:29 -04:00 committed by Cody Herriges
parent c1fcfb0cae
commit 4a5e0adbe2
2 changed files with 150 additions and 0 deletions

86
manifests/quota_set.pp Normal file
View File

@ -0,0 +1,86 @@
# == Class: cinder::quota_set
#
# Setup and configure Cinder quotas per volume type.
#
# === Parameters
#
# [*os_password*]
# (Required) The keystone tenant:username password.
#
# [*os_tenant_name*]
# (Optional) The keystone tenant name.
# Defaults to 'admin'.
#
# [*os_username*]
# (Optional) The keystone user name.
# Defaults to 'admin'.
#
# [*os_auth_url*]
# (Optional) The keystone auth url.
# Defaults to 'http://127.0.0.1:5000/v2.0/'.
#
# [*os_region_name*]
# (Optional) The keystone region name.
# Default is unset.
#
# [*quota_volumes*]
# (Optional) Number of volumes allowed per project.
# Defaults to 10.
#
# [*quota_snapshots*]
# (Optional) Number of volume snapshots allowed per project.
# Defaults to 10.
#
# [*quota_gigabytes*]
# (Optional) Number of volume gigabytes (snapshots are also included)
# allowed per project.
# Defaults to 1000.
#
# [*class_name*]
# (Optional) Quota class to use.
# Defaults to 'default'.
#
# [*volume_type*]
# volume type that will have quota changed
# Defaults to $name
#
define cinder::quota_set (
$os_password,
$os_tenant_name = 'admin',
$os_username = 'admin',
$os_auth_url = 'http://127.0.0.1:5000/v2.0/',
$os_region_name = undef,
$quota_volumes = 10,
$quota_snapshots = 10,
$quota_gigabytes = 1000,
$class_name = 'default',
$volume_type = $name,
) {
if $os_region_name {
$cinder_env = [
"OS_TENANT_NAME=${os_tenant_name}",
"OS_USERNAME=${os_username}",
"OS_PASSWORD=${os_password}",
"OS_AUTH_URL=${os_auth_url}",
"OS_REGION_NAME=${os_region_name}",
]
}
else {
$cinder_env = [
"OS_TENANT_NAME=${os_tenant_name}",
"OS_USERNAME=${os_username}",
"OS_PASSWORD=${os_password}",
"OS_AUTH_URL=${os_auth_url}",
]
}
exec {"cinder quota-class-update ${class_name}":
command => "cinder quota-class-update ${class_name} --volumes ${quota_volumes} --snapshots ${quota_snapshots} --gigabytes ${quota_gigabytes} --volume-type '${volume_type}'",
onlyif => 'cinder quota-class-show default | grep -qP -- -1',
environment => $cinder_env,
require => Package['python-cinderclient'],
path => ['/usr/bin', '/bin'],
}
}

View File

@ -0,0 +1,64 @@
#Author: Craig DeLatte <craig.delatte@twcable.com>
require 'spec_helper'
describe 'cinder::quota_set' do
let(:title) {'hippo'}
let :params do {
:os_password => 'asdf',
:os_tenant_name => 'admin',
:os_username => 'admin',
:os_auth_url => 'http://127.127.127.1:5000/v2.0/',
:quota_volumes => '10',
:quota_snapshots => '10',
:quota_gigabytes => '1000',
:class_name => 'default',
}
end
shared_examples_for 'cinder_quota_set' do
[{},
{ :os_region_name => 'test' }
].each do |param_set|
describe "when #{param_set == {} ? 'using default' : 'specifying'} class parameters" do
before do
params.merge!(param_set)
end
it do
is_expected.to contain_exec('cinder quota-class-update default').with(
:command => "cinder quota-class-update default --volumes 10 --snapshots 10 --gigabytes 1000 --volume-type 'hippo'",
:environment => (param_set == {}) ?
['OS_TENANT_NAME=admin',
'OS_USERNAME=admin',
'OS_PASSWORD=asdf',
'OS_AUTH_URL=http://127.127.127.1:5000/v2.0/'] :
['OS_TENANT_NAME=admin',
'OS_USERNAME=admin',
'OS_PASSWORD=asdf',
'OS_AUTH_URL=http://127.127.127.1:5000/v2.0/',
'OS_REGION_NAME=test'],
:onlyif => 'cinder quota-class-show default | grep -qP -- -1',
:require => 'Package[python-cinderclient]')
end
end
end
end
context 'on Debian platforms' do
let :facts do
{ :operatingsystem => 'Ubuntu',
:osfamily => 'Debian' }
end
it_configures 'cinder_quota_set'
end
context 'on Redhat platforms' do
let :facts do
{ :operatingsystem => 'Redhat',
:osfamily => 'Redhat' }
end
it_configures 'cinder_quota_set'
end
end