Manage access project for nova flavors

Add a new 'project' parameter to nova_flavor.
This way we can manage to create flavors for specific tenants /
projects.

Change-Id: Ib2fcc4d73557c199d1b1e7d744f64a335d5b17f4
Signed-off-by: Arnaud Morin <arnaud.morin@corp.ovh.com>
(cherry picked from commit 14f1029125)
This commit is contained in:
Arnaud Morin 2017-06-01 23:02:32 +02:00 committed by Arnaud Morin
parent d92af817ba
commit bcc5f6a1c6
2 changed files with 41 additions and 2 deletions

View File

@ -13,6 +13,7 @@ Puppet::Type.type(:nova_flavor).provide(
def initialize(value={})
super(value)
@property_flush = {}
@project_flush = {}
end
def create
@ -31,6 +32,11 @@ Puppet::Type.type(:nova_flavor).provide(
prop_opts << props_to_s(@resource[:properties])
self.class.request('flavor', 'set', prop_opts)
end
if @resource[:project]
proj_opts = [@resource[:name]]
proj_opts << '--project' << @resource[:project]
self.class.request('flavor', 'set', proj_opts)
end
@property_hash[:ensure] = :present
end
@ -76,8 +82,19 @@ Puppet::Type.type(:nova_flavor).provide(
@property_flush[:properties] = value
end
def project=(value)
@project_flush[:project] = value
end
def self.instances
request('flavor', 'list', ['--long', '--all']).collect do |attrs|
project = request('flavor', 'show', [attrs[:id], '-c', 'access_project_ids'])
# Client can return None and this should be considered as ''
if project[:access_project_ids].downcase.chomp == 'none'
project_value = ''
else
project_value = project[:access_project_ids]
end
properties = Hash[attrs[:properties].scan(/(\S+)='([^']*)'/)] rescue nil
new(
:ensure => :present,
@ -90,7 +107,8 @@ Puppet::Type.type(:nova_flavor).provide(
:is_public => attrs[:is_public].downcase.chomp == 'true'? true : false,
:swap => attrs[:swap],
:rxtx_factor => attrs[:rxtx_factor],
:properties => properties
:properties => properties,
:project => project_value
)
end
end
@ -112,6 +130,17 @@ Puppet::Type.type(:nova_flavor).provide(
self.class.request('flavor', 'set', opts)
@property_flush.clear
end
unless @project_flush.empty?
opts = [@resource[:name]]
unless @project_flush[:project]
opts << '--project' << @project_flush[:project]
self.class.request('flavor', 'set', opts)
else
opts << '--project' << @property_hash[:project]
self.class.request('flavor', 'unset', opts)
end
@project_flush.clear
end
end
private

View File

@ -42,6 +42,11 @@
# A key => value hash used to set the properties for the flavor. This is
# the only parameter that can be updated after the creation of the flavor.
# Optional
#
# [*project*]
# Set flavor access to project (name or ID).
# If you set this option, take care to set is_public to false.
# Optional
require 'puppet'
Puppet::Type.newtype(:nova_flavor) do
@ -100,7 +105,7 @@ Puppet::Type.newtype(:nova_flavor) do
end
newparam(:is_public) do
desc "Whether the image is public or not. Default true"
desc "Whether the flavor is public or not. Default true"
newvalues(/(y|Y)es/, /(n|N)o/, /(t|T)rue/, /(f|F)alse/, true, false)
defaultto(true)
munge do |v|
@ -114,6 +119,11 @@ Puppet::Type.newtype(:nova_flavor) do
end
end
newproperty(:project) do
desc 'Set flavor access to project (name or ID).'
defaultto('')
end
newproperty(:properties) do
desc "The set of flavor properties"