virtbox 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +25 -0
- data/README.md +23 -0
- data/lib/virtbox.rb +5 -0
- data/lib/virtbox/version.rb +3 -0
- data/lib/virtbox/vm.rb +57 -0
- data/virtbox.gemspec +21 -0
- metadata +51 -0
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
*.swp
|
2
|
+
log/*
|
3
|
+
!.gitignore
|
4
|
+
junit
|
5
|
+
acceptance-tests
|
6
|
+
pkg
|
7
|
+
Gemfile.lock
|
8
|
+
options.rb
|
9
|
+
test.cfg
|
10
|
+
.yardoc
|
11
|
+
coverage
|
12
|
+
.bundle
|
13
|
+
.vendor
|
14
|
+
_vendor
|
15
|
+
tmp/
|
16
|
+
doc
|
17
|
+
# JetBrains IDEA
|
18
|
+
*.iml
|
19
|
+
.idea/
|
20
|
+
# rbenv file
|
21
|
+
.ruby-version
|
22
|
+
.ruby-gemset
|
23
|
+
# Vagrant folder
|
24
|
+
.vagrant/
|
25
|
+
.vagrant_files/
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Small pure ruby library to control VirtualBox VMs
|
2
|
+
|
3
|
+
You need VBoxManage in your PATH. On OSX you can do this by adding */Applications/VirtualBox.app/Contents/MacOS* to your PATH.
|
4
|
+
|
5
|
+
```
|
6
|
+
export PATH=/Applications/VirtualBox.app/Contents/MacOS:$PATH
|
7
|
+
```
|
8
|
+
|
9
|
+
```
|
10
|
+
require "virtbox"
|
11
|
+
|
12
|
+
vm = VirtBox::VM.new("vm-name")
|
13
|
+
|
14
|
+
exist = vm.exists?
|
15
|
+
|
16
|
+
vm_snaps = vm.snapshots
|
17
|
+
|
18
|
+
vm.revert_to_snapshot "snap-name"
|
19
|
+
|
20
|
+
vm.stop
|
21
|
+
|
22
|
+
vm.start
|
23
|
+
```
|
data/lib/virtbox.rb
ADDED
data/lib/virtbox/vm.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module VirtBox
|
2
|
+
class VM
|
3
|
+
|
4
|
+
def initialize(name)
|
5
|
+
@name = name
|
6
|
+
@id = nil
|
7
|
+
_read_vbox
|
8
|
+
end
|
9
|
+
|
10
|
+
def _read_vbox
|
11
|
+
%x{VBoxManage list vms}.split(/\n/).each { |line|
|
12
|
+
line.scan(/"([^"]+)"\s+\{([^\}]+)\}/) { |match|
|
13
|
+
if match[0] == @name
|
14
|
+
@id = match[1]
|
15
|
+
return
|
16
|
+
end
|
17
|
+
}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def exists?
|
22
|
+
if @id
|
23
|
+
return true
|
24
|
+
else
|
25
|
+
return false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def snapshots
|
30
|
+
snaps = Array.new
|
31
|
+
%x{VBoxManage snapshot #{@id} list --machinereadable}.split(/\n/).each { |line|
|
32
|
+
line.scan(/^SnapshotName(\-\d+)?="([^"]+)"/) { |match|
|
33
|
+
snaps << match[1]
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
snaps
|
38
|
+
end
|
39
|
+
|
40
|
+
def revert_to_snapshot(snap)
|
41
|
+
%x{VBoxManage snapshot #{@id} restore #{snap}}
|
42
|
+
end
|
43
|
+
|
44
|
+
def stop(name)
|
45
|
+
%x{VBoxManage controlvm #{@id} poweroff}
|
46
|
+
end
|
47
|
+
|
48
|
+
def start(options = {})
|
49
|
+
if options[:headless] && options[:headless] == true
|
50
|
+
%x{VBoxManage startvm #{@id} --type headless}
|
51
|
+
else
|
52
|
+
%x{VBoxManage startvm #{@id} --type gui}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/virtbox.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
require "virtbox/version"
|
3
|
+
|
4
|
+
files = `git ls-files`.split("\r\n")
|
5
|
+
p files
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "virtbox"
|
9
|
+
s.version = VirtBox::VERSION
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.authors = ["Tsiduia"]
|
12
|
+
s.email = ["tsiduia@gmail.com"]
|
13
|
+
s.homepage = "http://github.com/tsiduia/ruby-virtbox"
|
14
|
+
s.summary = "Library to control virtualbox with VirtManage"
|
15
|
+
s.description = "Library to control virtualbox with VirtManage"
|
16
|
+
|
17
|
+
s.required_rubygems_version = ">= 1.3.6"
|
18
|
+
|
19
|
+
s.files = files
|
20
|
+
s.require_path = 'lib'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: virtbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tsiduia
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Library to control virtualbox with VirtManage
|
15
|
+
email:
|
16
|
+
- tsiduia@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- README.md
|
23
|
+
- lib/virtbox.rb
|
24
|
+
- lib/virtbox/version.rb
|
25
|
+
- lib/virtbox/vm.rb
|
26
|
+
- virtbox.gemspec
|
27
|
+
homepage: http://github.com/tsiduia/ruby-virtbox
|
28
|
+
licenses: []
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.3.6
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 1.8.23
|
48
|
+
signing_key:
|
49
|
+
specification_version: 3
|
50
|
+
summary: Library to control virtualbox with VirtManage
|
51
|
+
test_files: []
|