Class: MiqHostDatastoreSystem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from VMwareWebService::Logging

#logger

Constructor Details

#initialize(dssMor, invObj) ⇒ MiqHostDatastoreSystem

Returns a new instance of MiqHostDatastoreSystem.



8
9
10
11
# File 'lib/VMwareWebService/MiqHostDatastoreSystem.rb', line 8

def initialize(dssMor, invObj)
  @invObj = invObj
  @dssMor = dssMor
end

Instance Attribute Details

#invObjObject (readonly)

Returns the value of attribute invObj.



6
7
8
# File 'lib/VMwareWebService/MiqHostDatastoreSystem.rb', line 6

def invObj
  @invObj
end

Instance Method Details

#addNasDatastoreByName(dsName, accessMode = "readWrite") ⇒ Object

Utility method to add an existing NAS datastore to the host in question.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/VMwareWebService/MiqHostDatastoreSystem.rb', line 37

def addNasDatastoreByName(dsName, accessMode = "readWrite")
  if (dsh = @invObj.dataStoresByFilter_local("summary.name" => dsName).first).nil?
    raise "MiqHostDatastoreSystem.addNasDatastoreByName: datastore #{sdName} not found"
  end

  unless dsh.summary.type.casecmp('nfs') == 0 || dsh.summary.type.casecmp('nas') == 0
    raise "MiqHostDatastoreSystem.addNasDatastoreByName: datastore #{dsName} is not NAS"
  end

  remoteHost  = dsh.info.nas.remoteHost
  remotePath  = dsh.info.nas.remotePath
  localPath = dsh.info.nas.name
  type    = dsh.info.nas.type

  logger.info "MiqHostDatastoreSystem.addNasDatastoreByName: remoteHost = #{remoteHost}, remotePath = #{remotePath}, localPath = #{localPath}"
  createNasDatastore(remoteHost, remotePath, localPath, accessMode, type)
end

#capabilitiesObject



13
14
15
# File 'lib/VMwareWebService/MiqHostDatastoreSystem.rb', line 13

def capabilities
  @capabilities ||= @invObj.getMoProp(@dssMor, 'capabilities')['capabilities']
end

#createNasDatastore(remoteHost, remotePath, localPath, accessMode = "readWrite", type = "nfs", userName = nil, password = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/VMwareWebService/MiqHostDatastoreSystem.rb', line 21

def createNasDatastore(remoteHost, remotePath, localPath, accessMode = "readWrite", type = "nfs", userName = nil, password = nil)
  spec = VimHash.new('HostNasVolumeSpec') do |s|
    s.remoteHost  = remoteHost
    s.remotePath  = remotePath
    s.localPath   = localPath
    s.accessMode  = accessMode
    s.type      = type
    s.userName    = userName
    s.password    = password
  end
  @invObj.createNasDatastore(@dssMor, spec)
end

#datastoreObject



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

def datastore
  @invObj.getMoProp(@dssMor, 'datastore')['datastore']
end