Class: NetVbox::VmSetConfig
- Inherits:
-
Object
- Object
- NetVbox::VmSetConfig
- Defined in:
- lib/netvbox/vm_set_config.rb
Instance Method Summary collapse
- #add_vm(vm_info) ⇒ Object
- #all_vm_info ⇒ Object
-
#initialize(config_file_path) ⇒ VmSetConfig
constructor
A new instance of VmSetConfig.
- #remove_vm(hostname, username, vm_name) ⇒ Object
Constructor Details
#initialize(config_file_path) ⇒ VmSetConfig
Returns a new instance of VmSetConfig.
6 7 8 |
# File 'lib/netvbox/vm_set_config.rb', line 6 def initialize(config_file_path) @config_file_path = config_file_path end |
Instance Method Details
#add_vm(vm_info) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/netvbox/vm_set_config.rb', line 20 def add_vm(vm_info) all = all_vm_info if all.detect {|i| i.clashes_with? vm_info}.nil? write_vm_info(all << vm_info) else raise "The VM, #{vm_info.vm_name}, is already under management" end end |
#all_vm_info ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/netvbox/vm_set_config.rb', line 10 def all_vm_info all_vm_info = [] if File.readable?(@config_file_path) CSV.foreach(@config_file_path) {|row| all_vm_info << a_to_vm_info(row)} else raise "Could not read file: #{@config_file_path}" end all_vm_info end |
#remove_vm(hostname, username, vm_name) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/netvbox/vm_set_config.rb', line 29 def remove_vm(hostname, username, vm_name) all = all_vm_info updated = all.select {|i| !i.clashes_with_params?(hostname, username, vm_name)} if all != updated write_vm_info(updated) else raise "The VM, #{vm_name}, is not under management" end end |