hammer_cli_csv 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,8 @@ module HammerCLICsv
18
18
  command_name 'content-view-filters'
19
19
  desc 'import or export content-view-filters'
20
20
 
21
+ option %w(--organization), 'ORGANIZATION', 'Only process organization matching this name'
22
+
21
23
  CONTENTVIEW = 'Content View'
22
24
  ORGANIZATION = 'Organization'
23
25
  DESCRIPTION = 'Description'
@@ -31,6 +33,8 @@ module HammerCLICsv
31
33
  @api.resource(:organizations).call(:index, {
32
34
  :per_page => 999999
33
35
  })['results'].each do |organization|
36
+ next if option_organization && organization['name'] != option_organization
37
+
34
38
  composite_contentviews = []
35
39
  @api.resource(:content_views).call(:index, {
36
40
  'per_page' => 999999,
@@ -84,6 +88,8 @@ module HammerCLICsv
84
88
  end
85
89
 
86
90
  def create_filters_from_csv(line)
91
+ return if option_organization && line[ORGANIZATION] != option_organization
92
+
87
93
  @existing_filters[line[ORGANIZATION]] ||= {}
88
94
  if !@existing_filters[line[ORGANIZATION]][line[CONTENTVIEW]]
89
95
  @existing_filters[line[ORGANIZATION]][line[CONTENTVIEW]] ||= {}
@@ -9,54 +9,47 @@
9
9
  # have received a copy of GPLv2 along with this software; if not, see
10
10
  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
11
11
 
12
+ require 'hammer_cli_foreman'
13
+ require 'hammer_cli_foreman_tasks'
14
+
12
15
  module HammerCLICsv
13
16
  class CsvCommand
14
17
  class ContentViewsCommand < BaseCommand
18
+ include ::HammerCLIForemanTasks::Helper
19
+
15
20
  command_name 'content-views'
16
21
  desc 'import or export content-views'
17
22
 
23
+ option %w(--organization), 'ORGANIZATION', 'Only process organization matching this name'
24
+
18
25
  LABEL = 'Label'
19
26
  ORGANIZATION = 'Organization'
20
27
  DESCRIPTION = 'Description'
21
28
  COMPOSITE = 'Composite'
22
29
  REPOSITORIES = 'Repositories or Composites'
23
- FILTERS = 'Filters'
30
+ ENVIRONMENTS = "Lifecycle Environments"
24
31
 
25
32
  def export
26
33
  CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
27
- csv << [NAME, COUNT, LABEL, ORGANIZATION, COMPOSITE, REPOSITORIES, FILTERS]
34
+ csv << [NAME, COUNT, LABEL, ORGANIZATION, COMPOSITE, REPOSITORIES, ENVIRONMENTS]
28
35
  @api.resource(:organizations).call(:index, {
29
36
  :per_page => 999999
30
37
  })['results'].each do |organization|
38
+ next if option_organization && organization['name'] != option_organization
39
+
31
40
  composite_contentviews = []
32
41
  @api.resource(:content_views).call(:index, {
33
42
  'per_page' => 999999,
34
43
  'organization_id' => organization['id'],
35
44
  'nondefault' => true
36
45
  })['results'].each do |contentview|
37
-
38
- filters = CSV.generate do |column|
39
- column << @api.resource(:content_view_filters).call(:index, {
40
- 'content_view_id' => contentview['id']
41
- })['results'].collect do |filter|
42
- rules = filter['rules'].collect do |rule|
43
- rule['name']
44
- end
45
- in_or_out = filter['inclusion'] == true ? 'Include' : 'Exclude'
46
- if filter['type'] == 'rpm'
47
- "#{ in_or_out }|#{ filter['type'] }|#{ rules.join(',')}"
48
- elsif filter['type'] == 'erratum'
49
- "#{ in_or_out }|#{ filter['type'] }|#{ rules['types'].join(',')}"
50
- else
51
- "???? #{filter['type']}"
52
- end
53
- end
54
- end
55
- filters.delete!("\n")
56
-
57
46
  name = contentview['name']
58
47
  label = contentview['label']
59
48
  orgname = organization['name']
49
+ environments = CSV.generate do |column|
50
+ column << environment_names(contentview)
51
+ end
52
+ environments.delete!("\n")
60
53
  composite = contentview['composite'] == true ? 'Yes' : 'No'
61
54
  if composite == 'Yes'
62
55
  contentviews = CSV.generate do |column|
@@ -65,10 +58,10 @@ module HammerCLICsv
65
58
  end
66
59
  end
67
60
  contentviews.delete!("\n")
68
- composite_contentviews << [name, 1, label, orgname, composite, contentviews, filters]
61
+ composite_contentviews << [name, 1, label, orgname, composite, contentviews, environments]
69
62
  else
70
63
  repositories = export_column(contentview, 'repositories', 'name')
71
- csv << [name, 1, label, orgname, composite, repositories, filters]
64
+ csv << [name, 1, label, orgname, composite, repositories, environments]
72
65
  end
73
66
  end
74
67
  composite_contentviews.each do |contentview|
@@ -87,6 +80,8 @@ module HammerCLICsv
87
80
  end
88
81
 
89
82
  def create_contentviews_from_csv(line)
83
+ return if option_organization && line[ORGANIZATION] != option_organization
84
+
90
85
  if !@existing_contentviews[line[ORGANIZATION]]
91
86
  @existing_contentviews[line[ORGANIZATION]] ||= {}
92
87
  @api.resource(:content_views).call(:index, {
@@ -103,7 +98,7 @@ module HammerCLICsv
103
98
  if is_composite
104
99
  composite_ids = collect_column(line[REPOSITORIES]) do |composite|
105
100
  # TODO: export version and use it here
106
- katello_contentviewversion(line[ORGANIZATION], composite, 1)
101
+ katello_contentviewversion(line[ORGANIZATION], composite)
107
102
  end
108
103
  else
109
104
  repository_ids = collect_column(line[REPOSITORIES]) do |repository|
@@ -116,7 +111,7 @@ module HammerCLICsv
116
111
 
117
112
  contentview_id = @existing_contentviews[line[ORGANIZATION]][name]
118
113
  if !contentview_id
119
- print "Creating content view '#{name}'..." if option_verbose?
114
+ print _("Creating content view '%{name}'...") % {:name => name} if option_verbose?
120
115
  options = {
121
116
  'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
122
117
  'name' => name,
@@ -133,7 +128,7 @@ module HammerCLICsv
133
128
  @existing_contentviews[line[ORGANIZATION]][name] = contentview_id
134
129
  publish = true
135
130
  else
136
- print "Updating content view '#{name}'..." if option_verbose?
131
+ print _("Updating content view '%{name}'...") % {:name => name} if option_verbose?
137
132
  options = {
138
133
  'id' => contentview_id,
139
134
  'description' => line[DESCRIPTION]
@@ -144,26 +139,52 @@ module HammerCLICsv
144
139
  options['repository_ids'] = repository_ids
145
140
  end
146
141
  contentview = @api.resource(:content_views).call(:update, options)
142
+ contentview_id = contentview['id']
147
143
  publish = contentview['versions'].empty?
148
144
  end
149
145
 
150
146
  # Content views cannot be used in composites unless a publish has occurred
151
- # TODO: this command cannot be called more than once during a run, why?
152
- if publish
153
- args = %W{
154
- --server #{ @server } --username #{ @username } --password #{ @server }
155
- content-view publish --id #{ contentview_id }
156
- --organization-id #{ foreman_organization(:name => line[ORGANIZATION]) }
157
- }
158
- hammer.run(args)
159
- end
147
+ publish_content_view(contentview_id, line) if publish
148
+ promote_content_view(contentview_id, line)
160
149
 
161
- puts 'done' if option_verbose?
150
+ puts _('done') if option_verbose?
162
151
  end
163
152
 
164
153
  rescue RuntimeError => e
165
154
  raise "#{e}\n #{line}"
166
155
  end
156
+
157
+ def environment_names(contentview)
158
+ names = []
159
+ contentview['versions'].each do |version|
160
+ version['environment_ids'].each do |environment_id|
161
+ names << lifecycle_environment(contentview['organization']['name'], :id => environment_id)
162
+ end
163
+ end
164
+ names.uniq
165
+ end
166
+
167
+ def publish_content_view(contentview_id, line)
168
+ task_progress(@api.resource(:content_views).call(:publish, {
169
+ 'id' => contentview_id
170
+ }))
171
+ end
172
+
173
+ def promote_content_view(contentview_id, line)
174
+ contentview = @api.resource(:content_views).call(:show, {'id' => contentview_id})
175
+ existing_names = environment_names(contentview)
176
+
177
+ CSV.parse_line(line[ENVIRONMENTS]).each do |environment_name|
178
+ next if environment_name == 'Library' || existing_names.include?(environment_name)
179
+
180
+ version = contentview['versions'][-1]
181
+ task_progress(@api.resource(:content_view_versions).call(:promote, {
182
+ 'id' => version['id'],
183
+ 'environment_id' => lifecycle_environment(line[ORGANIZATION], :name => environment_name),
184
+ 'force' => true
185
+ }))
186
+ end
187
+ end
167
188
  end
168
189
  end
169
190
  end
@@ -57,7 +57,7 @@ module HammerCLICsv
57
57
  domains architectures partition_tables lifecycle_environments
58
58
  provisioning_templates
59
59
  hosts reports )
60
- skipped_resources += %w( subscriptions content_hosts roles users ) # TODO: not implemented yet
60
+ skipped_resources += %w( subscriptions roles users ) # TODO: not implemented yet
61
61
  else
62
62
  @api = ApipieBindings::API.new({
63
63
  :uri => @server,
@@ -9,20 +9,6 @@
9
9
  # have received a copy of GPLv2 along with this software; if not, see
10
10
  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
11
11
 
12
- #
13
- # -= System Groups CSV =-
14
- #
15
- # Columns
16
- # Name
17
- # - System group name
18
- # - May contain '%d' which will be replaced with current iteration number of Count
19
- # - eg. "group%d" -> "group1"
20
- # Count
21
- # - Number of times to iterate on this line of the CSV file
22
- # Org Label
23
- # Limit
24
- # Description
25
- #
26
12
 
27
13
  require 'hammer_cli'
28
14
  require 'json'
@@ -34,6 +20,8 @@ module HammerCLICsv
34
20
  command_name 'host-collections'
35
21
  desc 'import or export host collections'
36
22
 
23
+ option %w(--organization), 'ORGANIZATION', 'Only process organization matching this name'
24
+
37
25
  ORGANIZATION = 'Organization'
38
26
  LIMIT = 'Limit'
39
27
  DESCRIPTION = 'Description'
@@ -43,6 +31,7 @@ module HammerCLICsv
43
31
  csv << [NAME, COUNT, ORGANIZATION, LIMIT, DESCRIPTION]
44
32
  if @server_status['release'] == 'Headpin'
45
33
  @headpin.get(:organizations).each do |organization|
34
+ next if option_organization && organization['name'] != option_organization
46
35
  @headpin.get("organizations/#{organization['label']}/system_groups").each do |systemgroup|
47
36
  csv << [systemgroup['name'], 1, organization['name'],
48
37
  systemgroup['max_systems'].to_i < 0 ? 'Unlimited' : systemgroup['max_systems'],
@@ -51,11 +40,13 @@ module HammerCLICsv
51
40
  end
52
41
  else
53
42
  @api.resource(:organizations).call(:index, {'per_page' => 999999})['results'].each do |organization|
43
+ next if option_organization && organization['name'] != option_organization
54
44
  @api.resource(:host_collections).call(:index, {
55
45
  'organization_id' => organization['id']
56
46
  })['results'].each do |hostcollection|
57
- csv << [hostcollection['name'], 1, organization['id'],
58
- hostcollection['max_systems'].to_i < 0 ? 'Unlimited' : hostcollection['max_systems'],
47
+ limit = hostcollection['unlimited_content_hosts'] ? 'Unlimited' : hostcollection['max_content_hosts']
48
+ csv << [hostcollection['name'], 1, organization['name'],
49
+ limit,
59
50
  hostcollection['description']]
60
51
  end
61
52
  end
@@ -72,6 +63,8 @@ module HammerCLICsv
72
63
  end
73
64
 
74
65
  def create_hostcollections_from_csv(line)
66
+ return if option_organization && line[ORGANIZATION] != option_organization
67
+
75
68
  if !@existing[line[ORGANIZATION]]
76
69
  @existing[line[ORGANIZATION]] = {}
77
70
  @api.resource(:host_collections).call(:index, {
@@ -84,23 +77,20 @@ module HammerCLICsv
84
77
 
85
78
  line[COUNT].to_i.times do |number|
86
79
  name = namify(line[NAME], number)
80
+ params = {
81
+ 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
82
+ 'name' => name,
83
+ 'unlimited_content_hosts' => (line[LIMIT] == 'Unlimited') ? true : false,
84
+ 'max_content_hosts' => (line[LIMIT] == 'Unlimited') ? nil : line[LIMIT].to_i,
85
+ 'description' => line[DESCRIPTION]
86
+ }
87
87
  if !@existing[line[ORGANIZATION]].include? name
88
- print "Creating system group '#{name}'..." if option_verbose?
89
- @api.resource(:host_collections).call(:create, {
90
- 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
91
- 'name' => name,
92
- 'max_systems' => (line[LIMIT] == 'Unlimited') ? -1 : line[LIMIT],
93
- 'description' => line[DESCRIPTION]
94
- })
88
+ print "Creating host collection '#{name}'..." if option_verbose?
89
+ @api.resource(:host_collections).call(:create, params)
95
90
  else
96
- print "Updating system group '#{name}'..." if option_verbose?
97
- @api.resource(:host_collections).call(:update, {
98
- 'organization_id' => line[ORGANIZATION],
99
- 'id' => @existing[line[ORGANIZATION]][name],
100
- 'name' => name,
101
- 'max_systems' => (line[LIMIT] == 'Unlimited') ? -1 : line[LIMIT],
102
- 'description' => line[DESCRIPTION]
103
- })
91
+ print "Updating host collection '#{name}'..." if option_verbose?
92
+ params['id'] = @existing[line[ORGANIZATION]][name]
93
+ @api.resource(:host_collections).call(:update, params)
104
94
  end
105
95
  print "done\n" if option_verbose?
106
96
  end
@@ -18,27 +18,21 @@ module HammerCLICsv
18
18
 
19
19
  option %w(-v --verbose), :flag, 'be verbose'
20
20
  option %w(--threads), 'THREAD_COUNT', 'Number of threads to hammer with', :default => 1
21
- option %w(--server), 'SERVER', 'Server URL'
22
- option %w(-u --username), 'USERNAME', 'Username to access server'
23
- option %w(-p --password), 'PASSWORD', 'Password to access server'
24
21
  option '--dir', 'DIRECTORY', 'directory to import from'
25
22
 
26
23
  RESOURCES = %w( organizations locations puppet_environments operating_systems
27
24
  domains architectures partition_tables lifecycle_environments host_collections
28
25
  provisioning_templates
29
- subscriptions activation_keys hosts content_hosts reports roles users )
26
+ subscriptions products content_views content_view_filters activation_keys
27
+ hosts content_hosts reports roles users )
30
28
  RESOURCES.each do |resource|
31
29
  dashed = resource.sub('_', '-')
32
30
  option "--#{dashed}", 'FILE', "csv file for #{dashed}"
33
31
  end
34
32
 
35
33
  def execute
36
- @api = ApipieBindings::API.new({
37
- :uri => option_server || HammerCLI::Settings.get(:csv, :host),
38
- :username => option_username || HammerCLI::Settings.get(:csv, :username),
39
- :password => option_password || HammerCLI::Settings.get(:csv, :password),
40
- :api_version => 2
41
- })
34
+ @api = ApipieBindings::API.new({:uri => get_option(:host), :username => get_option(:username),
35
+ :password => get_option(:password), :api_version => 2})
42
36
 
43
37
  # Swing the hammers
44
38
  RESOURCES.each do |resource|
@@ -71,6 +65,15 @@ module HammerCLICsv
71
65
  args += %W( --threads #{option_threads} )
72
66
  hammer.run(args)
73
67
  end
68
+
69
+ private
70
+
71
+ def get_option(name)
72
+ HammerCLI::Settings.settings[:_params][name] ||
73
+ HammerCLI::Settings.get(:csv, name) ||
74
+ HammerCLI::Settings.get(:katello, name) ||
75
+ HammerCLI::Settings.get(:foreman, name)
76
+ end
74
77
  end
75
78
  end
76
79
  end
@@ -31,6 +31,8 @@ module HammerCLICsv
31
31
  command_name 'lifecycle-environments'
32
32
  desc 'import or export lifecycle environments'
33
33
 
34
+ option %w(--organization), 'ORGANIZATION', 'Only process organization matching this name'
35
+
34
36
  ORGANIZATION = 'Organization'
35
37
  PRIORENVIRONMENT = 'Prior Environment'
36
38
  DESCRIPTION = 'Description'
@@ -41,14 +43,16 @@ module HammerCLICsv
41
43
  @api.resource(:organizations).call(:index, {
42
44
  'per_page' => 999999
43
45
  })['results'].each do |organization|
46
+ next if option_organization && organization['name'] != option_organization
47
+
44
48
  @api.resource(:lifecycle_environments).call(:index, {
45
49
  'per_page' => 999999,
46
50
  'organization_id' => organization['id']
47
- })['results'].each do |environment|
51
+ })['results'].sort { |a, b| a['created_at'] <=> b['created_at'] }.each do |environment|
48
52
  if environment['name'] != 'Library'
49
53
  name = environment['name']
50
54
  count = 1
51
- prior = environment['prior']
55
+ prior = environment['prior']['name']
52
56
  description = environment['description']
53
57
  csv << [name, count, organization['name'], prior, description]
54
58
  end
@@ -77,6 +81,8 @@ module HammerCLICsv
77
81
  end
78
82
 
79
83
  def create_environments_from_csv(line)
84
+ return if option_organization && line[ORGANIZATION] != option_organization
85
+
80
86
  line[COUNT].to_i.times do |number|
81
87
  name = namify(line[NAME], number)
82
88
  prior = namify(line[PRIORENVIRONMENT], number)
@@ -87,6 +93,7 @@ module HammerCLICsv
87
93
  'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
88
94
  'name' => name,
89
95
  'prior' => lifecycle_environment(line[ORGANIZATION], :name => prior),
96
+ 'prior_id' => lifecycle_environment(line[ORGANIZATION], :name => prior),
90
97
  'description' => line[DESCRIPTION]
91
98
  })
92
99
  else
@@ -96,7 +103,6 @@ module HammerCLICsv
96
103
  'name' => name,
97
104
  'new_name' => name,
98
105
  'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
99
- 'prior' => prior,
100
106
  'description' => line[DESCRIPTION]
101
107
  })
102
108
  end
@@ -13,7 +13,10 @@ module HammerCLICsv
13
13
  class CsvCommand
14
14
  class ProductsCommand < BaseCommand
15
15
  command_name 'products'
16
- desc 'import or export products'
16
+ desc _('import or export products')
17
+
18
+ option %w(--organization), 'ORGANIZATION', _('Only process organization matching this name')
19
+ option %w(--sync), 'true|false', _('Sync product repositories (default true)')
17
20
 
18
21
  LABEL = 'Label'
19
22
  ORGANIZATION = 'Organization'
@@ -28,18 +31,20 @@ module HammerCLICsv
28
31
  @api.resource(:organizations).call(:index, {
29
32
  :per_page => 999999
30
33
  })['results'].each do |organization|
34
+ next if option_organization && organization['name'] != option_organization
31
35
  @api.resource(:products).call(:index, {
32
36
  'per_page' => 999999,
33
37
  'enabled' => true,
34
38
  'organization_id' => organization['id']
35
39
  })['results'].each do |product|
36
- unless product['provider']['name'] == 'Red Hat'
37
- product['repositories'].each do |repository|
38
- repository_type = repository['product_type'] == 'custom' ? 'Custom' : 'Red Hat'
39
- repository_type += " #{repository['content_type'].capitalize}"
40
- csv << [product['name'], 1, product['label'], organization['name'],
41
- repository['name'], repository_type, repository['url']]
42
- end
40
+ @api.resource(:repositories).call(:index, {
41
+ 'product_id' => product['id'],
42
+ 'organization_id' => organization['id']
43
+ })['results'].each do |repository|
44
+ repository_type = repository['product_type'] == 'custom' ? 'Custom' : 'Red Hat'
45
+ repository_type += " #{repository['content_type'].capitalize}"
46
+ csv << [product['name'], 1, product['label'], organization['name'],
47
+ repository['name'], repository_type, repository['url']]
43
48
  end
44
49
  end
45
50
  end
@@ -55,7 +60,11 @@ module HammerCLICsv
55
60
  end
56
61
  end
57
62
 
63
+ # FIXME: TODO remove this rubocop
64
+ # rubocop:disable CyclomaticComplexity
58
65
  def create_products_from_csv(line)
66
+ return if option_organization && line[ORGANIZATION] != option_organization
67
+
59
68
  if !@existing_products[line[ORGANIZATION]]
60
69
  @existing_products[line[ORGANIZATION]] = {}
61
70
  @api.resource(:products).call(:index, {
@@ -82,9 +91,10 @@ module HammerCLICsv
82
91
  name = namify(line[NAME], number)
83
92
  product_id = @existing_products[line[ORGANIZATION]][name]
84
93
  if product_id.nil?
85
- print "Creating product '#{name}'..." if option_verbose?
94
+ print _("Creating product '%{name}'...") % {:name => name} if option_verbose?
86
95
  if line[REPOSITORY_TYPE] =~ /Red Hat/
87
- raise "Red Hat product '#{name}' does not exist in '#{line[ORGANIZATION]}'"
96
+ raise _("Red Hat product '%{name}' does not exist in '%{organization}'") %
97
+ {:name => name, :organization => line[ORGANIZATION]}
88
98
  end
89
99
 
90
100
  product_id = @api.resource(:products).call(:create, {
@@ -94,10 +104,9 @@ module HammerCLICsv
94
104
  @existing_products[line[ORGANIZATION]][name] = product_id
95
105
  else
96
106
  # Nothing to update for products
97
- print "Updating product '#{name}'..." if option_verbose?
107
+ print _("Updating product '%{name}'...") % {:name => name} if option_verbose?
98
108
  end
99
109
  @existing_repositories[line[ORGANIZATION] + name] = {}
100
- print "done\n" if option_verbose?
101
110
 
102
111
  repository_name = namify(line[REPOSITORY], number)
103
112
 
@@ -116,7 +125,10 @@ module HammerCLICsv
116
125
  if !repository
117
126
  raise "Red Hat product '#{name}' does not have repository '#{repository_name}'" if line[REPOSITORY_TYPE] =~ /Red Hat/
118
127
 
119
- print "Creating repository '#{repository_name}' in product '#{name}'..." if option_verbose?
128
+ if option_verbose?
129
+ print _("Creating repository '%{repository_name}' in product '%{name}'...") %
130
+ {:repository_name => repository_name, :name => name}
131
+ end
120
132
  repository = @api.resource(:repositories).call(:create, {
121
133
  'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
122
134
  'name' => repository_name,
@@ -126,16 +138,10 @@ module HammerCLICsv
126
138
  'content_type' => content_type(line[REPOSITORY_TYPE])
127
139
  })
128
140
  @existing_repositories[line[ORGANIZATION] + name][line[LABEL]] = repository
129
- puts 'done' if option_verbose?
130
141
  end
131
142
 
132
- print "Sync'ing repository '#{repository_name}' in product '#{name}'..." if option_verbose?
133
- if repository['sync_state'] == 'finished'
134
- puts 'already done' if option_verbose?
135
- else
136
- sync_repository(line, repository)
137
- print "done\n" if option_verbose?
138
- end
143
+ sync_repository(line, repository)
144
+ puts _('done') if option_verbose?
139
145
  end
140
146
 
141
147
  rescue RuntimeError => e
@@ -156,8 +162,23 @@ module HammerCLICsv
156
162
  end
157
163
 
158
164
  def sync_repository(line, repository)
159
- # TODO: --server needs to come from config/settings
160
- args = %W{ repository synchronize
165
+ if option_sync =~ (/A(true|1|yes)$/i) || HammerCLI::Settings.get(:csv, :products_sync) ||
166
+ (option_sync.nil? && HammerCLI::Settings.get(:csv, :products_sync).nil?)
167
+ if option_verbose?
168
+ print _("syncing repository '%{repository_name}' in product '%{name}'...") %
169
+ {:repository_name => repository_name, :name => name}
170
+ end
171
+ if repository['sync_state'] == 'finished'
172
+ print _("previously synced, skipping...") if option_verbose?
173
+ else
174
+ exec_sync_repository(line, repository)
175
+ end
176
+ end
177
+ end
178
+
179
+ def exec_sync_repository(line, repository)
180
+ args = %W{ --server #{ @server } --username #{ @username } --password #{ @password }
181
+ repository synchronize
161
182
  --id #{ repository['id'] }
162
183
  --organization-id #{ foreman_organization(:name => line[ORGANIZATION]) } }
163
184
  hammer.run(args)