Class: HammerCLICsv::CsvCommand::SmartProxiesCommand
- Inherits:
-
BaseCommand
- Object
- HammerCLI::Apipie::Command
- BaseCommand
- HammerCLICsv::CsvCommand::SmartProxiesCommand
show all
- Defined in:
- lib/hammer_cli_csv/smart_proxies.rb
Constant Summary
collapse
- ORGANIZATIONS =
'Organizations'
- LOCATIONS =
'Locations'
- URL =
'URL'
- LIFECYCLE_ENVIRONMENTS =
'Lifecycle Environments'
Constants inherited
from BaseCommand
BaseCommand::COUNT, BaseCommand::NAME
Instance Method Summary
collapse
Methods inherited from BaseCommand
#apipie_check_param, #associate_locations, #associate_organizations, #build_os_name, #check_server_status, #collect_column, #count, #execute, #export_column, #foreman_architecture, #foreman_container, #foreman_domain, #foreman_environment, #foreman_filter, #foreman_host, #foreman_hostgroup, #foreman_location, #foreman_operatingsystem, #foreman_organization, #foreman_partitiontable, #foreman_permission, #foreman_provisioning_template, #foreman_role, #foreman_smart_proxy, #foreman_template_kind, #hammer, #hammer_context, #katello_contentview, #katello_contentviewversion, #katello_hostcollection, #katello_product, #katello_repository, #katello_subscription, #labelize, #lifecycle_environment, #namify, #pluralize, #split_os_name, #thread_import
Instance Method Details
#create_smart_proxies_from_csv(line) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/hammer_cli_csv/smart_proxies.rb', line 37
def create_smart_proxies_from_csv(line)
count(line[COUNT]).times do |number|
name = namify(line[NAME], number)
id = @existing[line[URL]]
if id.nil?
print "Creating smart proxy '#{name}'..." if option_verbose?
id = @api.resource(:smart_proxies).call(:create, {
'smart_proxy' => {
'name' => name,
'url' => line[URL]
}
})['id']
else
print "Updating smart proxy '#{name}'..." if option_verbose?
@api.resource(:smart_proxies).call(:update, {
'id' => id,
'smart_proxy' => {
'name' => name,
'url' => line[URL]
}
})
end
associate_organizations(id, line[ORGANIZATIONS], 'smart_proxy')
associate_locations(id, line[LOCATIONS], 'smart_proxy')
print "done\n" if option_verbose?
end
rescue RuntimeError => e
raise "#{e}\n #{line}"
end
|
#export ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/hammer_cli_csv/smart_proxies.rb', line 12
def export
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
csv << [NAME, ORGANIZATIONS, LOCATIONS, URL, LIFECYCLE_ENVIRONMENTS]
@api.resource(:smart_proxies).call(:index, {:per_page => 999999})['results'].each do |smart_proxy|
smart_proxy = @api.resource(:smart_proxies).call(:show, {'id' => smart_proxy['id']})
name = smart_proxy['name']
organizations = export_column(smart_proxy, 'organizations', 'name')
locations = export_column(smart_proxy, 'locations', 'name')
url = smart_proxy['url']
csv << [name, organizations, locations, url]
end
end
end
|
#import ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/hammer_cli_csv/smart_proxies.rb', line 26
def import
@existing = {}
@api.resource(:smart_proxies).call(:index, {:per_page => 999999})['results'].each do |smart_proxy|
@existing[smart_proxy['url']] = smart_proxy['id'] if smart_proxy
end
thread_import do |line|
create_smart_proxies_from_csv(line)
end
end
|