Class: Fission::VM
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .all ⇒ Object
- .all_running ⇒ Object
- .clone(source_vm, target_vm) ⇒ Object
- .exists?(vm_name) ⇒ Boolean
- .path(vm_name) ⇒ Object
Instance Method Summary collapse
- #conf_file ⇒ Object
-
#initialize(name) ⇒ VM
constructor
A new instance of VM.
- #start ⇒ Object
- #stop ⇒ Object
- #suspend ⇒ Object
Constructor Details
#initialize(name) ⇒ VM
Returns a new instance of VM.
5 6 7 |
# File 'lib/fission/vm.rb', line 5 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/fission/vm.rb', line 3 def name @name end |
Class Method Details
.all ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/fission/vm.rb', line 46 def self.all vm_dirs = Dir[File.join Fission.config.attributes['vm_dir'], '*.vmwarevm'].select do |d| File.directory? d end vm_dirs.map { |d| File.basename d, '.vmwarevm' } end |
.all_running ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fission/vm.rb', line 54 def self.all_running command = "#{Fission.config.attributes['vmrun_cmd']} list" output = `#{command}` vms = [] if $?.exitstatus == 0 output.split("\n").each do |vm| if vm.include?('.vmx') if File.exists?(vm) && (File.extname(vm) == '.vmx') vms << File.basename(vm, '.vmx') end end end else Fission.ui.output_and_exit "Unable to determine the list of running VMs", 1 end vms end |
.clone(source_vm, target_vm) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/fission/vm.rb', line 84 def self.clone(source_vm, target_vm) Fission.ui.output "Cloning #{source_vm} to #{target_vm}" FileUtils.cp_r path(source_vm), path(target_vm) Fission.ui.output "Configuring #{target_vm}" rename_vm_files source_vm, target_vm update_config source_vm, target_vm end |
.exists?(vm_name) ⇒ Boolean
76 77 78 |
# File 'lib/fission/vm.rb', line 76 def self.exists?(vm_name) File.directory? path(vm_name) end |
Instance Method Details
#conf_file ⇒ Object
42 43 44 |
# File 'lib/fission/vm.rb', line 42 def conf_file File.join self.class.path(@name), "#{@name}.vmx" end |
#start ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fission/vm.rb', line 9 def start command = "#{Fission.config.attributes['vmrun_cmd']} start #{conf_file.gsub ' ', '\ '} gui 2>&1" output = `#{command}` if $?.exitstatus == 0 Fission.ui.output "VM started" else Fission.ui.output "There was a problem starting the VM. The error was:\n#{output}" end end |
#stop ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fission/vm.rb', line 20 def stop command = "#{Fission.config.attributes['vmrun_cmd']} stop #{conf_file.gsub ' ', '\ '} 2>&1" output = `#{command}` if $?.exitstatus == 0 Fission.ui.output "VM stopped" else Fission.ui.output "There was a problem stopping the VM. The error was:\n#{output}" end end |
#suspend ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fission/vm.rb', line 31 def suspend command = "#{Fission.config.attributes['vmrun_cmd']} suspend #{conf_file.gsub ' ', '\ '} 2>&1" output = `#{command}` if $?.exitstatus == 0 Fission.ui.output "VM suspended" else Fission.ui.output "There was a problem suspending the VM. The error was:\n#{output}" end end |