foreman_content 0.1 → 0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66165cc1d29ef234bd0d15923511264f87045b55
4
- data.tar.gz: 2166c67ba266eaf2c9d478ba4e64839fb7a703a9
3
+ metadata.gz: 76fd79ca9fac589c6e62a1a0ec2ba6c9df2ac608
4
+ data.tar.gz: 34734b08623ad025a96fa107974143e5678c80e2
5
5
  SHA512:
6
- metadata.gz: 851db5cbe0dda9500b5bd6d30506d4ab63c565e0802cd5365b81a1b5a53c15d3362410e3ae347fbe82dc1da385c8e881953f72117253925bcc973916e3d0f444
7
- data.tar.gz: c202eedf2998d5baca4d8a76ad2df98c745b280fd2a02726ae604c43477aea38a2c1a658e0b9bbea85276a518fa9e6623fa7b1db78247e5da2dfd3d728428377
6
+ metadata.gz: 1bb2945c7a124cc7ebd769ff32f2181f9f617f44efc283b5536b8e409feb738afe3defc05ae2a4d8de6aedbf778695ee5dd71707c6b00914b173f0206db1bb44
7
+ data.tar.gz: 86d1ef1b4b71b460f5af210bac3523e6d61323ab7b3a41a34263abc1de637081c020866386e39c4cc15681bf46451654bc1627a8965325fab680931ba21cf96d
@@ -1,5 +1,7 @@
1
1
  module Content
2
2
  module CustomRepositoryPaths
3
+ extend ActiveSupport::Concern
4
+
3
5
  def repo_path_from_content_path(environment, content_path)
4
6
  content_path = content_path.sub(/^\//, "")
5
7
  path_prefix = [environment.organization.label, environment.label].join("/")
@@ -0,0 +1,9 @@
1
+ module Content::EnvironmentExtensions
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ has_many :environment_products, :dependent => :destroy, :uniq => true, :class_name => 'Content::EnvironmentProduct'
6
+ has_many :products, :through => :environment_products, :class_name => 'Content::Product'
7
+ end
8
+
9
+ end
@@ -0,0 +1,18 @@
1
+ module Content::HomeHelper
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ alias_method_chain :setting_options, :content_link
5
+ end
6
+
7
+ # Adds a content link to the More menu
8
+ def setting_options_with_content_link
9
+ choices = setting_options_without_content_link
10
+ content_group =
11
+ [
12
+ [_('Products'), :"content/products"],
13
+ [_('Repositories'), :"content/repositories"],
14
+ [_('Gpg keys'), :"content/gpg_keys"]
15
+ ]
16
+ choices.insert(3, [:divider], [:group, _("Content"), content_group])
17
+ end
18
+ end
@@ -0,0 +1,50 @@
1
+ module Content::HostExtensions
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ has_many :host_products, :dependent => :destroy, :uniq => true, :foreign_key => :host_id, :class_name => 'Content::HostProduct'
6
+ has_many :products, :through => :host_products, :class_name => 'Content::Product'
7
+
8
+ scoped_search :in => :products, :on => :name, :complete_value => true, :rename => :product
9
+
10
+ alias_method_chain :params, :repositories
11
+ end
12
+
13
+ # adds repository hash to ENC global parameters
14
+ def params_with_repositories
15
+ # convert all repos to a format that puppet create_resource with yumrepo can consume
16
+ repos = Hash[attached_repositories.map { |repo| [repo.to_label, format_repo(repo)] }]
17
+ # adds a global parameter called repositories contain all repos
18
+ params_without_repositories.merge('repositories' => repos)
19
+ end
20
+
21
+ # product_ids from the os default and hostgroup.
22
+ def inherited_product_ids
23
+ products = []
24
+ products += operatingsystem.product_ids if operatingsystem
25
+ products += Content::HostgroupProduct.where(:hostgroup_id => hostgroup.path_ids).pluck(:product_id) if hostgroup_id
26
+ products.uniq
27
+ end
28
+
29
+ def all_product_ids
30
+ (inherited_product_ids + product_ids).uniq
31
+ end
32
+
33
+ def attached_repositories
34
+ Content::Repository.attached_to_host(self)
35
+ end
36
+
37
+ private
38
+
39
+ # convert a repository to a format that puppet create_resource with yumrepo can consume
40
+ def format_repo repo
41
+ {
42
+ 'baseurl' => repo.full_path,
43
+ # yum repos have descr field but no name, if descr is empty use the repo name
44
+ 'descr' => repo.description.blank? ? repo.name : repo.description,
45
+ 'enabled' => repo.enabled ? '1' : '0',
46
+ 'gpgcheck' => !!repo.gpg_key ? '1' : '0'
47
+ }
48
+ end
49
+
50
+ end
@@ -0,0 +1,18 @@
1
+ module Content::HostgroupExtensions
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ has_many :hostgroup_products, :dependent => :destroy, :uniq => true, :class_name => 'Content::HostgroupProduct'
6
+ has_many :products, :through => :hostgroup_products, :class_name => 'Content::Product'
7
+
8
+ scoped_search :in => :products, :on => :name, :complete_value => true, :rename => :product
9
+ end
10
+
11
+ def inherited_product_ids
12
+ Content::HostgroupProduct.where(:hostgroup_id => hostgroup.ancestor_ids).pluck(:product_id)
13
+ end
14
+
15
+ def all_product_ids
16
+ (inherited_product_ids + product_ids).uniq
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module Content::OperatingsystemExtensions
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ has_many :operatingsystem_repositories, :dependent => :destroy, :uniq => true, :class_name => 'Content::OperatingsystemRepository'
6
+ has_many :repositories, :through => :operatingsystem_repositories, :class_name => 'Content::Repository'
7
+ has_many :product_operatingsystems, :dependent => :destroy, :uniq => true, :class_name => 'Content::ProductOperatingsystem'
8
+ has_many :products, :through => :product_operatingsystems, :class_name => 'Content::Product'
9
+ has_many :default_repositories, :through => :products, :source => :repositories, :class_name => 'Content::Repository'
10
+ end
11
+
12
+ end
@@ -0,0 +1,33 @@
1
+ module Content::RedhatExtensions
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ alias_method_chain :medium_uri, :content_uri
6
+ end
7
+
8
+ def medium_uri_with_content_uri host, url = nil
9
+ if url.nil? && (full_path = Content::Repository.available_for_host(host).kickstart.first.try(:full_path))
10
+ URI.parse(full_path)
11
+ else
12
+ medium_uri_without_content_uri(host, url)
13
+ end
14
+ end
15
+
16
+ # return an array of repositories for kickstart script as additional repos
17
+ # to the kickstart main repo, this list will typically include updates and epel
18
+ def repos host
19
+ host.attached_repositories.yum.map { |repo| format_repo(repo) }
20
+ end
21
+
22
+ private
23
+ # convert a repository to a format that kickstart script can consume
24
+ def format_repo repo
25
+ {
26
+ :baseurl => repo.full_path,
27
+ :name => repo.to_label,
28
+ :description => repo.product.description,
29
+ :enabled => repo.enabled,
30
+ :gpgcheck => !!repo.gpg_key
31
+ }
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ module Content::TaxonomyExtensions
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ has_many :products, :through => :taxable_taxonomies, :source => :taxable, :source_type => 'Content::Product'
6
+ alias_method_chain :dup, :content_dup
7
+ end
8
+
9
+ def dup_with_content_dup
10
+ new = dup_without_content_dup
11
+ new.products = products
12
+ new
13
+ end
14
+ end
@@ -37,6 +37,8 @@ module Content
37
37
 
38
38
  protected
39
39
  def initialize_pulp
40
+ # initiate pulp connection
41
+ Content::PulpConfiguration.new
40
42
  self.pulp_id ||= Foreman.uuid.gsub("-", '')
41
43
  self.relative_path ||= custom_repo_path("acme_org", "library", product.name, name) if name
42
44
  end
@@ -1,11 +1,12 @@
1
1
  require 'runcible'
2
+ require 'uri'
2
3
 
3
- class PulpConfiguration
4
- def self.initialize_runcible
5
- Runcible::Base.config = runcible_config
4
+ class Content::PulpConfiguration
5
+ def initialize options = {}
6
+ Runcible::Base.config = runcible_config.merge(options)
6
7
  end
7
8
 
8
- def self.runcible_config
9
+ def runcible_config
9
10
  pulp_url = URI(Setting.pulp_url)
10
11
  {
11
12
  :url => "#{pulp_url.scheme}://#{pulp_url.host}:#{pulp_url.port}",
@@ -1,18 +1,11 @@
1
- require 'content_home_helper_patch'
2
- require 'content_taxonomy'
3
- require 'content_environment'
4
- require 'content_operatingsystem'
5
- require 'content_redhat'
6
- require 'content_hostgroup'
7
- require 'content_host'
8
- require 'pulp_configuration'
9
-
10
-
11
1
  module Content
12
2
  ENGINE_NAME = "content"
13
3
  class Engine < ::Rails::Engine
14
4
  engine_name Content::ENGINE_NAME
15
5
 
6
+ config.autoload_paths += Dir["#{config.root}/app/services"]
7
+ config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
8
+
16
9
  # Load this before the Foreman config initializers, so that the Setting.descendants
17
10
  # list includes the plugin STI setting class
18
11
  initializer 'foreman_content.load_default_settings', :before => :load_config_initializers do |app|
@@ -21,26 +14,24 @@ module Content
21
14
 
22
15
  initializer "foreman_content.load_app_instance_data" do |app|
23
16
  app.config.paths['db/migrate'] += Content::Engine.paths['db/migrate'].existent
24
- app.config.autoload_paths += Dir["#{config.root}/app/services)"]
25
17
  end
26
18
 
27
19
  # Include extensions to models in this config.to_prepare block
28
20
  config.to_prepare do
29
- ::PulpConfiguration.initialize_runcible
30
21
  # Patch the menu
31
- ::HomeHelper.send :include, ContentHomeHelperPatch
22
+ ::HomeHelper.send :include, Content::HomeHelper
32
23
  # Extend the taxonomy model
33
- ::Taxonomy.send :include, ContentTaxonomy
24
+ ::Taxonomy.send :include, Content::TaxonomyExtensions
34
25
  # Extend the environment model
35
- ::Environment.send :include, ContentEnvironment
26
+ ::Environment.send :include, Content::EnvironmentExtensions
36
27
  # Extend OS model
37
- ::Operatingsystem.send :include, ContentOperatingsystem
28
+ ::Operatingsystem.send :include, Content::OperatingsystemExtensions
38
29
  # Extend RedHat OS family model
39
- ::Redhat.send :include, ContentRedhat
30
+ ::Redhat.send :include, Content::RedhatExtensions
40
31
  # Extend the hostgroup model
41
- ::Hostgroup.send :include, ContentHostgroup
32
+ ::Hostgroup.send :include, Content::HostgroupExtensions
42
33
  # Extend the host model
43
- ::Host::Managed.send :include, ContentHost
34
+ ::Host::Managed.send :include, Content::HostExtensions
44
35
  end
45
36
  end
46
37
 
@@ -1,3 +1,3 @@
1
1
  module Content
2
- VERSION = "0.1"
2
+ VERSION = "0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_content
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitri Dolguikh
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-08-01 00:00:00.000000000 Z
13
+ date: 2013-08-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -44,14 +44,14 @@ dependencies:
44
44
  name: runcible
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ~>
47
+ - - '='
48
48
  - !ruby/object:Gem::Version
49
49
  version: 0.4.10
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ~>
54
+ - - '='
55
55
  - !ruby/object:Gem::Version
56
56
  version: 0.4.10
57
57
  - !ruby/object:Gem::Dependency
@@ -86,7 +86,6 @@ files:
86
86
  - app/models/content/gpg_key.rb
87
87
  - app/models/content/orchestration/pulp.rb
88
88
  - app/models/content/hostgroup_product.rb
89
- - app/models/content/custom_repository_paths.rb
90
89
  - app/models/content/operatingsystem_repository.rb
91
90
  - app/models/content/validators/no_trailing_space.rb
92
91
  - app/models/content/validators/name_format.rb
@@ -95,7 +94,16 @@ files:
95
94
  - app/models/content/repository.rb
96
95
  - app/models/content/product.rb
97
96
  - app/models/content/environment_product.rb
97
+ - app/models/concerns/content/taxonomy_extensions.rb
98
+ - app/models/concerns/content/hostgroup_extensions.rb
99
+ - app/models/concerns/content/environment_extensions.rb
100
+ - app/models/concerns/content/operatingsystem_extensions.rb
101
+ - app/models/concerns/content/custom_repository_paths.rb
102
+ - app/models/concerns/content/home_helper.rb
103
+ - app/models/concerns/content/host_extensions.rb
104
+ - app/models/concerns/content/redhat_extensions.rb
98
105
  - app/services/content/pulp_event_handler.rb
106
+ - app/services/content/pulp_configuration.rb
99
107
  - app/overrides/add_os_conent_tab.rb
100
108
  - app/overrides/add_host_conent_tab.rb
101
109
  - app/overrides/add_hostgroup_conent_tab.rb
@@ -135,18 +143,10 @@ files:
135
143
  - db/migrate/20130729032320_create_content_product_operatingsystems.rb
136
144
  - db/migrate/20130702140034_create_content_repositories.rb
137
145
  - db/migrate/20130723084911_create_content_hostgroup_products.rb
138
- - lib/content_hostgroup.rb
139
- - lib/content_environment.rb
140
- - lib/content_redhat.rb
141
- - lib/content_home_helper_patch.rb
142
- - lib/content_taxonomy.rb
143
146
  - lib/content/engine.rb
144
147
  - lib/content/version.rb
145
- - lib/content_operatingsystem.rb
146
148
  - lib/foreman_content.rb
147
149
  - lib/tasks/content_tasks.rake
148
- - lib/content_host.rb
149
- - lib/pulp_configuration.rb
150
150
  - Rakefile
151
151
  - README.md
152
152
  - test/unit/content/description_format_validator_test.rb
@@ -1,13 +0,0 @@
1
- module ContentEnvironment
2
- def self.included(base)
3
- base.send(:include, InstanceMethods)
4
-
5
- base.class_eval do
6
- has_many :environment_products, :dependent => :destroy, :uniq=>true, :class_name => 'Content::EnvironmentProduct'
7
- has_many :products, :through => :environment_products, :class_name => 'Content::Product'
8
- end
9
- end
10
-
11
- module InstanceMethods
12
- end
13
- end
@@ -1,23 +0,0 @@
1
- module ContentHomeHelperPatch
2
- def self.included(base)
3
- base.send(:include, InstanceMethods)
4
-
5
- base.class_eval do
6
- alias_method_chain :setting_options, :content_link
7
- end
8
- end
9
-
10
- module InstanceMethods
11
- # Adds a content link to the More menu
12
- def setting_options_with_content_link
13
- choices = setting_options_without_content_link
14
- content_group =
15
- [
16
- [_('Products'), :"content/products"],
17
- [_('Repositories'), :"content/repositories"],
18
- [_('Gpg keys'), :"content/gpg_keys"]
19
- ]
20
- choices.insert(3, [:divider], [:group, _("Content"), content_group])
21
- end
22
- end
23
- end
data/lib/content_host.rb DELETED
@@ -1,55 +0,0 @@
1
- module ContentHost
2
- def self.included(base)
3
- base.send(:include, InstanceMethods)
4
-
5
- base.class_eval do
6
- has_many :host_products, :dependent => :destroy, :uniq=>true,:foreign_key => :host_id, :class_name => 'Content::HostProduct'
7
- has_many :products, :through => :host_products, :class_name => 'Content::Product'
8
-
9
- scoped_search :in=>:products, :on=>:name, :complete_value => true, :rename => :product
10
-
11
- alias_method_chain :params, :repositories
12
- end
13
- end
14
-
15
- module InstanceMethods
16
-
17
- # adds repository hash to ENC global parameters
18
- def params_with_repositories
19
- # convert all repos to a format that puppet create_resource with yumrepo can consume
20
- repos = Hash[attached_repositories.map{ |repo| [repo.to_label, format_repo(repo)] }]
21
- # adds a global parameter called repositories contain all repos
22
- params_without_repositories.merge('repositories' => repos)
23
- end
24
-
25
- # product_ids from the os default and hostgroup.
26
- def inherited_product_ids
27
- products = []
28
- products += operatingsystem.product_ids if operatingsystem
29
- products += Content::HostgroupProduct.where(:hostgroup_id => hostgroup.path_ids).pluck(:product_id) if hostgroup_id
30
- products.uniq
31
- end
32
-
33
- def all_product_ids
34
- (inherited_product_ids + product_ids).uniq
35
- end
36
-
37
- def attached_repositories
38
- Content::Repository.attached_to_host(self)
39
- end
40
-
41
- private
42
-
43
- # convert a repository to a format that puppet create_resource with yumrepo can consume
44
- def format_repo repo
45
- {
46
- 'baseurl' => repo.full_path,
47
- # yum repos have descr field but no name, if descr is empty use the repo name
48
- 'descr' => repo.description.blank? ? repo.name : repo.description,
49
- 'enabled' => repo.enabled ? '1': '0',
50
- 'gpgcheck' => !!repo.gpg_key ? '1': '0'
51
- }
52
- end
53
-
54
- end
55
- end
@@ -1,22 +0,0 @@
1
- module ContentHostgroup
2
- def self.included(base)
3
- base.send(:include, InstanceMethods)
4
-
5
- base.class_eval do
6
- has_many :hostgroup_products, :dependent => :destroy, :uniq=>true, :class_name => 'Content::HostgroupProduct'
7
- has_many :products, :through => :hostgroup_products, :class_name => 'Content::Product'
8
-
9
- scoped_search :in=>:products, :on=>:name, :complete_value => true, :rename => :product
10
- end
11
- end
12
-
13
- module InstanceMethods
14
- def inherited_product_ids
15
- Content::HostgroupProduct.where(:hostgroup_id => hostgroup.ancestor_ids).pluck(:product_id)
16
- end
17
-
18
- def all_product_ids
19
- (inherited_product_ids + product_ids).uniq
20
- end
21
- end
22
- end
@@ -1,17 +0,0 @@
1
- module ContentOperatingsystem
2
- def self.included(base)
3
- base.send(:include, InstanceMethods)
4
-
5
- base.class_eval do
6
- has_many :operatingsystem_repositories, :dependent => :destroy, :uniq => true, :class_name => 'Content::OperatingsystemRepository'
7
- has_many :repositories, :through => :operatingsystem_repositories, :class_name => 'Content::Repository'
8
-
9
- has_many :product_operatingsystems, :dependent => :destroy, :uniq => true, :class_name => 'Content::ProductOperatingsystem'
10
- has_many :products, :through => :product_operatingsystems, :class_name => 'Content::Product'
11
- has_many :default_repositories, :through => :products, :source => :repositories, :class_name => 'Content::Repository'
12
- end
13
- end
14
-
15
- module InstanceMethods
16
- end
17
- end
@@ -1,36 +0,0 @@
1
- module ContentRedhat
2
- def self.included(base)
3
- base.send(:include, InstanceMethods)
4
- base.class_eval do
5
- alias_method_chain :medium_uri, :content_uri
6
- end
7
- end
8
-
9
- module InstanceMethods
10
- def medium_uri_with_content_uri host, url = nil
11
- if url.nil? && (full_path = Content::Repository.available_for_host(host).kickstart.first.try(:full_path))
12
- URI.parse(full_path)
13
- else
14
- medium_uri_without_content_uri(host, url)
15
- end
16
- end
17
-
18
- # return an array of repositories for kickstart script as additional repos
19
- # to the kickstart main repo, this list will typically include updates and epel
20
- def repos host
21
- host.attached_repositories.yum.map{ |repo| format_repo(repo) }
22
- end
23
-
24
- private
25
- # convert a repository to a format that kickstart script can consume
26
- def format_repo repo
27
- {
28
- :baseurl => repo.full_path,
29
- :name => repo.to_label,
30
- :description => repo.product.description,
31
- :enabled => repo.enabled,
32
- :gpgcheck => !!repo.gpg_key
33
- }
34
- end
35
- end
36
- end
@@ -1,18 +0,0 @@
1
- module ContentTaxonomy
2
- def self.included(base)
3
- base.send(:include, InstanceMethods)
4
-
5
- base.class_eval do
6
- has_many :products, :through => :taxable_taxonomies, :source => :taxable, :source_type => 'Content::Product'
7
- alias_method_chain :dup, :content_dup
8
- end
9
- end
10
-
11
- module InstanceMethods
12
- def dup_with_content_dup
13
- new = dup_without_content_dup
14
- new.products = products
15
- new
16
- end
17
- end
18
- end