virtualman 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/virtualman.rb +23 -10
  2. metadata +1 -1
@@ -26,16 +26,20 @@ class Vm
26
26
  puts `VBoxManage #{action} #{@name} #{param.join(" ")}`
27
27
  end
28
28
 
29
- # A method to automatically Export a VM as an "importable" appliance
30
- # /!\ be careful, this operation requires to poweroff the VM.
31
- def backup!(folder)
32
- self.manage("controlvm","poweroff")
33
-
34
- filename = Time.now().strftime("#{@name.delete "\""}_%Y%m%dT%H%M")
35
-
36
- self.manage("export","-o #{folder}/#{filename}.ova")
29
+ # A method to stop properly a vm
30
+ # It assumes that you have the name of the VM on your personnal hosts file or DNS
31
+ # It can be modified to use GuestAdditions instead
32
+ def stop!
33
+ $stdout.sync = true
34
+ if self.running?
35
+ `ssh root@#{self.name.delete "\""} "shutdown -h now"`
36
+ puts "Waiting for complete shutdown of #{self.name}"
37
+ while self.running?
38
+ print "."
39
+ sleep (1)
40
+ end
41
+ end
37
42
 
38
- self.manage("startvm", "--type headless")
39
43
  end
40
44
  end
41
45
 
@@ -80,6 +84,15 @@ class VmLister < Array
80
84
 
81
85
  # A method to automatically export the list of VMs
82
86
  def backup!(folder)
83
- self.each {|vm| vm.backup!(folder)}
87
+ self.each {|vm| vm.stop!}
88
+ sleep (5)
89
+
90
+ self.each do |vm|
91
+ filename = Time.now().strftime("#{vm.name.delete "\""}_%Y%m%dT%H%M")
92
+ vm.manage("export","-o #{folder}/#{filename}.ova")
93
+ sleep(5)
94
+ end
95
+
96
+ self.each {|vm| vm.manage("startvm", "--type headless")}
84
97
  end
85
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virtualman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: