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/import.rb
28 28
      option %w(-u --username), 'USERNAME', 'Username to access server'
29 29
      option %w(-p --password), 'PASSWORD', 'Password to access server'
30 30
      option '--dir', 'DIRECTORY', 'directory to import from'
31
      option '--roles', 'FILE', 'source to import roles'
32
      option '--users', 'FILE', 'source to import users'
33
      option '--hosts', 'FILE', 'source to import hosts'
34
      option '--organizations', 'FILE', 'source to import organizations'
35
      option '--locations', 'FILE', 'source to import locations'
36
      option '--puppet-environments', 'FILE', 'source to puppet environments'
37
      option '--operating-systems', 'FILE', 'source to operating systems'
38
      option '--architectures', 'FILE', 'source to architectures'
39
      option '--domains', 'FILE', 'source to domains'
40
      option '--architectures', 'FILE', 'source to architectures'
41
      option '--partition-tables', 'FILE', 'source to partition-tables'
31

  
32
      RESOURCES = %w( organizations locations roles users puppet_environments operating_systems
33
            domains architectures partition_tables lifecycle_environments host_collections
34
            subscriptions activation_keys hosts content_hosts reports )
35
      RESOURCES.each do |resource|
36
        dashed = resource.sub('_', '-')
37
        option "--#{dashed}", 'FILE', "csv file for #{dashed}"
38
      end
42 39

  
43 40
      def ctx
44 41
        {
......
61 58
                                       })
62 59

  
63 60
        # Swing the hammers
64
        %w( organizations locations roles users puppet_environments operating_systems
65
            hosts domains architectures partition_tables ).each do |resource|
66
          swing(resource)
61
        RESOURCES.each do |resource|
62
          hammer_resource(resource)
67 63
        end
68 64

  
69 65
        HammerCLI::EX_OK
70 66
      end
71 67

  
72
      def swing(resource)
68
      def hammer_resource(resource)
73 69
        return if !self.send("option_#{resource}") && !option_dir
74 70
        options_file = self.send("option_#{resource}") || "#{option_dir}/#{resource.sub('_', '-')}.csv"
75
        raise "File for #{resource} '#{options_file}' does not exist" unless File.exists? options_file
76
        args = %W{ csv #{resource.sub('_', '-')} --csv-file #{options_file} }
71
        if !File.exists? options_file
72
          return if option_dir
73
          raise "File for #{resource} '#{options_file}' does not exist"
74
        end
75

  
76
        args = %W( csv #{resource.sub('_', '-')} --csv-file #{options_file} )
77 77
        args << '-v' if option_verbose?
78 78
        hammer.run(args)
79 79
      end

Also available in: Unified diff