vmware_web_service 2.0.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/VMwareWebService/MiqHostDatastoreSystem.rb +5 -1
- data/lib/VMwareWebService/MiqVim.rb +80 -56
- data/lib/VMwareWebService/MiqVimClientBase.rb +11 -10
- data/lib/VMwareWebService/MiqVimCluster.rb +6 -2
- data/lib/VMwareWebService/MiqVimDataStore.rb +9 -6
- data/lib/VMwareWebService/MiqVimDump.rb +1 -1
- data/lib/VMwareWebService/MiqVimEventHistoryCollector.rb +5 -1
- data/lib/VMwareWebService/MiqVimEventMonitor.rb +22 -20
- data/lib/VMwareWebService/MiqVimFolder.rb +15 -11
- data/lib/VMwareWebService/MiqVimHost.rb +15 -13
- data/lib/VMwareWebService/MiqVimInventory.rb +78 -79
- data/lib/VMwareWebService/MiqVimPerfHistory.rb +13 -10
- data/lib/VMwareWebService/MiqVimUpdate.rb +50 -50
- data/lib/VMwareWebService/MiqVimVdlMod.rb +7 -7
- data/lib/VMwareWebService/MiqVimVm.rb +102 -101
- data/lib/VMwareWebService/VimService.rb +5 -2
- data/lib/VMwareWebService/VixDiskLib/VixDiskLib.rb +15 -7
- data/lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb +15 -15
- data/lib/VMwareWebService/VixDiskLib/vdl_wrapper.rb +26 -27
- data/lib/VMwareWebService/exception.rb +0 -2
- data/lib/VMwareWebService/logging.rb +16 -0
- data/lib/VMwareWebService/version.rb +1 -1
- data/lib/vmware_web_service.rb +2 -0
- metadata +15 -48
- data/lib/VMwareWebService/DMiqVim.rb +0 -95
- data/lib/VMwareWebService/DMiqVimSync.rb +0 -45
- data/lib/VMwareWebService/MiqVimBroker.rb +0 -581
- data/lib/VMwareWebService/MiqVimBrokerMods.rb +0 -222
- data/lib/VMwareWebService/MiqVimCoreUpdater.rb +0 -269
- data/lib/VMwareWebService/miq_fault_tolerant_vim.rb +0 -246
| @@ -1,581 +0,0 @@ | |
| 1 | 
            -
            require 'drb'
         | 
| 2 | 
            -
            require 'drb/acl'
         | 
| 3 | 
            -
            require 'sync'
         | 
| 4 | 
            -
            require 'tmpdir'
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            require 'VMwareWebService/MiqVimInventory'
         | 
| 7 | 
            -
            require 'VMwareWebService/VimTypes'
         | 
| 8 | 
            -
             | 
| 9 | 
            -
            class MiqVimBroker
         | 
| 10 | 
            -
              class VimBrokerIdConv < DRb::DRbIdConv
         | 
| 11 | 
            -
                def to_obj(ref)
         | 
| 12 | 
            -
                  obj = super(ref)
         | 
| 13 | 
            -
                  if obj.respond_to?(:connectionRemoved?) && obj.connectionRemoved?
         | 
| 14 | 
            -
                    $vim_log.info "VimBrokerIdConv: #{obj.class.name} - connection removed"
         | 
| 15 | 
            -
                    raise RangeError, "#{ref} is recycled object"
         | 
| 16 | 
            -
                  end
         | 
| 17 | 
            -
                  obj
         | 
| 18 | 
            -
                end
         | 
| 19 | 
            -
              end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
              attr_reader :shuttingDown
         | 
| 22 | 
            -
             | 
| 23 | 
            -
              MB = 1048576
         | 
| 24 | 
            -
              DRb::DRbServer.default_load_limit(100 * MB)
         | 
| 25 | 
            -
             | 
| 26 | 
            -
              @@preLoad   = false
         | 
| 27 | 
            -
              @@debugUpdates  = false
         | 
| 28 | 
            -
              @@classModed  = false
         | 
| 29 | 
            -
              @@notifyMethod  = nil
         | 
| 30 | 
            -
              @@updateDelay = nil
         | 
| 31 | 
            -
              @@cacheScope  = :cache_scope_full
         | 
| 32 | 
            -
              @@selectorHash  = {}
         | 
| 33 | 
            -
              @@maxWait    = 60
         | 
| 34 | 
            -
              @@maxObjects = 250
         | 
| 35 | 
            -
             | 
| 36 | 
            -
              def initialize(mode = :client, uri = nil)
         | 
| 37 | 
            -
                if mode == :client
         | 
| 38 | 
            -
                  require 'rubygems'
         | 
| 39 | 
            -
                  require 'httpclient'  # needed for exception classes
         | 
| 40 | 
            -
                  require 'VMwareWebService/MiqVimDump'
         | 
| 41 | 
            -
                  require 'VMwareWebService/MiqVimVdlMod'
         | 
| 42 | 
            -
                  #
         | 
| 43 | 
            -
                  # Modify the meta-class of DRb::DRbObject
         | 
| 44 | 
            -
                  # so we can alias class methods
         | 
| 45 | 
            -
                  #
         | 
| 46 | 
            -
                  unless @@classModed
         | 
| 47 | 
            -
                    class <<DRb::DRbObject
         | 
| 48 | 
            -
                      alias_method :new_with_original, :new_with
         | 
| 49 | 
            -
                      def new_with(uri, ref)
         | 
| 50 | 
            -
                        obj = new_with_original(uri, ref)
         | 
| 51 | 
            -
                        obj.extend(MiqVimVdlVcConnectionMod) if obj.respond_to?(:vdlVcConnection)
         | 
| 52 | 
            -
                        obj.registerBrokerObj($$) if obj.respond_to?(:registerBrokerObj)
         | 
| 53 | 
            -
                        (obj)
         | 
| 54 | 
            -
                      end
         | 
| 55 | 
            -
                    end
         | 
| 56 | 
            -
             | 
| 57 | 
            -
                    DRb.instance_variable_set(:@mutex, Sync.new)
         | 
| 58 | 
            -
                    DRb::DRbConn.instance_variable_set(:@mutex, Sync.new)
         | 
| 59 | 
            -
                    @@classModed = true
         | 
| 60 | 
            -
                  end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                  @mode = :client
         | 
| 63 | 
            -
             | 
| 64 | 
            -
                  # start DRb service if it hasn't been started before
         | 
| 65 | 
            -
                  begin
         | 
| 66 | 
            -
                    DRb.current_server
         | 
| 67 | 
            -
                  rescue DRb::DRbServerNotFound
         | 
| 68 | 
            -
                    DRb.start_service
         | 
| 69 | 
            -
                  end
         | 
| 70 | 
            -
             | 
| 71 | 
            -
                  @broker = DRbObject.new(nil, uri)
         | 
| 72 | 
            -
                elsif mode == :server
         | 
| 73 | 
            -
                  require 'timeout'
         | 
| 74 | 
            -
                  require 'VMwareWebService/broker_timeout'
         | 
| 75 | 
            -
             | 
| 76 | 
            -
                  unless @@classModed
         | 
| 77 | 
            -
                    DRb.instance_variable_set(:@mutex, sync_for_drb)
         | 
| 78 | 
            -
                    DRb::DRbConn.instance_variable_set(:@mutex, sync_for_drb_drbconn)
         | 
| 79 | 
            -
                  end
         | 
| 80 | 
            -
                  @@classModed = true
         | 
| 81 | 
            -
             | 
| 82 | 
            -
                  require 'VMwareWebService/MiqVimBrokerMods' # only needed by the server
         | 
| 83 | 
            -
                  @mode = :server
         | 
| 84 | 
            -
                  @shuttingDown = false
         | 
| 85 | 
            -
             | 
| 86 | 
            -
                  @connectionHash = {}
         | 
| 87 | 
            -
                  @lockHash = {}        # Protects individual @connectionHash entries
         | 
| 88 | 
            -
                  @connectionLock = connection_lock # Protects @lockHash
         | 
| 89 | 
            -
             | 
| 90 | 
            -
                  @configLock   = config_lock
         | 
| 91 | 
            -
                  @selectorHash = @@selectorHash
         | 
| 92 | 
            -
                  @cacheScope   = @@cacheScope
         | 
| 93 | 
            -
             | 
| 94 | 
            -
                  acl = ACL.new(%w( deny all allow 127.0.0.1/32 ))
         | 
| 95 | 
            -
                  DRb.install_acl(acl)
         | 
| 96 | 
            -
             | 
| 97 | 
            -
                  Dir::Tmpname.create('MiqVimBroker', nil) do |path|
         | 
| 98 | 
            -
                    DRb.start_service("drbunix://#{path}", self, :idconv => VimBrokerIdConv.new)
         | 
| 99 | 
            -
                    FileUtils.chmod(0o750, path)
         | 
| 100 | 
            -
                  end
         | 
| 101 | 
            -
                else
         | 
| 102 | 
            -
                  raise "MiqVimBroker: unrecognized mode #{mode}"
         | 
| 103 | 
            -
                end
         | 
| 104 | 
            -
              end
         | 
| 105 | 
            -
             | 
| 106 | 
            -
              def connection_lock
         | 
| 107 | 
            -
                Sync.new
         | 
| 108 | 
            -
              end
         | 
| 109 | 
            -
             | 
| 110 | 
            -
              def config_lock
         | 
| 111 | 
            -
                Sync.new
         | 
| 112 | 
            -
              end
         | 
| 113 | 
            -
             | 
| 114 | 
            -
              def sync_for_lock_hash(_key)
         | 
| 115 | 
            -
                Sync.new
         | 
| 116 | 
            -
              end
         | 
| 117 | 
            -
             | 
| 118 | 
            -
              def sync_for_drb_drbconn
         | 
| 119 | 
            -
                Sync.new
         | 
| 120 | 
            -
              end
         | 
| 121 | 
            -
             | 
| 122 | 
            -
              def sync_for_drb
         | 
| 123 | 
            -
                Sync.new
         | 
| 124 | 
            -
              end
         | 
| 125 | 
            -
             | 
| 126 | 
            -
              def self.cacheScope
         | 
| 127 | 
            -
                @@cacheScope
         | 
| 128 | 
            -
              end
         | 
| 129 | 
            -
             | 
| 130 | 
            -
              def self.cacheScope=(val)
         | 
| 131 | 
            -
                @@cacheScope = val
         | 
| 132 | 
            -
              end
         | 
| 133 | 
            -
             | 
| 134 | 
            -
              attr_reader :cacheScope
         | 
| 135 | 
            -
             | 
| 136 | 
            -
              attr_writer :cacheScope
         | 
| 137 | 
            -
             | 
| 138 | 
            -
              #
         | 
| 139 | 
            -
              # The setSelector() and removeSelector() class methods, set the Selector specs that will be inherited
         | 
| 140 | 
            -
              # by all subsequent MiqVimBroker instances.
         | 
| 141 | 
            -
              #
         | 
| 142 | 
            -
              # Should only be called on the server-side.
         | 
| 143 | 
            -
              #
         | 
| 144 | 
            -
              def self.setSelector(selSpec)
         | 
| 145 | 
            -
                raise "MiqVimBroker.setSelector: selSpec must be a hash, received #{selSpec.class}" unless selSpec.kind_of?(Hash)
         | 
| 146 | 
            -
                selSpec.each_key do |k|
         | 
| 147 | 
            -
                  raise "MiqVimBroker.setSelector: selSpec keys must be symbols, received #{k.class}" unless k.kind_of?(Symbol)
         | 
| 148 | 
            -
                end
         | 
| 149 | 
            -
                ov = nil
         | 
| 150 | 
            -
                selSpec.each_value do |v|
         | 
| 151 | 
            -
                  if v.kind_of?(Array)
         | 
| 152 | 
            -
                    v.each do |vv|
         | 
| 153 | 
            -
                      unless vv.kind_of?(String)
         | 
| 154 | 
            -
                        ov = vv
         | 
| 155 | 
            -
                        break
         | 
| 156 | 
            -
                      end
         | 
| 157 | 
            -
                    end
         | 
| 158 | 
            -
                  else
         | 
| 159 | 
            -
                    ov = v unless v.kind_of?(String)
         | 
| 160 | 
            -
                  end
         | 
| 161 | 
            -
                  raise "MiqVimBroker.setSelector: selSpec values must be strings or arrays of strings, received #{ov.class}" unless ov.nil?
         | 
| 162 | 
            -
                end
         | 
| 163 | 
            -
                @@selectorHash.merge!(selSpec)
         | 
| 164 | 
            -
              end
         | 
| 165 | 
            -
             | 
| 166 | 
            -
              def self.removeSelector(selName)
         | 
| 167 | 
            -
                remKeys = nil
         | 
| 168 | 
            -
                if selName.kind_of?(Symbol)
         | 
| 169 | 
            -
                  remKeys = [selName]
         | 
| 170 | 
            -
                elsif selName.kind_of?(Hash)
         | 
| 171 | 
            -
                  remKeys = selName.keys
         | 
| 172 | 
            -
                elsif selName.kind_of?(Array)
         | 
| 173 | 
            -
                  remKeys = selName
         | 
| 174 | 
            -
                else
         | 
| 175 | 
            -
                  raise "MiqVimBroker.removeSelector: selName must be a symbol, hash or array, received #{selName.class}"
         | 
| 176 | 
            -
                end
         | 
| 177 | 
            -
                remKeys.each do |rk|
         | 
| 178 | 
            -
                  raise "MiqVimBroker.removeSelector: keys must be symbols, received #{rk.class}" unless rk.kind_of?(Symbol)
         | 
| 179 | 
            -
                end
         | 
| 180 | 
            -
             | 
| 181 | 
            -
                remKeys.each do |rk|
         | 
| 182 | 
            -
                  @@selectorHash.delete(rk)
         | 
| 183 | 
            -
                end
         | 
| 184 | 
            -
              end
         | 
| 185 | 
            -
             | 
| 186 | 
            -
              #
         | 
| 187 | 
            -
              # The setSelector() and removeSelector() instance methods, set the Selector specs that will be inherited
         | 
| 188 | 
            -
              # by all subsequent connections.
         | 
| 189 | 
            -
              #
         | 
| 190 | 
            -
              def setSelector(selSpec)
         | 
| 191 | 
            -
                if @mode == :client
         | 
| 192 | 
            -
                  return @broker.setSelector(selSpec)
         | 
| 193 | 
            -
                end
         | 
| 194 | 
            -
             | 
| 195 | 
            -
                raise "setSelector: selSpec must be a hash, received #{selSpec.class}" unless selSpec.kind_of?(Hash)
         | 
| 196 | 
            -
                selSpec.each_key do |k|
         | 
| 197 | 
            -
                  raise "setSelector: selSpec keys must be symbols, received #{k.class}" unless k.kind_of?(Symbol)
         | 
| 198 | 
            -
                end
         | 
| 199 | 
            -
                ov = nil
         | 
| 200 | 
            -
                selSpec.each_value do |v|
         | 
| 201 | 
            -
                  if v.kind_of?(Array)
         | 
| 202 | 
            -
                    v.each do |vv|
         | 
| 203 | 
            -
                      unless vv.kind_of?(String)
         | 
| 204 | 
            -
                        ov = vv
         | 
| 205 | 
            -
                        break
         | 
| 206 | 
            -
                      end
         | 
| 207 | 
            -
                    end
         | 
| 208 | 
            -
                  else
         | 
| 209 | 
            -
                    ov = v unless v.kind_of?(String)
         | 
| 210 | 
            -
                  end
         | 
| 211 | 
            -
                  raise "setSelector: selSpec values must be strings or arrays of strings, received #{ov.class}" unless ov.nil?
         | 
| 212 | 
            -
                end
         | 
| 213 | 
            -
             | 
| 214 | 
            -
                @configLock.synchronize(:EX) do
         | 
| 215 | 
            -
                  @selectorHash.merge!(selSpec)
         | 
| 216 | 
            -
                end
         | 
| 217 | 
            -
              end
         | 
| 218 | 
            -
             | 
| 219 | 
            -
              def removeSelector(selName)
         | 
| 220 | 
            -
                if @mode == :client
         | 
| 221 | 
            -
                  return @broker.removeSelector(selName)
         | 
| 222 | 
            -
                end
         | 
| 223 | 
            -
             | 
| 224 | 
            -
                remKeys = nil
         | 
| 225 | 
            -
                if selName.kind_of?(Symbol)
         | 
| 226 | 
            -
                  remKeys = [selName]
         | 
| 227 | 
            -
                elsif selName.kind_of?(Hash)
         | 
| 228 | 
            -
                  remKeys = selName.keys
         | 
| 229 | 
            -
                elsif selName.kind_of?(Array)
         | 
| 230 | 
            -
                  remKeys = selName
         | 
| 231 | 
            -
                else
         | 
| 232 | 
            -
                  raise "removeSelector: selName must be a symbol, hash or array, received #{selName.class}"
         | 
| 233 | 
            -
                end
         | 
| 234 | 
            -
                remKeys.each do |rk|
         | 
| 235 | 
            -
                  raise "removeSelector: keys must be symbols, received #{rk.class}" unless rk.kind_of?(Symbol)
         | 
| 236 | 
            -
                end
         | 
| 237 | 
            -
             | 
| 238 | 
            -
                @configLock.synchronize(:EX) do
         | 
| 239 | 
            -
                  remKeys.each do |rk|
         | 
| 240 | 
            -
                    @selectorHash.delete(rk)
         | 
| 241 | 
            -
                  end
         | 
| 242 | 
            -
                end
         | 
| 243 | 
            -
              end
         | 
| 244 | 
            -
             | 
| 245 | 
            -
              def self.preLoad=(val)
         | 
| 246 | 
            -
                @@preLoad = val
         | 
| 247 | 
            -
              end
         | 
| 248 | 
            -
             | 
| 249 | 
            -
              def self.preLoad
         | 
| 250 | 
            -
                @@preLoad
         | 
| 251 | 
            -
              end
         | 
| 252 | 
            -
             | 
| 253 | 
            -
              def self.debugUpdates=(val)
         | 
| 254 | 
            -
                @@debugUpdates = val
         | 
| 255 | 
            -
              end
         | 
| 256 | 
            -
             | 
| 257 | 
            -
              def self.debugUpdates
         | 
| 258 | 
            -
                @@debugUpdates
         | 
| 259 | 
            -
              end
         | 
| 260 | 
            -
             | 
| 261 | 
            -
              #
         | 
| 262 | 
            -
              # Instance method changes the debugUpdates value of existing connections.
         | 
| 263 | 
            -
              #
         | 
| 264 | 
            -
              def debugUpdates=(val)
         | 
| 265 | 
            -
                return if @mode == :client
         | 
| 266 | 
            -
                @connectionHash.keys.each do |key|
         | 
| 267 | 
            -
                  @lockHash[key].synchronize(:SH) do
         | 
| 268 | 
            -
                    next if (vim = @connectionHash[key]).nil?
         | 
| 269 | 
            -
                    vim.debugUpdates = val
         | 
| 270 | 
            -
                  end
         | 
| 271 | 
            -
                end
         | 
| 272 | 
            -
              end
         | 
| 273 | 
            -
             | 
| 274 | 
            -
              def self.notifyMethod=(val)
         | 
| 275 | 
            -
                @@notifyMethod = val
         | 
| 276 | 
            -
              end
         | 
| 277 | 
            -
             | 
| 278 | 
            -
              def self.notifyMethod
         | 
| 279 | 
            -
                @@notifyMethod
         | 
| 280 | 
            -
              end
         | 
| 281 | 
            -
             | 
| 282 | 
            -
              #
         | 
| 283 | 
            -
              # Instance method changes the notifyMethod value of existing connections.
         | 
| 284 | 
            -
              #
         | 
| 285 | 
            -
              def notifyMethod=(val)
         | 
| 286 | 
            -
                return if @mode == :client
         | 
| 287 | 
            -
                @connectionHash.keys.each do |key|
         | 
| 288 | 
            -
                  @lockHash[key].synchronize(:SH) do
         | 
| 289 | 
            -
                    next if (vim = @connectionHash[key]).nil?
         | 
| 290 | 
            -
                    vim.notifyMethod = val
         | 
| 291 | 
            -
                  end
         | 
| 292 | 
            -
                end
         | 
| 293 | 
            -
              end
         | 
| 294 | 
            -
             | 
| 295 | 
            -
              def self.updateDelay=(val)
         | 
| 296 | 
            -
                @@updateDelay = val
         | 
| 297 | 
            -
              end
         | 
| 298 | 
            -
             | 
| 299 | 
            -
              def self.updateDelay
         | 
| 300 | 
            -
                @@updateDelay
         | 
| 301 | 
            -
              end
         | 
| 302 | 
            -
             | 
| 303 | 
            -
              #
         | 
| 304 | 
            -
              # Instance method changes the updateDelay value of existing connections.
         | 
| 305 | 
            -
              #
         | 
| 306 | 
            -
              def updateDelay=(val)
         | 
| 307 | 
            -
                return if @mode == :client
         | 
| 308 | 
            -
                @connectionHash.keys.each do |key|
         | 
| 309 | 
            -
                  @lockHash[key].synchronize(:SH) do
         | 
| 310 | 
            -
                    next if (vim = @connectionHash[key]).nil?
         | 
| 311 | 
            -
                    vim.updateDelay = val
         | 
| 312 | 
            -
                  end
         | 
| 313 | 
            -
                end
         | 
| 314 | 
            -
              end
         | 
| 315 | 
            -
             | 
| 316 | 
            -
              def self.maxWait=(val)
         | 
| 317 | 
            -
                @@maxWait = val
         | 
| 318 | 
            -
              end
         | 
| 319 | 
            -
             | 
| 320 | 
            -
              def self.maxWait
         | 
| 321 | 
            -
                @@maxWait
         | 
| 322 | 
            -
              end
         | 
| 323 | 
            -
             | 
| 324 | 
            -
              def self.maxObjects=(val)
         | 
| 325 | 
            -
                @@maxObjects = val
         | 
| 326 | 
            -
              end
         | 
| 327 | 
            -
             | 
| 328 | 
            -
              def self.maxObjects
         | 
| 329 | 
            -
                @@maxObjects
         | 
| 330 | 
            -
              end
         | 
| 331 | 
            -
             | 
| 332 | 
            -
              def releaseSession(sessionId)
         | 
| 333 | 
            -
                if @mode == :client
         | 
| 334 | 
            -
                  $vim_log.info "Client releaseSession: #{sessionId}"
         | 
| 335 | 
            -
                  @broker.releaseSession(sessionId)
         | 
| 336 | 
            -
                else
         | 
| 337 | 
            -
                  $vim_log.info "Server releaseSession: #{sessionId}"
         | 
| 338 | 
            -
                  $miqBrokerObjRegistry[sessionId].dup.each(&:release)
         | 
| 339 | 
            -
                end
         | 
| 340 | 
            -
              end
         | 
| 341 | 
            -
             | 
| 342 | 
            -
              def objectCounts
         | 
| 343 | 
            -
                if @mode == :client
         | 
| 344 | 
            -
                  @broker.objectCounts
         | 
| 345 | 
            -
                else
         | 
| 346 | 
            -
                  $miqBrokerObjRegistryLock.synchronize(:SH) do
         | 
| 347 | 
            -
                    return $miqBrokerObjCounts.dup
         | 
| 348 | 
            -
                  end
         | 
| 349 | 
            -
                end
         | 
| 350 | 
            -
              end
         | 
| 351 | 
            -
             | 
| 352 | 
            -
              def self.connectionKey(server, username)
         | 
| 353 | 
            -
                "#{server}_#{username}"
         | 
| 354 | 
            -
              end
         | 
| 355 | 
            -
             | 
| 356 | 
            -
              def connectionKey(server, username)
         | 
| 357 | 
            -
                self.class.connectionKey(server, username)
         | 
| 358 | 
            -
              end
         | 
| 359 | 
            -
             | 
| 360 | 
            -
              def lockHash(key)
         | 
| 361 | 
            -
                @connectionLock.synchronize(:EX) do
         | 
| 362 | 
            -
                  raise "MiqVimBroker is shutting down" if @shuttingDown
         | 
| 363 | 
            -
                  #
         | 
| 364 | 
            -
                  # Once set, @lockHash[key] doesn't change.
         | 
| 365 | 
            -
                  #
         | 
| 366 | 
            -
                  @lockHash[key] ||= sync_for_lock_hash(key)
         | 
| 367 | 
            -
                end
         | 
| 368 | 
            -
              end
         | 
| 369 | 
            -
             | 
| 370 | 
            -
              def connSync(mode, server, username, &block)
         | 
| 371 | 
            -
                key = connectionKey(server, username)
         | 
| 372 | 
            -
                lock = lockHash(key)
         | 
| 373 | 
            -
             | 
| 374 | 
            -
                begin
         | 
| 375 | 
            -
                  lock.sync_lock(mode)
         | 
| 376 | 
            -
                  if block.arity < 1
         | 
| 377 | 
            -
                    block.call
         | 
| 378 | 
            -
                  elsif block.arity == 1
         | 
| 379 | 
            -
                    block.call(key)
         | 
| 380 | 
            -
                  elsif block.arity == 2
         | 
| 381 | 
            -
                    block.call(key, @connectionHash[key])
         | 
| 382 | 
            -
                  else
         | 
| 383 | 
            -
                    raise "MiqVimBroker.connSync: unexpected number of block args: #{block.arity}"
         | 
| 384 | 
            -
                  end
         | 
| 385 | 
            -
                ensure
         | 
| 386 | 
            -
                  lock.sync_unlock
         | 
| 387 | 
            -
                end
         | 
| 388 | 
            -
              end
         | 
| 389 | 
            -
             | 
| 390 | 
            -
              def connTrySync(mode, server, username, &block)
         | 
| 391 | 
            -
                key = connectionKey(server, username)
         | 
| 392 | 
            -
                lock = lockHash(key)
         | 
| 393 | 
            -
             | 
| 394 | 
            -
                begin
         | 
| 395 | 
            -
                  locked = lock.sync_try_lock(mode)
         | 
| 396 | 
            -
                  return unless locked
         | 
| 397 | 
            -
             | 
| 398 | 
            -
                  if block.arity < 1
         | 
| 399 | 
            -
                    block.call
         | 
| 400 | 
            -
                  elsif block.arity == 1
         | 
| 401 | 
            -
                    block.call(key)
         | 
| 402 | 
            -
                  elsif block.arity == 2
         | 
| 403 | 
            -
                    block.call(key, @connectionHash[key])
         | 
| 404 | 
            -
                  else
         | 
| 405 | 
            -
                    raise "MiqVimBroker.connTrySync: unexpected number of block args: #{block.arity}"
         | 
| 406 | 
            -
                  end
         | 
| 407 | 
            -
                ensure
         | 
| 408 | 
            -
                  lock.sync_unlock if locked
         | 
| 409 | 
            -
                end
         | 
| 410 | 
            -
              end
         | 
| 411 | 
            -
             | 
| 412 | 
            -
              def getMiqVim(server, username, password)
         | 
| 413 | 
            -
                if @mode == :client
         | 
| 414 | 
            -
                  vim = @broker.getMiqVim(server, username, password)
         | 
| 415 | 
            -
                  vim.extend(MiqVimDump)
         | 
| 416 | 
            -
                  vim.extend(MiqVimVdlConnectionMod)
         | 
| 417 | 
            -
                  return(vim)
         | 
| 418 | 
            -
                else # :server
         | 
| 419 | 
            -
                  connSync(:EX, server, username) do |key, vim|
         | 
| 420 | 
            -
                    if vim
         | 
| 421 | 
            -
                      $vim_log.info "MiqVimBroker.getMiqVim: found connection for #{key}"
         | 
| 422 | 
            -
                      if vim.isAlive?
         | 
| 423 | 
            -
                        $vim_log.info "MiqVimBroker.getMiqVim: returning existing connection for #{key}"
         | 
| 424 | 
            -
                        return(vim)
         | 
| 425 | 
            -
                      end
         | 
| 426 | 
            -
                      $vim_log.info "MiqVimBroker.getMiqVim: existing connection for #{key} not alive"
         | 
| 427 | 
            -
                      removeMiqVimSS(key, vim)
         | 
| 428 | 
            -
                    end
         | 
| 429 | 
            -
                    begin
         | 
| 430 | 
            -
                      vim = DMiqVim.new(server.untaint, username, password, self, @@preLoad, @@debugUpdates, @@notifyMethod, @cacheScope, @@maxWait, @@maxObjects)
         | 
| 431 | 
            -
                      vim.updateDelay = @@updateDelay if @@updateDelay
         | 
| 432 | 
            -
                      vim.setSelector(@selectorHash) unless @selectorHash.empty?
         | 
| 433 | 
            -
                      $vim_log.info "MiqVimBroker.getMiqVim: returning new connection for #{key}"
         | 
| 434 | 
            -
                      @connectionHash[key] = vim
         | 
| 435 | 
            -
                      return(vim)
         | 
| 436 | 
            -
                    rescue Exception => err
         | 
| 437 | 
            -
                      $vim_log.error "MiqVimBroker.getMiqVim: failed to create new connection for #{key}"
         | 
| 438 | 
            -
                      $vim_log.error "#{err.class}: #{err}"
         | 
| 439 | 
            -
                      if $vim_log.debug?
         | 
| 440 | 
            -
                        $vim_log.debug "Stack trace START"
         | 
| 441 | 
            -
                        $vim_log.debug err.backtrace.join("\n")
         | 
| 442 | 
            -
                        $vim_log.debug "Stack trace END"
         | 
| 443 | 
            -
                      end
         | 
| 444 | 
            -
                      raise err
         | 
| 445 | 
            -
                    end
         | 
| 446 | 
            -
                  end
         | 
| 447 | 
            -
                end # :server
         | 
| 448 | 
            -
              end
         | 
| 449 | 
            -
             | 
| 450 | 
            -
              def removeMiqVim(server, username)
         | 
| 451 | 
            -
                if @mode == :client
         | 
| 452 | 
            -
                  @broker.removeMiqVim(server, username)
         | 
| 453 | 
            -
                  return
         | 
| 454 | 
            -
                end
         | 
| 455 | 
            -
             | 
| 456 | 
            -
                # server
         | 
| 457 | 
            -
                log_prefix = "MiqVimBroker.removeMiqVim"
         | 
| 458 | 
            -
                $vim_log.info "#{log_prefix}: client request to remove connection (#{server}, #{username})...Starting"
         | 
| 459 | 
            -
                connSync(:EX, server, username) do |key, vim|
         | 
| 460 | 
            -
                  removeMiqVimSS(key, vim)
         | 
| 461 | 
            -
                end
         | 
| 462 | 
            -
                $vim_log.info "#{log_prefix}: client request to remove connection (#{server}, #{username})...Comolete"
         | 
| 463 | 
            -
              end
         | 
| 464 | 
            -
             | 
| 465 | 
            -
              #
         | 
| 466 | 
            -
              # Server-side removal of VIM connection.
         | 
| 467 | 
            -
              # Must be called within a connSync(:EX, server, username) context.
         | 
| 468 | 
            -
              #
         | 
| 469 | 
            -
              def removeMiqVimSS(key, vim)
         | 
| 470 | 
            -
                log_prefix = "MiqVimBroker.removeMiqVimSS"
         | 
| 471 | 
            -
                $vim_log.info "#{log_prefix}: removing connection for #{key}...Starting"
         | 
| 472 | 
            -
             | 
| 473 | 
            -
                if @shuttingDown
         | 
| 474 | 
            -
                  $vim_log.info "#{log_prefix}: not removing connection for #{key} - broker shutting down"
         | 
| 475 | 
            -
                  return
         | 
| 476 | 
            -
                end
         | 
| 477 | 
            -
                if vim.nil?
         | 
| 478 | 
            -
                  $vim_log.info "#{log_prefix}: not removing connection for #{key} - connection not found"
         | 
| 479 | 
            -
                  return
         | 
| 480 | 
            -
                end
         | 
| 481 | 
            -
                if vim.connectionRemoved?
         | 
| 482 | 
            -
                  $vim_log.info "#{log_prefix}: not removing connection for #{key} - connection already removed"
         | 
| 483 | 
            -
                  return
         | 
| 484 | 
            -
                end
         | 
| 485 | 
            -
             | 
| 486 | 
            -
                vim.shutdownConnection
         | 
| 487 | 
            -
                $miqBrokerObjRegistryByConn[key].dup.each(&:release)
         | 
| 488 | 
            -
                @connectionHash.delete(key)
         | 
| 489 | 
            -
                vim.connectionRemoved
         | 
| 490 | 
            -
             | 
| 491 | 
            -
                $vim_log.info "#{log_prefix}: removing connection for #{key}...Complete"
         | 
| 492 | 
            -
              end
         | 
| 493 | 
            -
             | 
| 494 | 
            -
              def shutdown
         | 
| 495 | 
            -
                raise "MiqVimBroker: shutdown cannot be called from client" if @mode == :client
         | 
| 496 | 
            -
                log_prefix = "MiqVimBroker.shutdown"
         | 
| 497 | 
            -
                $vim_log.info "#{log_prefix}...Starting"
         | 
| 498 | 
            -
                @connectionLock.synchronize(:EX) do
         | 
| 499 | 
            -
                  @shuttingDown = true
         | 
| 500 | 
            -
                end
         | 
| 501 | 
            -
                @connectionHash.keys.each do |id|
         | 
| 502 | 
            -
                  @lockHash[id].synchronize(:EX) do
         | 
| 503 | 
            -
                    next if (vim = @connectionHash[id]).nil?
         | 
| 504 | 
            -
                    vim.shutdownConnection
         | 
| 505 | 
            -
                    @connectionHash.delete(id)
         | 
| 506 | 
            -
                    vim.connectionRemoved
         | 
| 507 | 
            -
                  end
         | 
| 508 | 
            -
                end
         | 
| 509 | 
            -
                DRb.stop_service
         | 
| 510 | 
            -
                $vim_log.info "#{log_prefix}...Complete"
         | 
| 511 | 
            -
              end
         | 
| 512 | 
            -
             | 
| 513 | 
            -
              def serverAlive?
         | 
| 514 | 
            -
                if @mode == :client
         | 
| 515 | 
            -
                  begin
         | 
| 516 | 
            -
                    return @broker.serverAlive?
         | 
| 517 | 
            -
                  rescue DRb::DRbConnError
         | 
| 518 | 
            -
                    return false
         | 
| 519 | 
            -
                  end
         | 
| 520 | 
            -
                end
         | 
| 521 | 
            -
                true
         | 
| 522 | 
            -
              end
         | 
| 523 | 
            -
             | 
| 524 | 
            -
              def connectionInfo
         | 
| 525 | 
            -
                return @broker.connectionInfo if @mode == :client
         | 
| 526 | 
            -
             | 
| 527 | 
            -
                # server
         | 
| 528 | 
            -
                ra = []
         | 
| 529 | 
            -
                @connectionHash.keys.each do |key|
         | 
| 530 | 
            -
                  @lockHash[key].synchronize(:SH) do
         | 
| 531 | 
            -
                    next if (vim = @connectionHash[key]).nil?
         | 
| 532 | 
            -
                    ra << [vim.server, vim.username]
         | 
| 533 | 
            -
                  end
         | 
| 534 | 
            -
                end
         | 
| 535 | 
            -
                ra
         | 
| 536 | 
            -
              end
         | 
| 537 | 
            -
             | 
| 538 | 
            -
              def logStatus
         | 
| 539 | 
            -
                if @mode == :client
         | 
| 540 | 
            -
                  @broker.logStatus
         | 
| 541 | 
            -
                  return
         | 
| 542 | 
            -
                end
         | 
| 543 | 
            -
             | 
| 544 | 
            -
                return unless $vim_log.info?
         | 
| 545 | 
            -
             | 
| 546 | 
            -
                # server
         | 
| 547 | 
            -
                $vim_log.info "MiqVimBroker status start"
         | 
| 548 | 
            -
                $vim_log.info "\tMiqVimBroker: Threads = #{Thread.list.length}"
         | 
| 549 | 
            -
             | 
| 550 | 
            -
                $vim_log.info "\tMiqVimBroker client object counts by type:"
         | 
| 551 | 
            -
                objectCounts.each { |t, c| $vim_log.info "\t\t#{t}: #{c}" }
         | 
| 552 | 
            -
                $vim_log.info "\tEnd MiqVimBroker client object counts by type"
         | 
| 553 | 
            -
             | 
| 554 | 
            -
                brokerCacheSz = 0
         | 
| 555 | 
            -
             | 
| 556 | 
            -
                $vim_log.info "\tMiqVimBroker open connections: #{@connectionHash.keys.length}"
         | 
| 557 | 
            -
                @connectionHash.keys.each do |k|
         | 
| 558 | 
            -
                  @lockHash[k].synchronize(:SH) do
         | 
| 559 | 
            -
                    next if (vim = @connectionHash[k]).nil?
         | 
| 560 | 
            -
                    $vim_log.info "\t\tMiqVimBroker connection #{k} cache counts:"
         | 
| 561 | 
            -
                    # vim.logCacheCounts("\t\t\t")
         | 
| 562 | 
            -
                    brokerCacheSz += vim.cacheStats("\t\t\t#{k} - ")
         | 
| 563 | 
            -
                    $vim_log.info "\t\tEnd MiqVimBroker connection #{k} cache counts"
         | 
| 564 | 
            -
                  end
         | 
| 565 | 
            -
                end
         | 
| 566 | 
            -
                $vim_log.info "\tEnd MiqVimBroker open connections"
         | 
| 567 | 
            -
                $vim_log.info "MiqVimBroker status end - Total broker cache size = #{brokerCacheSz}"
         | 
| 568 | 
            -
              end
         | 
| 569 | 
            -
             | 
| 570 | 
            -
              def forceGC
         | 
| 571 | 
            -
                if @mode == :client
         | 
| 572 | 
            -
                  @broker.forceGC
         | 
| 573 | 
            -
                  return
         | 
| 574 | 
            -
                end
         | 
| 575 | 
            -
             | 
| 576 | 
            -
                log_prefix = "MiqVimBroker.forceGC"
         | 
| 577 | 
            -
                $vim_log.info "#{log_prefix}: GC.start...Starting"
         | 
| 578 | 
            -
                GC.start
         | 
| 579 | 
            -
                $vim_log.info "#{log_prefix}: GC.start...Complete"
         | 
| 580 | 
            -
              end
         | 
| 581 | 
            -
            end # class MiqVimBroker
         |