Project

General

Profile

Revision 502df2e4

Added by Thomas McKay about 6 years ago

repo enable for subscriptions that don't have release version

View differences:

lib/hammer_cli_csv/base.rb
94 94
    end
95 95

  
96 96
    def namify(name_format, number = 0)
97
      return '' unless name_format
97 98
      if name_format.index('%')
98 99
        name = name_format % number
99 100
      else
lib/hammer_cli_csv/organizations.rb
41 41
          name = namify(line[NAME], number)
42 42
          return if option_organization && name != option_organization
43 43
          label = namify(line[LABEL], number)
44
          if !@existing.include? name
44
          organization_id = @existing[name]
45
          if organization_id.nil?
45 46
            print "Creating organization '#{name}'... " if option_verbose?
46 47
            @api.resource(:organizations).call(:create, {
47 48
                'name' => name,
......
53 54
            })
54 55
          else
55 56
            print "Updating organization '#{name}'... " if option_verbose?
57
            organization = @api.resource(:organizations).call(:show, {'id' => organization_id})
56 58
            @api.resource(:organizations).call(:update, {
57
                'id' => foreman_organization(:name => name),
59
                'id' => organization_id,
58 60
                'organization' => {
59
                    'id' => foreman_organization(:name => name),
61
                    'id' => organization_id,
60 62
                    'description' => line[DESCRIPTION]
61 63
                }
62 64
            })
lib/hammer_cli_csv/subscriptions.rb
51 51
        end
52 52
      end
53 53

  
54
      # FIXME: TODO remove this rubocop
55
      # rubocop:disable CyclomaticComplexity
54 56
      def enable_products_from_csv(line)
55 57
        organization = line[ORGANIZATION] || option_organization
56 58
        raise "Organization is required in either input CSV or by option --organization" if organization.nil? || organization.empty?
......
77 79
        repository_set = results[0]
78 80

  
79 81
        repository = repository_set['repositories'].find do |repo|
80
          repo['name'].end_with?("#{line[ARCH]} #{line[RELEASE]}")
82
          if line[RELEASE].nil? || line[RELEASE].empty?
83
            repo['name'].end_with?("#{line[ARCH]}")
84
          else
85
            repo['name'].end_with?("#{line[ARCH]} #{line[RELEASE]}")
86
          end
81 87
        end
82 88

  
83 89
        if repository.nil?
......
87 93
          end
88 94
          raise "No match for content set '#{line[CONTENT_SET]}'" if !product_content
89 95

  
90
          @api.resource(:repository_sets).call(:enable, {
96
          params = {
91 97
              'id' => product_content['content']['id'],
92 98
              'product_id' => product['id'],
93
              'basearch' => line[ARCH],
94
              'releasever' => line[RELEASE]
95
          })
99
              'basearch' => line[ARCH]
100
          }
101
          params['releasever'] = line[RELEASE] unless line[RELEASE].nil? || line[RELEASE].empty?
102

  
103
          @api.resource(:repository_sets).call(:enable, params)
96 104
          puts 'done' if option_verbose?
97 105
        else
98 106
          puts "Repository #{repository['name']} already enabled" if option_verbose?

Also available in: Unified diff