From 7e2e1162d0466f6094e695e87fdba390c95cc6a2 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Tue, 2 Jun 2015 16:33:05 +0200 Subject: [PATCH] Add support for min ram and min disk Add min_ram and min_disk properties to the glance_image resource. Change-Id: I27202559bc73283a318575669c957238f5aee988 --- lib/puppet/provider/glance_image/openstack.rb | 16 +++++++++++++++- lib/puppet/type/glance_image.rb | 12 ++++++++++++ spec/unit/provider/glance_image_spec.rb | 12 +++++++----- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/puppet/provider/glance_image/openstack.rb b/lib/puppet/provider/glance_image/openstack.rb index 134b3310..26f180fe 100644 --- a/lib/puppet/provider/glance_image/openstack.rb +++ b/lib/puppet/provider/glance_image/openstack.rb @@ -45,6 +45,8 @@ Puppet::Type.type(:glance_image).provide( end properties << "--container-format=#{resource[:container_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 @property_hash = self.class.request('image', 'create', properties) @property_hash[:ensure] = :present @@ -83,6 +85,14 @@ Puppet::Type.type(:glance_image).provide( @property_hash[:container_format] end + def min_ram=(value) + @property_flush[:min_ram] = value + end + + def min_disk=(value) + @property_flush[:min_disk] = value + end + def id=(id) fail('id is read only') end @@ -101,7 +111,9 @@ Puppet::Type.type(:glance_image).provide( :is_public => attrs[:is_public].downcase.chomp == 'true'? true : false, :container_format => attrs[:container_format], :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 @@ -122,6 +134,8 @@ Puppet::Type.type(:glance_image).provide( (properties << '--private') if @property_flush[:is_public] == :false (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 << "--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) @property_flush.clear end diff --git a/lib/puppet/type/glance_image.rb b/lib/puppet/type/glance_image.rb index 658acc5c..d731f39f 100644 --- a/lib/puppet/type/glance_image.rb +++ b/lib/puppet/type/glance_image.rb @@ -11,6 +11,8 @@ Puppet::Type.newtype(:glance_image) do container_format => ovf, disk_format => 'qcow2', 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: @@ -72,6 +74,16 @@ Puppet::Type.newtype(:glance_image) do newvalues(/\S+/) 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 autorequire(:service) do ['glance'] diff --git a/spec/unit/provider/glance_image_spec.rb b/spec/unit/provider/glance_image_spec.rb index 275f9ca9..51803cc2 100644 --- a/spec/unit/provider/glance_image_spec.rb +++ b/spec/unit/provider/glance_image_spec.rb @@ -23,6 +23,8 @@ describe provider_class do :container_format => 'bare', :disk_format => 'qcow2', :source => 'http://example.com/image1.img', + :min_ram => 1024, + :min_disk => 1024, } end @@ -43,7 +45,7 @@ describe provider_class do "534 5b502-efe4-4852-a45d-edaba3a3acc6","image1","raw","bare",1270,"active" ') 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" container_format="bare" created_at="2015-04-08T18:28:01" @@ -52,8 +54,8 @@ deleted_at="None" disk_format="qcow2" id="5345b502-efe4-4852-a45d-edaba3a3acc6" is_public="True" -min_disk="0" -min_ram="0" +min_disk="1024" +min_ram="1024" name="image1" owner="None" properties="{}" @@ -99,8 +101,8 @@ deleted_at="None" disk_format="qcow2" id="5345b502-efe4-4852-a45d-edaba3a3acc6" is_public="True" -min_disk="0" -min_ram="0" +min_disk="1024" +min_ram="1024" name="image1" owner="None" properties="{}"