Class: ForemanMco::McoProxyApi

Inherits:
ProxyAPI::Resource
  • Object
show all
Defined in:
app/models/services/foreman_mco/mco_proxy_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ McoProxyApi

Returns a new instance of McoProxyApi.



2
3
4
5
# File 'app/models/services/foreman_mco/mco_proxy_api.rb', line 2

def initialize args
  @url     = args[:url] + "/mcollective"
  super args
end

Instance Method Details

#install_package(package_name, filters) ⇒ Object



11
12
13
# File 'app/models/services/foreman_mco/mco_proxy_api.rb', line 11

def install_package(package_name, filters)
  parse(resource["packages/#{package_name}"].post({}, 'params' => {:filters => filters}))
end

#parse(response) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'app/models/services/foreman_mco/mco_proxy_api.rb', line 47

def parse(response)
    if response and response.code >= 200 and response.code < 300
      response.body.present? ? (JSON.parse(response.body) rescue response.body) : true
    else
      false
    end
  rescue => e
    logger.warn "Failed to parse response: #{response} -> #{e}"
    false
end

#ping(filters) ⇒ Object



43
44
45
# File 'app/models/services/foreman_mco/mco_proxy_api.rb', line 43

def ping(filters)
  parse(resource["ping"].get('params' => {:filters => filters}))
end

#puppet_disable(filters) ⇒ Object



39
40
41
# File 'app/models/services/foreman_mco/mco_proxy_api.rb', line 39

def puppet_disable(filters)
  parse(resource["puppet/disable"].post({}, 'params' => {:filters => filters}))
end

#puppet_enable(filters) ⇒ Object



35
36
37
# File 'app/models/services/foreman_mco/mco_proxy_api.rb', line 35

def puppet_enable(filters)
  parse(resource["puppet/enable"].post({}, 'params' => {:filters => filters}))
end

#puppet_runonce(filters) ⇒ Object



31
32
33
# File 'app/models/services/foreman_mco/mco_proxy_api.rb', line 31

def puppet_runonce(filters)
  parse(resource["puppet/runonce"].post({}, 'params' => {:filters => filters}))
end

#service_status(service_name, filters) ⇒ Object



19
20
21
# File 'app/models/services/foreman_mco/mco_proxy_api.rb', line 19

def service_status(service_name, filters)
  parse(resource[ "services/#{service_name}"].get('params' => {:filters => filters}))
end

#start_service(service_name, filters) ⇒ Object



23
24
25
# File 'app/models/services/foreman_mco/mco_proxy_api.rb', line 23

def start_service(service_name, filters)
  parse(resource["services/#{service_name}/start"].post({}, 'params' => {:filters => filters}))
end

#stop_service(service_name, filters) ⇒ Object



27
28
29
# File 'app/models/services/foreman_mco/mco_proxy_api.rb', line 27

def stop_service(service_name, filters)
  parse(resource["services/#{service_name}/stop"].post({}, 'params' => {:filters => filters}))
end

#testObject



7
8
9
# File 'app/models/services/foreman_mco/mco_proxy_api.rb', line 7

def test
  parse(resource["test/test_command"].post(:name => "blah", 'params' => {:filters => filters}))
end

#uninstall_package(package_name, filters) ⇒ Object



15
16
17
# File 'app/models/services/foreman_mco/mco_proxy_api.rb', line 15

def uninstall_package(package_name, filters)
  parse(resource["packages/#{package_name}"].delete('params' => {:filters => filters}))
end