hammer_cli_csv 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/config/cli_config.yml +2 -0
- data/lib/hammer_cli_csv.rb +4 -11
- data/lib/hammer_cli_csv/activation_keys.rb +7 -21
- data/lib/hammer_cli_csv/architectures.rb +6 -37
- data/lib/hammer_cli_csv/base.rb +177 -21
- data/lib/hammer_cli_csv/compute_profiles.rb +4 -21
- data/lib/hammer_cli_csv/compute_resources.rb +4 -16
- data/lib/hammer_cli_csv/containers.rb +65 -0
- data/lib/hammer_cli_csv/content_hosts.rb +22 -26
- data/lib/hammer_cli_csv/content_view_filters.rb +90 -60
- data/lib/hammer_cli_csv/content_views.rb +4 -17
- data/lib/hammer_cli_csv/csv.rb +0 -12
- data/lib/hammer_cli_csv/domains.rb +74 -38
- data/lib/hammer_cli_csv/exception_handler.rb +0 -11
- data/lib/hammer_cli_csv/export.rb +14 -20
- data/lib/hammer_cli_csv/headpin_api.rb +0 -11
- data/lib/hammer_cli_csv/host_collections.rb +5 -23
- data/lib/hammer_cli_csv/host_groups.rb +115 -0
- data/lib/hammer_cli_csv/hosts.rb +32 -56
- data/lib/hammer_cli_csv/import.rb +46 -24
- data/lib/hammer_cli_csv/installation_medias.rb +4 -15
- data/lib/hammer_cli_csv/job_templates.rb +142 -0
- data/lib/hammer_cli_csv/lifecycle_environments.rb +5 -38
- data/lib/hammer_cli_csv/locations.rb +4 -33
- data/lib/hammer_cli_csv/operating_systems.rb +17 -33
- data/lib/hammer_cli_csv/organizations.rb +13 -41
- data/lib/hammer_cli_csv/partition_tables.rb +66 -54
- data/lib/hammer_cli_csv/products.rb +12 -24
- data/lib/hammer_cli_csv/provisioning_templates.rb +4 -18
- data/lib/hammer_cli_csv/puppet_environments.rb +36 -59
- data/lib/hammer_cli_csv/puppet_facts.rb +36 -58
- data/lib/hammer_cli_csv/puppet_reports.rb +4 -38
- data/lib/hammer_cli_csv/reports.rb +4 -15
- data/lib/hammer_cli_csv/roles.rb +4 -15
- data/lib/hammer_cli_csv/settings.rb +49 -0
- data/lib/hammer_cli_csv/smart_proxies.rb +9 -24
- data/lib/hammer_cli_csv/splice.rb +0 -12
- data/lib/hammer_cli_csv/subnets.rb +10 -21
- data/lib/hammer_cli_csv/subscriptions.rb +21 -24
- data/lib/hammer_cli_csv/sync_plans.rb +4 -19
- data/lib/hammer_cli_csv/users.rb +4 -15
- data/lib/hammer_cli_csv/version.rb +1 -12
- data/test/content_hosts_test.rb +1 -1
- data/test/content_views_test.rb +52 -0
- data/test/data/content-hosts.csv +1 -1
- data/test/data/content-view-filters.csv +1 -1
- data/test/data/content-views.csv +5 -5
- data/test/data/hosts.csv +2 -2
- data/test/data/operating-systems.csv +16 -16
- data/test/data/products.csv +1 -1
- data/test/data/settings.csv +5 -0
- data/test/import_test.rb +79 -0
- metadata +14 -18
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTEwYmI3Y2E5OTYxMGNhYzYwYzg2YjI2YzYyOGQ4MGJkYjkxNWNjNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzM5ODc4MzE5YmE1NThkMjgyYWY2N2YwMDhjY2ZhN2YyMjE5MWRhZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDQyZTliM2I3N2JkYmJmYjc4ZjExYjE4MTQ2M2JkODU1NGVkZGMzODQwMTBk
|
10
|
+
Y2Y3MmJlYzRmYzY2NGVmNWZjMGNiYmJhNTViZmFhY2M0ODA2ZTRlN2FmMmMy
|
11
|
+
NjdlZjIzYjJhMmVhNGIyMTNiNTA3ODVkYmYzZTBiMjI0MjhhZDY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmE3N2Y1MDNmZmM4ZGE0Y2FkYTgwMDhiZWY0ZjNiYWNlZDUwZmMyZDBkNjc1
|
14
|
+
YTMyZTUzMzIxZjRlMzkzYmFlZjAzYWM0MDViYzhmNDI0MzNiYzRhMWU2MGY4
|
15
|
+
MGE2NGU5YmMyOGU3NGY3MDZlNzM1ZmM4NDViMDYxOGZjM2Y3MTg=
|
data/config/cli_config.yml
CHANGED
data/lib/hammer_cli_csv.rb
CHANGED
@@ -1,14 +1,3 @@
|
|
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
1
|
require 'hammer_cli'
|
13
2
|
require 'hammer_cli/exit_codes'
|
14
3
|
|
@@ -24,6 +13,7 @@ module HammerCLICsv
|
|
24
13
|
require 'hammer_cli_csv/architectures'
|
25
14
|
require 'hammer_cli_csv/compute_profiles'
|
26
15
|
require 'hammer_cli_csv/compute_resources'
|
16
|
+
require 'hammer_cli_csv/containers'
|
27
17
|
require 'hammer_cli_csv/content_hosts'
|
28
18
|
require 'hammer_cli_csv/content_views'
|
29
19
|
require 'hammer_cli_csv/content_view_filters'
|
@@ -31,8 +21,10 @@ module HammerCLICsv
|
|
31
21
|
require 'hammer_cli_csv/export'
|
32
22
|
require 'hammer_cli_csv/host_collections'
|
33
23
|
require 'hammer_cli_csv/hosts'
|
24
|
+
require 'hammer_cli_csv/host_groups'
|
34
25
|
require 'hammer_cli_csv/import'
|
35
26
|
require 'hammer_cli_csv/installation_medias'
|
27
|
+
require 'hammer_cli_csv/job_templates'
|
36
28
|
require 'hammer_cli_csv/lifecycle_environments'
|
37
29
|
require 'hammer_cli_csv/locations'
|
38
30
|
require 'hammer_cli_csv/operating_systems'
|
@@ -45,6 +37,7 @@ module HammerCLICsv
|
|
45
37
|
require 'hammer_cli_csv/puppet_reports'
|
46
38
|
require 'hammer_cli_csv/reports'
|
47
39
|
require 'hammer_cli_csv/roles'
|
40
|
+
require 'hammer_cli_csv/settings'
|
48
41
|
require 'hammer_cli_csv/smart_proxies'
|
49
42
|
require 'hammer_cli_csv/splice'
|
50
43
|
require 'hammer_cli_csv/subnets'
|
@@ -1,22 +1,9 @@
|
|
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
1
|
module HammerCLICsv
|
13
2
|
class CsvCommand
|
14
3
|
class ActivationKeysCommand < BaseCommand
|
15
4
|
command_name 'activation-keys'
|
16
5
|
desc _('import or export activation keys')
|
17
6
|
|
18
|
-
option %w(--organization), 'ORGANIZATION', _('Only process organization matching this name')
|
19
|
-
|
20
7
|
ORGANIZATION = 'Organization'
|
21
8
|
DESCRIPTION = 'Description'
|
22
9
|
LIMIT = 'Limit'
|
@@ -26,8 +13,8 @@ module HammerCLICsv
|
|
26
13
|
SUBSCRIPTIONS = 'Subscriptions'
|
27
14
|
|
28
15
|
def export
|
29
|
-
CSV.open(
|
30
|
-
csv << [NAME,
|
16
|
+
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
|
17
|
+
csv << [NAME, ORGANIZATION, DESCRIPTION, LIMIT, ENVIRONMENT, CONTENTVIEW,
|
31
18
|
HOSTCOLLECTIONS, SUBSCRIPTIONS]
|
32
19
|
if @server_status['release'] == 'Headpin'
|
33
20
|
@headpin.get(:organizations).each do |organization|
|
@@ -35,7 +22,6 @@ module HammerCLICsv
|
|
35
22
|
|
36
23
|
@headpin.get("organizations/#{organization['label']}/activation_keys").each do |activationkey|
|
37
24
|
name = namify(activationkey['name'])
|
38
|
-
count = 1
|
39
25
|
description = activationkey['description']
|
40
26
|
limit = activationkey['usage_limit'].to_i < 0 ? 'Unlimited' : activationkey['usage_limit']
|
41
27
|
environment = @headpin.environment(activationkey['environment_id'])['name']
|
@@ -50,7 +36,7 @@ module HammerCLICsv
|
|
50
36
|
end
|
51
37
|
end
|
52
38
|
subscriptions.delete!("\n")
|
53
|
-
csv << [name,
|
39
|
+
csv << [name, organization['label'], description, limit, environment, contentview,
|
54
40
|
hostcollections, subscriptions]
|
55
41
|
end
|
56
42
|
end
|
@@ -111,7 +97,7 @@ module HammerCLICsv
|
|
111
97
|
end
|
112
98
|
end
|
113
99
|
|
114
|
-
line[COUNT].
|
100
|
+
count(line[COUNT]).times do |number|
|
115
101
|
name = namify(line[NAME], number)
|
116
102
|
|
117
103
|
params = {
|
@@ -146,9 +132,9 @@ module HammerCLICsv
|
|
146
132
|
if line[HOSTCOLLECTIONS] && line[HOSTCOLLECTIONS] != ''
|
147
133
|
# TODO: note that existing system groups are not removed
|
148
134
|
CSV.parse_line(line[HOSTCOLLECTIONS], {:skip_blanks => true}).each do |name|
|
149
|
-
@api.resource(:
|
150
|
-
'id' =>
|
151
|
-
'
|
135
|
+
@api.resource(:activation_keys).call(:add_host_collections, {
|
136
|
+
'id' => activationkey['id'],
|
137
|
+
'host_collection_ids' => [katello_hostcollection(line[ORGANIZATION], :name => name)]
|
152
138
|
})
|
153
139
|
end
|
154
140
|
end
|
@@ -1,30 +1,3 @@
|
|
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
|
-
# -= Architectures CSV =-
|
14
|
-
#
|
15
|
-
# Columns
|
16
|
-
# Name
|
17
|
-
# - Architecture name
|
18
|
-
# - May contain '%d' which will be replaced with current iteration number of Count
|
19
|
-
# - eg. "os%d" -> "os1"
|
20
|
-
# Count
|
21
|
-
# - Number of times to iterate on this line of the CSV file
|
22
|
-
#
|
23
|
-
|
24
|
-
require 'hammer_cli'
|
25
|
-
require 'json'
|
26
|
-
require 'csv'
|
27
|
-
|
28
1
|
module HammerCLICsv
|
29
2
|
class CsvCommand
|
30
3
|
class ArchitecturesCommand < BaseCommand
|
@@ -34,17 +7,13 @@ module HammerCLICsv
|
|
34
7
|
OPERATINGSYSTEMS = 'Operating Systems'
|
35
8
|
|
36
9
|
def export
|
37
|
-
CSV.open(
|
38
|
-
csv << [NAME,
|
10
|
+
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
|
11
|
+
csv << [NAME, OPERATINGSYSTEMS]
|
39
12
|
@api.resource(:architectures).call(:index, {:per_page => 999999})['results'].each do |architecture|
|
13
|
+
architecture = @api.resource(:architectures).call(:show, {:id => architecture['id']})
|
40
14
|
name = architecture['name']
|
41
|
-
|
42
|
-
|
43
|
-
#operatingsystems = architecture['operatingsystem_ids'].collect do |operatingsystem_id|
|
44
|
-
# foreman_operatingsystem(:id => operatingsystem_id)
|
45
|
-
#end.join(',')
|
46
|
-
operatingsystems = ''
|
47
|
-
csv << [name, count, operatingsystems]
|
15
|
+
operatingsystems = export_column(architecture, 'operatingsystems', 'title')
|
16
|
+
csv << [name, operatingsystems]
|
48
17
|
end
|
49
18
|
end
|
50
19
|
end
|
@@ -61,7 +30,7 @@ module HammerCLICsv
|
|
61
30
|
end
|
62
31
|
|
63
32
|
def create_architectures_from_csv(line)
|
64
|
-
line[COUNT].
|
33
|
+
count(line[COUNT]).times do |number|
|
65
34
|
name = namify(line[NAME], number)
|
66
35
|
architecture_id = @existing[name]
|
67
36
|
operatingsystem_ids = CSV.parse_line(line[OPERATINGSYSTEMS]).collect do |operatingsystem_name|
|
data/lib/hammer_cli_csv/base.rb
CHANGED
@@ -1,17 +1,7 @@
|
|
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
1
|
require 'apipie-bindings'
|
13
2
|
require 'hammer_cli'
|
14
3
|
require 'json'
|
4
|
+
require 'open-uri'
|
15
5
|
require 'csv'
|
16
6
|
require 'hammer_cli_csv/csv'
|
17
7
|
|
@@ -19,24 +9,37 @@ require 'hammer_cli_csv/csv'
|
|
19
9
|
module HammerCLICsv
|
20
10
|
class BaseCommand < HammerCLI::Apipie::Command
|
21
11
|
option %w(-v --verbose), :flag, 'be verbose'
|
22
|
-
option %w(--threads), 'THREAD_COUNT', 'Number of threads to hammer with',
|
23
|
-
|
24
|
-
option %w(--
|
12
|
+
option %w(--threads), 'THREAD_COUNT', 'Number of threads to hammer with',
|
13
|
+
:default => 1, :hidden => true
|
14
|
+
option %w(--export), :flag, 'Export current data instead of importing'
|
15
|
+
option %w(--file), 'FILE_NAME', 'CSV file (default to /dev/stdout with --csv-export, otherwise required)'
|
25
16
|
option %w(--prefix), 'PREFIX', 'Prefix for all name columns'
|
17
|
+
option %w(--organization), 'ORGANIZATION', _('Only process organization matching this name')
|
18
|
+
|
19
|
+
option %w(--csv-file), 'FILE_NAME', 'Option --csv-file is deprecated. Use --file',
|
20
|
+
:deprecated => "Use --file", :hidden => true,
|
21
|
+
:attribute_name => :option_file
|
22
|
+
option %w(--csv-export), :flag, 'Option --csv-export is deprecated. Use --export',
|
23
|
+
:deprecated => "Use --export", :hidden => true,
|
24
|
+
:attribute_name => :option_export
|
25
|
+
|
26
26
|
|
27
27
|
NAME = 'Name'
|
28
28
|
COUNT = 'Count'
|
29
29
|
|
30
30
|
def execute
|
31
|
-
@server = HammerCLI::Settings.settings[:_params]
|
31
|
+
@server = (HammerCLI::Settings.settings[:_params] &&
|
32
|
+
HammerCLI::Settings.settings[:_params][:host]) ||
|
32
33
|
HammerCLI::Settings.get(:csv, :host) ||
|
33
34
|
HammerCLI::Settings.get(:katello, :host) ||
|
34
35
|
HammerCLI::Settings.get(:foreman, :host)
|
35
|
-
@username = HammerCLI::Settings.settings[:_params]
|
36
|
+
@username = (HammerCLI::Settings.settings[:_params] &&
|
37
|
+
HammerCLI::Settings.settings[:_params][:username]) ||
|
36
38
|
HammerCLI::Settings.get(:csv, :username) ||
|
37
39
|
HammerCLI::Settings.get(:katello, :username) ||
|
38
40
|
HammerCLI::Settings.get(:foreman, :username)
|
39
|
-
@password = HammerCLI::Settings.settings[:_params]
|
41
|
+
@password = (HammerCLI::Settings.settings[:_params] &&
|
42
|
+
HammerCLI::Settings.settings[:_params][:password]) ||
|
40
43
|
HammerCLI::Settings.get(:csv, :password) ||
|
41
44
|
HammerCLI::Settings.get(:katello, :password) ||
|
42
45
|
HammerCLI::Settings.get(:foreman, :password)
|
@@ -58,7 +61,7 @@ module HammerCLICsv
|
|
58
61
|
})
|
59
62
|
end
|
60
63
|
|
61
|
-
|
64
|
+
option_export? ? export : import
|
62
65
|
HammerCLI::EX_OK
|
63
66
|
end
|
64
67
|
|
@@ -91,6 +94,7 @@ module HammerCLICsv
|
|
91
94
|
end
|
92
95
|
|
93
96
|
def namify(name_format, number = 0)
|
97
|
+
return '' unless name_format
|
94
98
|
if name_format.index('%')
|
95
99
|
name = name_format % number
|
96
100
|
else
|
@@ -105,13 +109,13 @@ module HammerCLICsv
|
|
105
109
|
end
|
106
110
|
|
107
111
|
def thread_import(return_headers = false, filename=nil, name_column=nil)
|
108
|
-
filename ||=
|
112
|
+
filename ||= option_file || '/dev/stdin'
|
109
113
|
csv = []
|
110
|
-
CSV.
|
114
|
+
CSV.new(open(filename), {
|
111
115
|
:skip_blanks => true,
|
112
116
|
:headers => :first_row,
|
113
117
|
:return_headers => return_headers
|
114
|
-
}) do |line|
|
118
|
+
}).each do |line|
|
115
119
|
csv << line
|
116
120
|
end
|
117
121
|
lines_per_thread = csv.length / option_threads.to_i + 1
|
@@ -480,6 +484,99 @@ module HammerCLICsv
|
|
480
484
|
result
|
481
485
|
end
|
482
486
|
|
487
|
+
def foreman_host(options = {})
|
488
|
+
@query_hosts ||= {}
|
489
|
+
|
490
|
+
if options[:name]
|
491
|
+
return nil if options[:name].nil? || options[:name].empty?
|
492
|
+
options[:id] = @query_hosts[options[:name]]
|
493
|
+
if !options[:id]
|
494
|
+
host = @api.resource(:hosts).call(:index, {
|
495
|
+
:per_page => 999999,
|
496
|
+
'search' => "name=\"#{options[:name]}\""
|
497
|
+
})['results']
|
498
|
+
raise "Host '#{options[:name]}' not found" if !host || host.empty?
|
499
|
+
options[:id] = host[0]['id']
|
500
|
+
@query_hosts[options[:name]] = options[:id]
|
501
|
+
end
|
502
|
+
result = options[:id]
|
503
|
+
else
|
504
|
+
return nil if options[:id].nil?
|
505
|
+
options[:name] = @query_hosts.key(options[:id])
|
506
|
+
if !options[:name]
|
507
|
+
host = @api.resource(:hosts).call(:show, {'id' => options[:id]})
|
508
|
+
raise "Host 'id=#{options[:id]}' not found" if !host || host.empty?
|
509
|
+
options[:name] = host['name']
|
510
|
+
@query_hosts[options[:name]] = options[:id]
|
511
|
+
end
|
512
|
+
result = options[:name]
|
513
|
+
end
|
514
|
+
|
515
|
+
result
|
516
|
+
end
|
517
|
+
|
518
|
+
def foreman_hostgroup(options = {})
|
519
|
+
@query_hostgroups ||= {}
|
520
|
+
|
521
|
+
if options[:name]
|
522
|
+
return nil if options[:name].nil? || options[:name].empty?
|
523
|
+
options[:id] = @query_hostgroups[options[:name]]
|
524
|
+
if !options[:id]
|
525
|
+
hostgroup = @api.resource(:hostgroups).call(:index, {
|
526
|
+
:per_page => 999999,
|
527
|
+
'search' => "name=\"#{options[:name]}\""
|
528
|
+
})['results']
|
529
|
+
raise "Host Group '#{options[:name]}' not found" if !hostgroup || hostgroup.empty?
|
530
|
+
options[:id] = hostgroup[0]['id']
|
531
|
+
@query_hostgroups[options[:name]] = options[:id]
|
532
|
+
end
|
533
|
+
result = options[:id]
|
534
|
+
else
|
535
|
+
return nil if options[:id].nil?
|
536
|
+
options[:name] = @query_hostgroups.key(options[:id])
|
537
|
+
if !options[:name]
|
538
|
+
hostgroup = @api.resource(:hostgroups).call(:show, {'id' => options[:id]})
|
539
|
+
raise "Host Group 'id=#{options[:id]}' not found" if !hostgroup || hostgroup.empty?
|
540
|
+
options[:name] = hostgroup['name']
|
541
|
+
@query_hostgroups[options[:name]] = options[:id]
|
542
|
+
end
|
543
|
+
result = options[:name]
|
544
|
+
end
|
545
|
+
|
546
|
+
result
|
547
|
+
end
|
548
|
+
|
549
|
+
def foreman_smart_proxy(options = {})
|
550
|
+
@query_smart_proxies ||= {}
|
551
|
+
|
552
|
+
if options[:name]
|
553
|
+
return nil if options[:name].nil? || options[:name].empty?
|
554
|
+
options[:id] = @query_smart_proxies[options[:name]]
|
555
|
+
if !options[:id]
|
556
|
+
smart_proxy = @api.resource(:smart_proxies).call(:index, {
|
557
|
+
:per_page => 999999,
|
558
|
+
'search' => "name=\"#{options[:name]}\""
|
559
|
+
})['results']
|
560
|
+
raise "Smart Proxy '#{options[:name]}' not found" if !smart_proxy || smart_proxy.empty?
|
561
|
+
options[:id] = smart_proxy[0]['id']
|
562
|
+
@query_smart_proxies[options[:name]] = options[:id]
|
563
|
+
end
|
564
|
+
result = options[:id]
|
565
|
+
else
|
566
|
+
return nil if options[:id].nil?
|
567
|
+
options[:name] = @query_smart_proxies.key(options[:id])
|
568
|
+
if !options[:name]
|
569
|
+
smart_proxy = @api.resource(:smart_proxies).call(:show, {'id' => options[:id]})
|
570
|
+
raise "Smart Proxy 'id=#{options[:id]}' not found" if !smart_proxy || smart_proxy.empty?
|
571
|
+
options[:name] = smart_proxy['name']
|
572
|
+
@query_smart_proxies[options[:name]] = options[:id]
|
573
|
+
end
|
574
|
+
result = options[:name]
|
575
|
+
end
|
576
|
+
|
577
|
+
result
|
578
|
+
end
|
579
|
+
|
483
580
|
def lifecycle_environment(organization, options = {})
|
484
581
|
@lifecycle_environments ||= {}
|
485
582
|
@lifecycle_environments[organization] ||= {
|
@@ -715,6 +812,38 @@ module HammerCLICsv
|
|
715
812
|
result
|
716
813
|
end
|
717
814
|
|
815
|
+
def foreman_container(options = {})
|
816
|
+
@containers ||= {}
|
817
|
+
|
818
|
+
if options[:name]
|
819
|
+
return nil if options[:name].nil? || options[:name].empty?
|
820
|
+
options[:id] = @containers[options[:name]]
|
821
|
+
if !options[:id]
|
822
|
+
container = @api.resource(:containers).call(:index, {
|
823
|
+
:per_page => 999999,
|
824
|
+
'search' => "name=\"#{options[:name]}\""
|
825
|
+
})['results']
|
826
|
+
raise "Container '#{options[:name]}' not found" if !container || container.empty?
|
827
|
+
options[:id] = container[0]['id']
|
828
|
+
@containers[options[:name]] = options[:id]
|
829
|
+
end
|
830
|
+
result = options[:id]
|
831
|
+
else
|
832
|
+
return nil if options[:id].nil?
|
833
|
+
options[:name] = @containers.key(options[:id])
|
834
|
+
if !options[:name]
|
835
|
+
container = @api.resource(:containers).call(:show, {'id' => options[:id]})
|
836
|
+
raise "Container 'id=#{options[:id]}' not found" if !container || container.empty?
|
837
|
+
options[:name] = container['name']
|
838
|
+
@containers[options[:name]] = options[:id]
|
839
|
+
end
|
840
|
+
result = options[:name]
|
841
|
+
end
|
842
|
+
|
843
|
+
result
|
844
|
+
end
|
845
|
+
|
846
|
+
|
718
847
|
def build_os_name(name, major, minor)
|
719
848
|
name += " #{major}" if major && major != ''
|
720
849
|
name += ".#{minor}" if minor && minor != ''
|
@@ -804,6 +933,33 @@ module HammerCLICsv
|
|
804
933
|
end if locations && !locations.empty?
|
805
934
|
end
|
806
935
|
|
936
|
+
def apipie_check_param(resource, action, name)
|
937
|
+
method = @api.resource(pluralize(resource).to_sym).apidoc[:methods].detect do |api_method|
|
938
|
+
api_method[:name] == action.to_s
|
939
|
+
end
|
940
|
+
return false unless method
|
941
|
+
|
942
|
+
found = method[:params].detect do |param|
|
943
|
+
param[:full_name] == name
|
944
|
+
end
|
945
|
+
if !found
|
946
|
+
nested = method[:params].detect do |param|
|
947
|
+
param[:name] == resource.to_s
|
948
|
+
end
|
949
|
+
if nested
|
950
|
+
found = nested[:params].detect do |param|
|
951
|
+
param[:full_name] == name
|
952
|
+
end
|
953
|
+
end
|
954
|
+
end
|
955
|
+
found
|
956
|
+
end
|
957
|
+
|
958
|
+
def count(value)
|
959
|
+
return 1 if value.nil? || value.empty?
|
960
|
+
value.to_i
|
961
|
+
end
|
962
|
+
|
807
963
|
private
|
808
964
|
|
809
965
|
def search_string(resource, name)
|