-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathMiqVimVdlMod.rb
54 lines (48 loc) · 2.2 KB
/
MiqVimVdlMod.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
module MiqVimVdlConnectionMod
#
# Return a VixDiskLib connection object for the same server that VIM is connected to.
#
def vdlConnection
require 'VMwareWebService/VixDiskLib/VixDiskLib'
VixDiskLib.init(->(s) { logger.info "VMware(VixDiskLib): #{s}" },
->(s) { logger.warn "VMware(VixDiskLib): #{s}" },
->(s) { logger.error "VMware(VixDiskLib): #{s}" })
$log.info "MiqVimVdlConnectionMod.vdlConnection: server - #{@server}"
VixDiskLib.connect(:serverName => server,
:port => 902,
:credType => VixDiskLib_raw::VIXDISKLIB_CRED_UID,
:userName => username,
:password => password)
end
def closeVdlConnection(connection)
logger.info "MiqVimMod.closeVdlConnection: #{connection.serverName}"
connection.disconnect
end
end # module MiqVimVdlConnectionMod
module MiqVimVdlVcConnectionMod
#
# Return a VixDiskLib connection object for the VC server that VIM is connected to.
# The connection is specific to this VM, and should be closed by the caller when it
# has finished accessing the VM's disk files.
#
def vdlVcConnection
require 'VMwareWebService/VixDiskLib/VixDiskLib'
VixDiskLib.init(->(s) { logger.info "VMware(VixDiskLib): #{s}" },
->(s) { logger.warn "VMware(VixDiskLib): #{s}" },
->(s) { logger.error "VMware(VixDiskLib): #{s}" })
$log.info "MiqVimVdlVcConnectionMod.vdlVcConnection: server - #{invObj.server}"
thumb_print = if invObj.isVirtualCenter?
VcenterThumbPrint.new(invObj.server)
else
ESXThumbPrint.new(invObj.server, invObj.username, invObj.password)
end
sha1 = thumb_print.to_sha1
VixDiskLib.connect(:serverName => invObj.server,
:vmxSpec => vixVmxSpec,
:thumbPrint => sha1,
:port => 902,
:credType => VixDiskLib_raw::VIXDISKLIB_CRED_UID,
:userName => invObj.username,
:password => invObj.password)
end
end # module MiqVimVdlVcConnectionMod