Class: Katello::CapsuleContent

Inherits:
Object
  • Object
show all
Defined in:
app/lib/katello/capsule_content.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(capsule) ⇒ CapsuleContent



5
6
7
8
# File 'app/lib/katello/capsule_content.rb', line 5

def initialize(capsule)
  # capsule is a smart proxy with pulp feature
  @capsule = capsule
end

Instance Attribute Details

#capsuleObject (readonly)

Returns the value of attribute capsule.



3
4
5
# File 'app/lib/katello/capsule_content.rb', line 3

def capsule
  @capsule
end

Class Method Details

.default_capsuleObject



164
165
166
167
# File 'app/lib/katello/capsule_content.rb', line 164

def self.default_capsule
  proxy = SmartProxy.with_features(SmartProxy::PULP_FEATURE).first
  self.new(proxy) if proxy
end

.with_environment(environment, include_default = false) ⇒ Object



154
155
156
157
158
159
160
161
162
# File 'app/lib/katello/capsule_content.rb', line 154

def self.with_environment(environment, include_default = false)
  features = [SmartProxy::PULP_NODE_FEATURE]
  features << SmartProxy::PULP_FEATURE if include_default

  scope = SmartProxy.with_features(features).joins(:capsule_lifecycle_environments).
      where(katello_capsule_lifecycle_environments: { lifecycle_environment_id: environment.id })

  scope.map { |proxy| self.new(proxy) }
end

Instance Method Details

#==(other) ⇒ Object



100
101
102
# File 'app/lib/katello/capsule_content.rb', line 100

def ==(other)
  other.class == self.class && other.capsule == capsule
end

#active_sync_tasksObject



64
65
66
# File 'app/lib/katello/capsule_content.rb', line 64

def active_sync_tasks
  sync_tasks.where(:result => 'pending')
end

#add_lifecycle_environment(environment) ⇒ Object



31
32
33
# File 'app/lib/katello/capsule_content.rb', line 31

def add_lifecycle_environment(environment)
  @capsule.lifecycle_environments << environment
end

#available_lifecycle_environments(organization_id = nil) ⇒ Object



44
45
46
47
48
# File 'app/lib/katello/capsule_content.rb', line 44

def available_lifecycle_environments(organization_id = nil)
  scope = Katello::KTEnvironment.not_in_capsule(@capsule)
  scope = scope.where(organization_id: organization_id) if organization_id
  scope
end

#cancel_syncObject



96
97
98
# File 'app/lib/katello/capsule_content.rb', line 96

def cancel_sync
  active_sync_tasks.map(&:cancel)
end

#consumerObject



52
53
54
55
56
57
58
# File 'app/lib/katello/capsule_content.rb', line 52

def consumer
  @consumer ||= @capsule.content_host
  unless @consumer
    fail Errors::CapsuleContentMissingConsumer, _("Could not find Content Host with exact name '%s', verify the Capsule is registered with that name.") % @capsule.name
  end
  @consumer
end

#current_repositories(environment_id = nil, content_view_id = nil) ⇒ Object

shows repos available both in katello and on the capsule.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/lib/katello/capsule_content.rb', line 113

def current_repositories(environment_id = nil, content_view_id = nil)
  @current_repositories ||= @capsule.pulp_repositories
  katello_repo_ids = []
  puppet_repo_ids = []

  @current_repositories.each do |repo|
    found_repo = Katello::Repository.where(:pulp_id => repo[:id]).first
    if !found_repo
      found_puppet = Katello::ContentViewPuppetEnvironment.where(:pulp_id => repo[:id]).first
      puppet_repo_ids << found_puppet.id if found_puppet
    else
      katello_repo_ids << found_repo.id if found_repo
    end
  end

  katello_repos = Katello::Repository.where(:id => katello_repo_ids)
  puppet_repos = Katello::ContentViewPuppetEnvironment.where(:id => puppet_repo_ids)

  if environment_id
    katello_repos = katello_repos.where(:environment_id => environment_id)
    puppet_repos = puppet_repos.where(:environment_id => environment_id)
  end

  if content_view_id
    katello_repos = katello_repos.in_content_views([content_view_id])
    puppet_repos = puppet_repos.in_content_view(content_view_id)
  end

  katello_repos + puppet_repos
end

#current_repositories_data(environment = nil, content_view = nil) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/lib/katello/capsule_content.rb', line 81

def current_repositories_data(environment = nil, content_view = nil)
  @pulp_repositories ||= @capsule.pulp_repositories

  repos = Katello::Repository
  repos = repos.in_environment(environment) if environment
  repos = repos.in_content_views([content_view]) if content_view
  puppet_envs = Katello::ContentViewPuppetEnvironment
  puppet_envs = puppet_envs.in_environment(environment) if environment
  puppet_envs = puppet_envs.in_content_view(content_view) if content_view

  repo_ids = repos.pluck(:pulp_id) + puppet_envs.pluck(:pulp_id)

  @pulp_repositories.select { |r| repo_ids.include?(r['id']) }
end

#default_capsule?Boolean



104
105
106
# File 'app/lib/katello/capsule_content.rb', line 104

def default_capsule?
  @capsule.default_capsule?
end

#environment_syncable?(env) ⇒ Boolean



77
78
79
# File 'app/lib/katello/capsule_content.rb', line 77

def environment_syncable?(env)
  last_sync_time.nil? || env.content_view_environments.where('updated_at > ?', last_sync_time).any?
end

#last_failed_sync_tasksObject



68
69
70
# File 'app/lib/katello/capsule_content.rb', line 68

def last_failed_sync_tasks
  sync_tasks.where('started_at > ?', last_sync_time).where.not(:result => 'pending')
end

#last_sync_timeObject



72
73
74
75
# File 'app/lib/katello/capsule_content.rb', line 72

def last_sync_time
  task = sync_tasks.where.not(:ended_at => nil).where(:result => 'success').order(:ended_at).last
  task.ended_at unless task.nil?
end

#lifecycle_environments(organization_id = nil) ⇒ Object



10
11
12
13
14
# File 'app/lib/katello/capsule_content.rb', line 10

def lifecycle_environments(organization_id = nil)
  scope = @capsule.lifecycle_environments
  scope = scope.where(organization_id: organization_id) if organization_id
  scope
end

#orphaned_reposObject



108
109
110
# File 'app/lib/katello/capsule_content.rb', line 108

def orphaned_repos
  @capsule.pulp_repositories.map { |x| x["id"] } - current_repositories.map { |x| x.pulp_id }
end

#pulp_repo_facts(pulp_id) ⇒ Object



148
149
150
151
152
# File 'app/lib/katello/capsule_content.rb', line 148

def pulp_repo_facts(pulp_id)
  self.pulp_server.extensions.repository.retrieve_with_details(pulp_id)
rescue RestClient::ResourceNotFound
  nil
end

#pulp_serverObject



16
17
18
# File 'app/lib/katello/capsule_content.rb', line 16

def pulp_server
  Katello::Pulp::Server.config(pulp_url, User.remote_user)
end

#pulp_urlObject



144
145
146
# File 'app/lib/katello/capsule_content.rb', line 144

def pulp_url
  self.capsule.url + "/pulp/api/v2/"
end

#remove_lifecycle_environment(environment) ⇒ Object



35
36
37
38
39
40
41
42
# File 'app/lib/katello/capsule_content.rb', line 35

def remove_lifecycle_environment(environment)
  @capsule.lifecycle_environments.find(environment)
  unless @capsule.lifecycle_environments.destroy(environment)
    fail _("Could not remove the lifecycle environment from the capsule")
  end
rescue ActiveRecord::RecordNotFound
  raise _("Lifecycle environment was not attached to the capsule; therefore, no changes were made.")
end

#repos_available_to_capsule(environments = nil, content_view = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'app/lib/katello/capsule_content.rb', line 20

def repos_available_to_capsule(environments = nil, content_view = nil)
  environments = lifecycle_environments if environments.nil?
  yum_repos = Katello::Repository.in_environment(environments)
  yum_repos = yum_repos.in_content_views([content_view]) if content_view
  yum_repos = yum_repos.find_all { |repo| repo.node_syncable? }

  puppet_environments = Katello::ContentViewPuppetEnvironment.in_environment(environments)
  puppet_environments = puppet_environments.in_content_view(content_view) if content_view
  yum_repos + puppet_environments
end

#sync_tasksObject



60
61
62
# File 'app/lib/katello/capsule_content.rb', line 60

def sync_tasks
  ForemanTasks::Task.for_resource(self.capsule)
end