Merge "Cinder-type param is_public/access_project_ids"
This commit is contained in:
commit
a8628dc884
@ -16,11 +16,17 @@ Puppet::Type.type(:cinder_type).provide(
|
|||||||
resource[:properties].each do |item|
|
resource[:properties].each do |item|
|
||||||
properties << '--property' << item
|
properties << '--property' << item
|
||||||
end
|
end
|
||||||
|
properties << (@resource[:is_public] == :true ? '--public' : '--private')
|
||||||
properties << name
|
properties << name
|
||||||
self.class.request('volume type', 'create', properties)
|
self.class.request('volume type', 'create', properties)
|
||||||
@property_hash[:ensure] = :present
|
@property_hash[:ensure] = :present
|
||||||
@property_hash[:properties] = resource[:properties]
|
@property_hash[:properties] = resource[:properties]
|
||||||
|
@property_hash[:is_public] = resource[:is_public]
|
||||||
@property_hash[:name] = name
|
@property_hash[:name] = name
|
||||||
|
unless @resource[:access_project_ids].nil?
|
||||||
|
set_access_project_ids(resource[:access_project_ids])
|
||||||
|
@property_hash[:access_project_ids] = resource[:access_project_ids]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@ -43,14 +49,53 @@ Puppet::Type.type(:cinder_type).provide(
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def access_project_ids=(value)
|
||||||
|
added = value - @property_hash[:access_project_ids]
|
||||||
|
set_access_project_ids(added)
|
||||||
|
removed = @property_hash[:access_project_ids] - value
|
||||||
|
unset_access_project_ids(removed)
|
||||||
|
unless access_project_ids.empty?
|
||||||
|
@property_hash[:access_project_ids] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_access_project_ids(projects)
|
||||||
|
opts = []
|
||||||
|
projects.each do |project|
|
||||||
|
opts << '--project' << project
|
||||||
|
self.class.request('volume type', 'set', [opts, @resource[:name]])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def unset_access_project_ids(projects)
|
||||||
|
opts = []
|
||||||
|
projects.each do |project|
|
||||||
|
opts << '--project' << project
|
||||||
|
self.class.request('volume type', 'unset', [opts, @resource[:name]])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.instances
|
def self.instances
|
||||||
list = request('volume type', 'list', '--long')
|
list = request('volume type', 'list', '--long')
|
||||||
|
list.each do |type|
|
||||||
|
if type[:is_public] == 'False'
|
||||||
|
type_details = request('volume type', 'show', type[:id])
|
||||||
|
type[:access_project_ids] = string2array(type_details[:access_project_ids])
|
||||||
|
type[:is_public] = false
|
||||||
|
else
|
||||||
|
type[:access_project_ids] = []
|
||||||
|
type[:is_public] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
list.collect do |type|
|
list.collect do |type|
|
||||||
new({
|
new({
|
||||||
:name => type[:name],
|
:name => type[:name],
|
||||||
:ensure => :present,
|
:ensure => :present,
|
||||||
:id => type[:id],
|
:id => type[:id],
|
||||||
:properties => string2array(type[:properties])
|
:properties => string2array(type[:properties]),
|
||||||
|
:is_public => type[:is_public],
|
||||||
|
:access_project_ids => type[:access_project_ids]
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,6 +20,20 @@ Puppet::Type.newtype(:cinder_type) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
newparam(:is_public, :boolean => true) do
|
||||||
|
desc 'Whether the type is public or not. Default to `true`'
|
||||||
|
newvalues(:true, :false)
|
||||||
|
defaultto true
|
||||||
|
end
|
||||||
|
|
||||||
|
newproperty(:access_project_ids, :array_matching => :all) do
|
||||||
|
desc 'Project ids which have access to private cinder type. Should be an array, [project1, project2, ...]'
|
||||||
|
def insync?(is)
|
||||||
|
return false unless is.is_a? Array
|
||||||
|
is.sort == should.sort
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
autorequire(:anchor) do
|
autorequire(:anchor) do
|
||||||
['cinder::service::end']
|
['cinder::service::end']
|
||||||
end
|
end
|
||||||
|
@ -17,6 +17,8 @@ describe provider_class do
|
|||||||
:name => 'Backend_1',
|
:name => 'Backend_1',
|
||||||
:ensure => :present,
|
:ensure => :present,
|
||||||
:properties => ['key=value', 'new_key=new_value'],
|
:properties => ['key=value', 'new_key=new_value'],
|
||||||
|
:is_public => true,
|
||||||
|
:access_project_ids => [],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -39,10 +41,12 @@ describe provider_class do
|
|||||||
describe '#create' do
|
describe '#create' do
|
||||||
it 'creates a type' do
|
it 'creates a type' do
|
||||||
provider_class.expects(:openstack)
|
provider_class.expects(:openstack)
|
||||||
.with('volume type', 'create', '--format', 'shell', ['--property', 'key=value', '--property', 'new_key=new_value', 'Backend_1'])
|
.with('volume type', 'create', '--format', 'shell', ['--property', 'key=value', '--property', 'new_key=new_value', '--public', 'Backend_1'])
|
||||||
.returns('id="90e19aff-1b35-4d60-9ee3-383c530275ab"
|
.returns('id="90e19aff-1b35-4d60-9ee3-383c530275ab"
|
||||||
name="Backend_1"
|
name="Backend_1"
|
||||||
properties="key=\'value\', new_key=\'new_value\'"
|
properties="key=\'value\', new_key=\'new_value\'"
|
||||||
|
is_public="True"
|
||||||
|
access_project_ids=""
|
||||||
')
|
')
|
||||||
provider.create
|
provider.create
|
||||||
expect(provider.exists?).to be_truthy
|
expect(provider.exists?).to be_truthy
|
||||||
@ -62,14 +66,28 @@ properties="key=\'value\', new_key=\'new_value\'"
|
|||||||
it 'finds types' do
|
it 'finds types' do
|
||||||
provider_class.expects(:openstack)
|
provider_class.expects(:openstack)
|
||||||
.with('volume type', 'list', '--quiet', '--format', 'csv', '--long')
|
.with('volume type', 'list', '--quiet', '--format', 'csv', '--long')
|
||||||
.returns('"ID","Name","Properties"
|
.returns('"ID","Name","Is Public","Properties"
|
||||||
"28b632e8-6694-4bba-bf68-67b19f619019","type-1","key1=\'value1\'"
|
"28b632e8-6694-4bba-bf68-67b19f619019","type-1","True","key1=\'value1\'"
|
||||||
"4f992f69-14ec-4132-9313-55cc06a6f1f6","type-2","key2=\'value2\'"
|
"4f992f69-14ec-4132-9313-55cc06a6f1f6","type-2","False","key2=\'value2\'"
|
||||||
')
|
')
|
||||||
|
provider_class.expects(:openstack)
|
||||||
|
.with('volume type', 'show', '--format', 'shell', '4f992f69-14ec-4132-9313-55cc06a6f1f6')
|
||||||
|
.returns('
|
||||||
|
id="4f992f69-14ec-4132-9313-55cc06a6f1f6"
|
||||||
|
name="type-2"
|
||||||
|
properties="key2=\'value2\'"
|
||||||
|
is_public="False"
|
||||||
|
access_project_ids="54f4d231201b4944a5fa4587a09bda23, 54f4d231201b4944a5fa4587a09bda28"
|
||||||
|
')
|
||||||
|
|
||||||
instances = provider_class.instances
|
instances = provider_class.instances
|
||||||
expect(instances.count).to eq(2)
|
expect(instances.count).to eq(2)
|
||||||
expect(instances[0].name).to eq('type-1')
|
expect(instances[0].name).to eq('type-1')
|
||||||
expect(instances[1].name).to eq('type-2')
|
expect(instances[1].name).to eq('type-2')
|
||||||
|
expect(instances[0].is_public).to be true
|
||||||
|
expect(instances[1].is_public).to be false
|
||||||
|
expect(instances[0].access_project_ids).to match_array([])
|
||||||
|
expect(instances[1].access_project_ids).to match_array(['54f4d231201b4944a5fa4587a09bda23', '54f4d231201b4944a5fa4587a09bda28'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user