runcible 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/Gemfile +2 -1
  2. data/README.md +1 -1
  3. data/Rakefile +16 -10
  4. data/lib/runcible.rb +1 -1
  5. data/lib/runcible/base.rb +24 -29
  6. data/lib/runcible/extensions/consumer.rb +25 -26
  7. data/lib/runcible/extensions/consumer_group.rb +10 -13
  8. data/lib/runcible/extensions/distribution.rb +0 -2
  9. data/lib/runcible/extensions/docker_image.rb +0 -1
  10. data/lib/runcible/extensions/errata.rb +0 -3
  11. data/lib/runcible/extensions/package_category.rb +0 -3
  12. data/lib/runcible/extensions/package_group.rb +0 -2
  13. data/lib/runcible/extensions/puppet_module.rb +0 -3
  14. data/lib/runcible/extensions/repository.rb +88 -72
  15. data/lib/runcible/extensions/rpm.rb +3 -5
  16. data/lib/runcible/extensions/unit.rb +10 -13
  17. data/lib/runcible/extensions/yum_repo_metadata_file.rb +0 -3
  18. data/lib/runcible/instance.rb +22 -28
  19. data/lib/runcible/models/distributor.rb +4 -5
  20. data/lib/runcible/models/docker_distributor.rb +4 -4
  21. data/lib/runcible/models/docker_importer.rb +2 -2
  22. data/lib/runcible/models/export_distributor.rb +1 -1
  23. data/lib/runcible/models/importer.rb +3 -6
  24. data/lib/runcible/models/iso_distributor.rb +3 -3
  25. data/lib/runcible/models/iso_importer.rb +1 -1
  26. data/lib/runcible/models/nodes_http_distributor.rb +0 -1
  27. data/lib/runcible/models/puppet_distributor.rb +2 -2
  28. data/lib/runcible/models/yum_clone_distributor.rb +3 -4
  29. data/lib/runcible/models/yum_distributor.rb +7 -7
  30. data/lib/runcible/models/yum_importer.rb +17 -17
  31. data/lib/runcible/resources/consumer.rb +17 -20
  32. data/lib/runcible/resources/consumer_group.rb +13 -15
  33. data/lib/runcible/resources/content.rb +10 -10
  34. data/lib/runcible/resources/event_notifier.rb +5 -9
  35. data/lib/runcible/resources/repository.rb +23 -23
  36. data/lib/runcible/resources/repository_group.rb +5 -7
  37. data/lib/runcible/resources/repository_schedule.rb +5 -7
  38. data/lib/runcible/resources/role.rb +5 -8
  39. data/lib/runcible/resources/task.rb +10 -13
  40. data/lib/runcible/resources/unit.rb +3 -6
  41. data/lib/runcible/resources/user.rb +7 -10
  42. data/lib/runcible/version.rb +1 -1
  43. metadata +2 -2
@@ -21,15 +21,12 @@
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
-
25
24
  module Runcible
26
25
  module Extensions
27
26
  class YumRepoMetadataFile < Runcible::Extensions::Unit
28
-
29
27
  def self.content_type
30
28
  'yum_repo_metadata_file'
31
29
  end
32
-
33
30
  end
34
31
  end
35
32
  end
@@ -23,14 +23,14 @@
23
23
 
24
24
  module Runcible
25
25
  class Instance
26
-
26
+ # rubocop:disable Style/ClassVars
27
27
  def self.resource_classes
28
- @@resource_classes ||= gather_classes("resources")
28
+ @@resource_classes ||= gather_classes('resources')
29
29
  @@resource_classes
30
30
  end
31
31
 
32
32
  def self.extension_classes
33
- @@extension_classes ||= gather_classes("extensions")
33
+ @@extension_classes ||= gather_classes('extensions')
34
34
  @@extension_classes
35
35
  end
36
36
 
@@ -46,22 +46,22 @@ module Runcible
46
46
  # @option config [String] :url Scheme and hostname for the pulp server e.g. https://localhost/
47
47
  # @option config [String] :api_path URL path for the api e.g. pulp/api/v2/
48
48
  # @option config [String] :timeout Timeout in seconds for the connection (defaults to rest client's default)
49
- # @option config [String] :open_timeout timeout in seconds for the connection to open(defaults to rest client's default)
49
+ # @option config [String] :open_timeout timeout in seconds for the connection
50
+ # to open(defaults to rest client's default)
50
51
  # @option config [Hash] :http_auth Needed when using simple http auth
51
52
  # @option http_auth [String] :password The password to use for simple auth
52
- def initialize(config={})
53
+ def initialize(config = {})
53
54
  @config = {
54
- :api_path => '/pulp/api/v2/',
55
- :url => 'https://localhost',
56
- :user => '',
57
- :http_auth => {:password => {} },
58
- :headers => {:content_type => 'application/json',
59
- :accept => 'application/json'},
60
- :logging => {}
61
- }.merge(config).with_indifferent_access
62
-
63
-
64
- initialize_wrappers(config)
55
+ :api_path => '/pulp/api/v2/',
56
+ :url => 'https://localhost',
57
+ :user => '',
58
+ :http_auth => {:password => {} },
59
+ :headers => {:content_type => 'application/json',
60
+ :accept => 'application/json'},
61
+ :logging => {}
62
+ }.merge(config).with_indifferent_access
63
+
64
+ initialize_wrappers
65
65
  end
66
66
 
67
67
  # Update an existing config value
@@ -71,13 +71,11 @@ module Runcible
71
71
  @config[key] = value
72
72
  end
73
73
 
74
- def config
75
- @config
76
- end
74
+ attr_reader :config
77
75
 
78
76
  private
79
77
 
80
- def initialize_wrappers(config)
78
+ def initialize_wrappers
81
79
  self.resources = Wrapper.new('resources')
82
80
  self.extensions = Wrapper.new('extensions')
83
81
 
@@ -95,22 +93,20 @@ module Runcible
95
93
  def accessible_class(class_object)
96
94
  #converts a class (Runcible::Resources::ConsumerGroup) to a user friendly name:
97
95
  # (e.g. consumer_group)
98
- class_object.name.split("::").last.underscore
96
+ class_object.name.split('::').last.underscore
99
97
  end
100
98
 
101
99
  def self.gather_classes(type)
102
100
  const = Runcible
103
101
  const = const.const_get(type.camelize)
104
102
  path = File.dirname(__FILE__) + "/#{type}/*.rb"
105
- base_names = Dir.glob(path).collect{|f| File.basename(f, '.rb') }
106
- classes = base_names.collect{|name| const.const_get(name.camelize)}
103
+ base_names = Dir.glob(path).map { |f| File.basename(f, '.rb') }
104
+ base_names.map { |name| const.const_get(name.camelize) }
107
105
  end
108
-
109
106
  end
110
107
 
111
108
  #Wrapper class to provide access to instances
112
109
  class Wrapper
113
-
114
110
  def initialize(name)
115
111
  @name = name
116
112
  @methods = []
@@ -122,9 +118,7 @@ module Runcible
122
118
  end
123
119
 
124
120
  def to_s
125
- "#{@name} - #{@methods.uniq.sort.to_s}"
121
+ "#{@name} - #{@methods.uniq.sort}"
126
122
  end
127
123
  end
128
-
129
124
  end
130
-
@@ -29,10 +29,10 @@ module Runcible
29
29
  class Distributor
30
30
  attr_accessor 'auto_publish', 'id'
31
31
 
32
- def initialize(params={})
32
+ def initialize(params = {})
33
33
  @auto_publish = false
34
- id = params[:id] || SecureRandom.hex(10)
35
- params.each{|k,v| send("#{k.to_s}=",v)}
34
+ self.id = params[:id] || SecureRandom.hex(10)
35
+ params.each { |k, v| send("#{k}=", v) }
36
36
  end
37
37
 
38
38
  # Distributor Type id
@@ -43,9 +43,8 @@ module Runcible
43
43
  end
44
44
 
45
45
  def self.type_id
46
- raise NotImplementedError("self.type_id")
46
+ fail NotImplementedError('self.type_id')
47
47
  end
48
-
49
48
  end
50
49
  end
51
50
  end
@@ -28,10 +28,10 @@ module Runcible
28
28
  module Models
29
29
  class DockerDistributor < Distributor
30
30
  #optional
31
- attr_accessor "docker_publish_directory", "protected",
32
- "redirect_url", "repo_registry_id"
31
+ attr_accessor 'docker_publish_directory', 'protected',
32
+ 'redirect_url', 'repo_registry_id'
33
33
 
34
- def initialize(params={})
34
+ def initialize(params = {})
35
35
  super(params)
36
36
  end
37
37
 
@@ -47,4 +47,4 @@ module Runcible
47
47
  end
48
48
  end
49
49
  end
50
- end
50
+ end
@@ -27,8 +27,8 @@ module Runcible
27
27
  ID = 'docker_importer'
28
28
  REPO_TYPE = 'docker-repo'
29
29
 
30
- attr_accessor 'feed', 'max_speed','max_downloads', 'upstream_name',
31
- 'proxy_port', 'proxy_password', 'proxy_username', "mask_id"
30
+ attr_accessor 'feed', 'max_speed', 'max_downloads', 'upstream_name',
31
+ 'proxy_port', 'proxy_password', 'proxy_username', 'mask_id'
32
32
 
33
33
  def id
34
34
  DockerImporter::ID
@@ -28,7 +28,7 @@ module Runcible
28
28
  module Models
29
29
  class ExportDistributor < Distributor
30
30
  #required
31
- attr_accessor "http", "https"
31
+ attr_accessor 'http', 'https'
32
32
 
33
33
  # Instantiates a export distributor
34
34
  #
@@ -24,17 +24,14 @@
24
24
  require 'active_support/core_ext/hash'
25
25
  require 'active_support/json'
26
26
 
27
-
28
27
  module Runcible
29
28
  module Models
30
-
31
- # Generic class to represent Pulp Importers
29
+ # Generic class to represent Pulp Importers
32
30
  # Child classes should supply id & config methods
33
31
  class Importer
34
- def initialize(params={})
35
- params.each{|k,v| send("#{k.to_s}=",v)}
32
+ def initialize(params = {})
33
+ params.each { |k, v| send("#{k}=", v) }
36
34
  end
37
35
  end
38
-
39
36
  end
40
37
  end
@@ -28,17 +28,17 @@ module Runcible
28
28
  module Models
29
29
  class IsoDistributor < Distributor
30
30
  #required
31
- attr_accessor "serve_http", "serve_https"
31
+ attr_accessor 'serve_http', 'serve_https'
32
32
 
33
33
  # Instantiates an iso distributor
34
34
  #
35
35
  # @param [boolean] http serve the contents over http
36
36
  # @param [boolean] https serve the contents over https
37
37
  # @return [Runcible::Extensions::IsoDistributor]
38
- def initialize(http, https)
38
+ def initialize(http, https, options = {})
39
39
  @serve_http = http
40
40
  @serve_https = https
41
- super({})
41
+ super(options)
42
42
  end
43
43
 
44
44
  # Distributor Type id
@@ -41,7 +41,7 @@ module Runcible
41
41
  #
42
42
  # @return [Hash]
43
43
  def config
44
- as_json
44
+ as_json
45
45
  end
46
46
  end
47
47
  end
@@ -27,7 +27,6 @@ require 'securerandom'
27
27
  module Runcible
28
28
  module Models
29
29
  class NodesHttpDistributor < Distributor
30
-
31
30
  # Instantiates an nodes distributor
32
31
  #
33
32
  # @param [Hash] params Distributor options
@@ -29,7 +29,7 @@ module Runcible
29
29
  class PuppetDistributor < Distributor
30
30
  attr_accessor 'serve_http', 'serve_https', 'http_dir', 'https_dir', 'absolute_path'
31
31
 
32
- def initialize(absolute_path, http, https, params={})
32
+ def initialize(absolute_path, http, https, params = {})
33
33
  @absolute_path = absolute_path
34
34
  @serve_http = http
35
35
  @serve_https = https
@@ -48,4 +48,4 @@ module Runcible
48
48
  end
49
49
  end
50
50
  end
51
- end
51
+ end
@@ -29,11 +29,10 @@ module Runcible
29
29
  # Requires the pulp-katello-plugins
30
30
  # https://github.com/Katello/pulp-katello-plugins
31
31
  class YumCloneDistributor < Distributor
32
-
33
32
  #optional
34
- attr_accessor "source_repo_id", "source_distributor_id", "destination_distributor_id"
33
+ attr_accessor 'source_repo_id', 'source_distributor_id', 'destination_distributor_id'
35
34
 
36
- def initialize(params={})
35
+ def initialize(params = {})
37
36
  super(params)
38
37
  end
39
38
 
@@ -49,4 +48,4 @@ module Runcible
49
48
  end
50
49
  end
51
50
  end
52
- end
51
+ end
@@ -28,14 +28,14 @@ module Runcible
28
28
  module Models
29
29
  class YumDistributor < Distributor
30
30
  #required
31
- attr_accessor "relative_url", "http", "https"
31
+ attr_accessor 'relative_url', 'http', 'https'
32
32
  #optional
33
- attr_accessor "protected", "auth_cert", "auth_ca",
34
- "https_ca", "gpgkey", "generate_metadata",
35
- "checksum_type", "skip", "https_publish_dir", "http_publish_dir"
33
+ attr_accessor 'protected', 'auth_cert', 'auth_ca',
34
+ 'https_ca', 'gpgkey', 'generate_metadata',
35
+ 'checksum_type', 'skip', 'https_publish_dir', 'http_publish_dir'
36
36
 
37
- def initialize(relative_url, http, https, params={})
38
- @relative_url=relative_url
37
+ def initialize(relative_url, http, https, params = {})
38
+ @relative_url = relative_url
39
39
  @http = http
40
40
  @https = https
41
41
  super(params)
@@ -53,4 +53,4 @@ module Runcible
53
53
  end
54
54
  end
55
55
  end
56
- end
56
+ end
@@ -24,26 +24,26 @@
24
24
  module Runcible
25
25
  module Models
26
26
  class YumImporter < Importer
27
- ID = 'yum_importer'
28
- REPO_TYPE = 'rpm-repo'
27
+ ID = 'yum_importer'
28
+ REPO_TYPE = 'rpm-repo'
29
29
 
30
- #https://github.com/pulp/pulp/blob/master/rpm-support/plugins/importers/yum_importer/importer.py
31
- attr_accessor 'feed', 'ssl_verify', 'ssl_ca_cert', 'ssl_client_cert', 'ssl_client_key',
32
- 'proxy_url', 'proxy_port', 'proxy_pass', 'proxy_user',
33
- 'max_speed', 'verify_size', 'verify_checksum', 'num_threads',
34
- 'newest', 'remove_old', 'num_old_packages', 'purge_orphaned', 'skip', 'checksum_type',
35
- 'num_retries', 'retry_delay'
36
- def id
37
- YumImporter::ID
38
- end
30
+ #https://github.com/pulp/pulp/blob/master/rpm-support/plugins/importers/yum_importer/importer.py
31
+ attr_accessor 'feed', 'ssl_verify', 'ssl_ca_cert', 'ssl_client_cert', 'ssl_client_key',
32
+ 'proxy_url', 'proxy_port', 'proxy_pass', 'proxy_user',
33
+ 'max_speed', 'verify_size', 'verify_checksum', 'num_threads',
34
+ 'newest', 'remove_old', 'num_old_packages', 'purge_orphaned', 'skip', 'checksum_type',
35
+ 'num_retries', 'retry_delay'
36
+ def id
37
+ YumImporter::ID
38
+ end
39
39
 
40
- def repo_type
41
- YumImporter::REPO_TYPE
42
- end
40
+ def repo_type
41
+ YumImporter::REPO_TYPE
42
+ end
43
43
 
44
- def config
45
- as_json
46
- end
44
+ def config
45
+ as_json
47
46
  end
47
+ end
48
48
  end
49
49
  end
@@ -21,18 +21,16 @@
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
-
25
24
  module Runcible
26
25
  module Resources
27
26
  # @see https://pulp-dev-guide.readthedocs.org/en/latest/rest-api/consumer/index.html
28
27
  class Consumer < Runcible::Base
29
-
30
28
  # Generates the API path for Consumers
31
29
  #
32
30
  # @param [String] id the ID of the consumer
33
31
  # @return [String] the consumer path, may contain the id if passed
34
- def self.path(id=nil)
35
- (id == nil) ? "consumers/" : "consumers/#{id}/"
32
+ def self.path(id = nil)
33
+ (id.nil?) ? 'consumers/' : "consumers/#{id}/"
36
34
  end
37
35
 
38
36
  # Creates a consumer
@@ -40,7 +38,7 @@ module Runcible
40
38
  # @param [String] id the ID of the consumer
41
39
  # @param [Hash] optional container for all optional parameters
42
40
  # @return [RestClient::Response]
43
- def create(id, optional={})
41
+ def create(id, optional = {})
44
42
  required = required_params(binding.send(:local_variables), binding)
45
43
  call(:post, path, :payload => { :required => required, :optional => optional })
46
44
  end
@@ -58,7 +56,7 @@ module Runcible
58
56
  # @param [String] id the ID of the consumer
59
57
  # @param [Hash] optional container for all optional parameters
60
58
  # @return [RestClient::Response]
61
- def update(id, optional={})
59
+ def update(id, optional = {})
62
60
  call(:put, path(id), :payload => { :delta => optional })
63
61
  end
64
62
 
@@ -77,7 +75,7 @@ module Runcible
77
75
  # @param [Hash] profile hash representing the consumer profile
78
76
  # @return [RestClient::Response]
79
77
  def upload_profile(id, content_type, profile)
80
- required = required_params(binding.send(:local_variables), binding, ["id"])
78
+ required = required_params(binding.send(:local_variables), binding, ['id'])
81
79
  call(:post, path("#{id}/profiles/"), :payload => { :required => required })
82
80
  end
83
81
 
@@ -115,9 +113,9 @@ module Runcible
115
113
  # @param [String] distributor_id the ID of the distributor
116
114
  # @param [Hash] optional optional parameters
117
115
  # @return [RestClient::Response]
118
- def bind(id, repo_id, distributor_id, optional={})
119
- required = required_params(binding.send(:local_variables), binding, ["id"])
120
- call(:post, path("#{id}/bindings/"), :payload => { :required => required, :optional=>optional })
116
+ def bind(id, repo_id, distributor_id, optional = {})
117
+ required = required_params(binding.send(:local_variables), binding, ['id'])
118
+ call(:post, path("#{id}/bindings/"), :payload => { :required => required, :optional => optional })
121
119
  end
122
120
 
123
121
  # Unbind a consumer to a repository for a given distributor
@@ -136,8 +134,8 @@ module Runcible
136
134
  # @param [Array] units array of units to install
137
135
  # @param [Hash] options hash of install options
138
136
  # @return [RestClient::Response]
139
- def install_units(id, units, options={})
140
- required = required_params(binding.send(:local_variables), binding, ["id"])
137
+ def install_units(id, units, options = {})
138
+ required = required_params(binding.send(:local_variables), binding, ['id'])
141
139
  call(:post, path("#{id}/actions/content/install/"), :payload => { :required => required })
142
140
  end
143
141
 
@@ -147,8 +145,8 @@ module Runcible
147
145
  # @param [Array] units array of units to update
148
146
  # @param [Hash] options hash of update options
149
147
  # @return [RestClient::Response]
150
- def update_units(id, units, options={})
151
- required = required_params(binding.send(:local_variables), binding, ["id"])
148
+ def update_units(id, units, options = {})
149
+ required = required_params(binding.send(:local_variables), binding, ['id'])
152
150
  call(:post, path("#{id}/actions/content/update/"), :payload => { :required => required })
153
151
  end
154
152
 
@@ -158,8 +156,8 @@ module Runcible
158
156
  # @param [Array] units array of units to uninstall
159
157
  # @param [Hash] options hash of uninstall options
160
158
  # @return [RestClient::Response]
161
- def uninstall_units(id, units, options={})
162
- required = required_params(binding.send(:local_variables), binding, ["id"])
159
+ def uninstall_units(id, units, options = {})
160
+ required = required_params(binding.send(:local_variables), binding, ['id'])
163
161
  call(:post, path("#{id}/actions/content/uninstall/"), :payload => { :required => required })
164
162
  end
165
163
 
@@ -168,17 +166,16 @@ module Runcible
168
166
  # @param [Hash] options payload representing criteria
169
167
  # @return [RestClient::Response]
170
168
  def regenerate_applicability(options = {})
171
- call(:post, path("actions/content/regenerate_applicability/"), :payload => { :required => options})
169
+ call(:post, path('actions/content/regenerate_applicability/'), :payload => { :required => options})
172
170
  end
173
171
 
174
172
  # retrieve the applicability for some set of consumers
175
173
  #
176
174
  # @param [Hash] options hash representing criteria
177
175
  # @return [RestClient::Response]
178
- def applicability(options={})
179
- call(:post, path + "content/applicability/", :payload => { :required => options })
176
+ def applicability(options = {})
177
+ call(:post, path + 'content/applicability/', :payload => { :required => options })
180
178
  end
181
-
182
179
  end
183
180
  end
184
181
  end