Class: MiqVimHost

Inherits:
Object
  • Object
show all
Includes:
VMwareWebService::Logging
Defined in:
lib/VMwareWebService/MiqVimHost.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from VMwareWebService::Logging

#logger

Constructor Details

#initialize(invObj, hh) ⇒ MiqVimHost

Returns a new instance of MiqVimHost.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/VMwareWebService/MiqVimHost.rb', line 21

def initialize(invObj, hh)
  @invObj                 = invObj
  @sic                    = invObj.sic
  @cfManager        = nil

  @configManager      = nil
  @datastoreSystem    = nil
  @storageSystem      = nil
  @firewallSystem     = nil
  @serviceSystem      = nil
  @networkSystem      = nil
  @hostVirtualNicManager  = nil
  @advancedOptionManager  = nil
  @snmpSystem       = nil
  @dvsConfig        = nil

  @hh           = hh
  @name                   = hh['summary']['config']['name']
  @hMor         = hh['summary']['host']
end

Instance Attribute Details

#invObjObject (readonly)

Returns the value of attribute invObj.



19
20
21
# File 'lib/VMwareWebService/MiqVimHost.rb', line 19

def invObj
  @invObj
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/VMwareWebService/MiqVimHost.rb', line 19

def name
  @name
end

Instance Method Details

#advancedOptionManagerObject



213
214
215
216
217
218
# File 'lib/VMwareWebService/MiqVimHost.rb', line 213

def advancedOptionManager
  return @advancedOptionManager if @advancedOptionManager
  return nil unless (ao = configManager('advancedOption'))
  @advancedOptionManager = MiqHostAdvancedOptionManager.new(ao, @invObj)
  @advancedOptionManager
end

#cfManagerObject

Custom field methods.



282
283
284
285
# File 'lib/VMwareWebService/MiqVimHost.rb', line 282

def cfManager
  @cfManager = @invObj.getMiqCustomFieldsManager unless @cfManager
  @cfManager
end

#configManager(mgr_type = nil) ⇒ Object



160
161
162
163
164
165
166
167
168
# File 'lib/VMwareWebService/MiqVimHost.rb', line 160

def configManager(mgr_type = nil)
  if @configManager.nil?
    mgr = @invObj.getMoProp(@hMor, "configManager")
    @configManager = mgr['configManager'] unless mgr.nil?
  end

  return @configManager[mgr_type] if mgr_type && @configManager
  @configManager
end

#datastoreSystemObject



170
171
172
173
174
175
# File 'lib/VMwareWebService/MiqVimHost.rb', line 170

def datastoreSystem
  return @datastoreSystem if @datastoreSystem
  return nil unless (dss = configManager('datastoreSystem'))
  @datastoreSystem = MiqHostDatastoreSystem.new(dss, @invObj)
  @datastoreSystem
end

#dvsConfig(refresh = false) ⇒ Object

Distributed virtual switch methods.



296
297
298
299
# File 'lib/VMwareWebService/MiqVimHost.rb', line 296

def dvsConfig(refresh = false)
  return @dvsConfig unless refresh || !@dvsConfig
  @dvsConfig = @invObj.queryDvsConfigTarget(@invObj.sic.dvSwitchManager, @hMor, nil)
end

#dvsPortGroupByFilter(filter, refresh = false) ⇒ Object



301
302
303
# File 'lib/VMwareWebService/MiqVimHost.rb', line 301

def dvsPortGroupByFilter(filter, refresh = false)
  @invObj.applyFilter(dvsConfig(refresh).distributedVirtualPortgroup, filter)
end

#dvsSwitchByFilter(filter, refresh = false) ⇒ Object



305
306
307
# File 'lib/VMwareWebService/MiqVimHost.rb', line 305

def dvsSwitchByFilter(filter, refresh = false)
  @invObj.applyFilter(dvsConfig(refresh).distributedVirtualSwitch, filter)
end

#enterMaintenanceMode(timeout = 0, evacuatePoweredOffVms = false, wait = true) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/VMwareWebService/MiqVimHost.rb', line 112

def enterMaintenanceMode(timeout = 0, evacuatePoweredOffVms = false, wait = true)
  logger.info "MiqVimHost(#{@invObj.server}, #{@invObj.username}).enterMaintenanceMode: calling enterMaintenanceMode_Task"
  taskMor = @invObj.enterMaintenanceMode_Task(@hMor, timeout, evacuatePoweredOffVms)
  logger.info "MiqVimHost(#{@invObj.server}, #{@invObj.username}).enterMaintenanceMode: returned from enterMaintenanceMode_Task"
  return taskMor unless wait
  waitForTask(taskMor)
end

#exitMaintenanceMode(timeout = 0, wait = true) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/VMwareWebService/MiqVimHost.rb', line 120

def exitMaintenanceMode(timeout = 0, wait = true)
  logger.info "MiqVimHost(#{@invObj.server}, #{@invObj.username}).exitMaintenanceMode: calling exitMaintenanceMode_Task"
  taskMor = @invObj.exitMaintenanceMode_Task(@hMor, timeout)
  logger.info "MiqVimHost(#{@invObj.server}, #{@invObj.username}).exitMaintenanceMode: returned from exitMaintenanceMode_Task"
  return taskMor unless wait
  waitForTask(taskMor)
end

#fileSystemVolume(selSpec = nil) ⇒ Object



258
259
260
261
262
263
264
265
266
# File 'lib/VMwareWebService/MiqVimHost.rb', line 258

def fileSystemVolume(selSpec = nil)
  if selSpec.nil?
    return @invObj.getMoProp(@hMor, "config.fileSystemVolume")
  else
    propPath = @invObj.selSpecToPropPath(selSpec)
    sd = @invObj.getMoProp(@hMor, propPath)
    return @invObj.applySelector(sd, selSpec)
  end
end

#firewallSystemObject



184
185
186
187
188
189
# File 'lib/VMwareWebService/MiqVimHost.rb', line 184

def firewallSystem
  return @firewallSystem if @firewallSystem
  return nil unless (fws = configManager('firewallSystem'))
  @firewallSystem = MiqHostFirewallSystem.new(fws, @invObj)
  @firewallSystem
end

#hhObject



50
51
52
# File 'lib/VMwareWebService/MiqVimHost.rb', line 50

def hh
  (@hh)
end

#hMorObject



46
47
48
# File 'lib/VMwareWebService/MiqVimHost.rb', line 46

def hMor
  (@hMor)
end

#hostConfigSpecObject



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/VMwareWebService/MiqVimHost.rb', line 227

def hostConfigSpec
  VimHash.new('HostConfigSpec') do |hcs|
    hcs.datastorePrincipal = @hh.config.datastorePrincipal if @hh.config.datastorePrincipal

    hcs.firewall = VimHash.new('HostFirewallConfig') do |hfc|
      fi = firewallSystem.firewallInfo
      hfc.defaultBlockingPolicy = fi.defaultPolicy
      hfc.rule = VimArray.new('ArrayOfHostFirewallConfigRuleSetConfig') do |hfcrca|
        fi.ruleset.each do |rs|
          hfcrca << VimHash.new('HostFirewallConfigRuleSetConfig') do |hfcrc|
            hfcrc.enabled = rs.enabled
            hfcrc.rulesetId = rs.key
          end
        end
      end
    end

    hcs.service = VimArray.new('ArrayOfHostServiceConfig') do |hsca|
      serviceSystem.serviceInfo.service.each do |svc|
        hsca << VimHash.new('HostServiceConfig') do |hsc|
          hsc.serviceId   = svc.key
          hsc.startupPolicy = svc.policy
        end
      end
    end

    hcs.nicTypeSelection = VimArray.new('ArrayOfHostVirtualNicManagerNicTypeSelection') do |_hvnmntsa|
    end
  end
end

#hostVirtualNicManagerObject



205
206
207
208
209
210
211
# File 'lib/VMwareWebService/MiqVimHost.rb', line 205

def hostVirtualNicManager
  raise "hostVirtualNicManager not supported in VIM #{@invObj.apiVersion}" if @invObj.v2
  return @hostVirtualNicManager if @hostVirtualNicManager
  return nil unless (vns = configManager('virtualNicManager'))
  @hostVirtualNicManager = MiqHostVirtualNicManager.new(vns, @invObj)
  @hostVirtualNicManager
end

#inMaintenanceMode?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/VMwareWebService/MiqVimHost.rb', line 104

def inMaintenanceMode?
  @invObj.getMoProp(@hMor, "runtime.inMaintenanceMode")['runtime']['inMaintenanceMode'] == "true"
end

#maintenanceModeSupported?Boolean

HostCapability

Returns:

  • (Boolean)


58
59
60
# File 'lib/VMwareWebService/MiqVimHost.rb', line 58

def maintenanceModeSupported?
  capabilityBool("maintenanceModeSupported")
end

#networkSystemObject



198
199
200
201
202
203
# File 'lib/VMwareWebService/MiqVimHost.rb', line 198

def networkSystem
  return @networkSystem if @networkSystem
  return nil unless (ns = configManager('networkSystem'))
  @networkSystem = MiqHostNetworkSystem.new(ns, @invObj)
  @networkSystem
end

#nfsSupported?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/VMwareWebService/MiqVimHost.rb', line 62

def nfsSupported?
  capabilityBool("nfsSupported")
end

#powerDownHostToStandBy(timeout = 0, evacuatePoweredOffVms = false, wait = true) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/VMwareWebService/MiqVimHost.rb', line 128

def powerDownHostToStandBy(timeout = 0, evacuatePoweredOffVms = false, wait = true)
  logger.info "MiqVimHost(#{@invObj.server}, #{@invObj.username}).powerDownHostToStandBy: calling powerDownHostToStandBy_Task"
  taskMor = @invObj.powerDownHostToStandBy_Task(@hMor, timeout, evacuatePoweredOffVms)
  logger.info "MiqVimHost(#{@invObj.server}, #{@invObj.username}).powerDownHostToStandBy: returned from powerDownHostToStandBy_Task"
  return taskMor unless wait
  waitForTask(taskMor)
end

#powerStateObject



108
109
110
# File 'lib/VMwareWebService/MiqVimHost.rb', line 108

def powerState
  @invObj.getMoProp(@hMor, "runtime.powerState")['runtime']['powerState']
end

#powerUpHostFromStandBy(timeout = 0, wait = true) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/VMwareWebService/MiqVimHost.rb', line 136

def powerUpHostFromStandBy(timeout = 0, wait = true)
  logger.info "MiqVimHost(#{@invObj.server}, #{@invObj.username}).powerUpHostFromStandBy: calling powerUpHostFromStandBy_Task"
  taskMor = @invObj.powerUpHostFromStandBy_Task(@hMor, timeout)
  logger.info "MiqVimHost(#{@invObj.server}, #{@invObj.username}).powerUpHostFromStandBy: returned from powerUpHostFromStandBy_Task"
  return taskMor unless wait
  waitForTask(taskMor)
end

#quickStatsObject



100
101
102
# File 'lib/VMwareWebService/MiqVimHost.rb', line 100

def quickStats
  @invObj.getMoProp(@hMor, "summary.quickStats")['summary']['quickStats']
end

#rebootHost(force = false, wait = true) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/VMwareWebService/MiqVimHost.rb', line 144

def rebootHost(force = false, wait = true)
  logger.info "MiqVimHost(#{@invObj.server}, #{@invObj.username}).rebootHost: calling rebootHost_Task"
  taskMor = @invObj.rebootHost_Task(@hMor, force)
  logger.info "MiqVimHost(#{@invObj.server}, #{@invObj.username}).rebootHost: returned from rebootHost_Task"
  return taskMor unless wait
  waitForTask(taskMor)
end

#rebootSupported?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/VMwareWebService/MiqVimHost.rb', line 66

def rebootSupported?
  capabilityBool("rebootSupported")
end

#releaseObject

def initialize



42
43
44
# File 'lib/VMwareWebService/MiqVimHost.rb', line 42

def release
  # @invObj.releaseObj(self)
end

#sanSupported?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/VMwareWebService/MiqVimHost.rb', line 70

def sanSupported?
  capabilityBool("sanSupported")
end

#serviceSystemObject



191
192
193
194
195
196
# File 'lib/VMwareWebService/MiqVimHost.rb', line 191

def serviceSystem
  return @serviceSystem if @serviceSystem
  return nil unless (ss = configManager('serviceSystem'))
  @serviceSystem = MiqHostServiceSystem.new(ss, @invObj)
  @serviceSystem
end

#setCustomField(name, value) ⇒ Object



287
288
289
290
# File 'lib/VMwareWebService/MiqVimHost.rb', line 287

def setCustomField(name, value)
  fk = cfManager.getFieldKey(name, @hMor.vimType)
  cfManager.setField(@hMor, fk, value)
end

#shutdownHost(force = false, wait = true) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/VMwareWebService/MiqVimHost.rb', line 152

def shutdownHost(force = false, wait = true)
  logger.info "MiqVimHost(#{@invObj.server}, #{@invObj.username}).shutdownHost: calling shutdownHost_Task"
  taskMor = @invObj.shutdownHost_Task(@hMor, force)
  logger.info "MiqVimHost(#{@invObj.server}, #{@invObj.username}).shutdownHost: returned from shutdownHost_Task"
  return taskMor unless wait
  waitForTask(taskMor)
end

#shutdownSupported?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/VMwareWebService/MiqVimHost.rb', line 74

def shutdownSupported?
  capabilityBool("shutdownSupported")
end

#snmpSystemObject



220
221
222
223
224
225
# File 'lib/VMwareWebService/MiqVimHost.rb', line 220

def snmpSystem
  return @snmpSystem if @snmpSystem
  return nil unless (ss = configManager('snmpSystem'))
  @snmpSystem = MiqHostSnmpSystem.new(ss, @invObj)
  @snmpSystem
end

#standbySupported?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/VMwareWebService/MiqVimHost.rb', line 78

def standbySupported?
  capabilityBool("standbySupported")
end

#storageDevice(selSpec = nil) ⇒ Object



268
269
270
271
272
273
274
275
276
# File 'lib/VMwareWebService/MiqVimHost.rb', line 268

def storageDevice(selSpec = nil)
  if selSpec.nil?
    return @invObj.getMoProp(@hMor, "config.storageDevice")
  else
    propPath = @invObj.selSpecToPropPath(selSpec)
    sd = @invObj.getMoProp(@hMor, propPath)
    return @invObj.applySelector(sd, selSpec)
  end
end

#storageSystemObject



177
178
179
180
181
182
# File 'lib/VMwareWebService/MiqVimHost.rb', line 177

def storageSystem
  return @storageSystem if @storageSystem
  return nil unless (hss = configManager('storageSystem'))
  @storageSystem = MiqHostStorageSystem.new(hss, @invObj)
  @storageSystem
end

#storageVMotionSupported?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/VMwareWebService/MiqVimHost.rb', line 82

def storageVMotionSupported?
  capabilityBool("storageVMotionSupported")
end

#vmotionSupported?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/VMwareWebService/MiqVimHost.rb', line 86

def vmotionSupported?
  capabilityBool("vmotionSupported")
end

#vmotionWithStorageVMotionSupported?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/VMwareWebService/MiqVimHost.rb', line 90

def vmotionWithStorageVMotionSupported?
  capabilityBool("vmotionWithStorageVMotionSupported")
end

#waitForTask(tmor) ⇒ Object



309
310
311
# File 'lib/VMwareWebService/MiqVimHost.rb', line 309

def waitForTask(tmor)
  @invObj.waitForTask(tmor, self.class.to_s)
end