runcible 0.4.12 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/README.md +42 -13
  2. data/Rakefile +1 -17
  3. data/lib/runcible/base.rb +26 -36
  4. data/lib/runcible/extensions/consumer.rb +22 -15
  5. data/lib/runcible/extensions/consumer_group.rb +12 -12
  6. data/lib/runcible/extensions/repository.rb +44 -38
  7. data/lib/runcible/extensions/rpm.rb +3 -3
  8. data/lib/runcible/extensions/unit.rb +21 -16
  9. data/lib/runcible/instance.rb +129 -0
  10. data/lib/runcible/{extensions → models}/distributor.rb +7 -3
  11. data/lib/runcible/{extensions → models}/export_distributor.rb +6 -3
  12. data/lib/runcible/{extensions → models}/importer.rb +2 -2
  13. data/lib/runcible/{extensions → models}/iso_distributor.rb +5 -2
  14. data/lib/runcible/{extensions → models}/iso_importer.rb +2 -2
  15. data/lib/runcible/models/nodes_http_distributor.rb +61 -0
  16. data/lib/runcible/{extensions → models}/yum_clone_distributor.rb +3 -1
  17. data/lib/runcible/{extensions → models}/yum_distributor.rb +2 -2
  18. data/lib/runcible/{extensions → models}/yum_importer.rb +2 -2
  19. data/lib/runcible/resources/consumer.rb +14 -14
  20. data/lib/runcible/resources/consumer_group.rb +9 -9
  21. data/lib/runcible/resources/event_notifier.rb +3 -3
  22. data/lib/runcible/resources/repository.rb +20 -20
  23. data/lib/runcible/resources/repository_group.rb +6 -6
  24. data/lib/runcible/resources/repository_schedule.rb +4 -4
  25. data/lib/runcible/resources/role.rb +2 -2
  26. data/lib/runcible/resources/task.rb +5 -5
  27. data/lib/runcible/resources/unit.rb +2 -2
  28. data/lib/runcible/resources/user.rb +4 -4
  29. data/lib/runcible/version.rb +1 -1
  30. data/lib/runcible.rb +6 -2
  31. metadata +84 -91
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Exposing Pulp's juiciest parts. http://www.pulpproject.org/
6
6
 
7
- Latest Live Tested Version: **pulp-server-2.2.0-0.20.beta.el6.noarch**
7
+ Latest Live Tested Version: **pulp-server-2.2.0-0.22.beta.el6.noarch**
8
8
 
9
9
  Current stable Runcible: https://github.com/Katello/runcible/tree/0.3
10
10
 
@@ -28,16 +28,28 @@ Or install it yourself as:
28
28
 
29
29
  ### Set Configuration
30
30
 
31
- The base configuration allows for the following to be set.
31
+ To use a single resource or extension, the configuration can be set:
32
32
 
33
- Runcible::Base.config = {
33
+ repo_api = Runcible::Resources::Repository.new({
34
34
  :url => "",
35
35
  :api_path => "",
36
36
  :user => "",
37
37
  :logger => ""
38
- }
38
+ })
39
+ repo_api.find(id)
39
40
 
40
- Required Configuration
41
+ Alternatively, a single 'server' instance which can easily use all
42
+ resources and extensions can be instantiated:
43
+
44
+ my_runcible = Runcible::Instance.new({
45
+ :url => "",
46
+ :api_path => "",
47
+ :user => "",
48
+ :logger => ""
49
+ })
50
+ runcible.resources.repository.find(id)
51
+
52
+ Required Configuration:
41
53
 
42
54
  :uri => The base URI of the Pulp server (default: https://localhost)
43
55
  :api_path => The API path of the Pulp server (default: pulp/api/v2/)
@@ -55,7 +67,7 @@ For an example on parsing the Pulp server.conf and using values provided within
55
67
 
56
68
  ### Make a Request
57
69
 
58
- Runcible provides two represntation's of Pulp entities to make API calls: [resources](https://github.com/Katello/runcible/tree/master/lib/runcible/resources) and [extensions](https://github.com/Katello/runcible/tree/master/lib/runcible/extensions)
70
+ Runcible provides two representations of Pulp entities to make API calls: [resources](https://github.com/Katello/runcible/tree/master/lib/runcible/resources) and [extensions](https://github.com/Katello/runcible/tree/master/lib/runcible/extensions)
59
71
 
60
72
  The best examples of how to use either the resources or extensions can be found within the [tests](https://github.com/Katello/runcible/tree/master/test/integration)
61
73
 
@@ -63,22 +75,39 @@ The best examples of how to use either the resources or extensions can be found
63
75
 
64
76
  Resources are designed to be one-for-one with the Pulp API calls in terms of required parameters and naming of the calls. For example, in order to create a repository, associate a Yum importer and a distributor:
65
77
 
66
- Runcible::Resources::Repository.create("Repository_ID")
67
- Runcible::Resources::Repository.associate_importer("Repository_ID", "yum_importer", {})
68
- Runcible::Resources::Repository.associate_distributor("Repository_ID", "yum_distributor", {"relative_url" => "/", "http" => true, "https" => true})
78
+ my_runcible = Runcible::Instance.new(config)
79
+ my_runcible.resources.repository.create("Repository_ID")
80
+ my_runcible.resources.repository.associate_importer("Repository_ID", "yum_importer", {})
81
+ my_runcible.resources.repository.associate_distributor("Repository_ID", "yum_distributor", {"relative_url" => "/", "http" => true, "https" => true})
82
+
83
+ or
84
+
85
+ Runcible::Resources::Repository.new(config).create("Repository_ID")
86
+ Runcible::Resources::Repository.new(config).associate_importer("Repository_ID", "yum_importer", {})
87
+ Runcible::Resources::Repository.new(config).associate_distributor("Repository_ID", "yum_distributor", {"relative_url" => "/", "http" => true, "https" => true})
69
88
 
70
89
  #### Extensions
71
90
 
72
91
  Extensions are constructs around the Pulp API that make retrieving, accessing or creating certain data types easier. For example, providing objects that represent the details of a yum importer or distributor, and providing functions to create a Repository with an importer and distributors in a single call. The same three step process above using extensions is:
73
92
 
74
- Runcible::Extensions::Repository.create_with_importer_and_distributors("Repository_ID", {:id=>'yum_importer'}, [{'type_id' => 'yum_distributor', 'id'=>'123', 'auto_publish'=>true, 'config'=>{'relative_url' => '/', 'http' => true, 'https' => true}}])
93
+ my_runcible = Runcible::Instance.new(config)
94
+ my_runcible.extensions.repository.create_with_importer_and_distributor("Repository_ID", {:id=>'yum_importer'}, [{'type_id' => 'yum_distributor', 'id'=>'123', 'auto_publish'=>true, 'config'=>{'relative_url' => '/', 'http' => true, 'https' => true}}])
95
+
96
+ or
97
+
98
+ Runcible::Extensions::Repository.new(config).create_with_importer_and_distributors("Repository_ID", {:id=>'yum_importer'}, [{'type_id' => 'yum_distributor', 'id'=>'123', 'auto_publish'=>true, 'config'=>{'relative_url' => '/', 'http' => true, 'https' => true}}])
75
99
 
76
100
  Alternatively, using distributor and importer objects:
77
101
 
78
- distributors = [Runcible::Extensions::YumDistributor.new('/path', true, true, :id => '123')]
79
- importer = Runcible::Extensions::YumImporter.new()
80
- Runcible::Extensions::Repository.create_with_importer_and_distributors("Repository_ID", importer, distributors)
102
+ distributors = [Runcible::Models::YumDistributor.new('/path', true, true, :id => '123')]
103
+ importer = Runcible::Models::YumImporter.new()
104
+
105
+ my_runcible = Runcible::Instance.new(config)
106
+ my_runcible.extensions.repository.create_with_importer_and_distributors("Repository_ID", importer, distributors)
107
+
108
+ or
81
109
 
110
+ Runcible::Extensions::Repository.new(config).create_with_importer_and_distributors("Repository_ID", importer, distributors)
82
111
 
83
112
  ## Testing
84
113
 
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ namespace :test do
16
16
  t.pattern = 'test/unit/test_*.rb'
17
17
  end
18
18
 
19
- [:resources, :extensions].each do |task_name|
19
+ [:resources, :extensions, :unit].each do |task_name|
20
20
  desc "Runs the #{task_name} tests"
21
21
  task task_name do
22
22
  options = {}
@@ -60,22 +60,6 @@ task :update_test_version do
60
60
  end
61
61
  end
62
62
 
63
- desc "Finds functions without dedicated tests"
64
- task :untested do
65
- test_functions = `grep -r 'def test_' test/ --exclude-dir=test/fixtures --include=*.rb --no-filename`
66
- lib_functions = `grep -r 'def self' lib/ --exclude=base.rb --include=*.rb --no-filename`
67
-
68
- test_functions = test_functions.split("\n").map{ |str| str.strip.split("def test_")[1] }.to_set
69
- lib_functions = lib_functions.split("\n").map{ |str| str.strip.split("def self.")[1].split("(").first }.to_set
70
-
71
- difference = (lib_functions - test_functions).to_a
72
-
73
- if !difference.empty?
74
- puts difference
75
- exit 1
76
- end
77
- end
78
-
79
63
  desc "Clears out all cassette files"
80
64
  task :clear_cassettes do
81
65
  clear_cassettes
data/lib/runcible/base.rb CHANGED
@@ -29,37 +29,23 @@ require 'json'
29
29
  module Runcible
30
30
  class Base
31
31
 
32
- # Accepted Configuration Values
33
- #
34
- # :user Pulp username
35
- # :password Password for this user
36
- # :oauth Oauth credentials
37
- # :headers Additional headers e.g. content-type => "application/json"
38
- # :url Scheme and hostname for the pulp server e.g. https://localhost/
39
- # :api_path URL path for the api e.g. pulp/api/v2/
40
- # :timeout timeout in seconds for the connection (defaults to rest client's default)
41
- # :open_timeout timeout in seconds for the connection to open(defaults to rest client's default)
42
- def self.config=(conf={})
43
- @@config = {
44
- :api_path => '/pulp/api/v2/',
45
- :url => 'https://localhost',
46
- :user => '',
47
- :http_auth => {:password => {} },
48
- :headers => {:content_type => 'application/json',
49
- :accept => 'application/json'},
50
- :logging => {}
51
- }.merge(conf)
52
- end
53
-
54
- def self.config
55
- if defined?(@@config)
56
- @@config
32
+ def initialize(config={})
33
+ @config = config
34
+ end
35
+
36
+ def config
37
+ if defined?(@config)
38
+ @config
57
39
  else
58
40
  raise Runcible::ConfigurationUndefinedError, Runcible::ConfigurationUndefinedError.message
59
41
  end
60
42
  end
61
43
 
62
- def self.call(method, path, options={})
44
+ def path(*args)
45
+ self.class.path(*args)
46
+ end
47
+
48
+ def call(method, path, options={})
63
49
  clone_config = self.config.clone
64
50
  #on occation path will already have prefix (sync cancel)
65
51
  path = clone_config[:api_path] + path if !path.start_with?(clone_config[:api_path])
@@ -100,7 +86,7 @@ module Runcible
100
86
  raise e
101
87
  end
102
88
 
103
- def self.get_response(client, path, *args)
89
+ def get_response(client, path, *args)
104
90
  client[path].send(*args) do |response, request, result, &block|
105
91
  resp = response.return!(request, result)
106
92
  log_debug
@@ -108,7 +94,7 @@ module Runcible
108
94
  end
109
95
  end
110
96
 
111
- def self.combine_get_params(path, params)
97
+ def combine_get_params(path, params)
112
98
  query_string = params.collect do |k, v|
113
99
  if v.is_a? Array
114
100
  v.collect{|y| "#{k.to_s}=#{y.to_s}" }.join('&')
@@ -119,7 +105,7 @@ module Runcible
119
105
  path + "?#{query_string}"
120
106
  end
121
107
 
122
- def self.generate_payload(options)
108
+ def generate_payload(options)
123
109
  if options[:payload]
124
110
  if options[:payload][:optional]
125
111
  if options[:payload][:required]
@@ -139,7 +125,7 @@ module Runcible
139
125
  return payload.to_json
140
126
  end
141
127
 
142
- def self.process_response(response)
128
+ def process_response(response)
143
129
  begin
144
130
  body = JSON.parse(response.body)
145
131
  if body.respond_to? :with_indifferent_access
@@ -156,7 +142,7 @@ module Runcible
156
142
  return response
157
143
  end
158
144
 
159
- def self.required_params(local_names, binding, keys_to_remove=[])
145
+ def required_params(local_names, binding, keys_to_remove=[])
160
146
  local_names = local_names.reduce({}) do |acc, v|
161
147
  value = binding.eval(v.to_s) unless v == :_
162
148
  acc[v] = value unless value.nil?
@@ -176,11 +162,11 @@ module Runcible
176
162
  return local_names
177
163
  end
178
164
 
179
- def self.add_http_auth_header
165
+ def add_http_auth_header
180
166
  return {:user => config[:user], :password => config[:http_auth][:password]}
181
167
  end
182
168
 
183
- def self.add_oauth_header(method, path, headers)
169
+ def add_oauth_header(method, path, headers)
184
170
  default_options = { :site => config[:url],
185
171
  :http_method => method,
186
172
  :request_token_path => "",
@@ -202,24 +188,28 @@ module Runcible
202
188
  return headers
203
189
  end
204
190
 
205
- def self.log_debug
191
+ def log_debug
206
192
  if self.config[:logging][:debug]
207
193
  log_message = generate_log_message
208
194
  self.config[:logging][:logger].debug(log_message)
209
195
  end
210
196
  end
211
197
 
212
- def self.log_exception
198
+ def log_exception
213
199
  if self.config[:logging][:exception]
214
200
  log_message = generate_log_message
215
201
  self.config[:logging][:logger].error(log_message)
216
202
  end
217
203
  end
218
204
 
219
- def self.generate_log_message
205
+ def generate_log_message
220
206
  RestClient.log.join('\n')
221
207
  end
222
208
 
209
+ def logger
210
+ self.config[:logging][:logger]
211
+ end
212
+
223
213
  end
224
214
 
225
215
  class ConfigurationUndefinedError < StandardError
@@ -32,9 +32,9 @@ module Runcible
32
32
  # @param [String] repo_id the repo ID to bind to
33
33
  # @param [Boolean] notify_agent sends consumer a notification
34
34
  # @return [RestClient::Response] set of tasks representing each bind operation
35
- def self.bind_all(id, repo_id, notify_agent=true)
36
- Runcible::Extensions::Repository.retrieve_with_details(repo_id)['distributors'].collect do |d|
37
- self.bind(id, repo_id, d['id'], {:notify_agent=>notify_agent})
35
+ def bind_all(id, repo_id, notify_agent=true)
36
+ repository_extension.retrieve_with_details(repo_id)['distributors'].collect do |d|
37
+ bind(id, repo_id, d['id'], {:notify_agent=>notify_agent})
38
38
  end.flatten
39
39
  end
40
40
 
@@ -43,9 +43,9 @@ module Runcible
43
43
  # @param [String] id the consumer ID
44
44
  # @param [String] repo_id the repo ID to unbind from
45
45
  # @return [RestClient::Response] set of tasks representing each unbind operation
46
- def self.unbind_all(id, repo_id)
47
- Runcible::Extensions::Repository.retrieve_with_details(repo_id)['distributors'].collect do |d|
48
- self.unbind(id, repo_id, d['id'])
46
+ def unbind_all(id, repo_id)
47
+ repository_extension.retrieve_with_details(repo_id)['distributors'].collect do |d|
48
+ unbind(id, repo_id, d['id'])
49
49
  end.flatten
50
50
  end
51
51
 
@@ -56,8 +56,8 @@ module Runcible
56
56
  # @param [Array] units array of units to install
57
57
  # @param [Hash] options to pass to content install
58
58
  # @return [RestClient::Response] task representing the install operation
59
- def self.install_content(id, type_id, units, options={})
60
- self.install_units(id, generate_content(type_id, units), options)
59
+ def install_content(id, type_id, units, options={})
60
+ install_units(id, generate_content(type_id, units), options)
61
61
  end
62
62
 
63
63
  # Update content on a consumer
@@ -67,8 +67,8 @@ module Runcible
67
67
  # @param [Array] units array of units to update
68
68
  # @param [Hash] options to pass to content update
69
69
  # @return [RestClient::Response] task representing the update operation
70
- def self.update_content(id, type_id, units, options={})
71
- self.update_units(id, generate_content(type_id, units, options), options)
70
+ def update_content(id, type_id, units, options={})
71
+ update_units(id, generate_content(type_id, units, options), options)
72
72
  end
73
73
 
74
74
  # Uninstall content from a consumer
@@ -77,8 +77,8 @@ module Runcible
77
77
  # @param [String] type_id the type of content to uninstall (e.g. rpm, errata)
78
78
  # @param [Array] units array of units to uninstall
79
79
  # @return [RestClient::Response] task representing the uninstall operation
80
- def self.uninstall_content(id, type_id, units)
81
- self.uninstall_units(id, generate_content(type_id, units))
80
+ def uninstall_content(id, type_id, units)
81
+ uninstall_units(id, generate_content(type_id, units))
82
82
  end
83
83
 
84
84
  # Generate the content units used by other functions
@@ -87,7 +87,7 @@ module Runcible
87
87
  # @param [Array] units array of units
88
88
  # @param [Hash] options contains options which may impact the format of the content (e.g :all => true)
89
89
  # @return [Array] array of formatted content units
90
- def self.generate_content(type_id, units, options={})
90
+ def generate_content(type_id, units, options={})
91
91
  content = []
92
92
 
93
93
  case type_id
@@ -123,7 +123,7 @@ module Runcible
123
123
  # applicable errata; otherwise, it will list
124
124
  # errata and the consumers they are applicable to
125
125
  # @return [RestClient::Response] content applicability hash with details of errata available to consumer(s)
126
- def self.applicable_errata(ids, repoids = [], consumer_report = true)
126
+ def applicable_errata(ids, repoids = [], consumer_report = true)
127
127
 
128
128
  ids = [ids] if ids.is_a? String
129
129
  consumer_criteria = { 'filters' => { 'id' => { '$in' => ids } } } unless ids.empty?
@@ -136,7 +136,14 @@ module Runcible
136
136
  'unit_criteria' => { 'erratum' => { } },
137
137
  'override_config' => { 'report_style' => report_style }
138
138
  }
139
- self.applicability(criteria)
139
+ applicability(criteria)
140
+ end
141
+
142
+
143
+ private
144
+
145
+ def repository_extension
146
+ Runcible::Extensions::Repository.new(self.config)
140
147
  end
141
148
 
142
149
  end
@@ -31,8 +31,8 @@ module Runcible
31
31
  # @param [String] id the consumer group ID
32
32
  # @param [Array] consumer_ids array of consumer IDs to add to the group
33
33
  # @return [RestClient::Response] list of consumer IDs
34
- def self.add_consumers_by_id(id, consumer_ids)
35
- self.associate(id, make_consumer_criteria(consumer_ids))
34
+ def add_consumers_by_id(id, consumer_ids)
35
+ associate(id, make_consumer_criteria(consumer_ids))
36
36
  end
37
37
 
38
38
  # Remove consumers by ID from a consumer group
@@ -40,15 +40,15 @@ module Runcible
40
40
  # @param [String] id the consumer group ID
41
41
  # @param [Array] consumer_ids array of consumer IDs to remove from the group
42
42
  # @return [RestClient::Response] list of consumer IDs
43
- def self.remove_consumers_by_id(id, consumer_ids)
44
- self.unassociate(id, make_consumer_criteria(consumer_ids))
43
+ def remove_consumers_by_id(id, consumer_ids)
44
+ unassociate(id, make_consumer_criteria(consumer_ids))
45
45
  end
46
46
 
47
47
  # Generates consumer criteria query
48
48
  #
49
49
  # @param [Array] consumer_ids array of consumer IDs
50
50
  # @return [Hash] the formatted query for consumers
51
- def self.make_consumer_criteria(consumer_ids)
51
+ def make_consumer_criteria(consumer_ids)
52
52
  {:criteria =>
53
53
  {:filters =>
54
54
  {:id =>{"$in" =>consumer_ids}}
@@ -63,8 +63,8 @@ module Runcible
63
63
  # @param [Array] units array of units to install
64
64
  # @param [Hash] options to pass to content install
65
65
  # @return [RestClient::Response] task representing the install operation
66
- def self.install_content(id, type_id, units, options={})
67
- self.install_units(id, generate_content(type_id, units), options)
66
+ def install_content(id, type_id, units, options={})
67
+ install_units(id, generate_content(type_id, units), options)
68
68
  end
69
69
 
70
70
  # Update content on a consumer group
@@ -74,8 +74,8 @@ module Runcible
74
74
  # @param [Array] units array of units to update
75
75
  # @param [Hash] options to pass to content update
76
76
  # @return [RestClient::Response] task representing the update operation
77
- def self.update_content(id, type_id, units, options={})
78
- self.update_units(id, generate_content(type_id, units, options), options)
77
+ def update_content(id, type_id, units, options={})
78
+ update_units(id, generate_content(type_id, units, options), options)
79
79
  end
80
80
 
81
81
  # Uninstall content from a consumer group
@@ -84,8 +84,8 @@ module Runcible
84
84
  # @param [String] type_id the type of content to uninstall (e.g. rpm, errata)
85
85
  # @param [Array] units array of units to uninstall
86
86
  # @return [RestClient::Response] task representing the uninstall operation
87
- def self.uninstall_content(id, type_id, units)
88
- self.uninstall_units(id, generate_content(type_id, units))
87
+ def uninstall_content(id, type_id, units)
88
+ uninstall_units(id, generate_content(type_id, units))
89
89
  end
90
90
 
91
91
  # Generate the content units used by other functions
@@ -94,7 +94,7 @@ module Runcible
94
94
  # @param [Array] units array of units
95
95
  # @param [Hash] options contains options which may impact the format of the content (e.g :all => true)
96
96
  # @return [Array] array of formatted content units
97
- def self.generate_content(type_id, units, options={})
97
+ def generate_content(type_id, units, options={})
98
98
  content = []
99
99
 
100
100
  case type_id
@@ -31,7 +31,7 @@ module Runcible
31
31
  # @param [String] id the id of the repository being created
32
32
  # @param [Hash, Runcible::Extensions::Importer] importer either a hash representing an importer or an Importer object
33
33
  # @return [RestClient::Response] the created repository
34
- def self.create_with_importer(id, importer)
34
+ def create_with_importer(id, importer)
35
35
  create_with_importer_and_distributors(id, importer)
36
36
  end
37
37
 
@@ -40,7 +40,7 @@ module Runcible
40
40
  # @param [String] id the id of the repository being created
41
41
  # @param [Array] distributors an array of hashes representing distributors or an array of Distributor objects
42
42
  # @return [RestClient::Response] the created repository
43
- def self.create_with_distributors(id, distributors)
43
+ def create_with_distributors(id, distributors)
44
44
  create_with_importer_and_distributors(id, nil, distributors)
45
45
  end
46
46
 
@@ -51,8 +51,8 @@ module Runcible
51
51
  # @param [Array] distributors an array of hashes representing distributors or an array of Distributor objects
52
52
  # @param [Hash] optional container for all optional parameters
53
53
  # @return [RestClient::Response] the created repository
54
- def self.create_with_importer_and_distributors(id, importer, distributors=[], optional={})
55
- if importer.is_a?(Importer)
54
+ def create_with_importer_and_distributors(id, importer, distributors=[], optional={})
55
+ if importer.is_a?(Runcible::Models::Importer)
56
56
  optional[:importer_type_id] = importer.id
57
57
  optional[:importer_config] = importer.config
58
58
  else
@@ -61,7 +61,7 @@ module Runcible
61
61
  end if importer
62
62
 
63
63
  optional[:distributors] = distributors.collect do |d|
64
- if d.is_a?(Distributor)
64
+ if d.is_a?(Runcible::Models::Distributor)
65
65
  {'distributor_type' => d.type_id,
66
66
  "distributor_config" => d.config,
67
67
  "auto_publish" => d.auto_publish,
@@ -83,23 +83,23 @@ module Runcible
83
83
  #
84
84
  # @param [String] repo_id the repository ID
85
85
  # @return [RestClient::Response] a task representing the sync status
86
- def self.sync_status(repo_id)
87
- Runcible::Resources::Task.list(["pulp:repository:#{repo_id}", "pulp:action:sync"])
86
+ def sync_status(repo_id)
87
+ Runcible::Resources::Task.new(self.config).list(["pulp:repository:#{repo_id}", "pulp:action:sync"])
88
88
  end
89
89
 
90
90
  # Retrieves the publish status for a repository
91
91
  #
92
92
  # @param [String] repo_id the repository ID
93
93
  # @return [RestClient::Response] a task representing the sync status
94
- def self.publish_status(repo_id)
95
- Runcible::Resources::Task.list(["pulp:repository:#{repo_id}", "pulp:action:publish"])
94
+ def publish_status(repo_id)
95
+ Runcible::Resources::Task.new(self.config).list(["pulp:repository:#{repo_id}", "pulp:action:publish"])
96
96
  end
97
97
 
98
98
  # Retrieves a set of repositories by their IDs
99
99
  #
100
100
  # @param [Array] repository_ids the repository ID
101
101
  # @return [RestClient::Response] the set of repositories requested
102
- def self.search_by_repository_ids(repository_ids)
102
+ def search_by_repository_ids(repository_ids)
103
103
  criteria = {:filters =>
104
104
  { "id" => {"$in" => repository_ids}}
105
105
  }
@@ -111,7 +111,13 @@ module Runcible
111
111
  #
112
112
  # @param [String] id the ID of the repository
113
113
  # @return [Array<String>] the array of repository RPM IDs
114
- def self.rpm_ids(id)
114
+
115
+ def rpm_ids(id)
116
+ criteria = {:type_ids=>[Runcible::Extensions::Rpm.content_type],
117
+ :fields=>{:unit=>[], :association=>['unit_id']}}
118
+ self.unit_search(id, criteria).collect{|i| i['unit_id']}
119
+ rescue RestClient::RequestTimeout
120
+ self.logger.warn("Call to rpm_ids timed out")
115
121
  # lazy evaluated iterator from zero to infinite
116
122
  pages = Enumerator.new { |y| page = 0; loop { y << page; page += 1 } }
117
123
 
@@ -122,7 +128,7 @@ module Runcible
122
128
  :fields => { :unit => [], :association => ['unit_id'] },
123
129
  :limit => page_size,
124
130
  :skip => 0 + page*page_size }
125
- result = self.unit_search(id, criteria).collect { |i| i['unit_id'] }
131
+ result = unit_search(id, criteria).collect { |i| i['unit_id'] }
126
132
  rpm_ids.concat(result)
127
133
  if result.empty? || result.size < 500
128
134
  break rpm_ids
@@ -136,9 +142,9 @@ module Runcible
136
142
  #
137
143
  # @param [String] id the ID of the repository
138
144
  # @return [RestClient::Response] the set of repository RPMs
139
- def self.rpms(id)
145
+ def rpms(id)
140
146
  criteria = {:type_ids=>[Runcible::Extensions::Rpm.content_type]}
141
- self.unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
147
+ unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
142
148
  end
143
149
 
144
150
  # Retrieves the RPMs by NVRE for a single repository
@@ -149,7 +155,7 @@ module Runcible
149
155
  # @param [String] release the release of the RPMs
150
156
  # @param [String] epoch the epoch of the RPMs
151
157
  # @return [RestClient::Response] the set of repository RPMs
152
- def self.rpms_by_nvre(id, name, version=nil, release=nil, epoch=nil)
158
+ def rpms_by_nvre(id, name, version=nil, release=nil, epoch=nil)
153
159
  and_condition = []
154
160
  and_condition << {:name=>name} if name
155
161
  and_condition << {:version=>version} if version
@@ -165,56 +171,56 @@ module Runcible
165
171
  :sort => {
166
172
  :unit => [ ['name', 'ascending'], ['version', 'descending'] ]
167
173
  }}
168
- self.unit_search(id, criteria).collect{|p| p['metadata'].with_indifferent_access}
174
+ unit_search(id, criteria).collect{|p| p['metadata'].with_indifferent_access}
169
175
  end
170
176
 
171
177
  # Retrieves the errata IDs for a single repository
172
178
  #
173
179
  # @param [String] id the ID of the repository
174
180
  # @return [RestClient::Response] the set of repository errata IDs
175
- def self.errata_ids(id)
181
+ def errata_ids(id)
176
182
  criteria = {:type_ids=>[Runcible::Extensions::Errata.content_type],
177
183
  :fields=>{:unit=>[], :association=>['unit_id']}}
178
184
 
179
- self.unit_search(id, criteria).collect{|i| i['unit_id']}
185
+ unit_search(id, criteria).collect{|i| i['unit_id']}
180
186
  end
181
187
 
182
188
  # Retrieves the errata for a single repository
183
189
  #
184
190
  # @param [String] id the ID of the repository
185
191
  # @return [RestClient::Response] the set of repository errata
186
- def self.errata(id)
192
+ def errata(id)
187
193
  criteria = {:type_ids=>[Runcible::Extensions::Errata.content_type]}
188
- self.unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
194
+ unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
189
195
  end
190
196
 
191
197
  # Retrieves the distributions for a single repository
192
198
  #
193
199
  # @param [String] id the ID of the repository
194
200
  # @return [RestClient::Response] the set of repository distributions
195
- def self.distributions(id)
201
+ def distributions(id)
196
202
  criteria = {:type_ids=>[Runcible::Extensions::Distribution.content_type]}
197
203
 
198
- self.unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
204
+ unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
199
205
  end
200
206
 
201
207
  # Retrieves the package groups for a single repository
202
208
  #
203
209
  # @param [String] id the ID of the repository
204
210
  # @return [RestClient::Response] the set of repository package groups
205
- def self.package_groups(id)
211
+ def package_groups(id)
206
212
  criteria = {:type_ids=>[Runcible::Extensions::PackageGroup.content_type]}
207
213
 
208
- self.unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
214
+ unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
209
215
  end
210
216
 
211
217
  # Retrieves the package group categoriess for a single repository
212
218
  #
213
219
  # @param [String] id the ID of the repository
214
220
  # @return [RestClient::Response] the set of repository package group categories
215
- def self.package_categories(id)
221
+ def package_categories(id)
216
222
  criteria = {:type_ids=>[Runcible::Extensions::PackageCategory.content_type]}
217
- self.unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
223
+ unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
218
224
  end
219
225
 
220
226
  # Creates or updates a sync schedule for a repository
@@ -223,12 +229,12 @@ module Runcible
223
229
  # @param [String] type the importer type
224
230
  # @param [String] schedule the time as an iso8601 interval
225
231
  # @return [RestClient::Response] the newly created or updated schedule
226
- def self.create_or_update_schedule(repo_id, type, schedule)
227
- schedules = Runcible::Resources::RepositorySchedule.list(repo_id, type)
232
+ def create_or_update_schedule(repo_id, type, schedule)
233
+ schedules = Runcible::Resources::RepositorySchedule.new(self.config).list(repo_id, type)
228
234
  if schedules.empty?
229
- Runcible::Resources::RepositorySchedule.create(repo_id, type, schedule)
235
+ Runcible::Resources::RepositorySchedule.new(self.config).create(repo_id, type, schedule)
230
236
  else
231
- Runcible::Resources::RepositorySchedule.update(repo_id, type, schedules[0]['_id'], {:schedule=>schedule})
237
+ Runcible::Resources::RepositorySchedule.new(self.config).update(repo_id, type, schedules[0]['_id'], {:schedule=>schedule})
232
238
  end
233
239
  end
234
240
 
@@ -237,10 +243,10 @@ module Runcible
237
243
  # @param [String] repo_id the ID of the repository
238
244
  # @param [String] type the importer type
239
245
  # @return [RestClient::Response]
240
- def self.remove_schedules(repo_id, type)
241
- schedules = Runcible::Resources::RepositorySchedule.list(repo_id, type)
246
+ def remove_schedules(repo_id, type)
247
+ schedules = Runcible::Resources::RepositorySchedule.new(self.config).list(repo_id, type)
242
248
  schedules.each do |schedule|
243
- Runcible::Resources::RepositorySchedule.delete(repo_id, type, schedule['_id'])
249
+ Runcible::Resources::RepositorySchedule.new(self.config).delete(repo_id, type, schedule['_id'])
244
250
  end
245
251
  end
246
252
 
@@ -248,10 +254,10 @@ module Runcible
248
254
  #
249
255
  # @param [String] repo_id the ID of the repository
250
256
  # @return [RestClient::Response] set of tasks representing each publish
251
- def self.publish_all(repo_id)
257
+ def publish_all(repo_id)
252
258
  to_ret = []
253
- self.retrieve_with_details(repo_id)['distributors'].each do |d|
254
- to_ret << self.publish(repo_id, d['id'])
259
+ retrieve_with_details(repo_id)['distributors'].each do |d|
260
+ to_ret << publish(repo_id, d['id'])
255
261
  end
256
262
  to_ret
257
263
  end
@@ -260,8 +266,8 @@ module Runcible
260
266
  #
261
267
  # @param [String] repo_id the ID of the repository
262
268
  # @return [RestClient::Response] the repository with full details
263
- def self.retrieve_with_details(repo_id)
264
- self.retrieve(repo_id, {:details => true})
269
+ def retrieve_with_details(repo_id)
270
+ retrieve(repo_id, {:details => true})
265
271
  end
266
272
 
267
273
  end