Project

General

Profile

Revision 9e11b4c5

Added by Thomas McKay over 7 years ago

updated to work with foreman-csv plugin

fixed roles

updated comment

View differences:

lib/hammer_cli_csv/content_hosts.rb
158 158
      end
159 159

  
160 160
      def import
161
        remote = @server_status['plugins'].detect { |plugin| plugin['name'] == 'foreman_csv' }
162
        if remote.nil?
163
          import_locally
164
        else
165
          import_remotely
166
        end
167
      end
168

  
169
      def import_remotely
170
        @api.resource(:csv).call(:import_content_hosts, {
171
            'content' => ::File.new(::File.expand_path(option_csv_file), 'rb')
172
        }, {
173
            :content_type => 'multipart/form-data',
174
            :multipart => true
175
        })
176
      end
177

  
178
      def import_locally
161 179
        @existing = {}
162 180
        @hypervisor_guests = {}
163 181

  
......
165 183
          create_content_hosts_from_csv(line)
166 184
        end
167 185

  
168
        print(_('Updating hypervisor and guest associations...')) if option_verbose? && !@hypervisor_guests.empty?
169
        @hypervisor_guests.each do |host_id, guest_ids|
170
          @api.resource(:systems).call(:update, {
171
              'id' => host_id,
172
              'guest_ids' => guest_ids
173
          })
186
        if !@hypervisor_guests.empty?
187
          print(_('Updating hypervisor and guest associations...')) if option_verbose?
188
          @hypervisor_guests.each do |host_id, guest_ids|
189
            @api.resource(:systems).call(:update, {
190
                'id' => host_id,
191
                'guest_ids' => guest_ids
192
            })
193
          end
174 194
        end
175
        puts _('done') if option_verbose? && !@hypervisor_guests.empty?
195
        puts _('done') if option_verbose?
176 196
      end
177 197

  
178 198
      def create_content_hosts_from_csv(line)
......
225 245
                    'facts' => facts(name, line),
226 246
                    'installed_products' => products(line)
227 247
                },
248
                'facts' => facts(name, line),
228 249
                'installed_products' => products(line),  # TODO: http://projects.theforeman.org/issues/9191,
229 250
                'service_level' => line[SLA]
230 251
            })['uuid']

Also available in: Unified diff