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'
RELEASE =
'Release'
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



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

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



23
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
# File 'lib/hammer_cli_csv/products.rb', line 23

def export(csv)
  csv << [NAME, LABEL, ORGANIZATION, DESCRIPTION, REPOSITORY, REPOSITORY_TYPE,
          CONTENT_SET, RELEASE, 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
        release = repository['minor'] #=~ /Server/ ? repository['minor'] : "#{repository['major']}.#{repository['minor']}"
        csv << [product['name'], product['label'], organization['name'],
                product['description'], repository['name'], repository_type,
                content_set, release, 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



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

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

  thread_import do |line|
    create_products_from_csv(line)
  end
end