Module: Pulpsak

Defined in:
lib/pulpsak.rb,
lib/pulpsak/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.3"
@@config =
YAML.load_file(config_yaml)

Class Method Summary collapse

Class Method Details

.distribution_inspect_by_name(name) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/pulpsak.rb', line 75

def self.distribution_inspect_by_name(name)
  api_instance = PulpRpmClient::DistributionsRpmApi.new
  api_instance.list.results.each do |dist|
    if dist.name == name
      return dist
    end
  end
  return nil
end

.find_existing_publication(pub_opts) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/pulpsak.rb', line 115

def self.find_existing_publication(pub_opts)
  pub_api = PulpRpmClient::PublicationsRpmApi.new
  existing_publication = nil
  if pub_opts.has_key?(:repository_version)
    # if we have a specific version, we can look through all
    # existing publications to avoid creating one, which can be
    # expensive
    pub_api.list.results.each do |pub|
      pub_hash = pub.to_hash
      match = true
      [:metadata_checksum_type,:package_checksum_type,:gpgcheck,:repo_gpgcheck,:repository_version].each do |p|
        if pub_opts[p] != pub_hash[p]
          match = false
          break
        end
      end
      if match
        existing_publication = pub
        break
      end
    end
  end
  return existing_publication
end

.remote_inspect(href) ⇒ Object



62
63
64
65
# File 'lib/pulpsak.rb', line 62

def self.remote_inspect(href)
  api_instance = PulpRpmClient::RemotesRpmApi.new
  return api_instance.read(href)
end

.remote_inspect_by_name(name) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/pulpsak.rb', line 66

def self.remote_inspect_by_name(name)
  api_instance = PulpRpmClient::RemotesRpmApi.new
  api_instance.list.results.each do |remote|
    if remote.name == name
      return remote_inspect(remote.pulp_href)
    end
  end
  return nil
end

.repository_inspect(href) ⇒ Object



45
46
47
48
# File 'lib/pulpsak.rb', line 45

def self.repository_inspect(href)
  api_instance = PulpRpmClient::RepositoriesRpmApi.new
  return api_instance.read(href)
end

.repository_inspect_by_name(name) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/pulpsak.rb', line 53

def self.repository_inspect_by_name(name)
  api_instance = PulpRpmClient::RepositoriesRpmApi.new
  api_instance.list.results.each do |repo|
    if repo.name == name
      return repository_inspect(repo.pulp_href)
    end
  end
  return nil
end

.repository_version_inspect(href) ⇒ Object



49
50
51
52
# File 'lib/pulpsak.rb', line 49

def self.repository_version_inspect(href)
  api_instance = PulpRpmClient::RepositoriesRpmVersionsApi.new
  return api_instance.read(href)
end

.task_cancel(href) ⇒ Object



88
89
90
91
# File 'lib/pulpsak.rb', line 88

def self.task_cancel(href)
  api_instance = PulpcoreClient::TasksApi.new
  return api_instance.tasks_cancel(href)
end

.task_inspect(href) ⇒ Object



84
85
86
87
# File 'lib/pulpsak.rb', line 84

def self.task_inspect(href)
  api_instance = PulpcoreClient::TasksApi.new
  return api_instance.read(href)
end

.wait_on_task(href, sleep_time: 3, spacer: '.', final: "\n") ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/pulpsak.rb', line 92

def self.wait_on_task(href,sleep_time: 3, spacer: '.', final: "\n")
  api = PulpcoreClient::TasksApi.new
  last_message = ''
  while true
    i = Pulpsak.task_inspect(href)
    if i.state == 'running' or i.state == 'waiting'
      if i.progress_reports.respond_to?(:length) and i.progress_reports.length() > 0
        if last_message != i.progress_reports[-1].message
          last_message = i.progress_reports[-1].message
          print last_message,"\n"
        end
      else
        print spacer
      end
      sleep sleep_time
    else
      break
    end
  end
  print final
  task = Pulpsak.task_inspect(href)
  return task
end