Class: RbVmomi::VIM::Datastore::FakeDatastoreFolder

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

Instance Attribute Summary collapse

Attributes included from RVC::InventoryObject

#rvc_arc, #rvc_parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RVC::InventoryObject

included, #ls_text, #rvc_link, #rvc_path, #rvc_path_str

Constructor Details

#initialize(datastore, path) ⇒ FakeDatastoreFolder

Returns a new instance of FakeDatastoreFolder.



66
67
68
69
# File 'lib/rvc/extensions/Datastore.rb', line 66

def initialize datastore, path
  @datastore = datastore
  @path = path
end

Instance Attribute Details

#datastoreObject (readonly)

Returns the value of attribute datastore.



64
65
66
# File 'lib/rvc/extensions/Datastore.rb', line 64

def datastore
  @datastore
end

#pathObject (readonly)

Returns the value of attribute path.



64
65
66
# File 'lib/rvc/extensions/Datastore.rb', line 64

def path
  @path
end

Class Method Details

.folder?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/rvc/extensions/Datastore.rb', line 119

def self.folder?
  true
end

Instance Method Details

#childrenObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rvc/extensions/Datastore.rb', line 85

def children
  results = @datastore.browser.SearchDatastore_Task(
    :datastorePath => datastore_path,
    :searchSpec => {
      :details => {
        :fileType => true,
        :fileSize => true,
        :fileOwner => false,
        :modification => false
      }
    }
  ).wait_for_completion

  Hash[results.file.map { |x| [x.path, search_result_to_object(x)] }]
end

#datastore_pathObject



71
72
73
74
# File 'lib/rvc/extensions/Datastore.rb', line 71

def datastore_path
  @ds_name ||= @datastore.name
  "[#{@ds_name}] #{@path}"
end

#display_infoObject



133
134
135
136
137
# File 'lib/rvc/extensions/Datastore.rb', line 133

def display_info
  puts "Datastore Folder"
  puts "datastore: #{@datastore.name}"
  puts "path: #{@path}"
end

#eql?(x) ⇒ Boolean

Returns:

  • (Boolean)


139
140
141
142
# File 'lib/rvc/extensions/Datastore.rb', line 139

def eql? x
  @datastore == x.instance_variable_get(:@datastore) &&
    @path == x.instance_variable_get(:@path)
end

#hashObject



144
145
146
# File 'lib/rvc/extensions/Datastore.rb', line 144

def hash
  @datastore.hash ^ @path.hash
end

#parentObject



123
124
125
126
127
128
129
130
131
# File 'lib/rvc/extensions/Datastore.rb', line 123

def parent
  els = path.split '/'
  if els.empty?
    @datastore
  else
    parent_path = els[0...-1].join '/'
    RbVmomi::VIM::Datastore::FakeDatastoreFolder.new(@datastore, parent_path)
  end
end

#search_result_to_object(x) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/rvc/extensions/Datastore.rb', line 76

def search_result_to_object x
  case x
  when RbVmomi::VIM::FolderFileInfo
    RbVmomi::VIM::Datastore::FakeDatastoreFolder.new(@datastore, "#{@path}/#{x.path}")
  when RbVmomi::VIM::FileInfo
    RbVmomi::VIM::Datastore::FakeDatastoreFile.new(@datastore, "#{@path}/#{x.path}", x)
  end
end

#traverse_one(arc) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/rvc/extensions/Datastore.rb', line 101

def traverse_one arc
  browser, ds_name = @datastore.collect :browser, :name
  results = browser.SearchDatastore_Task(
    :datastorePath => "[#{ds_name}] #{@path}",
    :searchSpec => {
      :details => {
        :fileType => true,
        :fileSize => true,
        :fileOwner => false,
        :modification => false
      },
      :matchPattern => [arc]
    }
  ).wait_for_completion
  return unless results.file.size == 1
  search_result_to_object results.file[0]
end