Project

General

Profile

Revision f370cc85

Added by Thomas McKay almost 6 years ago

fixes #16501 - subnets import not setting proxies

Changed the vcr recording by adding --reload-cache to all the hammer commands. This hopefully will avoid the intermittent failures due to fetching the v2.json.

View differences:

lib/hammer_cli_csv/subnets.rb
8 8
      LOCATIONS = 'Locations'
9 9
      NETWORK = 'Network'
10 10
      NETWORK_MASK = 'Network Mask'
11
      NETWORK_PREFIX = 'Network Prefix'
11 12
      NETWORK_FROM = 'From'
12 13
      NETWORK_TO = 'To'
13 14
      DOMAINS = 'Domains'
......
20 21
      VLAN_ID = 'VLAN ID'
21 22

  
22 23
      def export(csv)
23
        csv << [NAME, ORGANIZATIONS, LOCATIONS, NETWORK, NETWORK_MASK,
24
        csv << [NAME, ORGANIZATIONS, LOCATIONS, NETWORK, NETWORK_MASK, NETWORK_PREFIX,
24 25
                NETWORK_FROM, NETWORK_TO, DOMAINS, GATEWAY, DHCP_PROXY, TFTP_PROXY, DNS_PROXY,
25 26
                DNS_PRIMARY, DNS_SECONDARY, VLAN_ID]
26 27
        @api.resource(:subnets).call(:index, {:per_page => 999999})['results'].each do |subnet|
......
31 32
          locations = export_column(subnet, 'locations', 'name')
32 33
          network = subnet['network']
33 34
          network_mask = subnet['mask']
35
          network_prefix = subnet['cidr']
34 36
          network_from = subnet['from']
35 37
          network_to = subnet['to']
36 38
          domains = export_column(subnet, 'domains', 'name')
......
41 43
          dns_primary = subnet['dns_primary']
42 44
          dns_secondary = subnet['dns_secondary']
43 45
          vlan_id = subnet['vlanid']
44
          csv << [name, organizations, locations, network, network_mask,
46
          csv << [name, organizations, locations, network, network_mask, network_prefix,
45 47
                  network_from, network_to, domains, gateway, dhcp_proxy, tftp_proxy, dns_proxy,
46 48
                  dns_primary, dns_secondary, vlan_id]
47 49
        end
......
59 61
      end
60 62

  
61 63
      def create_subnets_from_csv(line)
64
        return if option_organization && line[ORGANIZATION] != option_organization
65

  
62 66
        line[DOMAINS] = (CSV.parse_line(line[DOMAINS]) || []).collect do |domain|
63 67
          foreman_domain(:name => domain)
64 68
        end
65 69

  
66 70
        count(line[COUNT]).times do |number|
67 71
          name = namify(line[NAME], number)
72
          params = {
73
            'subnet' => {
74
              'name' => name,
75
              'network' => line[NETWORK],
76
              'mask' => line[NETWORK_MASK],
77
              'from' => line[NETWORK_FROM],
78
              'to' => line[NETWORK_TO],
79
              'domain_ids' => line[DOMAINS],
80
              'tftp_id' => foreman_smart_proxy(:name => line[TFTP_PROXY]),
81
              'dns_id' => foreman_smart_proxy(:name => line[DNS_PROXY]),
82
              'dhcp_id' => foreman_smart_proxy(:name => line[DHCP_PROXY])
83
            }
84
          }
68 85
          if !@existing.include? name
69
            print "Creating subnet '#{name}'..." if option_verbose?
70
            id = @api.resource(:subnets).call(:create, {
71
                'subnet' => {
72
                  'name' => name,
73
                  'network' => line[NETWORK],
74
                  'mask' => line[NETWORK_MASK],
75
                  #'from' => line[NETWORK_FROM],
76
                  #'to' => line[NETWORK_TO],
77
                  #'domain_ids' => line[DOMAINS]
78
                }
79
            })['id']
86
            print _("Creating subnet '%{name}'...") % {:name => name} if option_verbose?
87
            id = @api.resource(:subnets).call(:create, params)['id']
80 88
          else
81
            print "Updating subnet '#{name}'..." if option_verbose?
82
            id = @api.resource(:subnets).call(:update, {
83
                'id' => @existing[name],
84
                'subnet' => {
85
                    'name' => name,
86
                    'network' => line[NETWORK],
87
                    'mask' => line[NETWORK_MASK],
88
                    'from' => line[NETWORK_FROM],
89
                    'to' => line[NETWORK_TO],
90
                    'domain_ids' => line[DOMAINS]
91
                }
92
            })['id']
89
            print _("Updating subnet '%{name}'...") % {:name => name} if option_verbose?
90
            params['id'] = @existing[name]
91
            id = @api.resource(:subnets).call(:update, params)['id']
93 92
          end
94 93

  
95
          # Update associated resources
96 94
          associate_organizations(id, line[ORGANIZATIONS], 'subnet')
97 95
          associate_locations(id, line[LOCATIONS], 'subnet')
98 96

  
99
          print "done\n" if option_verbose?
97
          puts _("done") if option_verbose?
100 98
        end
101 99
      end
102 100
    end

Also available in: Unified diff