Add support for min ram and min disk

Add min_ram and min_disk properties to the glance_image resource.

Change-Id: I27202559bc73283a318575669c957238f5aee988
This commit is contained in:
gcmalloc 2015-06-02 16:33:05 +02:00 committed by Colleen Murphy
parent 28bcf83e14
commit 7e2e1162d0
3 changed files with 34 additions and 6 deletions

View File

@ -45,6 +45,8 @@ Puppet::Type.type(:glance_image).provide(
end end
properties << "--container-format=#{resource[:container_format]}" properties << "--container-format=#{resource[:container_format]}"
properties << "--disk-format=#{resource[:disk_format]}" properties << "--disk-format=#{resource[:disk_format]}"
properties << "--min-disk=#{resource[:min_disk]}" if resource[:min_disk]
properties << "--min-ram=#{resource[:min_ram]}" if resource[:min_ram]
properties << location properties << location
@property_hash = self.class.request('image', 'create', properties) @property_hash = self.class.request('image', 'create', properties)
@property_hash[:ensure] = :present @property_hash[:ensure] = :present
@ -83,6 +85,14 @@ Puppet::Type.type(:glance_image).provide(
@property_hash[:container_format] @property_hash[:container_format]
end end
def min_ram=(value)
@property_flush[:min_ram] = value
end
def min_disk=(value)
@property_flush[:min_disk] = value
end
def id=(id) def id=(id)
fail('id is read only') fail('id is read only')
end end
@ -101,7 +111,9 @@ Puppet::Type.type(:glance_image).provide(
:is_public => attrs[:is_public].downcase.chomp == 'true'? true : false, :is_public => attrs[:is_public].downcase.chomp == 'true'? true : false,
:container_format => attrs[:container_format], :container_format => attrs[:container_format],
:id => attrs[:id], :id => attrs[:id],
:disk_format => attrs[:disk_format] :disk_format => attrs[:disk_format],
:min_disk => attrs['min_disk'],
:min_ram => attrs['min_ram']
) )
end end
end end
@ -122,6 +134,8 @@ Puppet::Type.type(:glance_image).provide(
(properties << '--private') if @property_flush[:is_public] == :false (properties << '--private') if @property_flush[:is_public] == :false
(properties << "--container-format=#{@property_flush[:container_format]}") if @property_flush[:container_format] (properties << "--container-format=#{@property_flush[:container_format]}") if @property_flush[:container_format]
(properties << "--disk-format=#{@property_flush[:disk_format]}") if @property_flush[:disk_format] (properties << "--disk-format=#{@property_flush[:disk_format]}") if @property_flush[:disk_format]
(properties << "--min-ram=#{@property_flush[:min_ram]}") if @property_flush[:min_ram]
(properties << "--min-disk=#{@property_flush[:min_disk]}") if @property_flush[:min_disk]
self.class.request('image', 'set', properties) self.class.request('image', 'set', properties)
@property_flush.clear @property_flush.clear
end end

View File

@ -11,6 +11,8 @@ Puppet::Type.newtype(:glance_image) do
container_format => ovf, container_format => ovf,
disk_format => 'qcow2', disk_format => 'qcow2',
source => 'http://uec-images.ubuntu.com/releases/precise/release/ubuntu-12.04-server-cloudimg-amd64-disk1.img' source => 'http://uec-images.ubuntu.com/releases/precise/release/ubuntu-12.04-server-cloudimg-amd64-disk1.img'
min_ram => 1234,
min_disk => 1234,
} }
Known problems / limitations: Known problems / limitations:
@ -72,6 +74,16 @@ Puppet::Type.newtype(:glance_image) do
newvalues(/\S+/) newvalues(/\S+/)
end end
newparam(:min_ram) do
desc "The minimal ram size"
newvalues(/\d+/)
end
newparam(:min_disk) do
desc "The minimal disk size"
newvalues(/\d+/)
end
# Require the Glance service to be running # Require the Glance service to be running
autorequire(:service) do autorequire(:service) do
['glance'] ['glance']

View File

@ -23,6 +23,8 @@ describe provider_class do
:container_format => 'bare', :container_format => 'bare',
:disk_format => 'qcow2', :disk_format => 'qcow2',
:source => 'http://example.com/image1.img', :source => 'http://example.com/image1.img',
:min_ram => 1024,
:min_disk => 1024,
} }
end end
@ -43,7 +45,7 @@ describe provider_class do
"534 5b502-efe4-4852-a45d-edaba3a3acc6","image1","raw","bare",1270,"active" "534 5b502-efe4-4852-a45d-edaba3a3acc6","image1","raw","bare",1270,"active"
') ')
provider.class.stubs(:openstack) provider.class.stubs(:openstack)
.with('image', 'create', '--format', 'shell', ['image1', '--public', '--container-format=bare', '--disk-format=qcow2', '--copy-from=http://example.com/image1.img' ]) .with('image', 'create', '--format', 'shell', ['image1', '--public', '--container-format=bare', '--disk-format=qcow2', '--min-disk=1024', '--min-ram=1024', '--copy-from=http://example.com/image1.img' ])
.returns('checksum="09b9c392dc1f6e914cea287cb6be34b0" .returns('checksum="09b9c392dc1f6e914cea287cb6be34b0"
container_format="bare" container_format="bare"
created_at="2015-04-08T18:28:01" created_at="2015-04-08T18:28:01"
@ -52,8 +54,8 @@ deleted_at="None"
disk_format="qcow2" disk_format="qcow2"
id="5345b502-efe4-4852-a45d-edaba3a3acc6" id="5345b502-efe4-4852-a45d-edaba3a3acc6"
is_public="True" is_public="True"
min_disk="0" min_disk="1024"
min_ram="0" min_ram="1024"
name="image1" name="image1"
owner="None" owner="None"
properties="{}" properties="{}"
@ -99,8 +101,8 @@ deleted_at="None"
disk_format="qcow2" disk_format="qcow2"
id="5345b502-efe4-4852-a45d-edaba3a3acc6" id="5345b502-efe4-4852-a45d-edaba3a3acc6"
is_public="True" is_public="True"
min_disk="0" min_disk="1024"
min_ram="0" min_ram="1024"
name="image1" name="image1"
owner="None" owner="None"
properties="{}" properties="{}"