Class: ForemanRhCloud::BranchInfo

Inherits:
Object
  • Object
show all
Defined in:
app/services/foreman_rh_cloud/branch_info.rb

Instance Method Summary collapse

Instance Method Details

#core_app_nameObject



20
21
22
# File 'app/services/foreman_rh_cloud/branch_info.rb', line 20

def core_app_name
  'Foreman'
end

#core_app_versionObject



24
25
26
# File 'app/services/foreman_rh_cloud/branch_info.rb', line 24

def core_app_version
  Foreman::Version.new
end

#generate(uuid, host, branch_id, request_hostname) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/services/foreman_rh_cloud/branch_info.rb', line 3

def generate(uuid, host, branch_id, request_hostname)
  {
    :remote_leaf => uuid,
    :remote_branch => branch_id,
    :display_name => host.organization.name,
    :hostname => request_hostname,
    :product => {
      :type => core_app_name,
      :major_version => core_app_version.major,
      :minor_version => core_app_version.minor,
    },
    :organization_id => host.organization.id,
    :satellite_instance_id => Foreman.instance_id,
    :labels => host_labels(host),
  }
end

#host_labels(host) ⇒ Object



40
41
42
43
44
# File 'app/services/foreman_rh_cloud/branch_info.rb', line 40

def host_labels(host)
  tags_generator = ForemanInventoryUpload::Generators::Tags.new(host)
  tags_generator.generate.map { |key, value| new_label(key, value, ForemanInventoryUpload::Generators::Slice::SATELLITE_NAMESPACE) } +
    tags_generator.generate_parameters.map { |key, value| new_label(key, value, ForemanInventoryUpload::Generators::Slice::SATELLITE_PARAMS_NAMESPACE) }
end

#labels_from_items(items, label_namespace, label_lamb, label_value_method = :to_s) ⇒ Object



36
37
38
# File 'app/services/foreman_rh_cloud/branch_info.rb', line 36

def labels_from_items(items, label_namespace, label_lamb, label_value_method = :to_s)
  items.map { |item| new_label(label_lamb.call(item), item.public_send(label_value_method), label_namespace) }
end

#new_label(key, value, namespace) ⇒ Object



28
29
30
31
32
33
34
# File 'app/services/foreman_rh_cloud/branch_info.rb', line 28

def new_label(key, value, namespace)
  {
    :namespace => namespace,
    :key => key,
    :value => value,
  }
end