def rest(method, uri)
      log_level = @options['log_level'] == :warn ? :error : @options['log_level'].to_sym # Default to :error
      client_setup('log_level' => log_level)
      uri_copy = uri.dup
      uri_copy.prepend('/') unless uri_copy.start_with?('/')
      if @options['data']
        begin
          data = { body: JSON.parse(@options['data']) }
        rescue JSON::ParserError => e
          fail_nice("Failed to parse data as JSON\n#{e.message}")
        end
      end
      data ||= {}
      response = @client.rest_api(method, uri_copy, data)
      if response.code.to_i.between?(200, 299)
        case @options['format']
        when 'yaml'
          puts JSON.parse(response.body).to_yaml
        when 'json'
          puts JSON.pretty_generate(JSON.parse(response.body))
        else # raw
          puts response.body
        end
      else
        body = JSON.pretty_generate(JSON.parse(response.body)) rescue response.body
        fail_nice("Request failed: #{response.inspect}\nHeaders: #{response.to_hash}\nBody: #{body}")
      end
    rescue OneviewSDK::InvalidRequest => e
      fail_nice(e.message)
    end
def rest(method, uri)
      log_level = @options['log_level'] == :warn ? :error : @options['log_level'].to_sym # Default to :error
      client_setup('log_level' => log_level)
      uri_copy = uri.dup
      uri_copy.prepend('/') unless uri_copy.start_with?('/')
      if @options['data']
        begin
          data = { body: JSON.parse(@options['data']) }
        rescue JSON::ParserError => e
          fail_nice("Failed to parse data as JSON\n#{e.message}")
        end
      end
      data ||= {}
      response = @client.rest_api(method, uri_copy, data)
      if response.code.to_i.between?(200, 299)
        case @options['format']
        when 'yaml'
          puts JSON.parse(response.body).to_yaml
        when 'json'
          puts JSON.pretty_generate(JSON.parse(response.body))
        else # raw
          puts response.body
        end
      else
        body = JSON.pretty_generate(JSON.parse(response.body)) rescue response.body
        fail_nice("Request failed: #{response.inspect}\nHeaders: #{response.to_hash}\nBody: #{body}")
      end
    rescue OneviewSDK::InvalidRequest => e
      fail_nice(e.message)
    end
Make REST call to the OneView API