Project

General

Profile

Revision c2496839

Added by Thomas McKay over 8 years ago

Checks /api/status for SAM (Headpin)

View differences:

lib/hammer_cli_csv/base.rb
60 60
                                       :api_version => 2
61 61
                                     })
62 62

  
63
      @server_status = check_server_status
64

  
63 65
      option_csv_export? ? export : import
64 66
      HammerCLI::EX_OK
65 67
    end
66 68

  
69
    def check_server_status
70
      server = option_server || HammerCLI::Settings.get(:csv, :host)
71
      username = option_username || HammerCLI::Settings.get(:csv, :username)
72
      password = option_password || HammerCLI::Settings.get(:csv, :password)
73
      url = "#{server}/api/status"
74
      uri = URI(url)
75
      server_status = Net::HTTP.start(uri.host, uri.port,
76
                               :use_ssl => uri.scheme == 'https',
77
                               :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
78
        request = Net::HTTP::Get.new uri.request_uri
79
        request.basic_auth(username, password)
80
        response = http.request(request)
81
        JSON.parse(response.body)
82
      end
83

  
84
      server_status
85
    end
86

  
67 87
    def namify(name_format, number = 0)
68 88
      if name_format.index('%')
69 89
        name = name_format % number
......
254 274
                                               'search' => "role=\"#{role}\""
255 275
                                             })['results']
256 276
      filters.each do |filter|
257
        resource_type = filter['resource_type'].split(':')[-1] # To remove "Katello::" when present
277
        resource_type = (filter['resource_type'] || '').split(':')[-1] # To remove "Katello::" when present
258 278
        return filter['id'] if resource_type == resource && filter['search'] == search
259 279
      end
260 280

  

Also available in: Unified diff