Class: OsCtl::Repo::Downloader::Direct

Inherits:
Base
  • Object
show all
Defined in:
lib/osctl/repo/downloader/direct.rb

Overview

Download image in a specified format, no caching involved

Constant Summary

Constants inherited from Base

Base::DEFAULT_ATTEMPTS, Base::DEFAULT_WAIT, Base::NETWORK_EXCEPTIONS

Instance Attribute Summary

Attributes inherited from Base

#repo

Instance Method Summary collapse

Methods inherited from Base

#connect, #index_uri, #initialize, #request_get, #retryable_http_code?, #with_retries

Constructor Details

This class inherits a constructor from OsCtl::Repo::Downloader::Base

Instance Method Details

#get(vendor, variant, arch, dist, vtag, format, _opts = {}, &block) ⇒ Object

yieldparam [String] downloaded data



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
# File 'lib/osctl/repo/downloader/direct.rb', line 27

def get(vendor, variant, arch, dist, vtag, format, _opts = {}, &block)
  with_retries do
    connect do |http|
      body = +''

      request_get(http, index_uri) do |res|
        raise BadHttpResponse, res.code if res.code != '200'

        res.read_body do |fragment|
          body << fragment
        end
      end

      index = Remote::Index.from_string(repo, body)
      t = index.lookup(vendor, variant, arch, dist, vtag)

      raise ImageNotFound, t unless t
      raise FormatNotFound.new(t, format) unless t.has_image?(format)

      request_get(http, URI(t.abs_image_url(format))) do |res|
        raise BadHttpResponse, res.code if res.code != '200'

        res.read_body(&block)
      end
    end
  end
end

#listArray<Remote::Image>

Returns:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/osctl/repo/downloader/direct.rb', line 8

def list
  with_retries do
    connect do |http|
      body = +''

      request_get(http, index_uri) do |res|
        raise BadHttpResponse, res.code if res.code != '200'

        res.read_body do |fragment|
          body << fragment
        end
      end

      Remote::Index.from_string(repo, body).images
    end
  end
end