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'

Constants inherited from BaseCommand

BaseCommand::COUNT, BaseCommand::NAME

Instance Method Summary collapse

Methods inherited from BaseCommand

#apipie_check_param, #associate_locations, #associate_organizations, #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, #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, #credentials, #resource_config

Instance Method Details

#create_products_from_csv(line) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/hammer_cli_csv/products.rb', line 60

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



17
18
19
20
21
22
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
# File 'lib/hammer_cli_csv/products.rb', line 17

def export(csv)
  csv << [NAME, LABEL, ORGANIZATION, DESCRIPTION, REPOSITORY, REPOSITORY_TYPE,
          CONTENT_SET, RELEASE, REPOSITORY_URL]
  # TODO: DOWNLOAD_POLICY
  @api.resource(:organizations).call(:index, {
      :per_page => 999999
  })['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}"
          content_set = nil
        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']]
      end
    end
  end
end

#importObject



51
52
53
54
55
56
57
58
# File 'lib/hammer_cli_csv/products.rb', line 51

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

  thread_import do |line|
    create_products_from_csv(line)
  end
end