vixen 0.0.3 → 0.0.4
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/Gemfile +3 -0
- data/README.md +9 -3
- data/lib/vixen/bridge.rb +73 -25
- data/lib/vixen/constants.rb +19 -1
- data/lib/vixen/model/vm.rb +65 -0
- data/vixen.gemspec +1 -1
- metadata +2 -1
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -19,13 +19,19 @@ Vixen can also be used on virtual machines that are not currently active:
|
|
19
19
|
```ruby
|
20
20
|
require 'vixen'
|
21
21
|
path = '/Users/jeff/Documents/Virtual Machines/win2003sat.vmwarevm/Windows Server 2003 Enterprise x64 Edition.vmx'
|
22
|
-
puts Vixen.local_connect.open_vm(path).current_snapshot.full_name
|
22
|
+
puts Vixen.local_connect.open_vm(path).power_on.current_snapshot.full_name
|
23
23
|
```
|
24
24
|
|
25
|
+
Capabilities
|
26
|
+
------------
|
27
|
+
|
28
|
+
* View running VMs
|
29
|
+
* Control power state (on, off, suspend, reset) of VMs
|
30
|
+
* Viewing the current snapshot
|
31
|
+
|
25
32
|
Limitations
|
26
33
|
-----------
|
27
|
-
Vixen currently only supports
|
28
|
-
It also only lists the current snapshot of each of the running virtual machines.
|
34
|
+
Vixen currently only supports running on Mac OS X or Linux.
|
29
35
|
|
30
36
|
See Also
|
31
37
|
--------
|
data/lib/vixen/bridge.rb
CHANGED
@@ -43,27 +43,27 @@ module Vixen::Bridge
|
|
43
43
|
attach_function :Vix_FreeBuffer, [:pointer], :void
|
44
44
|
attach_function :VixVM_GetCurrentSnapshot, [:handle, :pointer], :int
|
45
45
|
attach_function :VixSnapshot_GetParent, [:handle, :pointer], :int
|
46
|
+
attach_function :VixVM_PowerOn, [:handle, :int, :handle, :VixEventProc, :pointer], :handle
|
46
47
|
|
47
48
|
def self.connect(hostType, hostname, port, username, password)
|
48
49
|
job_handle = VixHandle[:invalid]
|
49
50
|
host_handle = VixHandle[:invalid]
|
50
|
-
job_handle = VixHost_Connect(VixApiVersion[:api_version],
|
51
|
-
hostType,
|
52
|
-
hostname,
|
53
|
-
port,
|
54
|
-
username,
|
55
|
-
password,
|
56
|
-
0,
|
57
|
-
VixHandle[:invalid],
|
58
|
-
nil,
|
51
|
+
job_handle = VixHost_Connect(VixApiVersion[:api_version],
|
52
|
+
hostType,
|
53
|
+
hostname,
|
54
|
+
port,
|
55
|
+
username,
|
56
|
+
password,
|
57
|
+
0,
|
58
|
+
VixHandle[:invalid],
|
59
|
+
nil,
|
59
60
|
nil)
|
60
61
|
host_handle = pointer_to_handle do |host_handle_pointer|
|
61
|
-
VixJob_Wait
|
62
|
-
|
63
|
-
:
|
64
|
-
:int, VixPropertyId[:none])
|
62
|
+
VixJob_Wait job_handle, VixPropertyId[:job_result_handle],
|
63
|
+
:pointer, host_handle_pointer,
|
64
|
+
:int, VixPropertyId[:none]
|
65
65
|
end
|
66
|
-
Vix_ReleaseHandle
|
66
|
+
Vix_ReleaseHandle job_handle
|
67
67
|
host_handle
|
68
68
|
end
|
69
69
|
|
@@ -74,7 +74,7 @@ module Vixen::Bridge
|
|
74
74
|
raise "problem executing pointer_to_handle block. (error: %s, %s)" %
|
75
75
|
[err, Vix_GetErrorText(err, nil)]
|
76
76
|
end
|
77
|
-
pointer.send
|
77
|
+
pointer.send "read_#{type}".to_sym
|
78
78
|
end
|
79
79
|
|
80
80
|
def self.pointer_to_handle(&block)
|
@@ -85,6 +85,20 @@ module Vixen::Bridge
|
|
85
85
|
pointer_to :pointer, &block
|
86
86
|
end
|
87
87
|
|
88
|
+
def self.pointer_to_int(&block)
|
89
|
+
pointer_to :int, &block
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.wait_for_async_job(operation, &block)
|
93
|
+
job_handle = yield
|
94
|
+
err = VixJob_Wait job_handle, VixPropertyId[:none]
|
95
|
+
unless err == VixError[:ok]
|
96
|
+
raise "couldn't %s. (error: %s, %s)" %
|
97
|
+
[operation, err, Vix_GetErrorText(err, nil)]
|
98
|
+
end
|
99
|
+
Vix_ReleaseHandle job_handle
|
100
|
+
end
|
101
|
+
|
88
102
|
def self.running_vms(host_handle)
|
89
103
|
available_vms = []
|
90
104
|
|
@@ -105,19 +119,18 @@ module Vixen::Bridge
|
|
105
119
|
# FIXME: we seem to go into deadlock without this sleep
|
106
120
|
# I'm not exactly sure why
|
107
121
|
sleep 0.5
|
108
|
-
err = VixJob_Wait
|
109
|
-
VixPropertyId[:none] )
|
122
|
+
err = VixJob_Wait job_handle, VixPropertyId[:none]
|
110
123
|
|
111
|
-
Vix_ReleaseHandle
|
124
|
+
Vix_ReleaseHandle job_handle
|
112
125
|
available_vms
|
113
126
|
end
|
114
127
|
|
115
128
|
def self.disconnect(handle)
|
116
|
-
VixHost_Disconnect
|
129
|
+
VixHost_Disconnect handle
|
117
130
|
end
|
118
131
|
|
119
132
|
def self.destroy(handle)
|
120
|
-
Vix_ReleaseHandle
|
133
|
+
Vix_ReleaseHandle handle
|
121
134
|
end
|
122
135
|
|
123
136
|
def self.open_vm(host_handle, vm_path)
|
@@ -133,26 +146,25 @@ module Vixen::Bridge
|
|
133
146
|
:pointer, vm_handle_pointer,
|
134
147
|
:int, VixPropertyId[:none])
|
135
148
|
end
|
136
|
-
Vix_ReleaseHandle
|
149
|
+
Vix_ReleaseHandle job_handle
|
137
150
|
vm_handle
|
138
151
|
end
|
139
152
|
|
140
153
|
def self.current_snapshot(vm_handle)
|
141
154
|
pointer_to_handle do |snapshot_handle_pointer|
|
142
|
-
VixVM_GetCurrentSnapshot
|
155
|
+
VixVM_GetCurrentSnapshot vm_handle, snapshot_handle_pointer
|
143
156
|
end
|
144
157
|
end
|
145
158
|
|
146
159
|
def self.get_parent(snapshot_handle)
|
147
160
|
pointer_to_handle do |snapshot_handle_pointer|
|
148
|
-
VixSnapshot_GetParent
|
161
|
+
VixSnapshot_GetParent snapshot_handle, snapshot_handle_pointer
|
149
162
|
end
|
150
163
|
end
|
151
164
|
|
152
165
|
def self.get_string_property(handle, property_id)
|
153
166
|
string = pointer_to_string do |string_pointer|
|
154
|
-
Vix_GetProperties(handle,
|
155
|
-
property_id,
|
167
|
+
Vix_GetProperties(handle, property_id,
|
156
168
|
:pointer, string_pointer,
|
157
169
|
:int, VixPropertyId[:none])
|
158
170
|
end
|
@@ -161,4 +173,40 @@ module Vixen::Bridge
|
|
161
173
|
return value
|
162
174
|
end
|
163
175
|
|
176
|
+
def self.get_int_property(handle, property_id)
|
177
|
+
pointer_to_int do |int_pointer|
|
178
|
+
Vix_GetProperties(handle, property_id,
|
179
|
+
:pointer, int_pointer,
|
180
|
+
:int, VixPropertyId[:none])
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def self.power_on(vm_handle)
|
185
|
+
wait_for_async_job "power on VM" do
|
186
|
+
VixVM_PowerOn vm_handle, VixVMPowerOptions[:normal], VixHandle[:invalid], nil, nil
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def self.power_off(vm_handle)
|
191
|
+
wait_for_async_job "power off VM" do
|
192
|
+
VixVM_PowerOff vm_handle, VixVMPowerOptions[:normal], nil, nil
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def self.reset(vm_handle)
|
197
|
+
wait_for_async_job "reset VM" do
|
198
|
+
VixVM_Reset vm_handle, VixVMPowerOptions[:normal], nil, nil
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def self.suspend(vm_handle)
|
203
|
+
wait_for_async_job "suspend VM" do
|
204
|
+
VixVM_Suspend vm_handle, VixVMPowerOptions[:normal], nil, nil
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def self.current_power_state(vm_handle)
|
209
|
+
get_int_property vm_handle, VixPropertyId[:vm_power_state]
|
210
|
+
end
|
211
|
+
|
164
212
|
end
|
data/lib/vixen/constants.rb
CHANGED
@@ -21,7 +21,7 @@ module Vixen::Constants
|
|
21
21
|
:blob, 6 )
|
22
22
|
|
23
23
|
VixError = enum( :ok, 0 )
|
24
|
-
|
24
|
+
|
25
25
|
VixPropertyId = enum( :none, 0,
|
26
26
|
:meta_data_container, 2,
|
27
27
|
:host_hosttype, 50,
|
@@ -94,4 +94,22 @@ module Vixen::Constants
|
|
94
94
|
:registered_vms, 4 )
|
95
95
|
|
96
96
|
VixVMOpenOptions = enum( :normal, 0x0 )
|
97
|
+
|
98
|
+
VixVMPowerOptions = enum( :normal, 0,
|
99
|
+
:from_guest, 0x0004,
|
100
|
+
:suppress_snapshot_poweron, 0x0080,
|
101
|
+
:launch_gui, 0x0200,
|
102
|
+
:start_vm_paused, 0x1000 )
|
103
|
+
|
104
|
+
VixPowerState = enum( :powering_off, 0x0001,
|
105
|
+
:powered_off, 0x0002,
|
106
|
+
:powering_on, 0x0004,
|
107
|
+
:powered_on, 0x0008,
|
108
|
+
:suspending, 0x0010,
|
109
|
+
:suspended, 0x0020,
|
110
|
+
:tools_running, 0x0040,
|
111
|
+
:resetting, 0x0080,
|
112
|
+
:blocked_on_msg, 0x0100,
|
113
|
+
:paused, 0x0200,
|
114
|
+
:resuming, 0x0800 )
|
97
115
|
end
|
data/lib/vixen/model/vm.rb
CHANGED
@@ -6,4 +6,69 @@ class Vixen::Model::VM < Vixen::Model::Base
|
|
6
6
|
def current_snapshot
|
7
7
|
Vixen::Model::Snapshot.new(Vixen::Bridge.current_snapshot(handle))
|
8
8
|
end
|
9
|
+
|
10
|
+
def power_on
|
11
|
+
return self if powered_on? or powering_on? or resuming?
|
12
|
+
Vixen::Bridge.power_on handle
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def resume
|
17
|
+
power_on
|
18
|
+
end
|
19
|
+
|
20
|
+
def suspend
|
21
|
+
Vixen::Bridge.suspend handle
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def power_off
|
26
|
+
Vixen::Bridge.power_off handle
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def reset
|
31
|
+
Vixen::Bridge.reset handle
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def powering_off?
|
36
|
+
current_power_states.include? :powering_off
|
37
|
+
end
|
38
|
+
|
39
|
+
def powered_off?
|
40
|
+
current_power_states.include? :powered_off
|
41
|
+
end
|
42
|
+
|
43
|
+
def powering_on?
|
44
|
+
current_power_states.include? :powering_on
|
45
|
+
end
|
46
|
+
|
47
|
+
def powered_on?
|
48
|
+
current_power_states.include? :powered_on
|
49
|
+
end
|
50
|
+
|
51
|
+
def resuming?
|
52
|
+
current_power_states.include? :resuming
|
53
|
+
end
|
54
|
+
|
55
|
+
def suspending?
|
56
|
+
current_power_states.include? :suspending
|
57
|
+
end
|
58
|
+
|
59
|
+
def suspended?
|
60
|
+
current_power_states.include? :suspended
|
61
|
+
end
|
62
|
+
|
63
|
+
def current_power_states
|
64
|
+
states = []
|
65
|
+
bitwise_state = Vixen::Bridge.current_power_state handle
|
66
|
+
[ :powering_off, :powered_off, :powering_on, :powered_on, :suspending,
|
67
|
+
:suspended, :tools_running, :resetting, :blocked_on_msg, :paused,
|
68
|
+
:resuming
|
69
|
+
].each do |state|
|
70
|
+
states << state if ((bitwise_state & VixPowerState[state]) == VixPowerState[state])
|
71
|
+
end
|
72
|
+
states
|
73
|
+
end
|
9
74
|
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.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -51,6 +51,7 @@ extensions: []
|
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
53
|
- .gitignore
|
54
|
+
- Gemfile
|
54
55
|
- LICENSE
|
55
56
|
- MIT.LICENSE
|
56
57
|
- README.md
|