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/partition_tables.rb
41 41
  class PartitionTablesCommand < BaseCommand
42 42

  
43 43
    OSFAMILY = 'OS Family'
44
    OPERATINGSYSTEMS = 'Operating Systems'
44 45
    LAYOUT = 'Layout'
45 46

  
46 47
    def export
47 48
      CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
48
        csv << [NAME, COUNT, OSFAMILY, LAYOUT]
49
        csv << [NAME, COUNT, OSFAMILY, OPERATINGSYSTEMS, LAYOUT]
49 50
        @f_partitiontable_api.index({:per_page => 999999})[0]['results'].each do |ptable|
50 51
          ptable = @f_partitiontable_api.show({'id' => ptable['id']})[0]
51 52
          name = ptable['name']
52 53
          count = 1
53 54
          osfamily = ptable['os_family']
54 55
          layout = ptable['layout']
56
          raise "TODO: operating systems"
55 57
          csv << [name, count, osfamily, layout]
56 58
        end
57 59
      end
......
71 73
    def create_ptables_from_csv(line)
72 74
      line[COUNT].to_i.times do |number|
73 75
        name = namify(line[NAME], number)
76
        operatingsystem_ids = CSV.parse_line(line[OPERATINGSYSTEMS]).collect do |operatingsystem_name|
77
          foreman_operatingsystem(:name => operatingsystem_name)
78
        end if line[OPERATINGSYSTEMS]
74 79
        if !@existing.include? name
75 80
          print "Creating ptable '#{name}'... " if option_verbose?
76 81
          @f_partitiontable_api.create({
77
                                 'ptable' => {
78
                                   'name' => name,
79
                                   'os_family' => line[OSFAMILY],
80
                                   'layout' => line[LAYOUT]
81
                             }
82
                           })
82
                                         'ptable' => {
83
                                           'name' => name,
84
                                           'os_family' => line[OSFAMILY],
85
                                           'operatingsystem_ids' => operatingsystem_ids,
86
                                           'layout' => line[LAYOUT]
87
                                         }
88
                                       })
83 89
        else
84 90
          print "Updating ptable '#{name}'..." if option_verbose?
85 91
          @f_partitiontable_api.update({
86
                                 'id' => @existing[name],
87
                                 'ptable' => {
88
                                   'name' => name,
89
                                   'os_family' => line[OSFAMILY],
90
                                   'layout' => line[LAYOUT]
92
                                         'id' => @existing[name],
93
                                         'ptable' => {
94
                                           'name' => name,
95
                                           'os_family' => line[OSFAMILY],
96
                                           'operatingsystem_ids' => operatingsystem_ids,
97
                                           'layout' => line[LAYOUT]
91 98
                                 }
92 99
                           })
93 100
        end

Also available in: Unified diff