vixen 0.0.11 → 0.0.12
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.
- data/lib/vixen/bridge.rb +33 -5
- data/lib/vixen/command_line.rb +15 -7
- data/lib/vixen/command_line/base.rb +20 -4
- data/lib/vixen/command_line/snapshot.rb +50 -1
- data/lib/vixen/command_line/start.rb +19 -0
- data/lib/vixen/command_line/status.rb +3 -4
- data/lib/vixen/command_line/stop.rb +19 -0
- data/lib/vixen/command_line/suspend.rb +13 -1
- data/lib/vixen/command_line/vm.rb +23 -0
- data/lib/vixen/model/snapshot.rb +9 -0
- data/lib/vixen/model/vm.rb +22 -0
- data/vixen.gemspec +2 -2
- metadata +5 -4
- data/lib/vixen/command_line/halt.rb +0 -7
- data/lib/vixen/command_line/up.rb +0 -7
data/lib/vixen/bridge.rb
CHANGED
@@ -50,8 +50,11 @@ module Vixen::Bridge
|
|
50
50
|
attach_function :VixVM_RemoveSnapshot, [:handle, :handle, :int, :VixEventProc, :pointer], :handle
|
51
51
|
attach_function :VixJob_CheckCompletion, [:handle, :pointer], :int
|
52
52
|
attach_function :Vix_GetHandleType, [:handle], :int
|
53
|
-
|
54
|
-
|
53
|
+
attach_function :VixVM_GetNumRootSnapshots, [:handle, :pointer], :int
|
54
|
+
attach_function :VixVM_GetRootSnapshot, [:handle, :int, :pointer], :int
|
55
|
+
attach_function :VixVM_GetNamedSnapshot, [:handle, :string, :pointer], :int
|
56
|
+
attach_function :VixSnapshot_GetNumChildren, [:handle, :pointer], :int
|
57
|
+
attach_function :VixSnapshot_GetChild, [:handle, :int, :pointer], :int
|
55
58
|
|
56
59
|
def self.safe_proc_from_block(&block)
|
57
60
|
return nil unless block_given?
|
@@ -217,7 +220,7 @@ module Vixen::Bridge
|
|
217
220
|
def self.create_snapshot(vm_handle, name, description, &block)
|
218
221
|
progress_proc = safe_proc_from_block &block
|
219
222
|
snapshot_handle = pointer_to_handle do |snapshot_handle_pointer|
|
220
|
-
wait_for_async_handle_creation_job "create snapshot", snapshot_handle_pointer,
|
223
|
+
wait_for_async_handle_creation_job "create snapshot", snapshot_handle_pointer, 0.2, 0.2 do
|
221
224
|
Vixen.logger.info "creating %s snapshot" % name
|
222
225
|
VixVM_CreateSnapshot vm_handle, name, description,
|
223
226
|
VixCreateSnapshotOptions[:include_memory],
|
@@ -228,7 +231,7 @@ module Vixen::Bridge
|
|
228
231
|
|
229
232
|
def self.revert_to_snapshot(vm, snapshot, &block)
|
230
233
|
progress_proc = safe_proc_from_block &block
|
231
|
-
wait_for_async_job(("revert to %s snapshot" % snapshot.display_name),
|
234
|
+
wait_for_async_job(("revert to %s snapshot" % snapshot.display_name), 0.2, 0.2) do
|
232
235
|
VixVM_RevertToSnapshot vm.handle, snapshot.handle, VixVMPowerOptions[:normal],
|
233
236
|
VixHandle[:invalid], progress_proc, nil
|
234
237
|
end
|
@@ -236,7 +239,7 @@ module Vixen::Bridge
|
|
236
239
|
|
237
240
|
def self.remove_snapshot(vm, snapshot, &block)
|
238
241
|
progress_proc = safe_proc_from_block &block
|
239
|
-
wait_for_async_job(("remove %s snapshot" % snapshot.display_name),
|
242
|
+
wait_for_async_job(("remove %s snapshot" % snapshot.display_name), 0.2, 0.2) do
|
240
243
|
VixVM_RemoveSnapshot vm.handle, snapshot.handle, 0, progress_proc, nil
|
241
244
|
end
|
242
245
|
end
|
@@ -248,6 +251,18 @@ module Vixen::Bridge
|
|
248
251
|
end
|
249
252
|
end
|
250
253
|
|
254
|
+
def self.get_root_snapshots(vm_handle)
|
255
|
+
count = pointer_to_int { |int_pointer| VixVM_GetNumRootSnapshots(vm_handle, int_pointer) }
|
256
|
+
snapshots = []
|
257
|
+
count.times do |n|
|
258
|
+
handle = pointer_to_handle do |handle_pointer|
|
259
|
+
VixVM_GetRootSnapshot(vm_handle, n, handle_pointer)
|
260
|
+
end
|
261
|
+
snapshots << Vixen::Model::Snapshot.new( handle )
|
262
|
+
end
|
263
|
+
snapshots
|
264
|
+
end
|
265
|
+
|
251
266
|
def self.get_parent(snapshot_handle)
|
252
267
|
pointer_to_handle do |snapshot_handle_pointer|
|
253
268
|
Vixen.logger.debug "retrieving snapshot parent"
|
@@ -255,6 +270,19 @@ module Vixen::Bridge
|
|
255
270
|
end
|
256
271
|
end
|
257
272
|
|
273
|
+
def self.get_children(snapshot_handle)
|
274
|
+
count = pointer_to_int { |int_pointer| VixSnapshot_GetNumChildren(snapshot_handle, int_pointer) }
|
275
|
+
children = []
|
276
|
+
count.times do |n|
|
277
|
+
handle = pointer_to_handle do |handle_pointer|
|
278
|
+
VixSnapshot_GetChild(snapshot_handle, n, handle_pointer)
|
279
|
+
end
|
280
|
+
child = Vixen::Model::Snapshot.new( handle )
|
281
|
+
children << child
|
282
|
+
end
|
283
|
+
children
|
284
|
+
end
|
285
|
+
|
258
286
|
def self.get_string_property(handle, property_id)
|
259
287
|
string = pointer_to_string do |string_pointer|
|
260
288
|
Vixen.logger.debug "getting %s property" % Vixen::Constants::VixPropertyId[property_id]
|
data/lib/vixen/command_line.rb
CHANGED
@@ -2,18 +2,26 @@ require 'vixen'
|
|
2
2
|
|
3
3
|
class Vixen::CommandLine
|
4
4
|
def execute
|
5
|
+
|
6
|
+
context = {}
|
7
|
+
|
5
8
|
command = ARGV.shift
|
6
9
|
command ||= 'status'
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
ARGV.unshift command
|
12
|
+
|
13
|
+
while ! ARGV.empty?
|
14
|
+
begin
|
15
|
+
command = ARGV.shift
|
16
|
+
require "vixen/command_line/#{command}"
|
10
17
|
|
11
|
-
|
12
|
-
|
18
|
+
klass = self.class.const_get(command.split('_').map {|s| s.capitalize }.join)
|
19
|
+
raise "Couldn't find #{command}" unless klass
|
13
20
|
|
14
|
-
|
15
|
-
|
16
|
-
|
21
|
+
klass.new(context).execute
|
22
|
+
rescue LoadError
|
23
|
+
puts "Unknown command: #{command}"
|
24
|
+
end
|
17
25
|
end
|
18
26
|
end
|
19
27
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
class Vixen::CommandLine::Base
|
2
|
-
attr_reader :start
|
2
|
+
attr_reader :start, :context
|
3
3
|
|
4
|
-
def initialize
|
4
|
+
def initialize(context)
|
5
5
|
@start = Time.now
|
6
|
+
@context = context
|
6
7
|
end
|
7
8
|
|
8
9
|
def elapsed_time
|
@@ -11,14 +12,29 @@ class Vixen::CommandLine::Base
|
|
11
12
|
|
12
13
|
def new_line_after
|
13
14
|
val = yield if block_given?
|
14
|
-
puts
|
15
|
+
$stdout.puts
|
15
16
|
val
|
16
17
|
end
|
17
18
|
|
18
19
|
def print(message, *args)
|
19
|
-
timed_message = "\r \r#{elapsed_time} " + message
|
20
|
+
timed_message = "\r \r#{elapsed_time} " + message.to_s
|
20
21
|
$stdout.print timed_message, args
|
21
22
|
$stdout.flush
|
22
23
|
end
|
23
24
|
|
25
|
+
def puts(message, *args)
|
26
|
+
new_line_after { print(message, args) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def host
|
30
|
+
return @host unless @host.nil?
|
31
|
+
@host = context[:host] || Vixen.local_connect
|
32
|
+
end
|
33
|
+
|
34
|
+
def vms
|
35
|
+
return @vms unless @vms.nil?
|
36
|
+
context[:vms] ||= host.running_vms
|
37
|
+
@vms = context[:vms]
|
38
|
+
end
|
39
|
+
|
24
40
|
end
|
@@ -2,6 +2,55 @@ require 'vixen/command_line/base'
|
|
2
2
|
|
3
3
|
class Vixen::CommandLine::Snapshot < Vixen::CommandLine::Base
|
4
4
|
def execute
|
5
|
-
|
5
|
+
action = ARGV.shift
|
6
|
+
action ||= default_action
|
7
|
+
|
8
|
+
action = action.to_sym
|
9
|
+
|
10
|
+
if defined? action
|
11
|
+
send action
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def list
|
16
|
+
total_snapshots = 0
|
17
|
+
|
18
|
+
vms.each do |vm|
|
19
|
+
puts "#{vm.name} : (#{vm.current_snapshot.display_name})"
|
20
|
+
all_snaps = vm.all_snapshots
|
21
|
+
total_snapshots += all_snaps.count
|
22
|
+
all_snaps.each do |snap|
|
23
|
+
puts " - #{snap.display_name}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
puts "Found #{total_snapshots} snapshots on #{vms.count} virtual machines"
|
27
|
+
end
|
28
|
+
|
29
|
+
def current
|
30
|
+
vms.each do |vm|
|
31
|
+
puts "#{vm.name}"
|
32
|
+
puts " - #{vm.current_snapshot.full_name}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def create
|
37
|
+
snapshot_name = ARGV.shift
|
38
|
+
vms.each do |vm|
|
39
|
+
new_line_after do
|
40
|
+
vm.create_snapshot(snapshot_name) do |job_handle, event_type, more_event_info, client_data|
|
41
|
+
print "Creating #{snapshot_name} snapshot on #{vm.name}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def revert
|
48
|
+
end
|
49
|
+
|
50
|
+
def remove
|
51
|
+
end
|
52
|
+
|
53
|
+
def default_action
|
54
|
+
'list'
|
6
55
|
end
|
7
56
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'vixen/command_line/base'
|
2
|
+
|
3
|
+
class Vixen::CommandLine::Start < Vixen::CommandLine::Base
|
4
|
+
def execute
|
5
|
+
count = 0
|
6
|
+
|
7
|
+
vms.each do |vm|
|
8
|
+
unless vm.powered_on?
|
9
|
+
new_line_after do
|
10
|
+
vm.power_on do |*args|
|
11
|
+
print "Powering on #{vm.name}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
count += 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
puts "Powered on #{count} machines"
|
18
|
+
end
|
19
|
+
end
|
@@ -2,19 +2,18 @@ require 'vixen/command_line/base'
|
|
2
2
|
|
3
3
|
class Vixen::CommandLine::Status < Vixen::CommandLine::Base
|
4
4
|
def execute
|
5
|
-
new_line_after { print "Connecting to
|
6
|
-
host = Vixen.local_connect
|
5
|
+
new_line_after { print "Connecting to host" }
|
7
6
|
|
8
7
|
vms = host.paths_of_running_vms do |job_handle, event_type, more_event_info, client_data|
|
9
8
|
print " <searching> "
|
10
9
|
if event_type == Vixen::Constants::VixEventType[:find_item]
|
11
10
|
path = Vixen::Bridge.get_string_property more_event_info, Vixen::Constants::VixPropertyId[:found_item_location]
|
12
11
|
if path
|
13
|
-
new_line_after { print File.basename path }
|
12
|
+
new_line_after { print " #{File.basename path}" }
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
|
-
|
17
|
+
puts "Found #{vms.size} running virtual machines"
|
19
18
|
end
|
20
19
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'vixen/command_line/base'
|
2
|
+
|
3
|
+
class Vixen::CommandLine::Stop < Vixen::CommandLine::Base
|
4
|
+
def execute
|
5
|
+
count = 0
|
6
|
+
|
7
|
+
vms.each do |vm|
|
8
|
+
if vm.powered_on?
|
9
|
+
new_line_after do
|
10
|
+
vm.power_off do |*args|
|
11
|
+
print "Powering off #{vm.name}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
count += 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
puts "Powered off #{count} machines"
|
18
|
+
end
|
19
|
+
end
|
@@ -2,6 +2,18 @@ require 'vixen/command_line/base'
|
|
2
2
|
|
3
3
|
class Vixen::CommandLine::Suspend < Vixen::CommandLine::Base
|
4
4
|
def execute
|
5
|
-
|
5
|
+
count = 0
|
6
|
+
|
7
|
+
vms.each do |vm|
|
8
|
+
if vm.powered_on?
|
9
|
+
new_line_after do
|
10
|
+
vm.suspend do |*args|
|
11
|
+
print "Suspending #{vm.name}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
count += 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
puts "Suspended #{count} machines"
|
6
18
|
end
|
7
19
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'vixen/command_line/base'
|
2
|
+
|
3
|
+
class Vixen::CommandLine::Vm < Vixen::CommandLine::Base
|
4
|
+
def execute
|
5
|
+
machines = ARGV.shift
|
6
|
+
|
7
|
+
return puts "A path to a virtual machine must be included" if machines.nil?
|
8
|
+
|
9
|
+
powered_count = 0
|
10
|
+
|
11
|
+
vm_paths = machines.split ','
|
12
|
+
vms = []
|
13
|
+
vm_paths.each do |path|
|
14
|
+
vm = new_line_after do
|
15
|
+
host.open_vm path do
|
16
|
+
print "Opening #{path}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
vms << vm
|
20
|
+
end
|
21
|
+
context[:vms] = vms
|
22
|
+
end
|
23
|
+
end
|
data/lib/vixen/model/snapshot.rb
CHANGED
@@ -22,6 +22,15 @@ class Vixen::Model::Snapshot < Vixen::Model::Base
|
|
22
22
|
File.join(root, display_name)
|
23
23
|
end
|
24
24
|
|
25
|
+
def children
|
26
|
+
Vixen::Bridge.get_children(handle)
|
27
|
+
end
|
28
|
+
|
29
|
+
def all_children
|
30
|
+
childs = children
|
31
|
+
(childs + childs.map {|child| child.all_children}).flatten
|
32
|
+
end
|
33
|
+
|
25
34
|
def to_s
|
26
35
|
display_name
|
27
36
|
end
|
data/lib/vixen/model/vm.rb
CHANGED
@@ -3,10 +3,32 @@ require File.join(File.dirname(__FILE__), 'snapshot')
|
|
3
3
|
|
4
4
|
class Vixen::Model::VM < Vixen::Model::Base
|
5
5
|
|
6
|
+
def name
|
7
|
+
get_string_property Vixen::Constants::VixPropertyId[:vm_name]
|
8
|
+
end
|
9
|
+
|
10
|
+
def path
|
11
|
+
get_string_property Vixen::Constants::VixPropertyId[:vmx_pathname]
|
12
|
+
end
|
13
|
+
|
14
|
+
def guest_os
|
15
|
+
get_string_property Vixen::Constants::VixPropertyId[:vm_guestos]
|
16
|
+
end
|
17
|
+
|
6
18
|
def current_snapshot
|
7
19
|
Vixen::Model::Snapshot.new(Vixen::Bridge.current_snapshot(handle))
|
8
20
|
end
|
9
21
|
|
22
|
+
def root_snapshots
|
23
|
+
Vixen::Bridge.get_root_snapshots handle
|
24
|
+
end
|
25
|
+
|
26
|
+
def all_snapshots
|
27
|
+
roots = root_snapshots
|
28
|
+
childs = roots.map {|s| s.all_children }
|
29
|
+
(roots + childs).flatten
|
30
|
+
end
|
31
|
+
|
10
32
|
def create_snapshot(name, description="", &block)
|
11
33
|
Vixen::Model::Snapshot.new(Vixen::Bridge.create_snapshot handle, name, description, &block)
|
12
34
|
end
|
data/vixen.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vixen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -64,12 +64,13 @@ files:
|
|
64
64
|
- lib/vixen/bridge.rb
|
65
65
|
- lib/vixen/command_line.rb
|
66
66
|
- lib/vixen/command_line/base.rb
|
67
|
-
- lib/vixen/command_line/halt.rb
|
68
67
|
- lib/vixen/command_line/resume.rb
|
69
68
|
- lib/vixen/command_line/snapshot.rb
|
69
|
+
- lib/vixen/command_line/start.rb
|
70
70
|
- lib/vixen/command_line/status.rb
|
71
|
+
- lib/vixen/command_line/stop.rb
|
71
72
|
- lib/vixen/command_line/suspend.rb
|
72
|
-
- lib/vixen/command_line/
|
73
|
+
- lib/vixen/command_line/vm.rb
|
73
74
|
- lib/vixen/constants.rb
|
74
75
|
- lib/vixen/model/base.rb
|
75
76
|
- lib/vixen/model/host.rb
|