Class: Rancher::Api::Instance::Action

Inherits:
Object
  • Object
show all
Includes:
Her::Model
Defined in:
lib/rancher/api/models/instance/action.rb

Overview

Few possible actions are:

- execute shell command
- render logs
- restart

Instance Method Summary collapse

Instance Method Details

#run!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rancher/api/models/instance/action.rb', line 17

def run!
  uri = URI.parse(url)
  uri.userinfo = "#{Rancher::Api.configuration.access_key}:#{Rancher::Api.configuration.secret_key}"
  uri.query = "token=#{token}"

  self.response = []

  EM.run do
    # 15 seconds timeout in case of slow operation
    #
    EM.add_timer(15) do
      EM.stop
    end

    ws = Faye::WebSocket::Client.new(uri.to_s)

    ws.on :message do |event|
      response << Base64.decode64(event.data)
    end

    ws.on :close do |_event|
      ws = nil
      EM.stop
    end
  end

  self.response = response.join

  self
end