Class: RbVmomi::VIM::Datastore

Inherits:
Object
  • Object
show all
Defined in:
lib/rvc/extensions/Datastore.rb

Overview

Copyright © 2011 VMware, Inc. All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ls_propertiesObject



37
38
39
# File 'lib/rvc/extensions/Datastore.rb', line 37

def self.ls_properties
  %w(name summary.capacity summary.freeSpace)
end

Instance Method Details

#childrenObject



48
49
50
51
52
53
54
# File 'lib/rvc/extensions/Datastore.rb', line 48

def children
  {
    'files' => FakeDatastoreFolder.new(self, ""),
    'vms' => RVC::FakeFolder.new(self, :children_vms),
    'hosts' => RVC::FakeFolder.new(self, :children_hosts),
  }
end

#children_hostsObject



60
61
62
63
# File 'lib/rvc/extensions/Datastore.rb', line 60

def children_hosts
  # XXX optimize
  Hash[host.map(&:key).map { |x| [x.name, x] }]
end

#children_vmsObject



56
57
58
# File 'lib/rvc/extensions/Datastore.rb', line 56

def children_vms
  RVC::Util.collect_children self, :vm
end

#display_infoObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rvc/extensions/Datastore.rb', line 22

def display_info
  s, info, = collect :summary, :info
  puts "type: #{s.type}"
  puts "url: #{s.accessible ? s.url : '<inaccessible>'}"
  puts "multipleHostAccess: #{s.multipleHostAccess}"
  puts "capacity: %0.2fGB" % (s.capacity.to_f/10**9)
  puts "free space: %0.2fGB" % (s.freeSpace.to_f/10**9)
  case info
  when VIM::VmfsDatastoreInfo
    puts "uuid: #{info.vmfs.uuid}"
  when VIM::NasDatastoreInfo
    puts "location: #{info.nas.remoteHost}:#{info.nas.remotePath}"
  end
end

#ls_text(r) ⇒ Object



41
42
43
44
45
46
# File 'lib/rvc/extensions/Datastore.rb', line 41

def ls_text r
  pct_used = 100*(1-(r['summary.freeSpace'].to_f/r['summary.capacity']))
  pct_used_text = "%0.1f%%" % pct_used
  capacity_text = "%0.2fGB" % (r['summary.capacity'].to_f/10**9)
  ": #{capacity_text} #{pct_used_text}"
end