Class: Katello::System

Inherits:
Model
  • Object
show all
Includes:
Authorization::System, ForemanTasks::Concerns::ActionSubject, Glue::Candlepin::Consumer, Glue::Pulp::Consumer, Glue
Defined in:
app/models/katello/system.rb

Direct Known Subclasses

Hypervisor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Glue

included, logger

Methods inherited from Model

#destroy!

Class Method Details

.architecturesObject



80
81
82
83
84
# File 'app/models/katello/system.rb', line 80

def architectures
  { 'i386' => 'x86', 'ia64' => 'Itanium', 'x86_64' => 'x86_64', 'ppc' => 'PowerPC',
    's390' => 'IBM S/390', 's390x' => 'IBM System z', 'sparc64' => 'SPARC Solaris',
    'i686' => 'i686'}
end

.available_locksObject



215
216
217
# File 'app/models/katello/system.rb', line 215

def self.available_locks
  [:read, :write]
end

.in_organization(organization) ⇒ Object



64
65
66
# File 'app/models/katello/system.rb', line 64

def self.in_organization(organization)
  where(:environment_id => organization.kt_environments.pluck(:id))
end

.uuids_to_ids(uuids) ⇒ Object



68
69
70
71
72
73
# File 'app/models/katello/system.rb', line 68

def self.uuids_to_ids(uuids)
  systems = by_uuids(uuids)
  ids_not_found = Set.new(uuids).subtract(systems.pluck(:uuid))
  fail Errors::NotFound, _("Systems [%s] not found.") % ids_not_found.to_a.join(',') unless ids_not_found.blank?
  systems.pluck(:id)
end

.virtualizedObject



86
87
88
# File 'app/models/katello/system.rb', line 86

def virtualized
  { "physical" => N_("Physical"), "virtualized" => N_("Virtual") }
end

Instance Method Details

#as_json(options) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'app/models/katello/system.rb', line 156

def as_json(options)
  json = super(options)
  json['environment'] = environment.as_json unless environment.nil?
  json['activation_key'] = activation_keys.as_json unless activation_keys.nil?

  json['content_view'] = content_view.as_json if content_view
  json['ipv4_address'] = facts.try(:[], 'network.ipv4_address') if respond_to?(:facts)

  if respond_to?(:virtual_guest)
    if self.virtual_guest == 'true'
      json['virtual_host'] = self.virtual_host.attributes if self.virtual_host
    else
      json['virtual_guests'] = self.virtual_guests.map(&:attributes)
    end
  end

  if options[:expanded]
    json['editable'] = editable?
    json['type'] = type
  end

  json
end

#available_contentObject



227
228
229
# File 'app/models/katello/system.rb', line 227

def available_content
  self.products.flat_map(&:available_content)
end

#available_releasesObject



97
98
99
# File 'app/models/katello/system.rb', line 97

def available_releases
  self.content_view.version(self.environment).available_releases
end

#consumed_pool_idsObject



93
94
95
# File 'app/models/katello/system.rb', line 93

def consumed_pool_ids
  self.pools.collect { |t| t['id'] }
end

#consumed_pool_ids=(attributes) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
# File 'app/models/katello/system.rb', line 101

def consumed_pool_ids=(attributes)
  attribs_to_unsub = consumed_pool_ids - attributes
  attribs_to_unsub.each do |id|
    self.unsubscribe id
  end

  attribs_to_sub = attributes - consumed_pool_ids
  attribs_to_sub.each do |id|
    self.subscribe id
  end
end

#hypervisor?Boolean

Returns:

  • (Boolean)


180
181
182
# File 'app/models/katello/system.rb', line 180

def hypervisor?
  self.is_a? Hypervisor
end

#install_package_groups(groups) ⇒ Object



146
147
148
149
# File 'app/models/katello/system.rb', line 146

def install_package_groups(groups)
  pulp_task = self.install_package_group(groups)
  save_task_status(pulp_task, :package_group_install, :groups, groups)
end

#install_packages(packages) ⇒ Object



130
131
132
133
# File 'app/models/katello/system.rb', line 130

def install_packages(packages)
  pulp_task = self.install_package(packages)
  save_task_status(pulp_task, :package_install, :packages, packages)
end

#refresh_tasksObject



197
198
199
200
# File 'app/models/katello/system.rb', line 197

def refresh_tasks
  refresh_running_tasks
  import_candlepin_tasks
end

#registered_byObject



75
76
77
# File 'app/models/katello/system.rb', line 75

def registered_by
  audits.first.try(:username) unless activation_keys.length > 0
end


219
220
221
# File 'app/models/katello/system.rb', line 219

def related_resources
  self.organization
end

#reportable_data(options = {}) ⇒ Object



207
208
209
210
211
212
213
# File 'app/models/katello/system.rb', line 207

def reportable_data(options = {})
  hash = self.as_json(options.slice(:only, :except))
  if options[:methods]
    options[:methods].each { |method| hash[method] = self.send(method) }
  end
  hash.with_indifferent_access
end

#save_bound_repos_by_path!(paths) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'app/models/katello/system.rb', line 113

def save_bound_repos_by_path!(paths)
  repos = []
  paths.each do |path|
    possible_repos = Repository.where(:relative_path => path.gsub('/pulp/repos/', ''))
    if possible_repos.empty?
      Rails.logger.warn("System #{self.name} (#{self.id}) requested binding to unknown repo #{path}")
    else
      repos << possible_repos.first
      Rails.logger.warn("System #{self.name} (#{self.id}) requested binding to path #{path} matching \
                        #{possible_repos.size} repositories.") if possible_repos.size > 1
    end
  end

  self.bound_repositories = repos
  self.save!
end

#system_typeObject



184
185
186
187
188
189
190
191
192
193
194
195
# File 'app/models/katello/system.rb', line 184

def system_type
  if respond_to?(:virtual_guest) && virtual_guest
    _("Virtual Guest")
  else
    case self
    when Hypervisor
      _("Hypervisor")
    else
      _("Host")
    end
  end
end

#tasksObject



202
203
204
205
# File 'app/models/katello/system.rb', line 202

def tasks
  refresh_tasks
  self.task_statuses
end

#to_action_inputObject



223
224
225
# File 'app/models/katello/system.rb', line 223

def to_action_input
  super.merge(uuid => uuid)
end

#uninstall_package_groups(groups) ⇒ Object



151
152
153
154
# File 'app/models/katello/system.rb', line 151

def uninstall_package_groups(groups)
  pulp_task = self.uninstall_package_group(groups)
  save_task_status(pulp_task, :package_group_remove, :groups, groups)
end

#uninstall_packages(packages) ⇒ Object



135
136
137
138
# File 'app/models/katello/system.rb', line 135

def uninstall_packages(packages)
  pulp_task = self.uninstall_package(packages)
  save_task_status(pulp_task, :package_remove, :packages, packages)
end

#update_packages(packages = nil) ⇒ Object



140
141
142
143
144
# File 'app/models/katello/system.rb', line 140

def update_packages(packages = nil)
  # if no packages are provided, a full system update will be performed (e.g ''yum update' equivalent)
  pulp_task = self.update_package(packages)
  save_task_status(pulp_task, :package_update, :packages, packages)
end