vmonkey 0.5.0 → 0.5.1
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.
- checksums.yaml +4 -4
- data/lib/vmonkey/version.rb +1 -1
- data/lib/vmonkey/vim/VirtualMachine.rb +49 -11
- data/spec/virtualmachine_spec.rb +19 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72cbcf9517482d8c9d0a3b9ea687536cf06ccef5
|
4
|
+
data.tar.gz: 73a280923d278454a00123ddd83ff266e209febd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0f05f8a88f96c7d8d9892a64f788484623021332a61c984ff8883708ba598f9738545c25558c6557a33bb394d3a8401f06cb8bb5842fa566a6184bac518f3c3
|
7
|
+
data.tar.gz: 35d37eab5e6103b330809a1bf84c7ac0c5f510b71985dc6a705631722db17bf23d7afce3e216f5cb131d51f9a4efef63b6376e9bba8a3b23234bb6be3c7f2e73
|
data/lib/vmonkey/version.rb
CHANGED
@@ -18,6 +18,13 @@ class RbVmomi::VIM::VirtualMachine
|
|
18
18
|
self.CloneVM_Task(params).wait_for_completion
|
19
19
|
end
|
20
20
|
|
21
|
+
def clone_to!(path)
|
22
|
+
dest_vm = monkey.vm(path)
|
23
|
+
dest_vm.destroy if dest_vm
|
24
|
+
|
25
|
+
clone_to(path)
|
26
|
+
end
|
27
|
+
|
21
28
|
def annotation
|
22
29
|
config.annotation
|
23
30
|
end
|
@@ -76,19 +83,50 @@ class RbVmomi::VIM::VirtualMachine
|
|
76
83
|
move_to(path)
|
77
84
|
end
|
78
85
|
|
79
|
-
def port_ready?(port)
|
86
|
+
def port_ready?(port, timeout = 5)
|
80
87
|
ip = guest_ip or return false
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
88
|
+
|
89
|
+
## modified from http://spin.atomicobject.com/2013/09/30/socket-connection-timeout-ruby/
|
90
|
+
addr = Socket.getaddrinfo(ip, nil)
|
91
|
+
sockaddr = Socket.pack_sockaddr_in(port, addr[0][3])
|
92
|
+
|
93
|
+
Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0).tap do |socket|
|
94
|
+
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
95
|
+
|
96
|
+
begin
|
97
|
+
# Initiate the socket connection in the background. If it doesn't fail
|
98
|
+
# immediately it will raise an IO::WaitWritable (Errno::EINPROGRESS)
|
99
|
+
# indicating the connection is in progress.
|
100
|
+
socket.connect_nonblock(sockaddr)
|
101
|
+
|
102
|
+
rescue IO::WaitWritable
|
103
|
+
# IO.select will block until the socket is writable or the timeout
|
104
|
+
# is exceeded - whichever comes first.
|
105
|
+
if IO.select(nil, [socket], nil, timeout)
|
106
|
+
begin
|
107
|
+
# Verify there is now a good connection
|
108
|
+
socket.connect_nonblock(sockaddr)
|
109
|
+
rescue Errno::EISCONN
|
110
|
+
# Good news everybody, the socket is connected!
|
111
|
+
socket.close
|
112
|
+
return true
|
113
|
+
rescue Errno::ETIMEDOUT, Errno::EPERM, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ENETUNREACH
|
114
|
+
socket.close
|
115
|
+
return false
|
116
|
+
rescue
|
117
|
+
# An unexpected exception was raised - the connection is no good.
|
118
|
+
raise
|
119
|
+
end
|
120
|
+
else
|
121
|
+
# IO.select returns nil when the socket is not ready before timeout
|
122
|
+
# seconds have elapsed
|
123
|
+
socket.close
|
124
|
+
return false
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
return false
|
87
129
|
end
|
88
|
-
rescue Errno::ETIMEDOUT, Errno::EPERM, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ENETUNREACH
|
89
|
-
false
|
90
|
-
ensure
|
91
|
-
tcp_socket && tcp_socket.close
|
92
130
|
end
|
93
131
|
|
94
132
|
def wait_for(max=300, interval=2, &block)
|
data/spec/virtualmachine_spec.rb
CHANGED
@@ -59,13 +59,31 @@ describe RbVmomi::VIM::VirtualMachine do
|
|
59
59
|
before(:all) { @spec_vm = @template.clone_to @vm_path }
|
60
60
|
after(:all) { @spec_vm.destroy }
|
61
61
|
|
62
|
-
describe '#
|
62
|
+
describe '#clone_to' do
|
63
63
|
context 'to a Folder' do
|
64
64
|
subject { @monkey.vm @vm_path }
|
65
65
|
it { should_not be_nil }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
describe '#clone_to!' do
|
70
|
+
before(:all) do
|
71
|
+
@other_path = "#{@vm_path}-other"
|
72
|
+
end
|
73
|
+
|
74
|
+
after(:all) do
|
75
|
+
other_vm = @monkey.vm @other_path
|
76
|
+
other_vm.destroy if other_vm
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should overwrite a VM when given a path of an existing VM' do
|
80
|
+
expect{
|
81
|
+
@other_vm = @spec_vm.clone_to! @other_path
|
82
|
+
@other_vm = @spec_vm.clone_to! @other_path
|
83
|
+
}.to_not raise_error
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
69
87
|
describe '#annotation=' do
|
70
88
|
it 'sets the annotation' do
|
71
89
|
@spec_vm.annotation = 'xyzzy'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmonkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Dupras
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-08-
|
12
|
+
date: 2014-08-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|