class MiqVimDataStore
Attributes
accessible[R]
capacityBytes[R]
dsType[R]
freeBytes[R]
invObj[R]
multipleHostAccess[R]
name[R]
uncommitted[R]
url[R]
Public Class Methods
new(invObj, dsh)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 10 def initialize(invObj, dsh) @invObj = invObj @sic = invObj.sic @dsh = dsh @accessible = (@dsh['summary']['accessible'] == 'true') @multipleHostAccess = (@dsh['summary']['multipleHostAccess'] == 'true') @name = @dsh['summary']['name'] @dsType = @dsh['summary']['type'] @url = @dsh['summary']['url'] @dsMor = @dsh['summary']['datastore'] @freeBytes = @dsh['summary']['freeSpace'].to_i @capacityBytes = @dsh['summary']['capacity'].to_i @uncommitted = @dsh['summary']['uncommitted'].to_i if @invObj.apiVersion[0, 1].to_i <= 4 && @dsh['summary']['uncommitted'] @browser = nil @dsHash = nil @cacheLock = Sync.new end
Public Instance Methods
browser()
click to toggle source
Public accessor
# File lib/VMwareWebService/MiqVimDataStore.rb, line 66 def browser @cacheLock.synchronize(:SH) do return(browser_locked) end end
browser_locked()
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 48 def browser_locked raise "browser_locked: cache lock not held" unless @cacheLock.sync_locked? return @browser if @browser begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) props = @invObj.getMoProp_local(@dsMor, "browser") @browser = props["browser"] if props ensure @cacheLock.sync_unlock if unlock end @browser end
dsFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 104 def dsFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true) return(dsSearch(nil, pattern, path, pathOnly, recurse)) if @invObj.v20 (dsSearch('FileQuery', pattern, path, pathOnly, recurse)) end
dsFloppyImageFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 72 def dsFloppyImageFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true) dsSearch('FloppyImageFileQuery', pattern, path, pathOnly, recurse) end
dsFolderFileList(path = nil)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 171 def dsFolderFileList(path = nil) dirs = dsFolderFileSearch(nil, path, true, false).inject({}) { |h, d| h[d] = nil; h } children = VimArray.new ret = dsFileSearch(nil, path, false, false) ret.each do |f| full_path = f['fullPath'] if dirs.key?(full_path) f['fileType'] = 'FolderFileInfo' full_path =~ /\] (.+)$/ children.concat(dsFolderFileList($1)) end end ret.concat(children) end
dsFolderFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 76 def dsFolderFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true) dsSearch('FolderFileQuery', pattern, path, pathOnly, recurse) end
dsHash(refresh = false)
click to toggle source
Public accessor
# File lib/VMwareWebService/MiqVimDataStore.rb, line 262 def dsHash(refresh = false) @cacheLock.synchronize(:SH) do return(dupObj(dsHash_locked(refresh))) end end
dsHash_locked(refresh = false)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 189 def dsHash_locked(refresh = false) raise "dsHash_locked: cache lock not held" unless @cacheLock.sync_locked? return(@dsHash) if @dsHash && !refresh begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) searchSpec = VimHash.new("HostDatastoreBrowserSearchSpec") do |hdbs| hdbs.details = VimHash.new("FileQueryFlags") do |fqf| fqf.fileSize = "true" fqf.fileType = "true" fqf.modification = "true" fqf.fileOwner = "true" end hdbs.sortFoldersFirst = "true" end logger.info "MiqVimDataStore(#{@invObj.server}, #{@invObj.username}).dsHash_locked: calling searchDatastoreSubFolders_Task" taskMor = @invObj.searchDatastoreSubFolders_Task(browser_locked, "[#{@name}]", searchSpec) logger.info "MiqVimDataStore(#{@invObj.server}, #{@invObj.username}).dsHash_locked: returned from searchDatastoreSubFolders_Task" retObj = waitForTask(taskMor) retObj = [retObj] unless retObj.kind_of?(Array) @dsHash = {} retObj.each do |dsbr| # puts "dsbr.class: #{dsbr.class.to_s}" # @invObj.dumpObj(dsbr) # puts "****** dsbr end" # puts "Folder Path: #{dsbr.folderPath}" dsl = (dsbr["folderPath"][-1, 1] == ']') if dsl rInfo = {} rInfo['fileType'] = "FolderFileInfo" @dsHash[dsbr["folderPath"]] = rInfo else dsbr["folderPath"] = dsbr["folderPath"][0..-2] if dsbr["folderPath"][-1, 1] == "/" end raise "[BUG] Parent directory '#{dsbr["folderPath"]}' not defined" unless (parentDir = @dsHash[dsbr["folderPath"]]) parentDir['dirEntries'] = [] unless parentDir['dirEntries'] dirEntries = parentDir['dirEntries'] dsbr["file"] = dsbr["file"] || [] dsbr["file"] = [dsbr["file"]] unless dsbr["file"].kind_of? Array dsbr["file"].each do |fInfo| # puts "***** fInfo.class: #{fInfo.class.to_s}" fInfoHash = fInfo # fInfoHash = @invObj.unMarshalSoapMappingObject(fInfo) fInfoHash['fileType'] = fInfoHash.xsiType # puts "\tType: #{fInfoHash['xmlattr_type']}, Path: #{fInfoHash["path"]}" if dsl path = dsbr["folderPath"] + " " + fInfoHash["path"] else path = File.join(dsbr["folderPath"], fInfoHash["path"]) end fInfoHash['dirEntries'] = [] if fInfoHash['fileType'] == "FolderFileInfo" && !fInfoHash['dirEntries'] dirEntries << fInfoHash["path"] @dsHash[path] = fInfoHash end end ensure @cacheLock.sync_unlock if unlock end @dsHash end
dsIsoImageFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 80 def dsIsoImageFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true) dsSearch('IsoImageFileQuery', pattern, path, pathOnly, recurse) end
dsMor()
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 40 def dsMor (@dsMor) end
dsSearch(typeClass, pattern = nil, path = nil, pathOnly = true, recurse = true)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 109 def dsSearch(typeClass, pattern = nil, path = nil, pathOnly = true, recurse = true) searchSpec = VimHash.new("HostDatastoreBrowserSearchSpec") do |hdbs| hdbs.details = VimHash.new("FileQueryFlags") do |fqf| fqf.fileSize = "true" fqf.fileType = "true" fqf.modification = "true" fqf.fileOwner = "true" end hdbs.query = VimArray.new("ArrayOfFileQuery") do |fqa| fqa << VimHash.new(typeClass) end if typeClass hdbs.matchPattern = pattern if pattern hdbs.sortFoldersFirst = "true" end browserMor = nil @cacheLock.synchronize(:SH) do browserMor = browser_locked end dsPath = "[#{@name}]" dsPath = "#{dsPath} #{path}" if path taskMor = nil if recurse logger.info "MiqVimDataStore(#{@invObj.server}, #{@invObj.username}).dsSearch: calling searchDatastoreSubFolders_Task" taskMor = @invObj.searchDatastoreSubFolders_Task(browserMor, dsPath, searchSpec) logger.info "MiqVimDataStore(#{@invObj.server}, #{@invObj.username}).dsSearch: returned from searchDatastoreSubFolders_Task" else logger.info "MiqVimDataStore(#{@invObj.server}, #{@invObj.username}).dsSearch: calling searchDatastore_Task" taskMor = @invObj.searchDatastore_Task(browserMor, dsPath, searchSpec) logger.info "MiqVimDataStore(#{@invObj.server}, #{@invObj.username}).dsSearch: returned from searchDatastore_Task" end retObj = waitForTask(taskMor) retObj = [retObj] unless retObj.kind_of?(Array) # @invObj.dumpObj(retObj) ra = VimArray.new retObj.each do |dsbr| dsl = (dsbr["folderPath"][-1, 1] == ']') dsbr["file"] = dsbr["file"] || [] # dsbr["file"] = [dsbr["file"]] if !dsbr["file"].kind_of? Array dsbr["file"].each do |fInfo| path = nil if dsl path = dsbr["folderPath"] + " " + fInfo["path"] else path = File.join(dsbr["folderPath"], fInfo["path"]) end fInfo["fullPath"] = path if pathOnly ra << path else ra << fInfo end end end (ra) end
dsVmConfigFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 100 def dsVmConfigFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true) dsSearch('VmConfigFileQuery', pattern, path, pathOnly, recurse) end
dsVmDiskFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 84 def dsVmDiskFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true) dsSearch('VmDiskFileQuery', pattern, path, pathOnly, recurse) end
dsVmLogFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 88 def dsVmLogFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true) dsSearch('VmLogFileQuery', pattern, path, pathOnly, recurse) end
dsVmNvramFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 92 def dsVmNvramFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true) dsSearch('VmNvramFileQuery', pattern, path, pathOnly, recurse) end
dsVmSnapshotFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 96 def dsVmSnapshotFileSearch(pattern = nil, path = nil, pathOnly = true, recurse = true) dsSearch('VmSnapshotFileQuery', pattern, path, pathOnly, recurse) end
dsh()
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 44 def dsh (@dsh) end
dumpProps()
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 269 def dumpProps props = @invObj.getMoProp_local(@dsMor, "browser")["browser"] @invObj.dumpObj(props) end
dupObj(obj)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 302 def dupObj(obj) obj end
get_file_content(filepath) { |ret| ... }
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 278 def get_file_content(filepath) # Sample URL required to read file # agentURI = "https://192.168.254.247/folder/BH_9336_1/BH_9336_1.vmsd?dcPath=ha-datacenter&dsName=DCRaid2" # Note: dcPath is only required if going through vCenter. raise "get_file_content not supported through Virtual Center" if @invObj.isVirtualCenter? /(\d*)\.(\d*)/ =~ @invObj.about['version'] raise "get_file_content not supported on [#{@invObj.about['fullName']}]" if $1.to_i < 3 || ($1.to_i == 3 && $2.to_i < 5) fileUrl = encode_datastore_url(filepath, @name) options = { :http_basic_authentication => [@invObj.username, @invObj.password], :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE } if block_given? open(fileUrl, options) { |ret| yield(ret) } else data = nil open(fileUrl, options) { |ret| data = ret.read } return data end end
release()
click to toggle source
Called when client is finished using this MiqVimVm
object. The server will delete its reference to the object, so the server-side object csn be GC'd
# File lib/VMwareWebService/MiqVimDataStore.rb, line 36 def release # @invObj.releaseObj(self) end
waitForTask(tmor)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 274 def waitForTask(tmor) @invObj.waitForTask(tmor, self.class.to_s) end
Private Instance Methods
encode_datastore_url(file_path, ds_name)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 308 def encode_datastore_url(file_path, ds_name) uri_parts = { :scheme => "https", :host => @invObj.server, :path => "/folder/#{encode_path_url(file_path)}", :query => "dsName=#{encode_path_url(ds_name)}" } URI::Generic.build(uri_parts).to_s end
encode_path_url(path)
click to toggle source
# File lib/VMwareWebService/MiqVimDataStore.rb, line 319 def encode_path_url(path) URI.encode(path, /[^#{URI::PATTERN::UNRESERVED}]/) end