Revision bfc065ce
Added by Thomas McKay over 8 years ago
lib/hammer_cli_csv/products.rb | ||
---|---|---|
44 | 44 |
class ProductsCommand < BaseCommand |
45 | 45 |
|
46 | 46 |
ORGANIZATION = 'Organization' |
47 |
PROVIDER = 'Provider' |
|
48 | 47 |
REPOSITORY = 'Repository' |
49 | 48 |
REPOSITORY_TYPE = 'Repository Type' |
50 | 49 |
REPOSITORY_URL = 'Repository Url' |
... | ... | |
55 | 54 |
|
56 | 55 |
def import |
57 | 56 |
@existing_products = {} |
58 |
@existing_providers = {} |
|
59 | 57 |
@existing_repositories = {} |
60 | 58 |
|
61 | 59 |
thread_import do |line| |
... | ... | |
64 | 62 |
end |
65 | 63 |
|
66 | 64 |
def create_products_from_csv(line) |
67 |
if !@existing_providers[line[ORGANIZATION]] |
|
68 |
# TODO: get the red hat provider explicitly and put into list since it's not returned by index |
|
69 |
@existing_providers[line[ORGANIZATION]] = {} |
|
70 |
@k_provider_api.index({'organization_id' => line[ORGANIZATION], 'page_size' => 999999, 'paged' => true})[0]['results'].each do |provider| |
|
71 |
@existing_providers[line[ORGANIZATION]][provider['name']] = provider['id'] if provider |
|
72 |
end |
|
73 |
|
|
65 |
if !@existing_products[line[ORGANIZATION]] |
|
74 | 66 |
@existing_products[line[ORGANIZATION]] = {} |
75 |
@k_product_api.index({'organization_id' => line[ORGANIZATION], 'page_size' => 999999, 'paged' => true})[0]['results'].each do |product| |
|
67 |
@k_product_api.index({ |
|
68 |
'organization_id' => katello_organization(:name => line[ORGANIZATION]), |
|
69 |
'page_size' => 999999, |
|
70 |
'paged' => true |
|
71 |
})[0]['results'].each do |product| |
|
76 | 72 |
@existing_products[line[ORGANIZATION]][product['name']] = product['id'] if product |
77 | 73 |
|
78 | 74 |
if product |
79 | 75 |
@k_repository_api.index({ |
80 |
'organization_id' => line[ORGANIZATION],
|
|
76 |
'organization_id' => katello_organization(:name => line[ORGANIZATION]),
|
|
81 | 77 |
'product_id' => product['id'], |
82 | 78 |
'enabled' => true, |
83 | 79 |
'library' => true, |
... | ... | |
90 | 86 |
end |
91 | 87 |
end |
92 | 88 |
|
93 |
# Only creating providers, not updating |
|
94 |
if !@existing_providers[line[ORGANIZATION]][line[PROVIDER]] |
|
95 |
print "Creating provider '#{line[PROVIDER]}'..." if option_verbose? |
|
96 |
id = @k_provider_api.create({ |
|
97 |
'name' => line[PROVIDER], |
|
98 |
'organization_id' => line[ORGANIZATION] |
|
99 |
})[0]['id'] |
|
100 |
@existing_providers[line[ORGANIZATION]][line[PROVIDER]] = id |
|
101 |
print "done\n" if option_verbose? |
|
102 |
end |
|
103 |
provider_id = @existing_providers[line[ORGANIZATION]][line[PROVIDER]] |
|
104 |
|
|
105 | 89 |
# Only creating products, not updating |
106 | 90 |
line[COUNT].to_i.times do |number| |
107 | 91 |
name = namify(line[NAME], number) |
... | ... | |
109 | 93 |
if !product_id |
110 | 94 |
print "Creating product '#{name}'..." if option_verbose? |
111 | 95 |
product_id = @k_product_api.create({ |
112 |
'name' => name,
|
|
113 |
'provider_id' => provider_id
|
|
96 |
'organization_id' => katello_organization(:name => line[ORGANIZATION]),
|
|
97 |
'name' => name
|
|
114 | 98 |
})[0]['id'] |
115 | 99 |
@existing_products[line[ORGANIZATION]][name] = product_id |
116 | 100 |
print "done\n" if option_verbose? |
... | ... | |
122 | 106 |
if !@existing_repositories[line[ORGANIZATION] + name][labelize(repository_name)] |
123 | 107 |
print "Creating repository '#{repository_name}' in product '#{name}'..." if option_verbose? |
124 | 108 |
@k_repository_api.create({ |
109 |
'organization_id' => katello_organization(:name => line[ORGANIZATION]), |
|
125 | 110 |
'name' => repository_name, |
126 | 111 |
'label' => labelize(repository_name), |
127 | 112 |
'product_id' => product_id, |
... | ... | |
137 | 122 |
end |
138 | 123 |
end |
139 | 124 |
|
140 |
HammerCLI::MainCommand.subcommand("csv:products", "import/export products and repositories", HammerCLICsv::ProductsCommand) |
|
125 |
HammerCLI::MainCommand.subcommand("csv:products", "import/export products and repositories", |
|
126 |
HammerCLICsv::ProductsCommand) |
|
141 | 127 |
end |
Also available in: Unified diff
roles-test - wip
roles-test - users now get roles, orgs, and locations