49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/hammer_cli_csv/splice.rb', line 49
def create_content_hosts_from_csv(line)
return if option_organization && line[ORGANIZATION] != option_organization
if !@existing[line[ORGANIZATION]]
create_organization(line)
@existing[line[ORGANIZATION]] = {}
total = @api.resource(:systems).call(:index, {
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'per_page' => 1
})['total'].to_i
(total / 20 + 2).to_i.times do |page|
@api.resource(:systems).call(:index, {
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'page' => page,
'per_page' => 20
})['results'].each do |host|
@existing[line[ORGANIZATION]][host['name']] = host['uuid'] if host
end
end
end
name = "#{line[NAME]}-#{line[UUID]}"
checkin_time = if line[LAST_CHECKIN_TIME].casecmp('now').zero?
DateTime.now.strftime("%a, %d %b %Y %H:%M:%S %z")
else
DateTime.parse(line[LAST_CHECKIN_TIME]).strftime("%a, %d %b %Y %H:%M:%S %z")
end
if !@existing[line[ORGANIZATION]].include? name
print(_("Creating content host '%{name}'...") % {:name => name}) if option_verbose?
host_id = @api.resource(:systems).call(:create, {
'name' => name,
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'environment_id' => lifecycle_environment(line[ORGANIZATION], :name => 'Library'),
'content_view_id' => katello_contentview(line[ORGANIZATION], :name => 'Default Organization View'),
'last_checkin' => checkin_time,
'facts' => facts(name, line),
'installed_products' => products(line),
'type' => 'system'
})['uuid']
@api.resource(:systems).call(:update, {
'id' => host_id,
'system' => {
'last_checkin' => checkin_time
},
'last_checkin' => checkin_time
})
else
print(_("Updating content host '%{name}'...") % {:name => name}) if option_verbose?
host_id = @api.resource(:systems).call(:update, {
'id' => @existing[line[ORGANIZATION]][name],
'system' => {
'name' => name,
'environment_id' => lifecycle_environment(line[ORGANIZATION], :name => 'Library'),
'content_view_id' => katello_contentview(line[ORGANIZATION], :name => 'Default Organization View'),
'last_checkin' => checkin_time,
'facts' => facts(name, line),
'installed_products' => products(line)
},
'installed_products' => products(line), 'last_checkin' => checkin_time
})['uuid']
@existing[line[ORGANIZATION]].delete(name) end
if @hosts.include? line[UUID]
@hosts[line[UUID]] = host_id
elsif @guests.include? line[UUID]
@guests[line[UUID]] = "#{line[ORGANIZATION]}/#{name}"
end
update_host_collections(host_id, line)
puts _('done') if option_verbose?
end
|