Module: OsCtld::Utils::Repository

Included in:
Commands::Repository::TemplateList, Container::Builder
Defined in:
lib/osctld/utils/repository.rb

Instance Method Summary collapse

Instance Method Details

#osctl_repo_get(repo, tpl, format, io) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/osctld/utils/repository.rb', line 49

def osctl_repo_get(repo, tpl, format, io)
  pid = Process.fork do
    SwitchUser.switch_to_system(
      Repository::USER,
      Repository::UID,
      Etc.getgrnam('nogroup').gid,
      RunState::REPOSITORY_DIR
    )

    STDOUT.reopen(io)

    Process.exec(
      #File.join(OsCtl::Repo.root, 'bin', 'osctl-repo-dev'),
      File.join(OsCtl::Repo.root, 'bin', 'osctl-repo'),
      'remote', 'get',
      '--cache', repo.cache_path,
      repo.url,
      tpl[:vendor], tpl[:variant], tpl[:arch], tpl[:distribution], tpl[:version],
      format
    )
  end

  io.close
  Process.wait(pid)

  case $?.exitstatus
  when OsCtl::Repo::EXIT_OK
    true

  when OsCtl::Repo::EXIT_FORMAT_NOT_FOUND
    false

  when OsCtl::Repo::EXIT_TEMPLATE_NOT_FOUND
    raise TemplateNotFound

  when OsCtl::Repo::EXIT_HTTP_ERROR, OsCtl::Repo::EXIT_NETWORK_ERROR
    raise TemplateRepositoryUnavailable

  else
    fail "osctl-repo remote get failed with exit status #{$?.exitstatus}"
  end
end

#osctl_repo_ls(repo) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
# File 'lib/osctld/utils/repository.rb', line 8

def osctl_repo_ls(repo)
  r, w = IO.pipe

  pid = Process.fork do
    SwitchUser.switch_to_system(
      Repository::USER,
      Repository::UID,
      Etc.getgrnam('nogroup').gid,
      RunState::REPOSITORY_DIR
    )

    STDOUT.reopen(w)
    r.close

    Process.exec(
      #File.join(OsCtl::Repo.root, 'bin', 'osctl-repo-dev'),
      File.join(OsCtl::Repo.root, 'bin', 'osctl-repo'),
      'remote', 'ls',
      '--cache', repo.cache_path,
      repo.url
    )
  end

  w.close

  data = r.read
  r.close
  Process.wait(pid)

  case $?.exitstatus
  when OsCtl::Repo::EXIT_OK
    JSON.parse(data, symbolize_names: true).map { |v| Repository::Template.new(v) }

  when OsCtl::Repo::EXIT_HTTP_ERROR, OsCtl::Repo::EXIT_NETWORK_ERROR
    raise TemplateRepositoryUnavailable

  else
    fail "osctl-repo remote ls failed with exit status #{$?.exitstatus}"
  end
end