forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MiqVimClientBase.rb
102 lines (81 loc) · 2.36 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
90
91
92
93
94
95
96
97
98
99
100
101
102
$:.push(File.dirname(__FILE__))
require 'pathname'
require Pathname.new(__dir__).join("../util/extensions/miq-uri")
require 'sync'
require 'VimService'
# require 'profile'
class MiqVimClientBase < VimService
@@receiveTimeout = 120
attr_reader :server, :username, :password, :connId
def initialize(server, username, password)
@server = server
@username = username
@password = password
@connId = "#{@server}_#{@username}"
@receiveTimeout = @@receiveTimeout
on_http_client_init do |http_client, headers|
http_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
http_client.ssl_config.verify_callback = method(:verify_callback).to_proc
http_client.receive_timeout = @receiveTimeout
end
on_log_header { |msg| $vim_log.info msg }
on_log_body { |msg| $vim_log.debug msg if $miq_wiredump }
super(:uri => sdk_uri, :version => 1)
@connected = false
@connLock = Sync.new
end
def sdk_uri
URI::HTTPS.build(:host => server, :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
$vim_log.debug "#{self.class.name}.connect(#{@connId}): #{$PROGRAM_NAME} #{ARGV.join(' ')}" if $vim_log.debug?
@connLock.synchronize(:EX) do
return if @connected
login(@sic.sessionManager, @username, @password)
@connected = true
end
end
def disconnect
$vim_log.debug "#{self.class.name}.disconnect(#{@connId}): #{$PROGRAM_NAME} #{ARGV.join(' ')}" if $vim_log.debug?
@connLock.synchronize(:EX) do
return if !@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
if !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