Class: HammerCLICsv::CsvCommand::ProductsCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/hammer_cli_csv/products.rb

Constant Summary collapse

LABEL =
'Label'
ORGANIZATION =
'Organization'
REPOSITORY =
'Repository'
REPOSITORY_TYPE =
'Repository Type'
CONTENT_SET =
'Content Set'
RELEASEVER =
'$releasever'
BASEARCH =
'$basearch'
REPOSITORY_URL =
'Repository Url'
DESCRIPTION =
'Description'
VERIFY_SSL =
'Verify SSL'
UPSTREAM_USERNAME =
'Username'
UPSTREAM_PASSWORD =
'Password'
DOWNLOAD_POLICY =
'Download Policy'
MIRROR_ON_SYNC =
'Mirror on Sync'
UNPROTECTED =
'Publish via HTTP'

Constants inherited from BaseCommand

BaseCommand::COUNT, BaseCommand::NAME

Instance Method Summary collapse

Methods inherited from BaseCommand

#apipie_check_param, #associate_locations, #associate_organizations, #authenticate_request, #build_os_name, #check_server_status, #collect_column, #count, #execute, #export_column, #foreman_architecture, #foreman_container, #foreman_domain, #foreman_environment, #foreman_filter, #foreman_host, #foreman_hostgroup, #foreman_location, #foreman_medium, #foreman_operatingsystem, #foreman_organization, #foreman_partitiontable, #foreman_permission, #foreman_provisioning_template, #foreman_role, #foreman_smart_proxy, #foreman_template_kind, #hammer, #hammer_context, #help, help_columns, #katello_contentview, #katello_contentviewversion, #katello_hostcollection, #katello_product, #katello_repository, #labelize, #lifecycle_environment, #namify, #pluralize, #split_os_name, #supported?, supported?, #thread_import

Methods included from Utils::Config

#api_connection

Instance Method Details

#create_products_from_csv(line) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/hammer_cli_csv/products.rb', line 77

def create_products_from_csv(line)
  return if option_organization && line[ORGANIZATION] != option_organization

  count(line[COUNT]).times do |number|
    product = create_or_update_product(line, number)
    create_or_update_repository(line, number, product)
    puts _('done') if option_verbose?
  end

end

#export(csv) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/hammer_cli_csv/products.rb', line 24

def export(csv)
  csv << [NAME, LABEL, ORGANIZATION, DESCRIPTION, REPOSITORY, REPOSITORY_TYPE,
          CONTENT_SET, BASEARCH, RELEASEVER, REPOSITORY_URL, VERIFY_SSL, UNPROTECTED, MIRROR_ON_SYNC, DOWNLOAD_POLICY,
          UPSTREAM_USERNAME, UPSTREAM_PASSWORD]
  @api.resource(:organizations).call(:index, {
      :per_page => 999999,
      :search => option_search
  })['results'].each do |organization|
    next if option_organization && organization['name'] != option_organization
    @api.resource(:products).call(:index, {
        'per_page' => 999999,
        'enabled' => true,
        'organization_id' => organization['id']
    })['results'].each do |product|
      @api.resource(:repositories).call(:index, {
          'product_id' => product['id'],
          'organization_id' => organization['id']
      })['results'].each do |repository|
        repository = @api.resource(:repositories).call(:show, {:id => repository['id']})
        if repository['product_type'] == 'custom'
          repository_type = "Custom #{repository['content_type'].capitalize}"
          if repository['content_type'] == 'docker'
            content_set = repository['docker_upstream_name']
          else
            content_set = nil
          end
        else
          repository_type = "Red Hat #{repository['content_type'].capitalize}"
          content_set = get_content_set(organization, product, repository)
        end
        releasever = repository['minor']
        basearch = nil
        csv << [product['name'], product['label'], organization['name'],
                product['description'], repository['name'], repository_type,
                content_set, basearch, releasever, repository['url'],
                repository['verify_ssl_on_sync'] ? 'Yes' : 'No',
                repository['unprotected'] ? 'Yes' : 'No',
                repository['mirror_on_sync'] ? 'Yes' : 'No', repository['download_policy'],
                repository['upstream_username'],nil]
      end
    end
  end
end

#importObject



68
69
70
71
72
73
74
75
# File 'lib/hammer_cli_csv/products.rb', line 68

def import
  @existing_products = {}
  @existing_repositories = {}

  thread_import do |line|
    create_products_from_csv(line)
  end
end