Class: VdlConnection

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

Overview

class VixDiskLib

Constant Summary collapse

MAX_DISK_WARN =
9

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connect_parms, vddk) ⇒ VdlConnection

Returns a new instance of VdlConnection.



91
92
93
94
95
96
97
98
99
100
# File 'lib/VMwareWebService/VixDiskLib/vdl_wrapper.rb', line 91

def initialize(connect_parms, vddk)
  @serverName     = connect_parms[:server_name]
  @logger         = Logger.new($stdout)

  @logger.info "VdlConnection.initialize: #{@serverName}"
  @vdl_connection  = VixDiskLibApi.connect(connect_parms)
  @disks           = []
  @disk_lock       = Sync.new
  @vddk            = vddk
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



87
88
89
# File 'lib/VMwareWebService/VixDiskLib/vdl_wrapper.rb', line 87

def logger
  @logger
end

#serverNameObject (readonly)

Returns the value of attribute serverName.



87
88
89
# File 'lib/VMwareWebService/VixDiskLib/vdl_wrapper.rb', line 87

def serverName
  @serverName
end

#vddkObject (readonly)

Returns the value of attribute vddk.



87
88
89
# File 'lib/VMwareWebService/VixDiskLib/vdl_wrapper.rb', line 87

def vddk
  @vddk
end

#vdl_connectionObject (readonly)

Returns the value of attribute vdl_connection.



87
88
89
# File 'lib/VMwareWebService/VixDiskLib/vdl_wrapper.rb', line 87

def vdl_connection
  @vdl_connection
end

Instance Method Details

#__close_disk__(diskObj) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/VMwareWebService/VixDiskLib/vdl_wrapper.rb', line 146

def __close_disk__(diskObj)
  @disk_lock.sync_lock(:EX) if (unlock = !@disk_lock.sync_exclusive?)

  @vddk.running = true
  VixDiskLibApi.close(diskObj.handle)
  if !@vdl_connection
    logger.warn "VDLConnection.disconnect: server: #{@serverName} not connected"
  else
    @disks.delete(diskObj)
    nd = VdlWrapper.dec_server_disk_count
    logger.warn "VdlConnection.__close_disk__: #{@serverName} open disks = #{nd}"
  end
ensure
  @disk_lock.sync_unlock if unlock
end

#disconnectObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/VMwareWebService/VixDiskLib/vdl_wrapper.rb', line 102

def disconnect
  logger.info "VdlConnection.disconnect: #{@serverName}"
  @disk_lock.synchronize(:EX) do
    if !@vdl_connection
      logger.warn "VDLConnection.disconnect: server: #{@serverName} not connected"
    else
      __close_disks__
      VdlWrapper.__disconnect__(self)
      @vdl_connection = nil
      @vddk.running = true
      @vddk.shutdown = true
    end
  end
end

#dumpDisksObject



117
118
119
120
121
122
123
124
125
126
# File 'lib/VMwareWebService/VixDiskLib/vdl_wrapper.rb', line 117

def dumpDisks
  raise VixDiskLibError, "VdlConnection.getDisk: server #{@serverName} not connected" unless @vdl_connection
  @vddk.running = true
  @disk_lock.sync_lock(:SH) if (unlock = !@disk_lock.sync_locked?)
  @disks.each do |d|
    logger.warn "    VdlDisk: #{d.path}, opened: #{d.timeStamp}"
  end
ensure
  @disk_lock.sync_unlock if unlock
end

#getDisk(path, flags) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/VMwareWebService/VixDiskLib/vdl_wrapper.rb', line 128

def getDisk(path, flags)
  @disk_lock.synchronize(:EX) do
    raise VixDiskLibError, "VdlConnection.getDisk: server #{@serverName} not connected" unless @vdl_connection
    @vddk.running = true
    disk = VdlDisk.new(self, path, flags)
    @disks << disk
    nd = VdlWrapper.inc_server_disk_count
    logger.info "VdlConnection.getDisk: #{@serverName} open disks = #{nd}"
    if nd >= MAX_DISK_WARN
      logger.warn "VdlConnection::getDisk: connection to server: #{@serverName}"
      logger.warn "VdlConnection::getDisk: number of open disks = #{nd}"
      logger.warn "VdlConnection::getDisk: subsequent open calls may fail"
      VdlWrapper.dumpDisks(@serverName)
    end
    return disk
  end
end