Class: Vmesh::Datastore
- Inherits:
-
Object
- Object
- Vmesh::Datastore
- Defined in:
- lib/vmesh/datastore.rb
Instance Attribute Summary collapse
-
#ds ⇒ Object
Returns the value of attribute ds.
Class Method Summary collapse
- .get(vim, name, datacenter) ⇒ Object
- .get_all(vim, datacenter) ⇒ Object
- .get_all_matching(vim, name, datacenter) ⇒ Object
Instance Method Summary collapse
- #capacity ⇒ Object
- #free_space ⇒ Object
-
#initialize(ds) ⇒ Datastore
constructor
A new instance of Datastore.
- #name ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(ds) ⇒ Datastore
Returns a new instance of Datastore.
6 7 8 |
# File 'lib/vmesh/datastore.rb', line 6 def initialize(ds) @ds = ds end |
Instance Attribute Details
#ds ⇒ Object
Returns the value of attribute ds.
5 6 7 |
# File 'lib/vmesh/datastore.rb', line 5 def ds @ds end |
Class Method Details
.get(vim, name, datacenter) ⇒ Object
10 11 12 13 |
# File 'lib/vmesh/datastore.rb', line 10 def self.get(vim, name, datacenter) Vmesh::logger.debug "Getting a single datastore named #{name} at datacenter #{datacenter.name}." get_all_matching(vim,name,datacenter).sort_by{ |ds| ds.free_space }.reverse.first end |
.get_all(vim, datacenter) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/vmesh/datastore.rb', line 28 def self.get_all(vim, datacenter) Vmesh::logger.debug "get_all datastores at #{datacenter.name}." vim.serviceContent.viewManager.CreateContainerView({ :container => datacenter.dc.datastoreFolder, :type => ["Datastore"], :recursive => true }).view.map{ |ds| Datastore.new(ds) } #.select{|ds| ds.name == name}.first end |
.get_all_matching(vim, name, datacenter) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vmesh/datastore.rb', line 15 def self.get_all_matching(vim, name, datacenter) Vmesh::logger.debug "Getting datastore matching name #{name} at datacenter #{datacenter.name}." stores = self.get_all(vim, datacenter).select{ |ds| ds.name == name } if stores.nil? or stores.empty? Vmesh::logger.info "No exact match found, searching for partial match" stores = self.get_all(vim, datacenter).select{ |ds| ds.name.include? name } Vmesh::logger.debug "Found #{stores.count} datastores." Vmesh::logger.debug "#{stores.map{|ds| "Name #{ds.name}, free space #{ds.free_space}"}}" end stores end |
Instance Method Details
#capacity ⇒ Object
45 46 47 |
# File 'lib/vmesh/datastore.rb', line 45 def capacity @ds.summary.capacity end |
#free_space ⇒ Object
41 42 43 |
# File 'lib/vmesh/datastore.rb', line 41 def free_space @ds.summary.freeSpace end |
#name ⇒ Object
37 38 39 |
# File 'lib/vmesh/datastore.rb', line 37 def name @ds.name end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/vmesh/datastore.rb', line 49 def to_s "name: #{name}, free_space: #{free_space}, capacity: #{capacity}" end |