hammer_cli_csv 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjA5NThhYWI0N2FhOGQ1OGQzMzhhMjVkOTkzZjhkZmRiNmU4Y2Q4MQ==
4
+ NmZkZjQ0Zjg5NmI0MDZkNzExZTI5ZGM1MWE2NzA2MjAzMGZiMWRlYw==
5
5
  data.tar.gz: !binary |-
6
- MGE4ZDU4M2ZlOGFkNTdkZjI1YmMxZWFmN2YyZWQ4NjAzMTlhODc5Zg==
6
+ MWYyZWY2MWQxNTMwNWM0ODBkN2I3Y2Q0ZmQzNmJmZTRiZTgwZTEwMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OWNhYjM3ODA5Mjc1MWJhM2E4ZGMzZWQyMzNjYzFiMzhjZGUxMjFmMGVlN2Vj
10
- NWZlNjllYzRjYzRmMDY1YmMxNjAxYjk0ZjBkYzAzZWI3MjU2NzkyZDc4NTQw
11
- MTczZjA0N2NiNDdlMWQzMGEwMjRhZTg5NTFhMDk4ZGZjYzY2ZGY=
9
+ ZGQxN2E3Mjg4MzRiN2Y2Y2VhNGY3NDhjZDI3YTkwMjU3MGUxMzQ2ODBkNmE4
10
+ YjFjNTUwMWI4NmIyNmFiMzE0NjdjYjVhZmM3NTE1MWZlNDMxNzYzNjZlYmJh
11
+ MzI0YWJlMDE5MTViOTEyOTIxOGI3NDAzMDQ1ZjI5OGJmODA4M2U=
12
12
  data.tar.gz: !binary |-
13
- YzA0YzQ0NDY4ZGE4NWU3N2I0N2Y5MzYwNGYxNTViOGY2Y2RhNTZjNTViOWM5
14
- YzFiYzU2YjFiODU0OWQyMTllMTg1OGJkN2E2NTY0MmU1NWI0YjU4MzYwMDM1
15
- MmY0YTIwN2Q5MWJjZTM3OWIyYzc2MDg4MTdkNzE1NTMzYTdmNTY=
13
+ NzIzZGE4OTg1NmE1ZDc0NjFiYjgzZjExZmQ1ODdkZmM2YmJlNGRhMmExODQ4
14
+ MWNhYWQ3MGI3NzIzMzQzZmVkYWM1ODAxYWZiODI3ZDAyNThlNWY4MDNhYmJl
15
+ OGZhNjQzMzU2ZDZjY2I2MTRiNWQxOWNiYmRjOTU3ZWNmZjU2Yzk=
@@ -25,6 +25,7 @@ module HammerCLICsv
25
25
  require 'hammer_cli_csv/content_views'
26
26
  require 'hammer_cli_csv/content_view_filters'
27
27
  require 'hammer_cli_csv/domains'
28
+ require 'hammer_cli_csv/export'
28
29
  require 'hammer_cli_csv/host_collections'
29
30
  require 'hammer_cli_csv/hosts'
30
31
  require 'hammer_cli_csv/import'
@@ -45,4 +46,6 @@ module HammerCLICsv
45
46
  require 'hammer_cli_csv/subnets'
46
47
  require 'hammer_cli_csv/subscriptions'
47
48
  require 'hammer_cli_csv/users'
49
+
50
+ require 'hammer_cli_csv/headpin_api'
48
51
  end
@@ -27,34 +27,60 @@ module HammerCLICsv
27
27
  CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
28
28
  csv << [NAME, COUNT, ORGANIZATION, DESCRIPTION, LIMIT, ENVIRONMENT, CONTENTVIEW,
29
29
  SYSTEMGROUPS, SUBSCRIPTIONS]
30
- @api.resource(:organizations)\
31
- .call(:index, {
32
- :per_page => 999999
33
- })['results'].each do |organization|
34
- @api.resource(:activation_keys)\
30
+ if @server_status['release'] == 'Headpin'
31
+ @headpin.get(:organizations).each do |organization|
32
+ @headpin.get("organizations/#{organization['label']}/activation_keys").each do |activationkey|
33
+ puts "Writing activation key '#{activationkey['name']}'" if option_verbose?
34
+ name = namify(activationkey['name'])
35
+ count = 1
36
+ description = activationkey['description']
37
+ limit = activationkey['usage_limit'].to_i < 0 ? 'Unlimited' : activationkey['usage_limit']
38
+ environment = @headpin.environment(activationkey['environment_id'])['name']
39
+ contentview = @headpin.content_view(activationkey['content_view_id'])['name']
40
+ # TODO: https://bugzilla.redhat.com/show_bug.cgi?id=1160888
41
+ # Act keys in SAM-1 do not include system groups
42
+ hostcollections = nil #???? export_column(activationkey, 'systemGroups', 'name')
43
+ subscriptions = CSV.generate do |column|
44
+ column << activationkey['pools'].collect do |subscription|
45
+ amount = subscription['calculatedAttributes']['compliance_type'] == 'Stackable' ? 1 : 'Automatic'
46
+ "#{amount}|#{subscription['productId']}|#{subscription['productName']}"
47
+ end
48
+ end
49
+ subscriptions.delete!("\n")
50
+ csv << [name, count, organization['label'], description, limit, environment, contentview,
51
+ hostcollections, subscriptions]
52
+ end
53
+ end
54
+ else
55
+ @api.resource(:organizations)\
35
56
  .call(:index, {
36
- 'per_page' => 999999,
37
- 'organization_id' => organization['id']
38
- })['results'].each do |activationkey|
39
- puts "Writing activation key '#{activationkey['name']}'" if option_verbose?
40
- name = namify(activationkey['name'])
41
- count = 1
42
- description = activationkey['description']
43
- limit = activationkey['usage_limit'].to_i < 0 ? 'Unlimited' : sytemgroup['usage_limit']
44
- environment = activationkey['environment']['label']
45
- contentview = activationkey['content_view']['name']
46
- hostcollections = export_column(activationkey, 'systemGroups', 'name')
47
- subscriptions = CSV.generate do |column|
48
- column << @api.resource(:subscriptions).call(:index, {
49
- 'activation_key_id' => activationkey['id']
50
- })['results'].collect do |subscription|
51
- amount = subscription['amount'] == 0 ? 'Automatic' : subscription['amount']
52
- "#{amount}|#{subscription['product_name']}"
57
+ :per_page => 999999
58
+ })['results'].each do |organization|
59
+ @api.resource(:activation_keys)\
60
+ .call(:index, {
61
+ 'per_page' => 999999,
62
+ 'organization_id' => organization['id']
63
+ })['results'].each do |activationkey|
64
+ puts "Writing activation key '#{activationkey['name']}'" if option_verbose?
65
+ name = namify(activationkey['name'])
66
+ count = 1
67
+ description = activationkey['description']
68
+ limit = activationkey['usage_limit'].to_i < 0 ? 'Unlimited' : sytemgroup['usage_limit']
69
+ environment = activationkey['environment']['label']
70
+ contentview = activationkey['content_view']['name']
71
+ hostcollections = export_column(activationkey, 'systemGroups', 'name')
72
+ subscriptions = CSV.generate do |column|
73
+ column << @api.resource(:subscriptions).call(:index, {
74
+ 'activation_key_id' => activationkey['id']
75
+ })['results'].collect do |subscription|
76
+ amount = subscription['amount'] == 0 ? 'Automatic' : subscription['amount']
77
+ "#{amount}|#{subscription['product_name']}"
78
+ end
53
79
  end
80
+ subscriptions.delete!("\n")
81
+ csv << [name, count, organization['label'], description, limit, environment, contentview,
82
+ hostcollections, subscriptions]
54
83
  end
55
- subscriptions.delete!("\n")
56
- csv << [name, count, organization['label'], description, limit, environment, contentview,
57
- hostcollections, subscriptions]
58
84
  end
59
85
  end
60
86
  end
@@ -109,10 +135,10 @@ module HammerCLICsv
109
135
  'description' => line[DESCRIPTION],
110
136
  'usage_limit' => usage_limit(line[LIMIT])
111
137
  })
112
- end
113
138
 
114
- update_subscriptions(activationkey, line)
115
- update_groups(activationkey, line)
139
+ update_subscriptions(activationkey, line)
140
+ update_groups(activationkey, line)
141
+ end
116
142
 
117
143
  puts 'done' if option_verbose?
118
144
  end
@@ -15,6 +15,7 @@ require 'json'
15
15
  require 'csv'
16
16
  require 'hammer_cli_csv/csv'
17
17
 
18
+ # rubocop:disable ClassLength
18
19
  module HammerCLICsv
19
20
  class BaseCommand < HammerCLI::Apipie::Command
20
21
  option %w(-v --verbose), :flag, 'be verbose'
@@ -40,17 +41,58 @@ module HammerCLICsv
40
41
  end
41
42
  end
42
43
 
43
- @api = ApipieBindings::API.new({
44
- :uri => option_server || HammerCLI::Settings.get(:csv, :host),
45
- :username => option_username || HammerCLI::Settings.get(:csv, :username),
46
- :password => option_password || HammerCLI::Settings.get(:csv, :password),
47
- :api_version => 2
48
- })
44
+ server = option_server ||
45
+ HammerCLI::Settings.get(:csv, :host) ||
46
+ HammerCLI::Settings.get(:katello, :host) ||
47
+ HammerCLI::Settings.get(:foreman, :host)
48
+ username = option_username ||
49
+ HammerCLI::Settings.get(:csv, :username) ||
50
+ HammerCLI::Settings.get(:katello, :username) ||
51
+ HammerCLI::Settings.get(:foreman, :username)
52
+ password = option_password ||
53
+ HammerCLI::Settings.get(:csv, :password) ||
54
+ HammerCLI::Settings.get(:katello, :password) ||
55
+ HammerCLI::Settings.get(:foreman, :password)
56
+
57
+ @server_status = check_server_status
58
+
59
+ unless @server_status['release'] == 'Headpin'
60
+ @api = ApipieBindings::API.new({
61
+ :uri => server,
62
+ :username => username,
63
+ :password => password,
64
+ :api_version => 2
65
+ })
66
+ else
67
+ @headpin = HeadpinApi.new({
68
+ :server => server,
69
+ :username => username,
70
+ :password => password
71
+ })
72
+ end
49
73
 
50
74
  option_csv_export? ? export : import
51
75
  HammerCLI::EX_OK
52
76
  end
53
77
 
78
+ def check_server_status
79
+ server = option_server || HammerCLI::Settings.get(:csv, :host)
80
+ username = option_username || HammerCLI::Settings.get(:csv, :username)
81
+ password = option_password || HammerCLI::Settings.get(:csv, :password)
82
+ url = "#{server}/api/status"
83
+ uri = URI(url)
84
+ server_status = Net::HTTP.start(uri.host, uri.port,
85
+ :use_ssl => uri.scheme == 'https',
86
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
87
+ request = Net::HTTP::Get.new uri.request_uri
88
+ request.basic_auth(username, password)
89
+ response = http.request(request)
90
+ JSON.parse(response.body)
91
+ end
92
+
93
+ server_status
94
+ end
95
+
54
96
  def namify(name_format, number = 0)
55
97
  if name_format.index('%')
56
98
  name = name_format % number
@@ -241,7 +283,8 @@ module HammerCLICsv
241
283
  'search' => "role=\"#{role}\""
242
284
  })['results']
243
285
  filters.each do |filter|
244
- return filter['id'] if filter['resource_type'] == resource && filter['search'] == search
286
+ resource_type = (filter['resource_type'] || '').split(':')[-1] # To remove "Katello::" when present
287
+ return filter['id'] if resource_type == resource && filter['search'] == search
245
288
  end
246
289
 
247
290
  nil
@@ -0,0 +1,72 @@
1
+ # Copyright 2013-2014 Red Hat, Inc.
2
+ #
3
+ # This software is licensed to you under the GNU General Public
4
+ # License as published by the Free Software Foundation; either version
5
+ # 2 of the License (GPLv2) or (at your option) any later version.
6
+ # There is NO WARRANTY for this software, express or implied,
7
+ # including the implied warranties of MERCHANTABILITY,
8
+ # NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
9
+ # have received a copy of GPLv2 along with this software; if not, see
10
+ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
11
+
12
+
13
+ module HammerCLICsv
14
+ class CsvCommand
15
+ class ExportCommand < HammerCLI::Apipie::Command
16
+ command_name 'export'
17
+ desc 'export into directory'
18
+
19
+ option %w(-v --verbose), :flag, 'be verbose'
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
+ option '--dir', 'DIRECTORY', 'directory to import from'
25
+
26
+ RESOURCES = %w( organizations locations puppet_environments operating_systems
27
+ domains architectures partition_tables lifecycle_environments host_collections
28
+ provisioning_templates
29
+ subscriptions activation_keys hosts content_hosts reports roles users )
30
+ RESOURCES.each do |resource|
31
+ dashed = resource.sub('_', '-')
32
+ option "--#{dashed}", 'FILE', "csv file for #{dashed}"
33
+ end
34
+
35
+ 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
+ })
42
+
43
+ # Swing the hammers
44
+ RESOURCES.each do |resource|
45
+ hammer_resource(resource)
46
+ end
47
+
48
+ HammerCLI::EX_OK
49
+ end
50
+
51
+ def hammer(context = nil)
52
+ context ||= {
53
+ :interactive => false,
54
+ :username => 'admin', # TODO: this needs to come from config/settings
55
+ :password => 'changeme' # TODO: this needs to come from config/settings
56
+ }
57
+
58
+ HammerCLI::MainCommand.new('', context)
59
+ end
60
+
61
+ def hammer_resource(resource)
62
+ return if !self.send("option_#{resource}") && !option_dir
63
+ options_file = self.send("option_#{resource}") || "#{option_dir}/#{resource.sub('_', '-')}.csv"
64
+ args = %W( csv #{resource.sub('_', '-')} --csv-export --csv-file #{options_file} )
65
+ args << '-v' if option_verbose?
66
+ args += %W( --threads #{option_threads} )
67
+ args += %W( --server #{option_server} ) if option_server
68
+ hammer.run(args)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,59 @@
1
+ # Copyright 2014 Red Hat, Inc.
2
+ #
3
+ # This software is licensed to you under the GNU General Public
4
+ # License as published by the Free Software Foundation; either version
5
+ # 2 of the License (GPLv2) or (at your option) any later version.
6
+ # There is NO WARRANTY for this software, express or implied,
7
+ # including the implied warranties of MERCHANTABILITY,
8
+ # NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
9
+ # have received a copy of GPLv2 along with this software; if not, see
10
+ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
11
+
12
+ require 'csv'
13
+
14
+ module HammerCLICsv
15
+ class HeadpinApi
16
+ def initialize(config)
17
+ @server = config[:server]
18
+ @username = config[:username]
19
+ @password = config[:password]
20
+ end
21
+
22
+ def get(name)
23
+ url = "#{@server}/api/#{name}"
24
+ uri = URI(url)
25
+ Net::HTTP.start(uri.host, uri.port,
26
+ :use_ssl => uri.scheme == 'https',
27
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
28
+ request = Net::HTTP::Get.new uri.request_uri
29
+ request.basic_auth(@username, @password)
30
+ response = http.request(request)
31
+ return JSON.parse(response.body)
32
+ end
33
+ end
34
+
35
+ def environment(id)
36
+ @environments ||= {}
37
+ environment = @environments[id]
38
+ if environment.nil?
39
+ environment = get("environments/#{id}")
40
+ raise environment['displayMessage'] if environment['displayMessage']
41
+ @environments[id] = environment
42
+ end
43
+
44
+ return environment
45
+ end
46
+
47
+ def content_view(id)
48
+ @content_views ||= {}
49
+ content_view = @content_views[id]
50
+ if content_view.nil?
51
+ content_view = get("content_views/#{id}")
52
+ raise content_view['displayMessage'] if content_view['displayMessage']
53
+ @content_views[id] = content_view
54
+ end
55
+
56
+ return content_view
57
+ end
58
+ end
59
+ end
@@ -9,13 +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
- require 'hammer_cli'
13
- require 'hammer_cli_csv'
14
- require 'hammer_cli_foreman'
15
- require 'hammer_cli_katello'
16
- require 'json'
17
- require 'csv'
18
- require 'uri'
19
12
 
20
13
  module HammerCLICsv
21
14
  class CsvCommand
@@ -30,9 +23,10 @@ module HammerCLICsv
30
23
  option %w(-p --password), 'PASSWORD', 'Password to access server'
31
24
  option '--dir', 'DIRECTORY', 'directory to import from'
32
25
 
33
- RESOURCES = %w( organizations locations roles users puppet_environments operating_systems
26
+ RESOURCES = %w( organizations locations puppet_environments operating_systems
34
27
  domains architectures partition_tables lifecycle_environments host_collections
35
- subscriptions activation_keys hosts content_hosts reports )
28
+ provisioning_templates
29
+ subscriptions activation_keys hosts content_hosts reports roles users )
36
30
  RESOURCES.each do |resource|
37
31
  dashed = resource.sub('_', '-')
38
32
  option "--#{dashed}", 'FILE', "csv file for #{dashed}"
@@ -39,7 +39,7 @@ module HammerCLICsv
39
39
  CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
40
40
  csv << [NAME, COUNT, PARENT]
41
41
  @api.resource(:locations).call(:index, {:per_page => 999999})['results'].each do |location|
42
- csv << [location['name'], 1]
42
+ csv << [location['name'], 1, '']
43
43
  end
44
44
  end
45
45
  end
@@ -37,30 +37,16 @@ module HammerCLICsv
37
37
  command_name 'organizations'
38
38
  desc 'import or export organizations'
39
39
 
40
- option %w(--sam), :flag, 'export from SAM-1.3 or SAM-1.4'
41
-
42
- ORGANIZATION = 'Organization'
40
+ LABEL = 'Label'
43
41
  DESCRIPTION = 'Description'
44
42
 
45
43
  def export
46
44
  CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
47
- csv << [NAME, COUNT, ORGANIZATION, DESCRIPTION]
48
- if option_sam?
49
- server = option_server || HammerCLI::Settings.get(:csv, :host)
50
- username = option_username || HammerCLI::Settings.get(:csv, :username)
51
- password = option_password || HammerCLI::Settings.get(:csv, :password)
52
- url = "#{server}/api/organizations"
53
- uri = URI(url)
54
- Net::HTTP.start(uri.host, uri.port,
55
- :use_ssl => uri.scheme == 'https',
56
- :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
57
- request = Net::HTTP::Get.new uri.request_uri
58
- request.basic_auth(username, password)
59
- response = http.request(request)
45
+ csv << [NAME, COUNT, LABEL, DESCRIPTION]
60
46
 
61
- JSON.parse(response.body).each do |organization|
62
- csv << [organization['name'], 1, organization['label'], organization['description']]
63
- end
47
+ if @server_status['release'] == 'Headpin'
48
+ @headpin.get(:organizations).each do |organization|
49
+ csv << [organization['name'], 1, organization['label'], organization['description']]
64
50
  end
65
51
  else
66
52
  @api.resource(:organizations).call(:index, {:per_page => 999999})['results'].each do |organization|
@@ -84,7 +70,7 @@ module HammerCLICsv
84
70
  def create_organizations_from_csv(line)
85
71
  line[COUNT].to_i.times do |number|
86
72
  name = namify(line[NAME], number)
87
- label = namify(line[ORGANIZATION], number)
73
+ label = namify(line[LABEL], number)
88
74
  if !@existing.include? name
89
75
  print "Creating organization '#{name}'... " if option_verbose?
90
76
  @api.resource(:organizations).call(:create, {
@@ -18,11 +18,11 @@ module HammerCLICsv
18
18
  ORGANIZATIONS = 'Organizations'
19
19
  LOCATIONS = 'Locations'
20
20
  KIND = 'Kind'
21
- SOURCE = 'Source'
21
+ TEMPLATE = 'Template'
22
22
 
23
23
  def export
24
24
  CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
25
- csv << [NAME, COUNT, ORGANIZATIONS, LOCATIONS, KIND, SOURCE]
25
+ csv << [NAME, COUNT, ORGANIZATIONS, LOCATIONS, KIND, TEMPLATE]
26
26
  @api.resource(:config_templates)\
27
27
  .call(:index, {
28
28
  :per_page => 999999
@@ -66,25 +66,73 @@ module HammerCLICsv
66
66
  name = namify(line[NAME], number)
67
67
  if !@existing.include? name
68
68
  print "Creating provisioning template '#{name}'..." if option_verbose?
69
- id = @api.resource(:config_templates)\
69
+ template_id = @api.resource(:config_templates)\
70
70
  .call(:create, {
71
71
  'name' => name,
72
72
  'snippet' => line[KIND] == 'snippet',
73
73
  'template_kind_id' => line[KIND] == 'snippet' ? nil : foreman_template_kind(:name => line[KIND]),
74
- 'organizations' => organizations,
75
- 'locations' => locations
74
+ 'organization_ids' => organizations,
75
+ 'location_ids' => locations,
76
+ 'template' => line[TEMPLATE]
76
77
  })['id']
77
78
  else
78
79
  print "Updating provisioning template '#{name}'..." if option_verbose?
79
- id = @api.resource(:config_template)\
80
+ template_id = @api.resource(:config_templates)\
80
81
  .call(:update, {
81
82
  'id' => @existing[name],
82
83
  'name' => name,
83
- 'organizations' => organizations,
84
- 'locations' => locations
84
+ 'snippet' => line[KIND] == 'snippet',
85
+ 'template_kind_id' => line[KIND] == 'snippet' ? nil : foreman_template_kind(:name => line[KIND]),
86
+ 'organization_ids' => organizations,
87
+ 'location_ids' => locations,
88
+ 'template' => line[TEMPLATE]
85
89
  })['id']
86
90
  end
87
- @existing[name] = id
91
+ @existing[name] = template_id
92
+
93
+ # Update associated resources
94
+ template_organizations ||= {}
95
+ organizations.each do |organization_id|
96
+ if template_organizations[organization_id].nil?
97
+ template_organizations[organization_id] = @api.resource(:organizations)\
98
+ .call(:show, {
99
+ 'id' => organization_id
100
+ })['config_templates'].collect do |template|
101
+ template['id']
102
+ end
103
+ end
104
+ if !template_organizations[organization_id].include? template_id
105
+ template_organizations[organization_id] += [template_id]
106
+ @api.resource(:organizations)\
107
+ .call(:update, {
108
+ 'id' => organization_id,
109
+ 'organization' => {
110
+ 'config_template_ids' => template_organizations[organization_id]
111
+ }
112
+ })
113
+ end
114
+ end
115
+ template_locations ||= {}
116
+ locations.each do |location_id|
117
+ if template_locations[location_id].nil?
118
+ template_locations[location_id] = @api.resource(:locations)\
119
+ .call(:show, {
120
+ 'id' => location_id
121
+ })['config_templates'].collect do |template|
122
+ template['id']
123
+ end
124
+ end
125
+ if !template_locations[location_id].include? template_id
126
+ template_locations[location_id] += [template_id]
127
+ @api.resource(:locations)\
128
+ .call(:update, {
129
+ 'id' => location_id,
130
+ 'location' => {
131
+ 'config_template_ids' => template_locations[location_id]
132
+ }
133
+ })
134
+ end
135
+ end
88
136
 
89
137
  print "done\n" if option_verbose?
90
138
  end
@@ -59,9 +59,20 @@ module HammerCLICsv
59
59
  end
60
60
 
61
61
  def create_roles_from_csv(line)
62
+
63
+ permissions = collect_column(line[PERMISSIONS]) do |permission|
64
+ foreman_permission(:name => permission)
65
+ end
66
+ organizations = collect_column(line[ORGANIZATIONS]) do |organization|
67
+ foreman_organization(:name => organization)
68
+ end
69
+ locations = collect_column(line[LOCATIONS]) do |location|
70
+ foreman_location(:name => location)
71
+ end
72
+
62
73
  line[COUNT].to_i.times do |number|
63
74
  name = namify(line[NAME], number)
64
- search = namify(line[SEARCH], number) if line[SEARCH]
75
+ search = line[SEARCH] ? namify(line[SEARCH], number) : nil
65
76
 
66
77
  if !@existing_roles[name]
67
78
  print "Creating role '#{name}'..." if option_verbose?
@@ -76,35 +87,29 @@ module HammerCLICsv
76
87
  })
77
88
  end
78
89
 
79
- permissions = collect_column(line[PERMISSIONS]) do |permission|
80
- foreman_permission(:name => permission)
81
- end
82
- organizations = collect_column(line[ORGANIZATIONS]) do |organization|
83
- foreman_organization(:name => organization)
84
- end
85
- locations = collect_column(line[LOCATIONS]) do |location|
86
- foreman_location(:name => location)
87
- end
88
-
89
90
  filter_id = foreman_filter(name, line[RESOURCE], search)
90
91
  if !filter_id
91
- print " creating filter #{line[RESOURCE]}..."
92
- @api.resource(:filters).call(:create, {
93
- 'role_id' => @existing_roles[name],
94
- 'search' => search,
95
- 'organization_ids' => organizations,
96
- 'location_ids' => locations,
97
- 'permission_ids' => permissions
98
- })
92
+ print " creating filter #{line[RESOURCE]}..." if option_verbose?
93
+ @api.resource(:filters)\
94
+ .call(:create, { 'filter' => {
95
+ 'role_id' => @existing_roles[name],
96
+ 'search' => search,
97
+ 'unlimited' => search.empty?,
98
+ 'organization_ids' => organizations,
99
+ 'location_ids' => locations,
100
+ 'permission_ids' => permissions
101
+ }})
99
102
  else
100
103
  print " updating filter #{line[RESOURCE]}..."
101
- @api.resource(:filters).call(:update, {
102
- 'id' => filter_id,
103
- 'search' => search,
104
- 'organization_ids' => organizations,
105
- 'location_ids' => locations,
106
- 'permission_ids' => permissions
107
- })
104
+ @api.resource(:filters)\
105
+ .call(:update, {
106
+ 'id' => filter_id,
107
+ 'search' => search,
108
+ 'unlimited' => search.empty?,
109
+ 'organization_ids' => organizations,
110
+ 'location_ids' => locations,
111
+ 'permission_ids' => permissions
112
+ })
108
113
  end
109
114
 
110
115
  puts 'done' if option_verbose?
@@ -11,6 +11,6 @@
11
11
 
12
12
  module HammerCLICsv
13
13
  def self.version
14
- @version ||= Gem::Version.new('0.0.2')
14
+ @version ||= Gem::Version.new('0.0.4')
15
15
  end
16
16
  end
@@ -1,3 +1,15 @@
1
+ :ui:
2
+ :interactive: true
3
+ :per_page: 20
4
+ :history_file: './log/history'
5
+
6
+ :watch_plain: true # enable/disable color output of logger in Clamp commands
7
+
8
+ :log_dir: './log'
9
+ :log_level: 'error'
10
+ :log_api_calls: false
11
+ :log_size: 5 # MB
12
+
1
13
  :csv:
2
14
  :enable_module: true
3
15
  :host: 'https://localhost'
@@ -12,6 +24,3 @@
12
24
 
13
25
  :katello:
14
26
  :enable_module: true
15
- :host: 'https://localhost'
16
- :username: 'admin'
17
- :password: 'changeme'
@@ -25,16 +25,15 @@ require 'hammer_cli_csv'
25
25
  require 'hammer_cli_foreman'
26
26
  require 'hammer_cli_katello'
27
27
 
28
- def ctx
29
- {
30
- :interactive => false,
31
- :username => 'admin',
32
- :password => 'changeme'
33
- }
28
+ module HammerCLIForeman
29
+ def self.clear_credentials
30
+ @credentials = nil
31
+ end
34
32
  end
35
33
 
34
+
36
35
  def hammer(context=nil)
37
- HammerCLI::MainCommand.new("", context || ctx)
36
+ HammerCLI::MainCommand.new("", context || HammerCLI::Settings.dump)
38
37
  end
39
38
 
40
39
  def capture
@@ -50,12 +49,22 @@ ensure
50
49
  end
51
50
 
52
51
  def set_user(username, password='changeme')
52
+ HammerCLI::Connection.drop_all
53
+ HammerCLIForeman.clear_credentials
53
54
  HammerCLI::Settings.load({
54
- :_params => {
55
- :username => username,
56
- :password => password,
57
- :interactive => false
58
- }})
55
+ :_params => {
56
+ :username => username,
57
+ :password => password
58
+ },
59
+ :foreman => {
60
+ :username => username,
61
+ :password => password
62
+ },
63
+ :csv => {
64
+ :username => username,
65
+ :password => password
66
+ }
67
+ })
59
68
  end
60
69
 
61
70
 
@@ -1,4 +1,4 @@
1
- "Name","Count","Organization","Description"
1
+ "Name","Count","Label","Description"
2
2
  "Mega Corporation","1","megacorp","The number one mega company in the world!"
3
3
  "Mega Subsidiary","1","subcorp","The number one subsidiary of the number one mega company in the world!"
4
4
 
@@ -15,6 +15,7 @@ chelseacalaway,1,ActivationKey,name = chelsea.calaway@megacorp.com,"view_activat
15
15
  cinthiacadieux,1,ActivationKey,name = cinthia.cadieux@megacorp.com,"view_activation_keys",Mega Corporation,
16
16
  coraleeculbert,1,ActivationKey,name = coralee.culbert@megacorp.com,"view_activation_keys",Mega Corporation,
17
17
  damondials,1,ActivationKey,name = damon.dials@megacorp.com,"view_activation_keys",Mega Corporation,
18
+ damondials,1,Organization,"name = ""Mega Corporation""","view_organizations",,
18
19
  danaedrayer,1,ActivationKey,name = danae.drayer@megacorp.com,"view_activation_keys",Mega Corporation,
19
20
  danettedewitt,1,ActivationKey,name = danette.dewitt@megacorp.com,"view_activation_keys",Mega Corporation,
20
21
  danilodilbeck,1,ActivationKey,name = danilo.dilbeck@megacorp.com,"view_activation_keys",Mega Corporation,
@@ -45,7 +46,7 @@ hsiuhenningsen,1,ActivationKey,name = hsiu.henningsen@megacorp.com,"view_activat
45
46
  jacquesjoaquin,1,ActivationKey,name = jacques.joaquin@megacorp.com,"view_activation_keys",Mega Corporation,
46
47
  janayjohnson,1,ActivationKey,name = janay.johnson@megacorp.com,"view_activation_keys",Mega Corporation,
47
48
  jeffersonjock,1,ActivationKey,name = jefferson.jock@megacorp.com,"view_activation_keys",Mega Corporation,
48
- jeneejahns,1,ActivationKey,,"view_activation_keys,create_activation_keys,edit_activation_keys,destroy_activation_keys",Mega Corporation,
49
+ jeneejahns,1,ActivationKey,name = jenee.jahns@megacorp.com,"view_activation_keys,create_activation_keys,edit_activation_keys,destroy_activation_keys",Mega Corporation,
49
50
  jeremyjong,1,ActivationKey,name = jeremy.jong@megacorp.com,"view_activation_keys",Mega Corporation,
50
51
  judithjoachim,1,ActivationKey,name = judith.joachim@megacorp.com,"view_activation_keys",Mega Corporation,
51
52
  juliojerabek,1,ActivationKey,name = julio.jerabek@megacorp.com,"view_activation_keys",Mega Corporation,
@@ -117,43 +118,43 @@ weswallner,1,ActivationKey,name = wes.wallner@megacorp.com,"view_activation_keys
117
118
  winifredwessels,1,ActivationKey,name = winifred.wessels@megacorp.com,"view_activation_keys",Mega Corporation,
118
119
  yunyarberry,1,ActivationKey,name = yun.yarberry@megacorp.com,"view_activation_keys",Mega Corporation,
119
120
  zelmazemke,1,ActivationKey,name = zelma.zemke@megacorp.com,"view_activation_keys",Mega Corporation,
120
- Mega Corporation Admin,1,ActivationKey,"","view_activation_keys,create_activation_keys,edit_activation_keys,destroy_activation_keys",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
121
- Mega Corporation Admin,1,Architecture,"","view_architectures,create_architectures,edit_architectures,destroy_architectures",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
122
- Mega Corporation Admin,1,Audit,"",view_audit_logs,Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
123
- Mega Corporation Admin,1,Bookmark,"","view_bookmarks,create_bookmarks,edit_bookmarks,destroy_bookmarks",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
124
- Mega Corporation Admin,1,CommonParameter,"","view_globals,create_globals,edit_globals,destroy_globals",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
125
- Mega Corporation Admin,1,ComputeProfile,"","view_compute_profiles,create_compute_profiles,edit_compute_profiles,destroy_compute_profiles",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
126
- Mega Corporation Admin,1,ComputeResource,"","console_compute_resources_vms,power_compute_resources_vms,destroy_compute_resources_vms,edit_compute_resources_vms,create_compute_resources_vms,view_compute_resources_vms,destroy_compute_resources,edit_compute_resources,create_compute_resources,view_compute_resources",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
127
- Mega Corporation Admin,1,System,"","view_content_hosts,create_content_hosts,edit_content_hosts,destroy_content_hosts",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
128
- Mega Corporation Admin,1,ContentView,"","view_content_views,create_content_views,edit_content_views,destroy_content_views,publish_content_views",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
129
- Mega Corporation Admin,1,Domain,"","view_domains,create_domains,edit_domains,destroy_domains",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
130
- Mega Corporation Admin,1,Environment,"","view_environments,create_environments,edit_environments,destroy_environments,import_environments",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
131
- Mega Corporation Admin,1,FactValue,"","view_facts,upload_facts",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
132
- Mega Corporation Admin,1,Filter,"","view_filters,create_filters,edit_filters,destroy_filters",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
133
- Mega Corporation Admin,1,GpgKey,"","view_gpg_keys,create_gpg_keys,edit_gpg_keys,destroy_gpg_keys",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
134
- Mega Corporation Admin,1,Hostgroup,"","view_hostgroups,create_hostgroups,edit_hostgroups,destroy_hostgroups",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
135
- Mega Corporation Admin,1,HostClass,"",edit_classes,Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
136
- Mega Corporation Admin,1,Host,"","puppetrun_hosts,ipmi_boot,console_hosts,power_hosts,build_hosts,destroy_hosts,edit_hosts,create_hosts,view_hosts",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
137
- Mega Corporation Admin,1,Image,"","view_images,create_images,edit_images,destroy_images",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
138
- Mega Corporation Admin,1,Location,"","view_locations,create_locations,edit_locations,destroy_locations,assign_locations",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
139
- Mega Corporation Admin,1,KTEnvironment,"","view_lifecycle_environments,create_lifecycle_environments,edit_lifecycle_environments,destroy_lifecycle_environments",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
140
- Mega Corporation Admin,1,LookupKey,"","view_external_variables,create_external_variables,edit_external_variables,destroy_external_variables",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
141
- Mega Corporation Admin,1,Medium,"","view_media,create_media,edit_media,destroy_media",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
142
- Mega Corporation Admin,1,Model,"","view_models,create_models,edit_models,destroy_models",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
143
- Mega Corporation Admin,1,Operatingsystem,"","view_operatingsystems,create_operatingsystems,edit_operatingsystems,destroy_operatingsystems",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
144
- Mega Corporation Admin,1,Organization,"","delete_manifest,import_manifest,unattach_subscriptions,attach_subscriptions,view_subscriptions,assign_organizations,edit_organizations,view_organizations",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
145
- Mega Corporation Admin,1,Parameter,"","create_params,edit_params,destroy_params",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
146
- Mega Corporation Admin,1,Ptable,"","view_ptables,create_ptables,edit_ptables,destroy_ptables",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
147
- Mega Corporation Admin,1,Product,"","view_products,create_products,edit_products,destroy_products,sync_products",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
148
- Mega Corporation Admin,1,ConfigTemplate,"","view_templates,create_templates,edit_templates,destroy_templates,deploy_templates",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
149
- Mega Corporation Admin,1,Puppetclass,"","view_puppetclasses,create_puppetclasses,edit_puppetclasses,destroy_puppetclasses,import_puppetclasses",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
150
- Mega Corporation Admin,1,Realm,"","view_realms,create_realms,edit_realms,destroy_realms",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
151
- Mega Corporation Admin,1,Report,"","view_reports,destroy_reports,upload_reports",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
152
- Mega Corporation Admin,1,Role,"","view_roles,create_roles,edit_roles,destroy_roles",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
153
- Mega Corporation Admin,1,SmartProxy,"","destroy_smart_proxies_puppetca,edit_smart_proxies_puppetca,view_smart_proxies_puppetca,destroy_smart_proxies_autosign,create_smart_proxies_autosign,view_smart_proxies_autosign,destroy_smart_proxies,edit_smart_proxies,create_smart_proxies,view_smart_proxies",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
154
- Mega Corporation Admin,1,Subnet,"","view_subnets,create_subnets,edit_subnets,destroy_subnets,import_subnets",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
155
- Mega Corporation Admin,1,SyncPlan,"","view_sync_plans,create_sync_plans,edit_sync_plans,destroy_sync_plans",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
156
- Mega Corporation Admin,1,Trend,"","view_trends,create_trends,edit_trends,destroy_trends,edit_trends",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
157
- Mega Corporation Admin,1,User,"","view_users,create_users,edit_users,destroy_users",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
158
- Mega Corporation Admin,1,Usergroup,"","view_usergroups,create_usergroups,edit_usergroups,destroy_usergroups",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
159
- Mega Corporation Admin,1,,"","view_tasks,view_statistics,view_plugins,access_settings,access_dashboard",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default_Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
121
+ Mega Corporation Admin,1,ActivationKey,"","view_activation_keys,create_activation_keys,edit_activation_keys,destroy_activation_keys",Mega Corporation,
122
+ Mega Corporation Admin,1,Architecture,"","view_architectures,create_architectures,edit_architectures,destroy_architectures",,
123
+ Mega Corporation Admin,1,Audit,"",view_audit_logs,,
124
+ Mega Corporation Admin,1,Bookmark,"","view_bookmarks,create_bookmarks,edit_bookmarks,destroy_bookmarks",,
125
+ Mega Corporation Admin,1,CommonParameter,"","view_globals,create_globals,edit_globals,destroy_globals",,
126
+ Mega Corporation Admin,1,ComputeProfile,"","view_compute_profiles,create_compute_profiles,edit_compute_profiles,destroy_compute_profiles",,
127
+ Mega Corporation Admin,1,ComputeResource,"","console_compute_resources_vms,power_compute_resources_vms,destroy_compute_resources_vms,edit_compute_resources_vms,create_compute_resources_vms,view_compute_resources_vms,destroy_compute_resources,edit_compute_resources,create_compute_resources,view_compute_resources",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
128
+ Mega Corporation Admin,1,System,"","view_content_hosts,create_content_hosts,edit_content_hosts,destroy_content_hosts",Mega Corporation,
129
+ Mega Corporation Admin,1,ContentView,"","view_content_views,create_content_views,edit_content_views,destroy_content_views,publish_content_views",Mega Corporation,
130
+ Mega Corporation Admin,1,Domain,"","view_domains,create_domains,edit_domains,destroy_domains",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
131
+ Mega Corporation Admin,1,Environment,"","view_environments,create_environments,edit_environments,destroy_environments,import_environments",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
132
+ Mega Corporation Admin,1,FactValue,"","view_facts,upload_facts",,
133
+ Mega Corporation Admin,1,Filter,"","view_filters,create_filters,edit_filters,destroy_filters",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
134
+ Mega Corporation Admin,1,GpgKey,"","view_gpg_keys,create_gpg_keys,edit_gpg_keys,destroy_gpg_keys",Mega Corporation,
135
+ Mega Corporation Admin,1,Hostgroup,"","view_hostgroups,create_hostgroups,edit_hostgroups,destroy_hostgroups",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
136
+ Mega Corporation Admin,1,HostClass,"",edit_classes,,
137
+ Mega Corporation Admin,1,Host,"","puppetrun_hosts,ipmi_boot,console_hosts,power_hosts,build_hosts,destroy_hosts,edit_hosts,create_hosts,view_hosts",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
138
+ Mega Corporation Admin,1,Image,"","view_images,create_images,edit_images,destroy_images",,
139
+ Mega Corporation Admin,1,Location,"","view_locations,create_locations,edit_locations,destroy_locations,assign_locations",,
140
+ Mega Corporation Admin,1,KTEnvironment,"","view_lifecycle_environments,create_lifecycle_environments,edit_lifecycle_environments,destroy_lifecycle_environments",Mega Corporation,
141
+ Mega Corporation Admin,1,LookupKey,"","view_external_variables,create_external_variables,edit_external_variables,destroy_external_variables",,
142
+ Mega Corporation Admin,1,Medium,"","view_media,create_media,edit_media,destroy_media",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
143
+ Mega Corporation Admin,1,Model,"","view_models,create_models,edit_models,destroy_models",,
144
+ Mega Corporation Admin,1,Operatingsystem,"","view_operatingsystems,create_operatingsystems,edit_operatingsystems,destroy_operatingsystems",,
145
+ Mega Corporation Admin,1,Organization,"","delete_manifest,import_manifest,unattach_subscriptions,attach_subscriptions,view_subscriptions,assign_organizations,edit_organizations,view_organizations",,
146
+ Mega Corporation Admin,1,Parameter,"","create_params,edit_params,destroy_params",,
147
+ Mega Corporation Admin,1,Ptable,"","view_ptables,create_ptables,edit_ptables,destroy_ptables",,
148
+ Mega Corporation Admin,1,Product,"","view_products,create_products,edit_products,destroy_products,sync_products",Mega Corporation,
149
+ Mega Corporation Admin,1,ConfigTemplate,"","view_templates,create_templates,edit_templates,destroy_templates,deploy_templates",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
150
+ Mega Corporation Admin,1,Puppetclass,"","view_puppetclasses,create_puppetclasses,edit_puppetclasses,destroy_puppetclasses,import_puppetclasses",,
151
+ Mega Corporation Admin,1,Realm,"","view_realms,create_realms,edit_realms,destroy_realms",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
152
+ Mega Corporation Admin,1,Report,"","view_reports,destroy_reports,upload_reports",,
153
+ Mega Corporation Admin,1,Role,"","view_roles,create_roles,edit_roles,destroy_roles",,
154
+ Mega Corporation Admin,1,SmartProxy,"","destroy_smart_proxies_puppetca,edit_smart_proxies_puppetca,view_smart_proxies_puppetca,destroy_smart_proxies_autosign,create_smart_proxies_autosign,view_smart_proxies_autosign,destroy_smart_proxies,edit_smart_proxies,create_smart_proxies,view_smart_proxies",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
155
+ Mega Corporation Admin,1,Subnet,"","view_subnets,create_subnets,edit_subnets,destroy_subnets,import_subnets",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
156
+ Mega Corporation Admin,1,SyncPlan,"","view_sync_plans,create_sync_plans,edit_sync_plans,destroy_sync_plans",Mega Corporation,
157
+ Mega Corporation Admin,1,Trend,"","view_trends,create_trends,edit_trends,destroy_trends,edit_trends",,
158
+ Mega Corporation Admin,1,User,"","view_users,create_users,edit_users,destroy_users",Mega Corporation,"Asia Pacific,Asia Pacific (Singapore) Region,Asia Pacific (Sydney) Region,Asia Pacific (Tokyo) Region,Default Location,EU (Ireland) Region,South America (Sao Paulo) Region,US East (Northern Virginia) Region,US West (Northern California) Region,US West (Oregon) Region"
159
+ Mega Corporation Admin,1,Usergroup,"","view_usergroups,create_usergroups,edit_usergroups,destroy_usergroups",,
160
+ Mega Corporation Admin,1,,"","view_tasks,view_statistics,view_plugins,access_settings,access_dashboard",,
@@ -1,5 +1,5 @@
1
1
  Name,Count,Organization,Manifest File,Content Set,Arch,Release
2
- MegaCorp,1,Mega Corporation,~/Downloads/megacorp.zip,
2
+ MegaCorp,1,Mega Corporation,test/data/megacorp.zip,
3
3
  Red Hat Enterprise Linux Server,1,Mega Corporation,,Red Hat Enterprise Linux 6 Server (RPMs),x86_64,6Server
4
4
  Red Hat Enterprise Linux Server,1,Mega Corporation,,Red Hat Enterprise Linux 6 Server (RPMs),x86_64,6.1
5
5
  Red Hat Enterprise Linux Server,1,Mega Corporation,,Red Hat Enterprise Linux 6 Server (RPMs),x86_64,6.2
@@ -3,35 +3,51 @@ require File.join(File.dirname(__FILE__), 'csv_test_helper')
3
3
  require 'stringio'
4
4
  require 'tempfile'
5
5
 
6
- describe 'something' do
6
+ describe 'roles tests' do
7
7
 
8
8
  extend CommandTestHelper
9
9
 
10
10
 
11
- before :each do
12
- HammerCLI::Settings.load_from_file 'test/config.yml'
13
- end
11
+ #before :each do
12
+ # HammerCLI::Settings.load_from_file 'test/config'
13
+ #end
14
+
15
+ context 'roles' do
16
+
17
+ it 'basic import' do
18
+ set_user 'admin'
19
+
20
+ rolename = "role#{rand(10000)}"
21
+
22
+ file = Tempfile.new('roles_test')
23
+ file.write("Name,Count,Resource,Search,Permissions,Organizations,Locations\n")
24
+ file.write("#{rolename},1,ActivationKey,name = key_name,view_activation_keys,Mega Corporation,\n")
25
+ file.rewind
14
26
 
15
- context 'activation keys' do
16
27
 
17
- # Expected output of the form:
18
- # ID,Name,Consumed
19
- # 1,damon.dials@megacorp.com,0 of Unlimited
20
- it 'allows show' do
21
- set_user 'damon.dials@megacorp.com'
28
+ stdout,stderr = capture {
29
+ hammer.run(%W{csv roles --verbose --csv-file #{file.path}})
30
+ }
31
+ stderr.must_equal ''
32
+ stdout[0..-2].must_equal "Creating role '#{rolename}'... creating filter ActivationKey...done"
33
+ file.unlink
34
+ end
35
+
36
+ it 'test role functionality' do
37
+ set_user('damon.dials@megacorp.com', 'redhat')
22
38
 
23
39
  stdout,stderr = capture {
24
- hammer.run(%W{activation-key list --organization-id megacorp}).must_equal HammerCLI::EX_OK
40
+ hammer.run(%W{activation-key list --organization-label megacorp}).must_equal HammerCLI::EX_OK
25
41
  }
26
42
  lines = stdout.split("\n")
27
- lines.length.must_equal 2
28
- lines[1].must_match /.*damon.dials@megacorp\.com.*/
43
+ lines.length.must_equal 5
44
+ lines[3].must_match /.*damon.dials@megacorp\.com.*/
29
45
 
30
- id = lines[1].split(',')[0]
46
+ id = lines[3].split(' ')[0]
31
47
  stdout,stderr = capture {
32
48
  hammer.run(%W{activation-key info --id #{id}}).must_equal HammerCLI::EX_OK
33
49
  }
34
- stdout.split("\n")[1].must_match /.*damon.dials@megacorp.com,[0-9]+,Individual account,Library,Default Organization View/
50
+ stdout.split("\n")[0].must_match /.*damon.dials@megacorp.com/
35
51
  end
36
52
 
37
53
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammer_cli_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom McKay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-16 00:00:00.000000000 Z
11
+ date: 2014-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hammer_cli_katello
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.4
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.4
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.17.0
33
+ version: 0.24.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.17.0
40
+ version: 0.24.1
41
41
  description: Hammer-CLI-CSV is a plugin for Hammer to provide bulk actions against
42
42
  a Katello server.
43
43
  email:
@@ -58,6 +58,8 @@ files:
58
58
  - lib/hammer_cli_csv/csv.rb
59
59
  - lib/hammer_cli_csv/domains.rb
60
60
  - lib/hammer_cli_csv/exception_handler.rb
61
+ - lib/hammer_cli_csv/export.rb
62
+ - lib/hammer_cli_csv/headpin_api.rb
61
63
  - lib/hammer_cli_csv/host_collections.rb
62
64
  - lib/hammer_cli_csv/hosts.rb
63
65
  - lib/hammer_cli_csv/import.rb