pulpsak 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 947929b5e45c3692fd4beb36cdb32030579b83aff4eb5f536121afbf496dfa59
4
+ data.tar.gz: af221b0a512a49f704ee9c0b0e8ca5292f8a6e7d692d6e8c368c229b3f05aa9d
5
+ SHA512:
6
+ metadata.gz: 365ff565d2bba4f9589b008fea8eea77f4b9237d7f7112a20d515337d1c52f80fdb8206611482aafedcac2f67059b4cc758b8d04a49a97ebcfb216c70765f9e2
7
+ data.tar.gz: 68d22e639905585d4107ec75078d74ba730c8a0126a4de5d3a3ee480c9f4f2a3e538f24113b7727d013fc4482f5b4a2430be6383d8f99d25a823b2d4d2b501e4
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pulpsak.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "thor", "~> 1.0"
9
+ gem "text-table"
10
+ gem 'pulp_rpm_client', ">= 3.12.0"
11
+ gem 'pulpcore_client', ">= 3.12.3"
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pulpsak (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.4.4)
10
+ faraday (1.4.2)
11
+ faraday-em_http (~> 1.0)
12
+ faraday-em_synchrony (~> 1.0)
13
+ faraday-excon (~> 1.1)
14
+ faraday-net_http (~> 1.0)
15
+ faraday-net_http_persistent (~> 1.1)
16
+ multipart-post (>= 1.2, < 3)
17
+ ruby2_keywords (>= 0.0.4)
18
+ faraday-em_http (1.0.0)
19
+ faraday-em_synchrony (1.0.0)
20
+ faraday-excon (1.1.0)
21
+ faraday-net_http (1.0.1)
22
+ faraday-net_http_persistent (1.1.0)
23
+ json (2.5.1)
24
+ multipart-post (2.1.1)
25
+ pulp_rpm_client (3.12.0)
26
+ faraday (>= 0.14.0)
27
+ json (~> 2.1, >= 2.1.0)
28
+ pulpcore_client (3.13.0)
29
+ faraday (>= 0.14.0)
30
+ json (~> 2.1, >= 2.1.0)
31
+ rake (12.3.3)
32
+ rspec (3.10.0)
33
+ rspec-core (~> 3.10.0)
34
+ rspec-expectations (~> 3.10.0)
35
+ rspec-mocks (~> 3.10.0)
36
+ rspec-core (3.10.1)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-expectations (3.10.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-mocks (3.10.2)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-support (3.10.2)
45
+ ruby2_keywords (0.0.4)
46
+ text-table (1.2.4)
47
+ thor (1.1.0)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ bundler (~> 2.1.4)
54
+ pulp_rpm_client (>= 3.12.0)
55
+ pulpcore_client (>= 3.12.3)
56
+ pulpsak!
57
+ rake (~> 12.0)
58
+ rspec (~> 3.0)
59
+ text-table
60
+ thor (~> 1.0)
61
+
62
+ BUNDLED WITH
63
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Pulpsak
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pulpsak`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'pulpsak'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install pulpsak
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pulpsak.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pulpsak"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/pulpsak ADDED
@@ -0,0 +1,517 @@
1
+ #! /bin/env -S ruby -I ./lib
2
+
3
+ require "thor"
4
+ require "pulpsak"
5
+ require "text-table"
6
+
7
+ class Tasks < Thor
8
+ desc "list", "list all tasks"
9
+ def list()
10
+ api_instance = PulpcoreClient::TasksApi.new
11
+ table = Text::Table.new
12
+ table.head = ["name","state","started","finished","pulp_href"]
13
+ table.rows = []
14
+ api_instance.list.results.each do |task|
15
+ table.rows << [ task.name, task.state, task.started_at, task.finished_at, task.pulp_href ]
16
+ end
17
+ print table.to_s
18
+ end
19
+ desc "inspect [PULP_HREF]", "inspect task by uuid"
20
+ def inspect(pulp_href)
21
+ pp Pulpsak.task_inspect(pulp_href)
22
+ end
23
+ desc "wait [PULP_HREF]", "monitor task progress by uuid"
24
+ def wait(pulp_href)
25
+ pp Pulpsak.wait_on_task(pulp_href)
26
+ end
27
+ desc "cancel [PULP_HREF]", "cancel task by uuid"
28
+ def cancel(pulp_href)
29
+ pp Pulpsak.task_cancel(pulp_href)
30
+ end
31
+ end
32
+ class Remotes < Thor
33
+ desc "list", "list all remotes"
34
+ def list()
35
+ remotes_api = PulpRpmClient::RemotesRpmApi.new
36
+ table = Text::Table.new
37
+ table.head = ["last update","name","url","download_concurrency","policy"]
38
+ table.rows = []
39
+ remotes_api.list.results.each do |remote|
40
+ table.rows << [
41
+ remote.pulp_last_updated.to_time,
42
+ remote.name,
43
+ remote.url,
44
+ remote.download_concurrency.to_s,
45
+ remote.policy,
46
+ ]
47
+ end
48
+ print table.to_s
49
+ end
50
+ desc "create [NAME] [URL]", "create remote"
51
+ method_option :ca_cert, :type => :string, :default => nil, :desc => "A PEM encoded CA certificate used to validate the server certificate presented by the remote server."
52
+ method_option :client_cert, :type => :string, :default => nil, :desc => "A PEM encoded client certificate used for authentication."
53
+ method_option :client_key, :type => :string, :default => nil, :desc => "A PEM encoded private key used for authentication."
54
+ method_option :tls_validation, :type => :boolean, :default => nil, :desc => "If True, TLS peer validation must be performed."
55
+ method_option :proxy_url, :type => :string, :default => nil, :desc => "The proxy URL. Format: scheme://user:password@host:port"
56
+ method_option :username, :type => :string, :default => nil, :desc => "The username to be used for authentication when syncing."
57
+ method_option :password, :type => :string, :default => nil, :desc => "The password to be used for authentication when syncing."
58
+ method_option :download_concurrency, :type => :numeric, :default => nil, :desc => "Total number of simultaneous connections."
59
+ method_option :policy, :type => :string, :default => nil, :desc => "The policy to use when downloading content. The possible values include: 'immediate', 'on_demand', and 'streamed'. 'immediate' is the default."
60
+ method_option :sles_auth_token, :type => :string, :default => nil, :desc => "Authentication token for SLES repositories."
61
+
62
+ def create(name,url)
63
+ remotes_api = PulpRpmClient::RemotesRpmApi.new
64
+ options[:name] = name
65
+ options[:url] = url
66
+ pp remotes_api.create(options)
67
+ end
68
+ desc "update [NAME]", "update remote"
69
+ method_option :ca_cert, :type => :string, :default => nil, :desc => "A PEM encoded CA certificate used to validate the server certificate presented by the remote server."
70
+ method_option :client_cert, :type => :string, :default => nil, :desc => "A PEM encoded client certificate used for authentication."
71
+ method_option :client_key, :type => :string, :default => nil, :desc => "A PEM encoded private key used for authentication."
72
+ method_option :tls_validation, :type => :boolean, :default => nil, :desc => "If True, TLS peer validation must be performed."
73
+ method_option :proxy_url, :type => :string, :default => nil, :desc => "The proxy URL. Format: scheme://user:password@host:port"
74
+ method_option :username, :type => :string, :default => nil, :desc => "The username to be used for authentication when syncing."
75
+ method_option :password, :type => :string, :default => nil, :desc => "The password to be used for authentication when syncing."
76
+ method_option :download_concurrency, :type => :numeric, :default => nil, :desc => "Total number of simultaneous connections."
77
+ method_option :policy, :type => :string, :default => nil, :desc => "The policy to use when downloading content. The possible values include: 'immediate', 'on_demand', and 'streamed'. 'immediate' is the default."
78
+ method_option :sles_auth_token, :type => :string, :default => nil, :desc => "Authentication token for SLES repositories."
79
+ method_option :url, :type => :string, :default => nil, :desc => "update the url"
80
+ method_option :rename, :type => :string, :default => nil, :desc => "rename the remote"
81
+
82
+ def update(name)
83
+ remotes_api = PulpRpmClient::RemotesRpmApi.new
84
+ remote = Pulpsak.remote_inspect_by_name(name)
85
+ if options[:rename]
86
+ options[:name] = options[:rename]
87
+ options.delete('rename')
88
+ else
89
+ options[:name] = remote.name
90
+ end
91
+ if not options[:url]
92
+ options[:url] = remote.url
93
+ end
94
+ puts "updating remote #{name}"
95
+ Pulpsak.wait_on_task(remotes_api.update(remote.pulp_href,options).task)
96
+ end
97
+ desc "delete [NAME]", "delete a remote"
98
+ def delete(name)
99
+ pp PulpRpmClient::RemotesRpmApi.new.delete(Pulpsak.remote_inspect_by_name(name).pulp_href)
100
+ end
101
+ end
102
+ class RepositotyVersions < Thor
103
+ desc "list [NAME]", "list all repo versions"
104
+ def list(name)
105
+ repover_api = PulpRpmClient::RepositoriesRpmVersionsApi.new
106
+ if repo = Pulpsak.repository_inspect_by_name(name)
107
+ table = Text::Table.new
108
+ table.head = ["created","number","added","present","removed"]
109
+ table.rows = []
110
+ repover_api.list(repo.pulp_href).results.each do |rver|
111
+ table.rows << [
112
+ rver.pulp_created.to_time,
113
+ rver.number.to_s,
114
+ rver.content_summary.added.length,
115
+ rver.content_summary.present.length,
116
+ rver.content_summary.removed.length,
117
+ ]
118
+ end
119
+ print table.to_s
120
+ end
121
+ end
122
+ end
123
+ class Repositories < Thor
124
+ desc "list", "list all repos"
125
+ def list()
126
+ remotes_api = PulpRpmClient::RemotesRpmApi.new
127
+
128
+ table = Text::Table.new
129
+ table.head = ["created","name","keep","remote"]
130
+ table.rows = []
131
+ PulpRpmClient::RepositoriesRpmApi.new.list.results.each do |dist|
132
+ table.rows << [dist.pulp_created.to_time,dist.name,dist.retain_package_versions,(dist.remote ? remotes_api.read(dist.remote).url : '')]
133
+ end
134
+ print table.to_s
135
+ end
136
+
137
+ desc "sync [NAME]", "call sync on repo"
138
+ method_option :mirror, :type => :boolean, :default => false, :desc => "mirror true removes rpms, false is merely additive"
139
+ method_option :remote, :type => :string, :desc => "mirror from alternate remote"
140
+ def sync(name)
141
+ repo_api = PulpRpmClient::RepositoriesRpmApi.new
142
+ repo_api.list.results.each do |dist|
143
+ if dist.name == name
144
+ opts = {mirror: options[:mirror]}
145
+ if options[:remote]
146
+ if remote = Pulpsak.remote_inspect_by_name(options[:remote])
147
+ opts['remote'] = remote.pulp_href
148
+ else
149
+ raise ArgumentError, "could not find remote #{options[:remote]}"
150
+ end
151
+ end
152
+ print "syncing #{name} (you can ctrl-c out, it will continue in the background)\n"
153
+ pp Pulpsak.wait_on_task(repo_api.sync(dist.pulp_href,opts).task)
154
+ break
155
+ end
156
+ end
157
+ end
158
+ desc "create [NAME]", "create a repository"
159
+ method_option :description, :type => :string, :default => nil, :desc => "An optional description."
160
+ method_option :retain_package_versions, :type => :numeric, :default => 0, :desc => "The number of versions of each package to keep in the repository; older versions will be purged. The default is '0', which will disable this feature and keep all versions of each package."
161
+ method_option :remote, :type => :string, :default => nil, :desc => "name of existing remote"
162
+ method_option :metadata_signing_service, :type => :string, :default => nil, :desc => "A reference to an associated signing service."
163
+ def create(name)
164
+ options[:name] = name
165
+ if options[:remote]
166
+ if remote = Pulpsak.remote_inspect_by_name(options[:remote])
167
+ options[:remote] = remote.pulp_href
168
+ else
169
+ raise ArgumentError, "could not find remote #{options[:remote]}"
170
+ end
171
+ end
172
+ repo_api = PulpRpmClient::RepositoriesRpmApi.new
173
+ pp repo_api.create(options)
174
+ end
175
+ desc "update [NAME]", "update a repository"
176
+ method_option :rename, :type => :string, :default => nil, :desc => "A (new) unique name for this repository."
177
+ method_option :description, :type => :string, :default => nil, :desc => "An optional description."
178
+ method_option :retain_package_versions, :type => :numeric, :default => 0, :desc => "The number of versions of each package to keep in the repository; older versions will be purged. The default is '0', which will disable this feature and keep all versions of each package."
179
+ method_option :remote, :type => :string, :default => nil, :desc => "name of existing remote"
180
+ method_option :metadata_signing_service, :type => :string, :default => nil, :desc => "A reference to an associated signing service."
181
+ def update(name)
182
+ repo_api = PulpRpmClient::RepositoriesRpmApi.new
183
+ opts = {}
184
+
185
+ repo = Pulpsak.repository_inspect_by_name(name)
186
+ if options[:remote]
187
+ if remote = Pulpsak.remote_inspect_by_name(options[:remote])
188
+ opts[:remote] = remote.pulp_href
189
+ else
190
+ raise ArgumentError, "could not find remote #{options[:remote]}"
191
+ end
192
+ end
193
+ if options[:description]
194
+ opts[:description] = options[:description]
195
+ end
196
+ if options[:metadata_signing_service]
197
+ opts[:metadata_signing_service] = options[:metadata_signing_service]
198
+ end
199
+ if options[:retain_package_versions]
200
+ opts[:retain_package_versions] = options[:retain_package_versions].to_i
201
+ end
202
+
203
+ if options[:rename]
204
+ opts[:name] = options[:rename]
205
+ pp repo_api.update(repo.pulp_href,opts)
206
+ else
207
+ pp repo_api.partial_update(repo.pulp_href,opts)
208
+ end
209
+ end
210
+ desc "delete [NAME]", "delete a repository"
211
+ def delete(name)
212
+ unless repo = Pulpsak.repository_inspect_by_name(name)
213
+ puts "unable to find specified repository #{name}"
214
+ exit 1
215
+ end
216
+ puts "delete repository #{name}"
217
+ Pulpsak.wait_on_task(PulpRpmClient::RepositoriesRpmApi.new.delete(repo.pulp_href).task)
218
+ end
219
+ desc "versions", "manage repository versions"
220
+ subcommand "versions", RepositotyVersions
221
+ end
222
+ class Distributions < Thor
223
+ desc "list", "list all distributions"
224
+ def list()
225
+ pubs = PulpRpmClient::PublicationsRpmApi.new
226
+
227
+ table = Text::Table.new
228
+ table.head = ["created","name","base","pub->repo","gpgcheck","repo_gpgcheck","metadata","package"]
229
+ table.rows = []
230
+ PulpRpmClient::DistributionsRpmApi.new.list.results.each do |dist|
231
+ repo_info = ['ORPHAN','ORPHAN','ORPHAN','ORPHAN','ORPHAN']
232
+ if dist.publication and pub = pubs.read(dist.publication) and pub.repository
233
+ repo_info = [Pulpsak.repository_inspect(pub.repository).name +
234
+ ':' +
235
+ Pulpsak.repository_version_inspect(pub.repository_version).number.to_s,
236
+ pub.gpgcheck,
237
+ pub.repo_gpgcheck,
238
+ pub.metadata_checksum_type,
239
+ pub.package_checksum_type, ]
240
+ end
241
+ table.rows << [dist.pulp_created.to_time,dist.name,dist.base_path,repo_info]
242
+ end
243
+ print table.to_s
244
+ end
245
+ desc "create [NAME] [BASE_PATH] [REPO]", "create a distribution using a unique name, base path, and repository specification"
246
+ method_option :version, :type => :numeric, :default => nil, :desc => "Integer version number of repository to reference, default is to use the latest"
247
+ method_option :metadata_checksum_type, :type => :string, :default => 'sha256', :desc => 'The checksum type for metadata, "unknown" "md5" "sha1" "sha224" "sha256" "sha384" "sha512"'
248
+ method_option :package_checksum_type, :type => :string, :default => 'sha256', :desc => 'The checksum type for packages, "unknown" "md5" "sha1" "sha224" "sha256" "sha384" "sha512"'
249
+ method_option :gpgcheck, :type => :boolean, :default => false, :desc => "An option specifying whether a client should perform a GPG signature check on packages."
250
+ method_option :repo_gpgcheck, :type => :boolean, :default => false, :desc => "An option specifying whether a client should perform a GPG signature check on the repodata."
251
+ method_option :content_guard, :type => :string, :default => nil, :desc => 'An optional content-guard.'
252
+ def create(name,base_path,repo_name)
253
+
254
+ pub_api = PulpRpmClient::PublicationsRpmApi.new
255
+ #repo_api = PulpRpmClient::RepositoriesRpmApi.new
256
+ dist_api = PulpRpmClient::DistributionsRpmApi.new
257
+ if Pulpsak.distribution_inspect_by_name(name)
258
+ puts("distribution already exist: #{name}\n")
259
+ exit 1
260
+ end
261
+ repo = Pulpsak.repository_inspect_by_name(repo_name)
262
+ unless repo
263
+ puts("unable to find repository #{repo_name}\n")
264
+ exit 1
265
+ end
266
+ # create a new publication for the new repo
267
+ pub_opts = {
268
+ :metadata_checksum_type => options[:metadata_checksum_type],
269
+ :package_checksum_type => options[:package_checksum_type],
270
+ :gpgcheck => options[:gpgcheck] ? 1 : 0,
271
+ :repo_gpgcheck => options[:repo_gpgcheck] ? 1 : 0,
272
+ }
273
+ if options[:version]
274
+ pub_opts[:repository_version] = repo.pulp_href + 'versions/' + options[:version].to_s + '/'
275
+ else
276
+ pub_opts[:repository] = repo.pulp_href
277
+ end
278
+ existing_publication = Pulpsak.find_existing_publication(pub_opts)
279
+ pub_href = ''
280
+ if existing_publication
281
+ pub_href = existing_publication.pulp_href
282
+ else
283
+ print "creating new publication"
284
+ begin
285
+ task = Pulpsak.wait_on_task(pub_api.create(pub_opts).task)
286
+ rescue PulpRpmClient::ApiError => e
287
+ puts "Exception when creating publication: #{e}"
288
+ exit 1
289
+ end
290
+ if task.state != 'completed'
291
+ print "unable to create publication, unable to continue\n"
292
+ exit 1
293
+ end
294
+ pub_href = task.created_resources[0]
295
+ end
296
+ print "creating distribution"
297
+ begin
298
+ task = Pulpsak.wait_on_task(
299
+ dist_api.create(
300
+ {
301
+ :name => name,
302
+ :base_path => base_path,
303
+ :content_guard => options[:content_guard],
304
+ :publication => pub_href,
305
+ }
306
+ ).task)
307
+ rescue PulpRpmClient::ApiError => e
308
+ puts "\nException when creating distibution, deleting associated publication: #{e}"
309
+ pub_api.delete(pub_href)
310
+ exit 1
311
+ end
312
+ if task.state != "completed"
313
+ print "unable to create distibution, deleting publication"
314
+ pub_api.delete(pub_href)
315
+ exit 1
316
+ end
317
+ end
318
+ desc "update [NAME]", "update a distribution"
319
+ method_option :version, :type => :numeric, :default => nil, :desc => "Integer version number of repository to reference, default is to use the latest"
320
+ method_option :metadata_checksum_type, :type => :string, :default => nil, :desc => 'The checksum type for metadata, "unknown" "md5" "sha1" "sha224" "sha256" "sha384" "sha512"'
321
+ method_option :package_checksum_type, :type => :string, :default => nil, :desc => 'The checksum type for packages, "unknown" "md5" "sha1" "sha224" "sha256" "sha384" "sha512"'
322
+ method_option :gpgcheck, :type => :boolean, :default => false, :desc => "An option specifying whether a client should perform a GPG signature check on packages."
323
+ method_option :repo_gpgcheck, :type => :boolean, :default => false, :desc => "An option specifying whether a client should perform a GPG signature check on the repodata."
324
+ method_option :content_guard, :type => :string, :default => nil, :desc => 'An optional content-guard.'
325
+ method_option :newname, :type => :string, :default => nil, :desc => 'A unique name. Ex, rawhide and stable.'
326
+ method_option :base_path, :type => :string, :default => nil, :desc => 'The base (relative) path component of the published url. Avoid paths that overlap with other distribution base paths (e.g. "foo" and "foo/bar")'
327
+ method_option :repo, :type => :string, :default => nil, :desc => 'set the repository this distribution\'s publication references'
328
+ def update(name)
329
+
330
+ pub_api = PulpRpmClient::PublicationsRpmApi.new
331
+ repo_api = PulpRpmClient::RepositoriesRpmApi.new
332
+ dist_api = PulpRpmClient::DistributionsRpmApi.new
333
+ repover_api = PulpRpmClient::RepositoriesRpmVersionsApi.new
334
+
335
+ unless dist = Pulpsak.distribution_inspect_by_name(name)
336
+ puts("distribution doesn't exist: #{name}\n")
337
+ exit 1
338
+ end
339
+ unless dist.publication or options[:repo]
340
+ puts "this distribution has no publication defined, therefore you must specify a repo using --repo and optionally --version"
341
+ exit 1
342
+ end
343
+ pub_opts = {}
344
+ if dist.publication and old_pub = pub_api.read(dist.publication)
345
+ old_pub_hash = old_pub.to_hash
346
+ [:metadata_checksum_type,:package_checksum_type,:gpgcheck,:repo_gpgcheck,:repository_version].each do |p|
347
+ pub_opts[p] = old_pub_hash[p]
348
+ end
349
+ end
350
+ [:metadata_checksum_type,:package_checksum_type,:gpgcheck,:repo_gpgcheck].each do |p|
351
+ if options.has_key?(p.to_s) and options[p.to_s] != nil
352
+ if p.to_s =~ /check$/
353
+ pub_opts[p] = options[p.to_s] == true ? 1 : 0
354
+ else
355
+ pub_opts[p] = options[p.to_s]
356
+ end
357
+ end
358
+ end
359
+ if options[:repo]
360
+ repo = Pulpsak.repository_inspect_by_name(options[:repo])
361
+ unless repo
362
+ puts("unable to find repository #{options[:repo]}\n")
363
+ exit 1
364
+ end
365
+ if options[:version]
366
+ pub_opts[:repository_version] = repo.pulp_href + 'versions/' + options[:version].to_s + '/'
367
+ else
368
+ pub_opts[:repository] = repo.pulp_href
369
+ pub_opts.delete(:repository_version)
370
+ end
371
+ elsif options[:version]
372
+ # we want to change the version but not the repo!, and we have
373
+ # an old publiction or a prior check would have failed
374
+ repo = repo_api.read(old_pub.repository)
375
+
376
+ # check the valid versions of the repo
377
+ version_list = []
378
+ repover_api.list(repo.pulp_href).results.each do |rver|
379
+ version_list.push( rver.number )
380
+ end
381
+ version_list.sort!
382
+ if options[:version] < 0
383
+ pub_opts[:repository_version] = repo.pulp_href + 'versions/' + version_list[options[:version]].to_s + '/'
384
+ elsif version_list.include?(options[:version])
385
+ pub_opts[:repository_version] = repo.pulp_href + 'versions/' + options[:version].to_s + '/'
386
+ else
387
+ puts "specified version (#{options[:version]}) does not exist for the repository in question"
388
+ exit 1
389
+ end
390
+ end
391
+ existing_publication = Pulpsak.find_existing_publication(pub_opts)
392
+ pub_href = ''
393
+ if existing_publication
394
+ pub_href = existing_publication.pulp_href
395
+ else
396
+ print "creating new publication"
397
+ begin
398
+ task = Pulpsak.wait_on_task(pub_api.create(pub_opts).task)
399
+ rescue PulpRpmClient::ApiError => e
400
+ puts "Exception when creating publication: #{e}"
401
+ exit 1
402
+ end
403
+ if task.state != 'completed'
404
+ pp task
405
+ print "unable to create publication, unable to continue\n"
406
+ exit 1
407
+ end
408
+ pub_href = task.created_resources[0]
409
+ end
410
+ dist_opts = {
411
+ :name => options[:newname] ? options[:newname] : dist.name,
412
+ :base_path => options[:base_path] ? options[:base_path] : dist.base_path,
413
+ :content_guard => options[:content_guard] ? options[:content_guard] : ( dist.content_guard ? dist.content_guard : nil),
414
+ :publication => pub_href,
415
+ }
416
+ print "updating distribution"
417
+ begin
418
+ task = Pulpsak.wait_on_task(dist_api.update(dist.pulp_href,dist_opts).task,final: " complete\n")
419
+ #pp task
420
+ #pp dist_api.update(dist.pulp_href,dist_opts)
421
+ rescue PulpRpmClient::ApiError => e
422
+ puts "Exception when updating distibution: #{e}"
423
+ exit 1
424
+ end
425
+ if task.state != "completed"
426
+ print "unable to create distibution"
427
+ exit 1
428
+ end
429
+ end
430
+ desc "delete [NAME]", "delete a repository"
431
+ def delete(name)
432
+ dist_api = PulpRpmClient::DistributionsRpmApi.new
433
+ unless dist = Pulpsak.distribution_inspect_by_name(name)
434
+ puts("distribution does not exist: #{name}\n")
435
+ exit 1
436
+ end
437
+ pp Pulpsak.wait_on_task(dist_api.delete(dist.pulp_href).task)
438
+ end
439
+ desc "sync [NAME]", "sync the underlying repository, create a new publicion, and update the distribution to reference it"
440
+ def sync(name)
441
+ pub_api = PulpRpmClient::PublicationsRpmApi.new
442
+ repo_api = PulpRpmClient::RepositoriesRpmApi.new
443
+ dist_api = PulpRpmClient::DistributionsRpmApi.new
444
+ repover_api = PulpRpmClient::RepositoriesRpmVersionsApi.new
445
+
446
+ unless dist = Pulpsak.distribution_inspect_by_name(name)
447
+ puts("distribution doesn't exist: #{name}\n")
448
+ exit 1
449
+ end
450
+ unless dist.publication or options[:repo]
451
+ puts "this distribution has no publication defined, therefore sync is not possible"
452
+ exit 1
453
+ end
454
+ repo = repo_api.read(pub_api.read(dist.publication).repository)
455
+ invoke "repositories:sync", [repo.name]
456
+ #task = repo_api.sync(repo.pulp_href,{}).task
457
+ #pp Pulpsak.wait_on_task(task)
458
+ version = 0
459
+ repover_api.list(repo.pulp_href).results.each do |rver|
460
+ if rver.number > version
461
+ version = rver.number
462
+ end
463
+ end
464
+ invoke "distributions:update", [name], :version => version
465
+ end
466
+ end
467
+
468
+ class Publications < Thor
469
+ desc "list", "list all publications"
470
+ def list()
471
+ table = Text::Table.new
472
+ table.head = ["created","repver","gpgcheck","repo_gpgcheck","metadata","package","pulp_href"]
473
+ table.rows = []
474
+ PulpRpmClient::PublicationsRpmApi.new.list.results.each do |pub|
475
+ table.rows << [pub.pulp_created,Pulpsak.repository_inspect(pub.repository).name + ':' + Pulpsak.repository_version_inspect(pub.repository_version).number.to_s,pub.gpgcheck,pub.repo_gpgcheck,pub.metadata_checksum_type,pub.package_checksum_type,pub.pulp_href]
476
+ end
477
+ print table.to_s
478
+ end
479
+ desc "cleanup", "delete all unreferenced publications"
480
+ def cleanup()
481
+ dists = PulpRpmClient::DistributionsRpmApi.new
482
+ pubs = PulpRpmClient::PublicationsRpmApi.new
483
+
484
+ pub_hrefs = []
485
+ dists.list.results.each do |dist|
486
+ if dist.publication
487
+ pub_hrefs.push(dist.publication)
488
+ end
489
+ end
490
+ pubs.list.results.each do |pub|
491
+ unless pub_hrefs.include?(pub.pulp_href)
492
+ puts "deleting publication #{pub.pulp_href}"
493
+ pubs.delete(pub.pulp_href)
494
+ end
495
+ end
496
+ end
497
+ end
498
+
499
+ class Rpm < Thor
500
+ desc "distributions", "manage distributions"
501
+ subcommand "distributions", Distributions
502
+ desc "publications", "manage publications"
503
+ subcommand "publications", Publications
504
+ desc "repositories", "manage repositories"
505
+ subcommand "repositories", Repositories
506
+ desc "remotes", "manage remotes"
507
+ subcommand "remotes", Remotes
508
+ end
509
+
510
+ class PulpsakCli < Thor
511
+ desc "rpm", "manage rpm plugins"
512
+ subcommand "rpm", Rpm
513
+ desc "tasks", "list/manage tasks"
514
+ subcommand "tasks", Tasks
515
+ end
516
+
517
+ PulpsakCli.start(ARGV)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/pulpsak.rb ADDED
@@ -0,0 +1,139 @@
1
+ require "pulpsak/version"
2
+ require 'pulp_rpm_client'
3
+ require 'pulpcore_client'
4
+ require 'yaml'
5
+
6
+ module Pulpsak
7
+ class Error < StandardError; end
8
+ @@config = {
9
+ }
10
+ config_yaml = ''
11
+ if ENV.has_key?('XDG_CONFIG_HOME')
12
+ config_yaml = File.join(ENV['XDG_CONFIG_HOME'],'pulpsak','config.yaml')
13
+ elsif ENV.has_key?('HOME')
14
+ config_yaml = File.join(ENV['HOME'],'.config','pulpsak','config.yaml')
15
+ end
16
+ if File.exists?(config_yaml)
17
+ @@config = YAML.load_file(config_yaml)
18
+ else
19
+ puts "#{config_yaml} does not exist, using defaults"
20
+ end
21
+
22
+ PulpcoreClient.configure do |config|
23
+ config_data = {}
24
+ if @@config.has_key?('pulpcore')
25
+ config_data = @@config['pulpcore']
26
+ elsif @@config.has_key?('default')
27
+ config_data = @@config['default']
28
+ end
29
+ config_data.each do |key, value|
30
+ config.instance_variable_set("@#{key}".to_sym, value)
31
+ end
32
+ end
33
+ PulpRpmClient.configure do |config|
34
+ config_data = {}
35
+ if @@config.has_key?('pulp_rpm')
36
+ config_data = @@config['pulp_rpm']
37
+ elsif @@config.has_key?('default')
38
+ config_data = @@config['default']
39
+ end
40
+ config_data.each do |key, value|
41
+ config.instance_variable_set("@#{key}".to_sym, value)
42
+ end
43
+ end
44
+
45
+ def self.repository_inspect(href)
46
+ api_instance = PulpRpmClient::RepositoriesRpmApi.new
47
+ return api_instance.read(href)
48
+ end
49
+ def self.repository_version_inspect(href)
50
+ api_instance = PulpRpmClient::RepositoriesRpmVersionsApi.new
51
+ return api_instance.read(href)
52
+ end
53
+ def self.repository_inspect_by_name(name)
54
+ api_instance = PulpRpmClient::RepositoriesRpmApi.new
55
+ api_instance.list.results.each do |repo|
56
+ if repo.name == name
57
+ return repository_inspect(repo.pulp_href)
58
+ end
59
+ end
60
+ return nil
61
+ end
62
+ def self.remote_inspect(href)
63
+ api_instance = PulpRpmClient::RemotesRpmApi.new
64
+ return api_instance.read(href)
65
+ end
66
+ def self.remote_inspect_by_name(name)
67
+ api_instance = PulpRpmClient::RemotesRpmApi.new
68
+ api_instance.list.results.each do |remote|
69
+ if remote.name == name
70
+ return remote_inspect(remote.pulp_href)
71
+ end
72
+ end
73
+ return nil
74
+ end
75
+ def self.distribution_inspect_by_name(name)
76
+ api_instance = PulpRpmClient::DistributionsRpmApi.new
77
+ api_instance.list.results.each do |dist|
78
+ if dist.name == name
79
+ return dist
80
+ end
81
+ end
82
+ return nil
83
+ end
84
+ def self.task_inspect(href)
85
+ api_instance = PulpcoreClient::TasksApi.new
86
+ return api_instance.read(href)
87
+ end
88
+ def self.task_cancel(href)
89
+ api_instance = PulpcoreClient::TasksApi.new
90
+ return api_instance.tasks_cancel(href)
91
+ end
92
+ def self.wait_on_task(href,sleep_time: 3, spacer: '.', final: "\n")
93
+ api = PulpcoreClient::TasksApi.new
94
+ last_message = ''
95
+ while true
96
+ i = Pulpsak.task_inspect(href)
97
+ if i.state == 'running' or i.state == 'waiting'
98
+ if i.progress_reports.respond_to?(:length) and i.progress_reports.length() > 0
99
+ if last_message != i.progress_reports[-1].message
100
+ last_message = i.progress_reports[-1].message
101
+ print last_message,"\n"
102
+ end
103
+ else
104
+ print spacer
105
+ end
106
+ sleep sleep_time
107
+ else
108
+ break
109
+ end
110
+ end
111
+ print final
112
+ task = Pulpsak.task_inspect(href)
113
+ return task
114
+ end
115
+ def self.find_existing_publication(pub_opts)
116
+ pub_api = PulpRpmClient::PublicationsRpmApi.new
117
+ existing_publication = nil
118
+ if pub_opts.has_key?(:repository_version)
119
+ # if we have a specific version, we can look through all
120
+ # existing publications to avoid creating one, which can be
121
+ # expensive
122
+ pub_api.list.results.each do |pub|
123
+ pub_hash = pub.to_hash
124
+ match = true
125
+ [:metadata_checksum_type,:package_checksum_type,:gpgcheck,:repo_gpgcheck,:repository_version].each do |p|
126
+ if pub_opts[p] != pub_hash[p]
127
+ match = false
128
+ break
129
+ end
130
+ end
131
+ if match
132
+ existing_publication = pub
133
+ break
134
+ end
135
+ end
136
+ end
137
+ return existing_publication
138
+ end
139
+ end
@@ -0,0 +1,3 @@
1
+ module Pulpsak
2
+ VERSION = "0.1.1"
3
+ end
data/pulpsak.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ require_relative 'lib/pulpsak/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "pulpsak"
5
+ spec.version = Pulpsak::VERSION
6
+ spec.licenses = ['GPL-3.0-or-later']
7
+ spec.authors = ["Aran Cox"]
8
+ spec.email = ["arancox@gmail.com"]
9
+
10
+ spec.summary = %q{command line interface to pulp3}
11
+ spec.description = %q{mostly focusing on the rpm plugin}
12
+ spec.homepage = 'https://github.com/aranc23/pulpsak'
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ #spec.metadata["allowed_push_host"] = 'https://github.com/aranc23/pulpsak'
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/commits/"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "bin"
27
+ spec.executables = ['pulpsak']
28
+ spec.require_paths = ["lib"]
29
+ spec.add_development_dependency "bundler", "~> 2.1.4"
30
+ spec.add_development_dependency "rake", ">= 12.3.3"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency "thor", "~> 1.0"
33
+ spec.add_development_dependency "text-table", "~> 1.2"
34
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pulpsak
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Aran Cox
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.4
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: text-table
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ description: mostly focusing on the rpm plugin
84
+ email:
85
+ - arancox@gmail.com
86
+ executables:
87
+ - pulpsak
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/pulpsak
100
+ - bin/setup
101
+ - lib/pulpsak.rb
102
+ - lib/pulpsak/version.rb
103
+ - pulpsak.gemspec
104
+ homepage: https://github.com/aranc23/pulpsak
105
+ licenses:
106
+ - GPL-3.0-or-later
107
+ metadata:
108
+ homepage_uri: https://github.com/aranc23/pulpsak
109
+ source_code_uri: https://github.com/aranc23/pulpsak
110
+ changelog_uri: https://github.com/aranc23/pulpsak/commits/
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 2.3.0
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.1.6
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: command line interface to pulp3
130
+ test_files: []