Class: SparseImage::ImageConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-sparseimage.rb

Constant Summary collapse

@@required =
[
	:volume_name,
	:image_type,
	:image_fs,
	:image_size,
	:image_folder
]
@@valid_image_types =
["SPARSEIMAGE", "SPARSEBUNDLE"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#auto_unmountObject

Configuration for a single sparse image Not exposed to vagrant.



123
124
125
# File 'lib/vagrant-sparseimage.rb', line 123

def auto_unmount
  @auto_unmount
end

#image_folderObject

Configuration for a single sparse image Not exposed to vagrant.



123
124
125
# File 'lib/vagrant-sparseimage.rb', line 123

def image_folder
  @image_folder
end

#image_fsObject

Configuration for a single sparse image Not exposed to vagrant.



123
124
125
# File 'lib/vagrant-sparseimage.rb', line 123

def image_fs
  @image_fs
end

#image_sizeObject

Configuration for a single sparse image Not exposed to vagrant.



123
124
125
# File 'lib/vagrant-sparseimage.rb', line 123

def image_size
  @image_size
end

#image_typeObject

Configuration for a single sparse image Not exposed to vagrant.



123
124
125
# File 'lib/vagrant-sparseimage.rb', line 123

def image_type
  @image_type
end

#mounted_nameObject

Configuration for a single sparse image Not exposed to vagrant.



123
124
125
# File 'lib/vagrant-sparseimage.rb', line 123

def mounted_name
  @mounted_name
end

#vm_mountpointObject

Configuration for a single sparse image Not exposed to vagrant.



123
124
125
# File 'lib/vagrant-sparseimage.rb', line 123

def vm_mountpoint
  @vm_mountpoint
end

#volume_nameObject

Configuration for a single sparse image Not exposed to vagrant.



123
124
125
# File 'lib/vagrant-sparseimage.rb', line 123

def volume_name
  @volume_name
end

Instance Method Details

#finalize!Object



157
158
159
160
161
162
163
164
# File 'lib/vagrant-sparseimage.rb', line 157

def finalize!
	if @auto_unmount.nil?
		@auto_unmount = true
	end
	if @mounted_name.nil?
		@mounted_name = "./#{@volume_name}"
	end
end

#to_hashObject



166
167
168
169
170
171
172
173
174
175
176
# File 'lib/vagrant-sparseimage.rb', line 166

def to_hash
	{	:vm_mountpoint  => @vm_mountpoint,
		:image_size     => @image_size,
		:image_fs       => @image_fs,
		:image_type     => @image_type,
		:volume_name	=> @volume_name,
		:auto_unmount	=> @auto_unmount,
		:image_folder	=> @image_folder,
		:mounted_name	=> @mounted_name
	}
end

#validateObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/vagrant-sparseimage.rb', line 136

def validate
	errors = []
	# Check for the required config keys
	@@required.each do |key|
		if not to_hash[key] or (to_hash[key].is_a? String  and to_hash[key].length == 0)
			errors.push "#{key} must be present."
		end
	end

	# Validate image type
	if not @@valid_image_types.include?(@image_type)
		errors.push "image_type: invalid value: only supports #{@@valid_image_types.join(',')}"
	end

	# Size must be an int
	if @image_size and not @image_size.is_a? Fixnum
		errors.push "image_size: Must be a number."
	end
	{ "vagrant-sparseimage" => errors }
end