Class: ProxyAPI::Salt

Inherits:
Resource
  • Object
show all
Defined in:
app/lib/proxy_api/salt.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Salt

Returns a new instance of Salt.



3
4
5
6
# File 'app/lib/proxy_api/salt.rb', line 3

def initialize(args)
  @url = "#{args[:url]}/salt/"
  super args
end

Instance Method Details

#autosign_create(name) ⇒ Object



14
15
16
17
18
# File 'app/lib/proxy_api/salt.rb', line 14

def autosign_create(name)
  parse(post('', "autosign/#{CGI.escape(name)}"))
rescue StandardError => e
  raise ProxyException.new(url, e, N_('Unable to set Salt autosign hostname for %s'), name)
end

#autosign_create_key(key) ⇒ Object



28
29
30
31
32
# File 'app/lib/proxy_api/salt.rb', line 28

def autosign_create_key(key)
  parse(post('', "autosign_key/#{CGI.escape(key)}"))
rescue StandardError => e
  raise ProxyException.new(url, e, N_('Unable to create Salt autosign key %s'), key)
end

#autosign_listObject



8
9
10
11
12
# File 'app/lib/proxy_api/salt.rb', line 8

def autosign_list
  parse(get('autosign'))
rescue StandardError => e
  raise ProxyException.new(url, e, N_('Unable to fetch autosign list'))
end

#autosign_remove(name) ⇒ Object



20
21
22
23
24
25
26
# File 'app/lib/proxy_api/salt.rb', line 20

def autosign_remove(name)
  parse(delete("autosign/#{CGI.escape(name)}"))
rescue RestClient::ResourceNotFound
  true # entry doesn't exists anyway
rescue StandardError => e
  raise ProxyException.new(url, e, N_('Unable to delete Salt autosign hostname for %s'), name)
end

#autosign_remove_key(key) ⇒ Object



34
35
36
37
38
39
40
# File 'app/lib/proxy_api/salt.rb', line 34

def autosign_remove_key(key)
  parse(delete("autosign_key/#{CGI.escape(key)}"))
rescue RestClient::ResourceNotFound
  true # entry doesn't exists anyway
rescue StandardError => e
  raise ProxyException.new(url, e, N_('Unable to delete Salt autosign key %s'), key)
end

#environments_listObject



42
43
44
45
46
# File 'app/lib/proxy_api/salt.rb', line 42

def environments_list
  parse(get('environments'))
rescue StandardError => e
  raise ProxyException.new(url, e, N_('Unable to fetch Salt environments list'))
end

#highstate(name) ⇒ Object



86
87
88
89
90
# File 'app/lib/proxy_api/salt.rb', line 86

def highstate(name)
  parse(post('', "highstate/#{name}"))
rescue StandardError => e
  raise ProxyException.new(url, e, N_('Unable to run Salt state.highstate for %s'), name)
end

#key_accept(name) ⇒ Object



66
67
68
69
70
# File 'app/lib/proxy_api/salt.rb', line 66

def key_accept(name)
  parse(post('', "key/#{name}"))
rescue StandardError => e
  raise ProxyException.new(url, e, N_('Unable to accept Salt key for %s'), name)
end

#key_delete(name) ⇒ Object



78
79
80
81
82
83
84
# File 'app/lib/proxy_api/salt.rb', line 78

def key_delete(name)
  parse(delete("key/#{name}"))
rescue RestClient::ResourceNotFound
  true
rescue StandardError => e
  raise ProxyException.new(url, e, N_('Unable to delete Salt key for %s'), name)
end

#key_listObject



60
61
62
63
64
# File 'app/lib/proxy_api/salt.rb', line 60

def key_list
  parse(get('key'))
rescue StandardError => e
  raise ProxyException.new(url, e, N_('Unable to fetch Salt key list'))
end

#key_reject(name) ⇒ Object



72
73
74
75
76
# File 'app/lib/proxy_api/salt.rb', line 72

def key_reject(name)
  parse(delete("key/reject/#{name}"))
rescue StandardError => e
  raise ProxyException.new(url, e, N_('Unable to reject Salt key for %s'), name)
end

#states_listObject



48
49
50
51
52
53
54
55
56
57
58
# File 'app/lib/proxy_api/salt.rb', line 48

def states_list
  states = {}

  environments_list.each do |environment|
    states[environment] = parse(get("environments/#{CGI.escape(environment)}"))
  end

  states
rescue StandardError => e
  raise ProxyException.new(url, e, N_('Unable to fetch Salt states list'))
end