forked from ManageIQ/vmware_web_service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMiqVimClientBase.rb
89 lines (72 loc) · 1.94 KB
/
MiqVimClientBase.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'pathname'
require 'sync'
require 'VMwareWebService/VimService'
# require 'profile'
class MiqVimClientBase < VimService
@@receiveTimeout = 120
attr_reader :server, :port, :username, :password, :connId
def initialize(server:, username:, password:, port: 443, ssl_options: {})
@server = server
@port = port
@username = username
@password = password
@connId = "#{@server}_#{@username}"
@receiveTimeout = @@receiveTimeout
@connected = false
@connLock = Sync.new
end
def sdk_uri
URI::HTTPS.build(:host => server, :port => port, :path => "/sdk")
end
def self.receiveTimeout=(val)
@@receiveTimeout = val
end
def self.receiveTimeout
@@receiveTimeout
end
def receiveTimeout=(val)
@connLock.synchronize(:EX) do
@receiveTimeout = val
http_client.receive_timeout = @receiveTimeout if http_client
end
end
def receiveTimeout
@connLock.synchronize(:SH) do
@receiveTimeout
end
end
def connect
logger.debug { "#{self.class.name}.connect(#{@connId}): #{$PROGRAM_NAME} #{ARGV.join(' ')}" }
@connLock.synchronize(:EX) do
return if @connected
login(@sic.sessionManager, @username, @password)
@connected = true
end
end
def disconnect
logger.debug { "#{self.class.name}.disconnect(#{@connId}): #{$PROGRAM_NAME} #{ARGV.join(' ')}" }
@connLock.synchronize(:EX) do
return unless @connected
logout(@sic.sessionManager)
@connected = false
end
end
def currentServerTime
DateTime.parse(currentTime)
end
def acquireCloneTicket
super(@sic.sessionManager)
end
def verify_callback(is_ok, ctx)
if $DEBUG
puts "#{is_ok ? 'ok' : 'ng'}: #{ctx.current_cert.subject}"
end
unless is_ok
depth = ctx.error_depth
code = ctx.error
msg = ctx.error_string
STDERR.puts "at depth #{depth} - #{code}: #{msg}" if $DEBUG
end
is_ok
end
end # class MiqVimClientBase