Class: OsCtl::Repo::Base::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/osctl/repo/base/image.rb

Direct Known Subclasses

Remote::Image

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, vendor, variant, arch, dist, ver, opts) ⇒ Image

Returns a new instance of Image.



19
20
21
22
23
24
25
26
27
28
# File 'lib/osctl/repo/base/image.rb', line 19

def initialize(repo, vendor, variant, arch, dist, ver, opts)
  @repo = repo
  @vendor = vendor
  @variant = variant
  @arch = arch
  @distribution = dist
  @version = ver
  @tags = opts[:tags] || []
  @image = opts[:image]
end

Instance Attribute Details

#archObject (readonly)

Returns the value of attribute arch.



16
17
18
# File 'lib/osctl/repo/base/image.rb', line 16

def arch
  @arch
end

#distributionObject (readonly)

Returns the value of attribute distribution.



16
17
18
# File 'lib/osctl/repo/base/image.rb', line 16

def distribution
  @distribution
end

#imageObject (readonly)

Returns the value of attribute image.



16
17
18
# File 'lib/osctl/repo/base/image.rb', line 16

def image
  @image
end

#repoObject (readonly)

Returns the value of attribute repo.



16
17
18
# File 'lib/osctl/repo/base/image.rb', line 16

def repo
  @repo
end

#tagsObject (readonly)

Returns the value of attribute tags.



16
17
18
# File 'lib/osctl/repo/base/image.rb', line 16

def tags
  @tags
end

#variantObject (readonly)

Returns the value of attribute variant.



16
17
18
# File 'lib/osctl/repo/base/image.rb', line 16

def variant
  @variant
end

#vendorObject (readonly)

Returns the value of attribute vendor.



16
17
18
# File 'lib/osctl/repo/base/image.rb', line 16

def vendor
  @vendor
end

#versionObject (readonly)

Returns the value of attribute version.



16
17
18
# File 'lib/osctl/repo/base/image.rb', line 16

def version
  @version
end

Class Method Details

.load(repo, data) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/osctl/repo/base/image.rb', line 3

def self.load(repo, data)
  new(
    repo,
    data[:vendor],
    data[:variant],
    data[:arch],
    data[:distribution],
    data[:version],
    tags: data[:tags],
    image: data[:image].keys.map(&:to_s)
  )
end

Instance Method Details

#<=>(other) ⇒ Object



87
88
89
90
91
# File 'lib/osctl/repo/base/image.rb', line 87

def <=>(other)
  [vendor, variant, arch, distribution, version] \
  <=> \
    [other.vendor, other.variant, other.arch, other.distribution, other.version]
end

#==(other) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/osctl/repo/base/image.rb', line 79

def ==(other)
  vendor == other.vendor \
    && variant == other.variant \
    && arch == other.arch \
    && distribution == other.distribution \
    && version == other.version
end

#abs_dir_pathObject



46
47
48
# File 'lib/osctl/repo/base/image.rb', line 46

def abs_dir_path
  File.join(repo.path, dir_path)
end

#abs_image_path(format) ⇒ Object



71
72
73
# File 'lib/osctl/repo/base/image.rb', line 71

def abs_image_path(format)
  File.join(repo.path, image_path(format))
end

#abs_tag_path(tag) ⇒ Object



50
51
52
# File 'lib/osctl/repo/base/image.rb', line 50

def abs_tag_path(tag)
  File.join(repo.path, vendor, variant, arch, distribution, tag)
end

#dir_pathObject



42
43
44
# File 'lib/osctl/repo/base/image.rb', line 42

def dir_path
  File.join(vendor, variant, arch, distribution, version)
end

#dumpObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/osctl/repo/base/image.rb', line 30

def dump
  {
    vendor:,
    variant:,
    arch:,
    distribution:,
    version:,
    tags: tags.sort,
    image: image.to_h { |v| [v, image_path(v)] }
  }
end

#has_image?(fmt) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/osctl/repo/base/image.rb', line 75

def has_image?(fmt)
  image.include?(fmt)
end

#image_name(format) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/osctl/repo/base/image.rb', line 62

def image_name(format)
  case format.to_sym
  when :tar
    'image-archive.tar'
  when :zfs
    'image-stream.tar'
  end
end

#image_path(format) ⇒ Object



54
55
56
# File 'lib/osctl/repo/base/image.rb', line 54

def image_path(format)
  File.join(dir_path, image_name(format))
end

#to_sObject



93
94
95
# File 'lib/osctl/repo/base/image.rb', line 93

def to_s
  "#{distribution}-#{version}-#{arch}-#{vendor}-#{variant}"
end

#version_image_path(format) ⇒ Object



58
59
60
# File 'lib/osctl/repo/base/image.rb', line 58

def version_image_path(format)
  File.join("v#{SCHEMA}", image_path(format))
end