Class: VmRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/ovfparse/vmrepository.rb

Constant Summary collapse

STRICT_CHECKING =
true
USE_CACHE =
true
ALLOWABLE_PKG_TYPES =

ALLOWABLE_PKG_TYPES = [“ovf”, “vmx”, “ova”]

["ovf"]
ALLOWABLE_PROTOCOLS =

ALLOWABLE_PROTOCOLS = [“ftp”, “http”, “https”, “file”, “smb”, “esx4”, “vc4”]

["ftp", "http", "https", "file"]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ VmRepository

Returns a new instance of VmRepository.



15
16
17
18
19
20
# File 'lib/ovfparse/vmrepository.rb', line 15

def initialize(uri)
    (@protocol, @url) = uri.split(":", 2) unless !uri
    @url.sub!(/^\/{0,2}/, '')
    @protocol.downcase
    @url.downcase
end

Instance Attribute Details

#protocolObject

Returns the value of attribute protocol.



13
14
15
# File 'lib/ovfparse/vmrepository.rb', line 13

def protocol
  @protocol
end

#repoObject

Returns the value of attribute repo.



13
14
15
# File 'lib/ovfparse/vmrepository.rb', line 13

def repo
  @repo
end

#urlObject

Returns the value of attribute url.



13
14
15
# File 'lib/ovfparse/vmrepository.rb', line 13

def url
  @url
end

Class Method Details

.create(uri, managed) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ovfparse/vmrepository.rb', line 22

def self.create(uri, managed)
  (@protocol, @url) = uri.split(":", 2) unless !uri
  @url.sub!(/^\/{0,2}/, '')
  @protocol.downcase
  @url.downcase

  if(managed)
    MarketplaceRepository.new(uri)
  elsif @protocol=='ftp'
    FtpVmRepository.new(uri) 
  elsif @protocol=='http'
    HttpVmRepository.new(uri) 
  elsif @protocol=='https'
    HttpsVmRepository.new(uri) 
  elsif @protocol=='file'
    FileVmRepository.new(uri) 
  elsif @protocol.match(/esx/)
    if @protocol.match(/esx4/) 
      Esx4VmRepository.new(uri) 
    else 
      raise NotImplementedError, "Cannot handle this version of ESX: " + @protocol + "\n"
    end
  elsif @protocol.match(/vc/)
    if @protocol.match(/vc4/) 
      Vc4VmRepository.new(uri) 
    else 
      raise NotImplementedError, "Cannot handle this version of VirtualCenter: " + @protocol + "\n"
    end
  else 
    raise NotImplementedError, "Unknown Repository Protocol: " + @protocol + " (bad URI string?)\n"
    VmRepository.new(uri) 
  end
end

.ESXParse(raw_file_list) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/ovfparse/esx4_vmrepository.rb', line 3

def VmRepository.ESXParse(raw_file_list) 
  file_list = Array.new 
  raw_file_list.each { |text_line|
    if text_line.include? "Name:" then
      fragment_arr = text_line.split(" ")
      file = fragment_arr.last 
      file_list.push(file)
    end
  }
  return file_list
end

.FTParse(raw_text_arr) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ovfparse/ftp_vmrepository.rb', line 3

def VmRepository.FTParse (raw_text_arr)
  file_list = Array.new
  raw_text_arr.each { |file_text| 
    ALLOWABLE_PKG_TYPES.each { |type| 
      if file_text.include? type then
          fragment_arr = file_text.split(" ")
          file = fragment_arr.last
          file_list.push(file)
        break;
      end
    }
  }
  return file_list    
end

.HTTParse(raw_html) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ovfparse/http_vmrepository.rb', line 3

def VmRepository.HTTParse (raw_html) 
  file_list = Array.new
  raw_html.each("</a>") { |file_text| 
    ALLOWABLE_PKG_TYPES.each { |type| 
      if file_text.include? type then
          fragment = file_text.split("</a>")
          split_expr = (type + "\">")
          file = fragment[0].split(split_expr)
          file_list.push(file[1])
        break
      end
    }          
  }
  return file_list
end

.LSParse(raw_file_text) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ovfparse/file_vmrepository.rb', line 3

def VmRepository.LSParse (raw_file_text) 
  file_list = Array.new 
  raw_file_text.each { |file_text|
    ALLOWABLE_PKG_TYPES.each { |type| 
      if file_text.include? type then
        fragment_arr = file_text.split(" ")
        file = fragment_arr.last
        file_list.push(file)
      end
    }
  }
  return file_list 
end

Instance Method Details

#fetchObject



67
68
# File 'lib/ovfparse/vmrepository.rb', line 67

def fetch 
end

#getObject



64
65
# File 'lib/ovfparse/vmrepository.rb', line 64

def get 
end

#simplePackageConstruction(package_list) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ovfparse/vmrepository.rb', line 70

def simplePackageConstruction(package_list)
  packages = Array.new
  package_list.each { |p|
    package = VmPackage.create(self.uri + "/" + p)
    package.base_path = self.uri + "/"
    package.name = p
# @todo remove this, or fix it. Supposed to be handled with a COPS mix-in
#      package.state = VmPackage::UNKNOWN
    packages.push(package)
  }

  return packages
end

#uriObject



56
57
58
59
60
61
62
# File 'lib/ovfparse/vmrepository.rb', line 56

def uri 
  if (nil==protocol) then
    return url
  else 
    return (protocol + "://" + url)
  end
end