Class: VDDKFactory

Inherits:
Object
  • Object
show all
Includes:
DRb::DRbUndumped
Defined in:
lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVDDKFactory

Returns a new instance of VDDKFactory.



20
21
22
23
24
25
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 20

def initialize
  @shutdown = nil
  @started = nil
  @running = nil
  @logger  = Logger.new($stdout)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



18
19
20
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 18

def logger
  @logger
end

#runningObject

Returns the value of attribute running.



17
18
19
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 17

def running
  @running
end

#shutdownObject

Returns the value of attribute shutdown.



16
17
18
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 16

def shutdown
  @shutdown
end

Instance Method Details

#connect(connect_parms) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 32

def connect(connect_parms)
  load_error = FFI::VixDiskLib::API.load_error
  unless load_error.nil?
    @shutdown = true
    raise VixDiskLibError, load_error
  end
  @running = true
  VdlWrapper.connect(connect_parms)
end

#initObject



27
28
29
30
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 27

def init
  VdlWrapper.init
  @started = true
end

#shut_down_drbObject



42
43
44
45
46
47
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 42

def shut_down_drb
  thr = DRb.thread
  DRb.stop_service
  thr.join unless thr.nil?
  logger.info "Finished shutting down DRb"
end

#shut_down_service(msg) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 49

def shut_down_service(msg)
  logger.info msg.to_s
  VdlWrapper.__exit__ if @started
  @running = true
  logger.info "VdlWrapper.__exit__ finished"
  shut_down_drb
end

#wait_for_status(status, secs_to_wait) ⇒ Object

Wait for the client to call our init function. If it isn’t called within “max_secs_to_wait” seconds, shut down the service.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 61

def wait_for_status(status, secs_to_wait)
  start_time = Time.now
  sleep_secs = 2
  until (status == "started") ? @started : @running
    sleep sleep_secs
    #
    # Specifically check the shutdown flag in case we've been asked
    # to wait for a different flag.
    #
    break if @shutdown
    #
    # Check if we've waited the specified number of seconds.
    #
    current_time = Time.now
    if current_time - start_time > secs_to_wait
      elapsed = current_time - start_time
      msg = "ERROR: Maximum time for a call to VixDiskLib has been reached after #{elapsed} seconds."
      msg += "\nShutting down VixDiskLib Service"
      @shutdown = true
      shut_down_service(msg)
      raise VixDiskLibError, msg
    end
  end
end