Class: VCloudSdk::OVFDirectory

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_vcloud_sdk/ovf_directory.rb

Instance Method Summary collapse

Constructor Details

#initialize(directory) ⇒ OVFDirectory

Returns a new instance of OVFDirectory.

Raises:



4
5
6
7
8
9
10
11
12
# File 'lib/ruby_vcloud_sdk/ovf_directory.rb', line 4

def initialize(directory)
  raise CloudError, "Requires string-like object for directory" unless
    directory.respond_to?(:to_s)
  @directory = directory
  @logger = Config.logger

  # Quick sanity check.  Raise an exception if OVF file not there
  self.ovf_file
end

Instance Method Details

#ovf_fileObject



27
28
29
# File 'lib/ruby_vcloud_sdk/ovf_directory.rb', line 27

def ovf_file
  File.new(ovf_file_path)
end

#ovf_file_pathObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_vcloud_sdk/ovf_directory.rb', line 14

def ovf_file_path
  ovf_files = Dir[File.join(@directory, "*.ovf")]
  if ovf_files.length > 1
    @logger.error "More than one OVF file found in dir #{@directory}"
    raise "More than one OVF file found in directory #{@directory}"
  end
  if ovf_files.length < 1
    @logger.error "No OVF file found in directory #{@directory}"
    raise "No OVF file found in directory #{@directory}"
  end
  ovf_files.pop
end

#vmdk_file(filename) ⇒ Object



40
41
42
# File 'lib/ruby_vcloud_sdk/ovf_directory.rb', line 40

def vmdk_file(filename)
  File.new(self.vmdk_file_path(filename), "rb")
end

#vmdk_file_path(filename) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/ruby_vcloud_sdk/ovf_directory.rb', line 31

def vmdk_file_path(filename)
  file_path = File.join(@directory, filename)
  unless File.exist? file_path
    @logger.error "#{filename} not found in #{@directory}"
    raise "#{filename} not found in #{@directory}"
  end
  file_path
end