Revision 5146ac68
Added by Thomas McKay almost 7 years ago
lib/hammer_cli_csv/products.rb | ||
---|---|---|
14 | 14 |
|
15 | 15 |
def export |
16 | 16 |
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv| |
17 |
csv << [NAME, LABEL, ORGANIZATION, REPOSITORY, REPOSITORY_TYPE, REPOSITORY_URL] |
|
17 |
csv << [NAME, LABEL, ORGANIZATION, DESCRIPTION, REPOSITORY, REPOSITORY_TYPE, |
|
18 |
REPOSITORY_URL] |
|
18 | 19 |
@api.resource(:organizations).call(:index, { |
19 | 20 |
:per_page => 999999 |
20 | 21 |
})['results'].each do |organization| |
... | ... | |
32 | 33 |
repository_type = repository['product_type'] == 'custom' ? 'Custom' : 'Red Hat' |
33 | 34 |
repository_type += " #{repository['content_type'].capitalize}" |
34 | 35 |
csv << [product['name'], product['label'], organization['name'], |
35 |
repository['name'], repository_type, repository['url']] |
|
36 |
product['description'], repository['name'], repository_type, |
|
37 |
repository['url']] |
|
36 | 38 |
end |
37 | 39 |
end |
38 | 40 |
end |
... | ... | |
77 | 79 |
|
78 | 80 |
count(line[COUNT]).times do |number| |
79 | 81 |
name = namify(line[NAME], number) |
82 |
params = { |
|
83 |
:name => name, |
|
84 |
'organization_id' => foreman_organization(:name => line[ORGANIZATION]) |
|
85 |
} |
|
86 |
params[:description] = line[DESCRIPTION] if !line[DESCRIPTION].nil? && |
|
87 |
!line[DESCRIPTION].empty? |
|
80 | 88 |
product_id = @existing_products[line[ORGANIZATION]][name] |
81 | 89 |
if product_id.nil? |
82 | 90 |
print _("Creating product '%{name}'...") % {:name => name} if option_verbose? |
... | ... | |
85 | 93 |
{:name => name, :organization => line[ORGANIZATION]} |
86 | 94 |
end |
87 | 95 |
|
88 |
product_id = @api.resource(:products).call(:create, { |
|
89 |
'organization_id' => foreman_organization(:name => line[ORGANIZATION]), |
|
90 |
'name' => name |
|
91 |
})['id'] |
|
96 |
product_id = @api.resource(:products).call(:create, params)['id'] |
|
92 | 97 |
@existing_products[line[ORGANIZATION]][name] = product_id |
93 | 98 |
else |
94 |
# Nothing to update for products |
|
95 | 99 |
print _("Updating product '%{name}'...") % {:name => name} if option_verbose? |
100 |
params[:id] = product_id |
|
101 |
@api.resource(:products).call(:update, params) |
|
96 | 102 |
end |
97 | 103 |
@existing_repositories[line[ORGANIZATION] + name] = {} |
98 | 104 |
|
Also available in: Unified diff
myriad changes in attempt to get import working against master/develop