Class: OsCtl::Image::Operations::Repository::GetImagePath

Inherits:
Base
  • Object
show all
Defined in:
lib/osctl/image/operations/repository/get_image_path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

run

Constructor Details

#initialize(repo_dir, attrs, format) ⇒ GetImagePath

Returns a new instance of GetImagePath.

Parameters:

  • repo_dir (String)
  • attrs (Hash)
  • format (:tar, :zfs)

Options Hash (attrs):

  • :distribution (String)
  • :version (String)
  • :arch (String)
  • :vendor (String)
  • :variant (String)


23
24
25
26
27
28
# File 'lib/osctl/image/operations/repository/get_image_path.rb', line 23

def initialize(repo_dir, attrs, format)
  super()
  @repo_dir = repo_dir
  @attrs = attrs
  @format = format.to_s
end

Instance Attribute Details

#attrsHash (readonly)

Returns:

  • (Hash)


10
11
12
# File 'lib/osctl/image/operations/repository/get_image_path.rb', line 10

def attrs
  @attrs
end

#formatString (readonly)

Returns:

  • (String)


13
14
15
# File 'lib/osctl/image/operations/repository/get_image_path.rb', line 13

def format
  @format
end

#repo_dirString (readonly)

Returns:

  • (String)


7
8
9
# File 'lib/osctl/image/operations/repository/get_image_path.rb', line 7

def repo_dir
  @repo_dir
end

Instance Method Details

#executeString

Returns path to the image.

Returns:

  • (String)

    path to the image

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/osctl/image/operations/repository/get_image_path.rb', line 31

def execute
  repo = OsCtl::Repo::Local::Repository.new(repo_dir)

  unless repo.exist?
    raise OperationError, 'repository does not exist'
  end

  img = repo.find(
    attrs[:vendor],
    attrs[:variant],
    attrs[:arch],
    attrs[:distribution],
    attrs[:version]
  )

  raise OperationError, 'image not found' unless img
  raise OperationError 'image format not found' unless img.has_image?(format)

  File.join(repo_dir, img.version_image_path(format))
end