Class: NetVbox::VmSetManager
- Inherits:
-
Object
- Object
- NetVbox::VmSetManager
- Defined in:
- lib/netvbox/vm_set_manager.rb
Constant Summary collapse
- DEFAULT_VM_SET_NAME =
'default'
- VM_SETS_FOLDER_NAME =
'vm_sets'
- CURRENT_VM_SET_FILENAME =
'current_vm_set'
- VM_SET_EXTENSION =
'vmset'
Instance Method Summary collapse
- #create_set(vm_set_name) ⇒ Object
- #current_set ⇒ Object
- #current_set_name ⇒ Object
- #exists?(vm_set_name) ⇒ Boolean
-
#initialize(netvbox_home) ⇒ VmSetManager
constructor
A new instance of VmSetManager.
- #remove_set(vm_set_name) ⇒ Object
- #use_default_set ⇒ Object
- #use_set(vm_set_name) ⇒ Object
- #vm_set_names ⇒ Object
Constructor Details
#initialize(netvbox_home) ⇒ VmSetManager
Returns a new instance of VmSetManager.
12 13 14 15 16 17 18 |
# File 'lib/netvbox/vm_set_manager.rb', line 12 def initialize(netvbox_home) @netvbox_home = netvbox_home FileUtils.mkdir_p "#{@netvbox_home}/#{VM_SETS_FOLDER_NAME}" FileUtils.touch vm_set_config_file(DEFAULT_VM_SET_NAME) current_vm_file = "#{@netvbox_home}/#{CURRENT_VM_SET_FILENAME}" IO.write(current_vm_file, DEFAULT_VM_SET_NAME) unless File.exists?(current_vm_file) end |
Instance Method Details
#create_set(vm_set_name) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/netvbox/vm_set_manager.rb', line 52 def create_set(vm_set_name) raise "Set: #{vm_set_name} already exists" if exists? vm_set_name begin FileUtils.touch vm_set_config_file(vm_set_name) rescue raise "Cannot create set with name: #{vm_set_name}" end end |
#current_set ⇒ Object
35 36 37 |
# File 'lib/netvbox/vm_set_manager.rb', line 35 def current_set VmSet.new(VmSetConfig.new(vm_set_config_file(current_set_name))) end |
#current_set_name ⇒ Object
30 31 32 33 |
# File 'lib/netvbox/vm_set_manager.rb', line 30 def current_set_name current_vm_file = "#{@netvbox_home}/#{CURRENT_VM_SET_FILENAME}" File.readable?(current_vm_file) ? IO.read(current_vm_file) : DEFAULT_VM_SET_NAME end |
#exists?(vm_set_name) ⇒ Boolean
20 21 22 |
# File 'lib/netvbox/vm_set_manager.rb', line 20 def exists?(vm_set_name) File.exists? vm_set_config_file(vm_set_name) end |
#remove_set(vm_set_name) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/netvbox/vm_set_manager.rb', line 61 def remove_set(vm_set_name) raise "Set: #{vm_set_name} does not exist" unless exists? vm_set_name raise "Cannot remove default set" if vm_set_name == DEFAULT_VM_SET_NAME use_default_set if current_set_name == vm_set_name File.delete vm_set_config_file(vm_set_name) end |
#use_default_set ⇒ Object
39 40 41 42 |
# File 'lib/netvbox/vm_set_manager.rb', line 39 def use_default_set FileUtils.touch vm_set_config_file(DEFAULT_VM_SET_NAME) IO.write("#{@netvbox_home}/#{CURRENT_VM_SET_FILENAME}", DEFAULT_VM_SET_NAME) end |
#use_set(vm_set_name) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/netvbox/vm_set_manager.rb', line 44 def use_set(vm_set_name) if File.exists? vm_set_config_file(vm_set_name) IO.write("#{@netvbox_home}/#{CURRENT_VM_SET_FILENAME}", vm_set_name) else raise "VM set #{vm_set_name} does not exist" end end |
#vm_set_names ⇒ Object
24 25 26 27 28 |
# File 'lib/netvbox/vm_set_manager.rb', line 24 def vm_set_names Dir.entries("#{@netvbox_home}/#{VM_SETS_FOLDER_NAME}") .select {|e| e.end_with?(VM_SET_EXTENSION)} .collect {|e| e[0...(-VM_SET_EXTENSION.length - 1)]} end |