summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Morin <arnaud.morin@corp.ovh.com>2017-06-01 23:02:32 +0200
committerArnaud Morin <arnaud.morin@gmail.com>2017-06-05 21:01:49 +0000
commitbcc5f6a1c6bc69fafdf7de74a1823b949217130a (patch)
tree76f9da52def782b52af0f6a08f0e4f5d31cd1253
parentd92af817bafaa36bd446c466a7a9e52a3b0f6c60 (diff)
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 14f1029125001ec9884eda7a81ce2bed89ce8c19)
Notes
Notes (review): Code-Review+2: Alex Schultz <aschultz@redhat.com> Code-Review+2: zhongshengping <chdzsp@163.com> Workflow+1: zhongshengping <chdzsp@163.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 07 Jun 2017 01:15:48 +0000 Reviewed-on: https://review.openstack.org/471129 Project: openstack/puppet-nova Branch: refs/heads/stable/ocata
-rw-r--r--lib/puppet/provider/nova_flavor/openstack.rb31
-rw-r--r--lib/puppet/type/nova_flavor.rb12
2 files changed, 41 insertions, 2 deletions
diff --git a/lib/puppet/provider/nova_flavor/openstack.rb b/lib/puppet/provider/nova_flavor/openstack.rb
index c8daf16..add8376 100644
--- a/lib/puppet/provider/nova_flavor/openstack.rb
+++ b/lib/puppet/provider/nova_flavor/openstack.rb
@@ -13,6 +13,7 @@ Puppet::Type.type(:nova_flavor).provide(
13 def initialize(value={}) 13 def initialize(value={})
14 super(value) 14 super(value)
15 @property_flush = {} 15 @property_flush = {}
16 @project_flush = {}
16 end 17 end
17 18
18 def create 19 def create
@@ -31,6 +32,11 @@ Puppet::Type.type(:nova_flavor).provide(
31 prop_opts << props_to_s(@resource[:properties]) 32 prop_opts << props_to_s(@resource[:properties])
32 self.class.request('flavor', 'set', prop_opts) 33 self.class.request('flavor', 'set', prop_opts)
33 end 34 end
35 if @resource[:project]
36 proj_opts = [@resource[:name]]
37 proj_opts << '--project' << @resource[:project]
38 self.class.request('flavor', 'set', proj_opts)
39 end
34 @property_hash[:ensure] = :present 40 @property_hash[:ensure] = :present
35 end 41 end
36 42
@@ -76,8 +82,19 @@ Puppet::Type.type(:nova_flavor).provide(
76 @property_flush[:properties] = value 82 @property_flush[:properties] = value
77 end 83 end
78 84
85 def project=(value)
86 @project_flush[:project] = value
87 end
88
79 def self.instances 89 def self.instances
80 request('flavor', 'list', ['--long', '--all']).collect do |attrs| 90 request('flavor', 'list', ['--long', '--all']).collect do |attrs|
91 project = request('flavor', 'show', [attrs[:id], '-c', 'access_project_ids'])
92 # Client can return None and this should be considered as ''
93 if project[:access_project_ids].downcase.chomp == 'none'
94 project_value = ''
95 else
96 project_value = project[:access_project_ids]
97 end
81 properties = Hash[attrs[:properties].scan(/(\S+)='([^']*)'/)] rescue nil 98 properties = Hash[attrs[:properties].scan(/(\S+)='([^']*)'/)] rescue nil
82 new( 99 new(
83 :ensure => :present, 100 :ensure => :present,
@@ -90,7 +107,8 @@ Puppet::Type.type(:nova_flavor).provide(
90 :is_public => attrs[:is_public].downcase.chomp == 'true'? true : false, 107 :is_public => attrs[:is_public].downcase.chomp == 'true'? true : false,
91 :swap => attrs[:swap], 108 :swap => attrs[:swap],
92 :rxtx_factor => attrs[:rxtx_factor], 109 :rxtx_factor => attrs[:rxtx_factor],
93 :properties => properties 110 :properties => properties,
111 :project => project_value
94 ) 112 )
95 end 113 end
96 end 114 end
@@ -112,6 +130,17 @@ Puppet::Type.type(:nova_flavor).provide(
112 self.class.request('flavor', 'set', opts) 130 self.class.request('flavor', 'set', opts)
113 @property_flush.clear 131 @property_flush.clear
114 end 132 end
133 unless @project_flush.empty?
134 opts = [@resource[:name]]
135 unless @project_flush[:project]
136 opts << '--project' << @project_flush[:project]
137 self.class.request('flavor', 'set', opts)
138 else
139 opts << '--project' << @property_hash[:project]
140 self.class.request('flavor', 'unset', opts)
141 end
142 @project_flush.clear
143 end
115 end 144 end
116 private 145 private
117 146
diff --git a/lib/puppet/type/nova_flavor.rb b/lib/puppet/type/nova_flavor.rb
index 2314ce0..ae098b3 100644
--- a/lib/puppet/type/nova_flavor.rb
+++ b/lib/puppet/type/nova_flavor.rb
@@ -42,6 +42,11 @@
42# A key => value hash used to set the properties for the flavor. This is 42# A key => value hash used to set the properties for the flavor. This is
43# the only parameter that can be updated after the creation of the flavor. 43# the only parameter that can be updated after the creation of the flavor.
44# Optional 44# Optional
45#
46# [*project*]
47# Set flavor access to project (name or ID).
48# If you set this option, take care to set is_public to false.
49# Optional
45require 'puppet' 50require 'puppet'
46 51
47Puppet::Type.newtype(:nova_flavor) do 52Puppet::Type.newtype(:nova_flavor) do
@@ -100,7 +105,7 @@ Puppet::Type.newtype(:nova_flavor) do
100 end 105 end
101 106
102 newparam(:is_public) do 107 newparam(:is_public) do
103 desc "Whether the image is public or not. Default true" 108 desc "Whether the flavor is public or not. Default true"
104 newvalues(/(y|Y)es/, /(n|N)o/, /(t|T)rue/, /(f|F)alse/, true, false) 109 newvalues(/(y|Y)es/, /(n|N)o/, /(t|T)rue/, /(f|F)alse/, true, false)
105 defaultto(true) 110 defaultto(true)
106 munge do |v| 111 munge do |v|
@@ -114,6 +119,11 @@ Puppet::Type.newtype(:nova_flavor) do
114 end 119 end
115 end 120 end
116 121
122 newproperty(:project) do
123 desc 'Set flavor access to project (name or ID).'
124 defaultto('')
125 end
126
117 newproperty(:properties) do 127 newproperty(:properties) do
118 desc "The set of flavor properties" 128 desc "The set of flavor properties"
119 129