Class: Puppet::Provider::XLReleaseRestProvider

Inherits:
Puppet::Provider
  • Object
show all
Defined in:
lib/puppet/provider/xlr_rest_provider.rb

Instance Method Summary collapse

Instance Method Details

#ci_exists?(id) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/puppet/provider/xlr_rest_provider.rb', line 24

def ci_exists?(id)

    output = rest_get("repository/tree/#{id}")

    case output
      when /not found/
        return false
      else

      return true
    end

end

#execute_rest(service, method, body = '') ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/puppet/provider/xlr_rest_provider.rb', line 38

def execute_rest(service, method, body='')
  uri = URI.parse("#{resource[:rest_url]}/#{service}")
  http = Net::HTTP.new(uri.host, uri.port)
  request = case method
              when 'get'    then Net::HTTP::Get.new(uri.request_uri)
              when 'post'   then Net::HTTP::Post.new(uri.request_uri)
              when 'put'    then Net::HTTP::Put.new(uri.request_uri)
              when 'delete' then Net::HTTP::Delete.new(uri.request_uri)
            end

  #p request.pretty_print_inspect

  request.basic_auth(uri.user, uri.password) if uri.user and uri.password
  request.body = body unless body == ''
  request.content_type = 'application/json'

  begin
    res = http.request(request)

    raise Puppet::Error, "cannot send request to deployit server #{res.code}/#{res.message}:#{res.body}" unless res.is_a?(Net::HTTPSuccess)
    return res.body
  rescue Exception => e
    return e.message
  end

end

#rest_delete(service) ⇒ Object



20
21
22
# File 'lib/puppet/provider/xlr_rest_provider.rb', line 20

def rest_delete(service)
  execute_rest(service, 'delete')
end

#rest_get(service) ⇒ Object



8
9
10
# File 'lib/puppet/provider/xlr_rest_provider.rb', line 8

def rest_get(service)
  execute_rest(service, 'get')
end

#rest_post(service, body = '') ⇒ Object



12
13
14
# File 'lib/puppet/provider/xlr_rest_provider.rb', line 12

def rest_post(service, body='')
  execute_rest(service, 'post', body)
end

#rest_put(service, body = '') ⇒ Object



16
17
18
# File 'lib/puppet/provider/xlr_rest_provider.rb', line 16

def rest_put(service, body='')
  execute_rest(service, 'put', body)
end

#to_hash(json) ⇒ Object



72
73
74
# File 'lib/puppet/provider/xlr_rest_provider.rb', line 72

def to_hash(json)
  JSON.parse(json)
end

#to_j(id, type, properties) ⇒ Object



66
67
68
69
70
# File 'lib/puppet/provider/xlr_rest_provider.rb', line 66

def to_j(id, type, properties)

  {"id" => id, "type" => type}.merge(properties).to_json

end