vixen 0.0.4 → 0.0.5

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 CHANGED
@@ -44,6 +44,7 @@ module Vixen::Bridge
44
44
  attach_function :VixVM_GetCurrentSnapshot, [:handle, :pointer], :int
45
45
  attach_function :VixSnapshot_GetParent, [:handle, :pointer], :int
46
46
  attach_function :VixVM_PowerOn, [:handle, :int, :handle, :VixEventProc, :pointer], :handle
47
+ attach_function :VixVM_CreateSnapshot, [:handle, :string, :string, :int, :handle, :VixEventProc, :pointer], :handle
47
48
 
48
49
  def self.connect(hostType, hostname, port, username, password)
49
50
  job_handle = VixHandle[:invalid]
@@ -99,6 +100,20 @@ module Vixen::Bridge
99
100
  Vix_ReleaseHandle job_handle
100
101
  end
101
102
 
103
+ def self.wait_for_async_handle_creation_job(operation, pointer_to_handle, &block)
104
+ job_handle = yield
105
+ sleep 0.5
106
+ err = VixJob_Wait job_handle, VixPropertyId[:job_result_handle],
107
+ :pointer, pointer_to_handle,
108
+ :int, VixPropertyId[:none]
109
+ unless err == VixError[:ok]
110
+ raise "couldn't %s. (error: %s, %s)" %
111
+ [operation, err, Vix_GetErrorText(err, nil)]
112
+ end
113
+ Vix_ReleaseHandle job_handle
114
+ err
115
+ end
116
+
102
117
  def self.running_vms(host_handle)
103
118
  available_vms = []
104
119
 
@@ -134,20 +149,22 @@ module Vixen::Bridge
134
149
  end
135
150
 
136
151
  def self.open_vm(host_handle, vm_path)
137
- job_handle = VixHost_OpenVM(host_handle,
138
- vm_path,
139
- VixVMOpenOptions[:normal],
140
- VixHandle[:invalid],
141
- nil,
142
- nil)
143
152
  vm_handle = pointer_to_handle do |vm_handle_pointer|
144
- VixJob_Wait(job_handle,
145
- VixPropertyId[:job_result_handle],
146
- :pointer, vm_handle_pointer,
147
- :int, VixPropertyId[:none])
153
+ wait_for_async_handle_creation_job "open vm", vm_handle_pointer do
154
+ VixHost_OpenVM host_handle, vm_path, VixVMOpenOptions[:normal],
155
+ VixHandle[:invalid], nil, nil
156
+ end
157
+ end
158
+ end
159
+
160
+ def self.create_snapshot(vm_handle, name, description)
161
+ snapshot_handle = pointer_to_handle do |snapshot_handle_pointer|
162
+ wait_for_async_handle_creation_job "create snapshot", snapshot_handle_pointer do
163
+ VixVM_CreateSnapshot vm_handle, name, description,
164
+ VixCreateSnapshotOptions[:include_memory],
165
+ VixHandle[:invalid], nil, nil
166
+ end
148
167
  end
149
- Vix_ReleaseHandle job_handle
150
- vm_handle
151
168
  end
152
169
 
153
170
  def self.current_snapshot(vm_handle)
@@ -112,4 +112,7 @@ module Vixen::Constants
112
112
  :blocked_on_msg, 0x0100,
113
113
  :paused, 0x0200,
114
114
  :resuming, 0x0800 )
115
+
116
+ VixCreateSnapshotOptions = enum( :include_memory, 0x0002 )
117
+
115
118
  end
@@ -7,8 +7,12 @@ class Vixen::Model::VM < Vixen::Model::Base
7
7
  Vixen::Model::Snapshot.new(Vixen::Bridge.current_snapshot(handle))
8
8
  end
9
9
 
10
+ def create_snapshot(name, description)
11
+ Vixen::Model::Snapshot.new(Vixen::Bridge.create_snapshot handle, name, description)
12
+ end
13
+
10
14
  def power_on
11
- return self if powered_on? or powering_on? or resuming?
15
+ return self if powered_on? or powering_on? or resuming? or resetting?
12
16
  Vixen::Bridge.power_on handle
13
17
  self
14
18
  end
@@ -60,6 +64,10 @@ class Vixen::Model::VM < Vixen::Model::Base
60
64
  current_power_states.include? :suspended
61
65
  end
62
66
 
67
+ def resetting?
68
+ current_power_states.include? :resetting
69
+ end
70
+
63
71
  def current_power_states
64
72
  states = []
65
73
  bitwise_state = Vixen::Bridge.current_power_state handle
data/vixen.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'vixen'
3
- s.version = '0.0.4'
3
+ s.version = '0.0.5'
4
4
  s.summary = 'Ruby bindings for VMware VIX API'
5
5
  s.description = <<-EOF
6
6
  Vixen is an easy way to interact with VMware virtual machines from Ruby.
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
4
+ version: 0.0.5
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-18 00:00:00.000000000 Z
12
+ date: 2012-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi