Class: OsCtld::OsCtlRepo
- Inherits:
-
Object
- Object
- OsCtld::OsCtlRepo
- Defined in:
- lib/osctld/osctl_repo.rb
Instance Attribute Summary collapse
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
-
#get_image_path(tpl, format) ⇒ String?
Path to the image in cache.
-
#initialize(repo) ⇒ OsCtlRepo
constructor
A new instance of OsCtlRepo.
- #list_images ⇒ Array<Repository::Image>
-
#osctl_repo(*args) ⇒ Array<Integer, String>
protected
Exit status and data.
Constructor Details
#initialize(repo) ⇒ OsCtlRepo
Returns a new instance of OsCtlRepo.
11 12 13 |
# File 'lib/osctld/osctl_repo.rb', line 11 def initialize(repo) @repo = repo end |
Instance Attribute Details
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
8 9 10 |
# File 'lib/osctld/osctl_repo.rb', line 8 def repo @repo end |
Instance Method Details
#get_image_path(tpl, format) ⇒ String?
Returns path to the image in cache.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/osctld/osctl_repo.rb', line 44 def get_image_path(tpl, format) exit_status, data = osctl_repo( File.join(OsCtl::Repo.root, 'bin', 'osctl-repo'), 'remote', 'get', 'path', '--cache', repo.cache_path, repo.url, tpl[:vendor], tpl[:variant], tpl[:arch], tpl[:distribution], tpl[:version], format.to_s ) case exit_status when OsCtl::Repo::EXIT_OK data.strip when OsCtl::Repo::EXIT_FORMAT_NOT_FOUND nil when OsCtl::Repo::EXIT_IMAGE_NOT_FOUND raise ImageNotFound when OsCtl::Repo::EXIT_HTTP_ERROR, OsCtl::Repo::EXIT_NETWORK_ERROR raise ImageRepositoryUnavailable else raise "osctl-repo remote get path failed with exit status #{exit_status}" end end |
#list_images ⇒ Array<Repository::Image>
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/osctld/osctl_repo.rb', line 16 def list_images exit_status, data = osctl_repo( File.join(OsCtl::Repo.root, 'bin', 'osctl-repo'), 'remote', 'ls', '--cache', repo.cache_path, repo.url ) case exit_status when OsCtl::Repo::EXIT_OK JSON.parse(data, symbolize_names: true).map { |v| Repository::Image.new(v) } when OsCtl::Repo::EXIT_HTTP_ERROR, OsCtl::Repo::EXIT_NETWORK_ERROR raise ImageRepositoryUnavailable else raise "osctl-repo remote ls failed with exit status #{exit_status}" end end |
#osctl_repo(*args) ⇒ Array<Integer, String> (protected)
Returns exit status and data.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/osctld/osctl_repo.rb', line 75 def osctl_repo(*args) r, w = IO.pipe pid = Process.fork do SwitchUser.switch_to_system( Repository::USER, Repository::UID, Etc.getgrnam('nogroup').gid, RunState::REPOSITORY_DIR ) ENV['GLI_DEBUG'] = 'true' $stdout.reopen(w) r.close Process.exec(*args) end w.close data = r.read r.close Process.wait(pid) [$?.exitstatus, data] end |