foreman_content 0.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.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +113 -0
  3. data/Rakefile +111 -0
  4. data/app/assets/javascripts/content/content.js +12 -0
  5. data/app/assets/stylesheets/content/application.css +13 -0
  6. data/app/controllers/content/api/repositories_controller.rb +27 -0
  7. data/app/controllers/content/gpg_keys_controller.rb +42 -0
  8. data/app/controllers/content/products_controller.rb +51 -0
  9. data/app/controllers/content/repositories_controller.rb +57 -0
  10. data/app/helpers/content/application_helper.rb +5 -0
  11. data/app/helpers/content/repositories_helper.rb +56 -0
  12. data/app/models/content/custom_repository_paths.rb +27 -0
  13. data/app/models/content/environment_product.rb +19 -0
  14. data/app/models/content/gpg_key.rb +32 -0
  15. data/app/models/content/host_product.rb +20 -0
  16. data/app/models/content/hostgroup_product.rb +19 -0
  17. data/app/models/content/operatingsystem_repository.rb +19 -0
  18. data/app/models/content/orchestration/pulp.rb +93 -0
  19. data/app/models/content/product.rb +28 -0
  20. data/app/models/content/product_operatingsystem.rb +19 -0
  21. data/app/models/content/remote/pulp/repository.rb +46 -0
  22. data/app/models/content/repository.rb +70 -0
  23. data/app/models/content/validators/content_validator.rb +25 -0
  24. data/app/models/content/validators/description_format.rb +24 -0
  25. data/app/models/content/validators/name_format.rb +40 -0
  26. data/app/models/content/validators/no_trailing_space.rb +27 -0
  27. data/app/models/setting/content.rb +42 -0
  28. data/app/overrides/add_host_conent_tab.rb +9 -0
  29. data/app/overrides/add_hostgroup_conent_tab.rb +9 -0
  30. data/app/overrides/add_os_conent_tab.rb +9 -0
  31. data/app/services/content/pulp_event_handler.rb +25 -0
  32. data/app/views/content/gpg_keys/_form.html.erb +8 -0
  33. data/app/views/content/gpg_keys/edit.html.erb +3 -0
  34. data/app/views/content/gpg_keys/index.html.erb +20 -0
  35. data/app/views/content/gpg_keys/new.html.erb +3 -0
  36. data/app/views/content/products/_form.html.erb +26 -0
  37. data/app/views/content/products/_form_tab.html.erb +3 -0
  38. data/app/views/content/products/_host_tab_pane.html.erb +5 -0
  39. data/app/views/content/products/_hostgroup_tab_pane.html.erb +5 -0
  40. data/app/views/content/products/_operatingsystem_tab_pane.html.erb +5 -0
  41. data/app/views/content/products/edit.html.erb +3 -0
  42. data/app/views/content/products/index.html.erb +27 -0
  43. data/app/views/content/products/new.html.erb +3 -0
  44. data/app/views/content/products/welcome.html.erb +8 -0
  45. data/app/views/content/repositories/_form.html.erb +30 -0
  46. data/app/views/content/repositories/edit.html.erb +3 -0
  47. data/app/views/content/repositories/index.html.erb +32 -0
  48. data/app/views/content/repositories/new.html.erb +3 -0
  49. data/app/views/content/repositories/show.html.erb +98 -0
  50. data/app/views/content/repositories/welcome.html.erb +8 -0
  51. data/config/routes.rb +36 -0
  52. data/db/migrate/20130702140034_create_content_repositories.rb +19 -0
  53. data/db/migrate/20130702162629_create_content_products.rb +10 -0
  54. data/db/migrate/20130709001120_create_content_gpg_keys.rb +10 -0
  55. data/db/migrate/20130717032320_create_content_environments_products.rb +9 -0
  56. data/db/migrate/20130722084911_create_content_operatingsystem_repositories.rb +9 -0
  57. data/db/migrate/20130723084911_create_content_hostgroup_products.rb +9 -0
  58. data/db/migrate/20130723124911_create_content_host_products.rb +9 -0
  59. data/db/migrate/20130729032320_create_content_product_operatingsystems.rb +9 -0
  60. data/lib/content/engine.rb +59 -0
  61. data/lib/content/version.rb +3 -0
  62. data/lib/content_environment.rb +13 -0
  63. data/lib/content_home_helper_patch.rb +23 -0
  64. data/lib/content_host.rb +55 -0
  65. data/lib/content_hostgroup.rb +22 -0
  66. data/lib/content_operatingsystem.rb +17 -0
  67. data/lib/content_redhat.rb +36 -0
  68. data/lib/content_taxonomy.rb +18 -0
  69. data/lib/foreman_content.rb +4 -0
  70. data/lib/pulp_configuration.rb +23 -0
  71. data/lib/tasks/content_tasks.rake +4 -0
  72. data/test/content_test.rb +7 -0
  73. data/test/fixtures/content/products.yml +11 -0
  74. data/test/fixtures/content/repositories.yml +11 -0
  75. data/test/integration/navigation_test.rb +10 -0
  76. data/test/test_helper.rb +23 -0
  77. data/test/unit/content/description_format_validator_test.rb +20 -0
  78. data/test/unit/content/name_format_validator_test.rb +28 -0
  79. data/test/unit/content/product_validation_test.rb +18 -0
  80. data/test/unit/content/repositories_test.rb +7 -0
  81. metadata +194 -0
@@ -0,0 +1,3 @@
1
+ <% title _("New Repository") %>
2
+
3
+ <%= render :partial => 'form' %>
@@ -0,0 +1,98 @@
1
+ <% javascript 'charts' %>
2
+ <% title @repository.to_label %>
3
+
4
+ <%= title_actions(button_group(
5
+ link_to_if_authorized(_("Edit"), hash_for_edit_repository_path(@repository)),
6
+ link_to_if_authorized(_("Synchronize"), hash_for_sync_repository_path(@repository), :method => :put)
7
+ )) %>
8
+ <div class="row">
9
+ <div class="span12">
10
+ <table class="table table-bordered table-striped">
11
+ <tr>
12
+ <th><%= _('Repository details') %></th>
13
+ <th></th>
14
+ </tr>
15
+ <tr>
16
+ <td> <%= _("Name") %> </td>
17
+ <td> <%= @repository.to_label %> </td>
18
+ </tr>
19
+ <tr>
20
+ <td> <%= _("Description") %> </td>
21
+ <td> <%= @repository.description %> </td>
22
+ </tr>
23
+ <tr>
24
+ <td> <%= _("Feed") %> </td>
25
+ <td> <%= @repository.feed %> </td>
26
+ </tr>
27
+ <tr>
28
+ <td> <%= _("Content type") %> </td>
29
+ <td> <%= @repository.content_type %> </td>
30
+ </tr>
31
+ <tr>
32
+ <td> <%= _("Architecture") %> </td>
33
+ <td> <%= @repository.architecture %> </td>
34
+ </tr>
35
+ <tr>
36
+ <td> <%= _("Enabled") %> </td>
37
+ <td> <%= @repository.enabled %> </td>
38
+ </tr>
39
+ <tr>
40
+ <td> <%= _("Unprotected") %> </td>
41
+ <td> <%= @repository.unprotected %> </td>
42
+ </tr>
43
+ <tr>
44
+ <td> <%= _("Full path") %> </td>
45
+ <td> <%= @repository.full_path %> </td>
46
+ </tr>
47
+ </table>
48
+ </div>
49
+ </div>
50
+ <div class="row-fluid">
51
+ <div class="stats-well span4">
52
+ <h4 class="ca" ><%= _('Last Update Metrics') -%></h4>
53
+ <div style="margin-top:50px;padding-bottom: 40px;">
54
+ <%= flot_pie_chart("metrics" ,_("Last Update Metrics"), sync_history_times(@sync_history), :class => "statistics-pie small")%>
55
+ </div>
56
+ </div>
57
+ <div class="stats-well span4">
58
+ <h4 class="ca" ><%= _('Update Summary') -%></h4>
59
+ <%= flot_bar_chart("status" ,"", _("Number of packages"), sync_history_metrics(@sync_history), :class => "statistics-bar")%>
60
+ </div>
61
+
62
+ <div class="span4">
63
+ <table class="table table-bordered table-striped">
64
+ <tr>
65
+ <th><%= _('Repository Counters') %></th>
66
+ <th></th>
67
+ </tr>
68
+ <% @details[:content_unit_counts].each do |name, value| -%>
69
+ <tr>
70
+ <td> <%= name.humanize %> </td>
71
+ <td> <%= value %> </td>
72
+ </tr>
73
+ <% end -%>
74
+ <tr>
75
+ <td> <%= _("Last published") %> </td>
76
+ <td> <%= last_publish @details %> </td>
77
+ </tr>
78
+ <tr>
79
+ <td> <%= _("Last synchronized") %> </td>
80
+ <td> <%= last_sync @details %> </td>
81
+ </tr>
82
+ </table>
83
+ </div>
84
+ <div class="span4">
85
+ <table class="table table-bordered table-striped">
86
+ <tr>
87
+ <th><%= _('Last Sync') %></th>
88
+ <th></th>
89
+ </tr>
90
+ <% sync_history_status(@sync_history).each do |name, value| -%>
91
+ <tr>
92
+ <td> <%= name.humanize %> </td>
93
+ <td> <%= value %> </td>
94
+ </tr>
95
+ <% end -%>
96
+ </table>
97
+ </div>
98
+ </div>
@@ -0,0 +1,8 @@
1
+ <% title_actions link_to(_("New repository"), new_repository_path) %>
2
+ <% title _("Repository configuration") %>
3
+ <div id="welcome">
4
+ <p>
5
+ <%= _("Here come some fancy explanation about content and content in general, bla bla.") %>
6
+ </p>
7
+
8
+ </div>
data/config/routes.rb ADDED
@@ -0,0 +1,36 @@
1
+ Rails.application.routes.draw do
2
+ scope :module => :content do
3
+ resources :gpg_keys do
4
+ collection do
5
+ get 'auto_complete_search'
6
+ end
7
+ end
8
+
9
+ resources :products do
10
+ collection do
11
+ get 'auto_complete_search'
12
+ end
13
+ member do
14
+ put :sync
15
+ end
16
+ end
17
+
18
+ resources :repositories do
19
+ collection do
20
+ get 'auto_complete_search'
21
+ end
22
+ member do
23
+ put :sync
24
+ end
25
+ end
26
+
27
+ namespace :api do
28
+ resources :repositories do
29
+ collection do
30
+ post 'events'
31
+ end
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ class CreateContentRepositories < ActiveRecord::Migration
2
+ def change
3
+ create_table :content_repositories do |t|
4
+ t.string :name, :null => false
5
+ t.string :description
6
+ t.string :content_type, :default => "yum", :null => false
7
+ t.boolean :enabled, :default => true
8
+ t.string :relative_path
9
+ t.string :feed
10
+ t.boolean :unprotected, :default => false
11
+ t.references :product, :null => false
12
+ t.string :pulp_id
13
+ t.references :gpg_key
14
+ t.references :architecture
15
+ t.timestamps
16
+ end
17
+ add_index :content_repositories, :pulp_id, :unique => true
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ class CreateContentProducts < ActiveRecord::Migration
2
+ def change
3
+ create_table :content_products do |t|
4
+ t.string :name
5
+ t.text :description
6
+ t.references :gpg_key
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreateContentGpgKeys < ActiveRecord::Migration
2
+ def change
3
+ create_table :content_gpg_keys do |t|
4
+ t.string :name, :null => false
5
+ t.text :content, :null => false
6
+ t.timestamps
7
+ end
8
+ add_index(:content_gpg_keys, [:name], :unique=>true)
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ class CreateContentEnvironmentsProducts < ActiveRecord::Migration
2
+ def change
3
+ create_table :content_environment_products do |t|
4
+ t.references :environment, :null =>false
5
+ t.references :product, :null =>false
6
+ end
7
+ add_index(:content_environment_products, [:environment_id, :product_id],:name=>'environment_products_index', :unique=>true)
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateContentOperatingsystemRepositories < ActiveRecord::Migration
2
+ def change
3
+ create_table :content_operatingsystem_repositories do |t|
4
+ t.references :repository, :null =>false
5
+ t.references :operatingsystem, :null =>false
6
+ end
7
+ add_index(:content_operatingsystem_repositories, [:repository_id, :operatingsystem_id],:name=>'operatingsystem_repositories_index', :unique=>true)
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateContentHostgroupProducts < ActiveRecord::Migration
2
+ def change
3
+ create_table :content_hostgroup_products do |t|
4
+ t.references :hostgroup, :null =>false
5
+ t.references :product, :null =>false
6
+ end
7
+ add_index(:content_hostgroup_products, [:product_id, :hostgroup_id],:name=>'hostgroup_products_index', :unique=>true)
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateContentHostProducts < ActiveRecord::Migration
2
+ def change
3
+ create_table :content_host_products do |t|
4
+ t.references :host, :null =>false
5
+ t.references :product, :null =>false
6
+ end
7
+ add_index(:content_host_products, [:product_id, :host_id],:name=>'host_products_index', :unique=>true)
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateContentProductOperatingsystems < ActiveRecord::Migration
2
+ def change
3
+ create_table :content_product_operatingsystems do |t|
4
+ t.references :operatingsystem, :null =>false
5
+ t.references :product, :null =>false
6
+ end
7
+ add_index(:content_product_operatingsystems, [:operatingsystem_id, :product_id],:name=>'product_operatingsystems_index', :unique=>true)
8
+ end
9
+ end
@@ -0,0 +1,59 @@
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
+ module Content
12
+ ENGINE_NAME = "content"
13
+ class Engine < ::Rails::Engine
14
+ engine_name Content::ENGINE_NAME
15
+
16
+ # Load this before the Foreman config initializers, so that the Setting.descendants
17
+ # list includes the plugin STI setting class
18
+ initializer 'foreman_content.load_default_settings', :before => :load_config_initializers do |app|
19
+ require_dependency File.expand_path("../../../app/models/setting/content.rb", __FILE__) if (Setting.table_exists? rescue(false))
20
+ end
21
+
22
+ initializer "foreman_content.load_app_instance_data" do |app|
23
+ app.config.paths['db/migrate'] += Content::Engine.paths['db/migrate'].existent
24
+ app.config.autoload_paths += Dir["#{config.root}/app/services)"]
25
+ end
26
+
27
+ # Include extensions to models in this config.to_prepare block
28
+ config.to_prepare do
29
+ ::PulpConfiguration.initialize_runcible
30
+ # Patch the menu
31
+ ::HomeHelper.send :include, ContentHomeHelperPatch
32
+ # Extend the taxonomy model
33
+ ::Taxonomy.send :include, ContentTaxonomy
34
+ # Extend the environment model
35
+ ::Environment.send :include, ContentEnvironment
36
+ # Extend OS model
37
+ ::Operatingsystem.send :include, ContentOperatingsystem
38
+ # Extend RedHat OS family model
39
+ ::Redhat.send :include, ContentRedhat
40
+ # Extend the hostgroup model
41
+ ::Hostgroup.send :include, ContentHostgroup
42
+ # Extend the host model
43
+ ::Host::Managed.send :include, ContentHost
44
+ end
45
+ end
46
+
47
+ def table_name_prefix
48
+ Content::ENGINE_NAME + '_'
49
+ end
50
+
51
+ def self.table_name_prefix
52
+ Content::ENGINE_NAME + '_'
53
+ end
54
+
55
+ def use_relative_model_naming
56
+ true
57
+ end
58
+
59
+ end
@@ -0,0 +1,3 @@
1
+ module Content
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,55 @@
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
@@ -0,0 +1,22 @@
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
@@ -0,0 +1,17 @@
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