Class: Virtualman::Interactive::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/virtualman/interactive/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/virtualman/interactive/configuration.rb', line 9

def initialize
	@filepath = File.join(ENV['HOME'],'.virtualman.rc.yaml')

	if File.exists? @filepath
	  @options = YAML.load_file(@filepath)
	else
		STDERR.puts("No configuration file found here ~/.vm_to_clone.rc.yaml")
		STDERR.puts("Thanks to create this file before continuing!")
		STDERR.puts "Config file example:"
		STDERR.puts "---"
		STDERR.puts "source_vm:"
		STDERR.puts " - name: 			Debian"
		STDERR.puts "   snapshot: 	ready to clone!"
		STDERR.puts " - name: 			Gentoo"
		STDERR.puts "   snapshot: 	almost ready"
		STDERR.puts "role_path: http://path/to/your/role/fodler"
		STDERR.puts "cookbook_path: http://path/to/your/cookbooks.tar.gz"
		STDERR.puts "roles:"
		STDERR.puts "- devtest"
		STDERR.puts "- devtest_jenkins"
		STDERR.puts "- build_pkg_devtest_jenkins"
		Kernel.abort("No configuration file found here ~/.vm_to_clone.rc.yaml")
	end
end

Instance Attribute Details

#filepathObject (readonly)

Returns the value of attribute filepath.



7
8
9
# File 'lib/virtualman/interactive/configuration.rb', line 7

def filepath
  @filepath
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/virtualman/interactive/configuration.rb', line 7

def options
  @options
end

Instance Method Details

#add_cloned_vm(vm_cloned) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/virtualman/interactive/configuration.rb', line 39

def add_cloned_vm(vm_cloned)
	if @options["cloned_vms"] != nil
		@options["cloned_vms"] << {"name" => vm_cloned.name}
	else
		@options.merge!({"cloned_vms" => [{"name" => vm_cloned.name}]})
	end
	record_conf("VM #{vm_cloned.name} has been saved")			
end

#delete_cloned_vm(vm_cloned) ⇒ Object



48
49
50
51
# File 'lib/virtualman/interactive/configuration.rb', line 48

def delete_cloned_vm(vm_cloned)
	@options["cloned_vms"].reject!{|vm| vm == {"name" => vm_cloned.name.gsub(/\"/,'')} }
	record_conf("VM #{vm_cloned.name} has been deleted")
end

#record_conf(msg) ⇒ Object



34
35
36
37
# File 'lib/virtualman/interactive/configuration.rb', line 34

def record_conf(msg)
	File.open(@filepath, "w") {|f| f.write(@options.to_yaml) }
	puts "#{msg} to your configuration file"
end