Project

General

Profile

Revision a77acc4a

Added by Thomas McKay about 9 years ago

a lot of fixes and updates across many resources to match katello updates

View differences:

lib/hammer_cli_csv/base.rb
126 126
      result
127 127
    end
128 128

  
129
    def katello_organization(options = {})
130
      @organizations ||= {}
131

  
132
      if options[:name]
133
        return nil if options[:name].nil? || options[:name].empty?
134
        options[:id] = @organizations[options[:name]]
135
        if !options[:id]
136
          organization = @api.resource(:organizations).call(:index, {
137
                                                              :per_page => 999999,
138
                                                              'search' => "name=\"#{options[:name]}\""
139
                                                            })['results']
140
          raise "Organization '#{options[:name]}' not found" if !organization || organization.empty?
141
          options[:id] = organization[0]['label']
142
          @organizations[options[:name]] = options[:id]
143
        end
144
        result = options[:id]
145
      else
146
        return nil if options[:id].nil?
147
        options[:name] = @organizations.key(options[:id])
148
        if !options[:name]
149
          organization = @api.resource(:organizations).call(:show, {'id' => options[:id]})
150
          raise "Organization 'id=#{options[:id]}' not found" if !organization || organization.empty?
151
          options[:name] = organization['name']
152
          @organizations[options[:name]] = options[:id]
153
        end
154
        result = options[:name]
155
      end
156

  
157
      result
158
    end
159

  
160 129
    def foreman_location(options = {})
161 130
      @locations ||= {}
162 131

  
......
435 404
        if !options[:id]
436 405
          @api.resource(:lifecycle_environments).call(:index, {
437 406
                                                        :per_page => 999999,
438
                                                        'organization_id' => katello_organization(:name => organization),
407
                                                        'organization_id' => foreman_organization(:name => organization),
439 408
                                                        'library' => true
440 409
                                                      })['results'].each do |environment|
441 410
            @environments[organization][environment['name']] = environment['id']
......
469 438
        if !options[:id]
470 439
          @api.resource(:content_views).call(:index, {
471 440
                                               :per_page => 999999,
472
                                               'organization_id' => katello_organization(:name => organization)
441
                                               'organization_id' => foreman_organization(:name => organization)
473 442
                                             })['results'].each do |contentview|
474 443
            @contentviews[organization][contentview['name']] = contentview['id']
475 444
          end
......
502 471
        if !options[:id]
503 472
          results = @api.resource(:subscriptions).call(:index, {
504 473
                                                         :per_page => 999999,
505
                                                         'organization_id' => katello_organization(:name => organization),
474
                                                         'organization_id' => foreman_organization(:name => organization),
506 475
                                                         'search' => "name:\"#{options[:name]}\""
507 476
                                                       })
508 477
          raise "No subscriptions match '#{options[:name]}'" if results['subtotal'] == 0
......
528 497
      result
529 498
    end
530 499

  
531
    def katello_systemgroup(organization, options = {})
532
      @systemgroups ||= {}
533
      @systemgroups[organization] ||= {}
500
    def katello_hostcollection(organization, options = {})
501
      @hostcollections ||= {}
502
      @hostcollections[organization] ||= {}
534 503

  
535 504
      if options[:name]
536 505
        return nil if options[:name].nil? || options[:name].empty?
537
        options[:id] = @systemgroups[organization][options[:name]]
506
        options[:id] = @hostcollections[organization][options[:name]]
538 507
        if !options[:id]
539
          @api.resource(:system_groups).call(:index,
508
          @api.resource(:host_collections).call(:index,
540 509
                  {
541 510
                    :per_page => 999999,
542
                    'organization_id' => katello_organization(:name => organization),
511
                    'organization_id' => foreman_organization(:name => organization),
543 512
                    'search' => "name:\"#{options[:name]}\""
544
                  })['results'].each do |systemgroup|
545
            @systemgroups[organization][systemgroup['name']] = systemgroup['id'] if systemgroup
513
                  })['results'].each do |hostcollection|
514
            @hostcollections[organization][hostcollection['name']] = hostcollection['id'] if hostcollection
546 515
          end
547
          options[:id] = @systemgroups[organization][options[:name]]
516
          options[:id] = @hostcollections[organization][options[:name]]
548 517
          raise "System group '#{options[:name]}' not found" if !options[:id]
549 518
        end
550 519
        result = options[:id]
551 520
      else
552 521
        return nil if options[:id].nil?
553
        options[:name] = @systemgroups.key(options[:id])
522
        options[:name] = @hostcollections.key(options[:id])
554 523
        if !options[:name]
555
          systemgroup = @api.resource(:system_groups).call(:show, {'id' => options[:id]})
556
          raise "System group '#{options[:name]}' not found" if !systemgroup || systemgroup.empty?
557
          options[:name] = systemgroup['name']
558
          @systemgroups[options[:name]] = options[:id]
524
          hostcollection = @api.resource(:host_collections).call(:show, {'id' => options[:id]})
525
          raise "System group '#{options[:name]}' not found" if !hostcollection || hostcollection.empty?
526
          options[:name] = hostcollection['name']
527
          @hostcollections[options[:name]] = options[:id]
559 528
        end
560 529
        result = options[:name]
561 530
      end

Also available in: Unified diff