Project

General

Profile

Revision 8c7ba4af

Added by Thomas McKay about 8 years ago

updates to csv

fixed lifecycle-env

ship it

View differences:

lib/hammer_cli_csv/lifecycle_environments.rb
31 31
      command_name 'lifecycle-environments'
32 32
      desc         'import or export lifecycle environments'
33 33

  
34
      LABEL = 'Label'
35 34
      ORGANIZATION = 'Organization'
36 35
      PRIORENVIRONMENT = 'Prior Environment'
37 36
      DESCRIPTION = 'Description'
38 37

  
39 38
      def export
40 39
        CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
41
          csv << [NAME, COUNT, LABEL, ORGANIZATION, PRIORENVIRONMENT, DESCRIPTION]
40
          csv << [NAME, COUNT, ORGANIZATION, PRIORENVIRONMENT, DESCRIPTION]
42 41
          @api.resource(:organizations).call(:index, {'per_page' => 999999})['results'].each do |organization|
43
            @api.resource(:environments).call(:index, {
42
            @api.resource(:lifecycle_environments).call(:index, {
44 43
                                       'per_page' => 999999,
45 44
                                       'organization_id' => organization['id']
46 45
                                     })['results'].each do |environment|
47
              if environment['label'] != 'Library'
46
              if environment['name'] != 'Library'
48 47
                name = environment['name']
49 48
                count = 1
50
                label = environment['label']
51 49
                prior = environment['prior']
52 50
                description = environment['description']
53
                csv << [name, count, label, organization['name'], prior, description]
51
                csv << [name, count, organization['name'], prior, description]
54 52
              end
55 53
            end
56 54
          end
......
60 58
      def import
61 59
        @existing = {}
62 60
        @api.resource(:organizations).call(:index, {'per_page' => 999999})['results'].each do |organization|
63
          @api.resource(:environments).call(:index, {
61
          @api.resource(:lifecycle_environments).call(:index, {
64 62
                                     'per_page' => 999999,
65 63
                                     'organization_id' => foreman_organization(:name => organization['name']),
66
                                     'library' => true
67 64
                                   })['results'].each do |environment|
68 65
            @existing[organization['name']] ||= {}
69 66
            @existing[organization['name']][environment['name']] = environment['id'] if environment
......
78 75
      def create_environments_from_csv(line)
79 76
        line[COUNT].to_i.times do |number|
80 77
          name = namify(line[NAME], number)
81
          label = namify(line[LABEL], number)
82 78
          prior = namify(line[PRIORENVIRONMENT], number)
83 79
          raise "Organization '#{line[ORGANIZATION]}' does not exist" if !@existing.include? line[ORGANIZATION]
84 80
          if !@existing[line[ORGANIZATION]].include? name
85 81
            print "Creating environment '#{name}'..." if option_verbose?
86
            @api.resource(:environments).call(:create, {
82
            @api.resource(:lifecycle_environments).call(:create, {
87 83
                                        'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
88 84
                                        'name' => name,
89
                                        'label' => label,
90
                                        'prior' => katello_environment(line[ORGANIZATION], :name => prior),
85
                                        'prior' => lifecycle_environment(line[ORGANIZATION], :name => prior),
91 86
                                        'description' => line[DESCRIPTION]
92 87
                                      })
93 88
          else
94 89
            print "Updating environment '#{name}'..." if option_verbose?
95
            @api.resource(:environments).call(:update, {
90
            @api.resource(:lifecycle_environments).call(:update, {
96 91
                                        'id' => @existing[line[ORGANIZATION]][name],
97 92
                                        'name' => name,
98 93
                                        'new_name' => name,

Also available in: Unified diff