Project

General

Profile

Revision bfc065ce

Added by Thomas McKay over 8 years ago

roles-test - wip

roles-test - users now get roles, orgs, and locations

View differences:

lib/hammer_cli_csv/puppet_environments.rb
40 40
module HammerCLICsv
41 41
  class PuppetEnvironmentsCommand < BaseCommand
42 42

  
43
    ORGANIZATIONS = 'Organizations'
44

  
43 45
    def export
44 46
      CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
45
        csv << [NAME, COUNT]
47
        csv << [NAME, COUNT, ORGANIZATIONS]
46 48
        @f_environment_api.index({:per_page => 999999})[0]['results'].each do |environment|
47 49
          name = environment['name']
48 50
          count = 1
51
          raise "TODO: organizations"
49 52
          csv << [name, count]
50 53
        end
51 54
      end
......
67 70
        name = namify(line[NAME], number)
68 71
        if !@existing.include? name
69 72
          print "Creating environment '#{name}'..." if option_verbose?
70
          @f_environment_api.create({
71
                                      'environment' => {
72
                                        'name' => name
73
                                      }
74
                                    })
73
          id = @f_environment_api.create({
74
                                           'environment' => {
75
                                             'name' => name
76
                                           }
77
                                         })[0]['environment']['id']
75 78
        else
76 79
          print "Updating environment '#{name}'..." if option_verbose?
77
          @f_environment_api.update({
78
                                      'id' => @existing[name],
79
                                      'environment' => {
80
                                        'name' => name
81
                                      }
82
                                    })
80
          id = @f_environment_api.update({
81
                                           'id' => @existing[name],
82
                                           'environment' => {
83
                                             'name' => name
84
                                           }
85
                                         })[0]['environment']['id']
86
        end
87

  
88
        CSV.parse_line(line[ORGANIZATIONS]).each do |organization|
89
          @k_organization_api.update({
90
                                       'id' => foreman_organization(:name => organization),
91
                                       'environment_ids' => [id]
92
                                     })
83 93
        end
94

  
84 95
        print "done\n" if option_verbose?
85 96
      end
86 97
    rescue RuntimeError => e

Also available in: Unified diff