Class: Ubalo::ContainerProcess

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/ubalo/container_process.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

append_config, columns, debug_mode?, decode_content, get_targz, indent, login_suggestion, normalize_pod_name, pluralize, put_targz, read_config, time_ago_in_words, write_config

Constructor Details

#initialize(account) ⇒ ContainerProcess

Returns a new instance of ContainerProcess.



13
14
15
# File 'lib/ubalo/container_process.rb', line 13

def initialize()
  @account = 
end

Instance Attribute Details

#exit_resultObject (readonly)

Returns the value of attribute exit_result.



11
12
13
# File 'lib/ubalo/container_process.rb', line 11

def exit_result
  @exit_result
end

#exit_typeObject (readonly)

Returns the value of attribute exit_type.



11
12
13
# File 'lib/ubalo/container_process.rb', line 11

def exit_type
  @exit_type
end

#outputObject (readonly)

Returns the value of attribute output.



11
12
13
# File 'lib/ubalo/container_process.rb', line 11

def output
  @output
end

#ssh_uriObject (readonly)

Returns the value of attribute ssh_uri.



11
12
13
# File 'lib/ubalo/container_process.rb', line 11

def ssh_uri
  @ssh_uri
end

#stateObject (readonly)

Returns the value of attribute state.



11
12
13
# File 'lib/ubalo/container_process.rb', line 11

def state
  @state
end

Class Method Details

.create_with_json(account, json) ⇒ Object



5
6
7
8
9
# File 'lib/ubalo/container_process.rb', line 5

def self.create_with_json(, json)
  container_process = new()
  container_process.update_attributes(json)
  container_process
end

Instance Method Details

#parse_datetime(string) ⇒ Object



62
63
64
65
66
# File 'lib/ubalo/container_process.rb', line 62

def parse_datetime(string)
  if string
    DateTime.parse(string)
  end
end

#pretty_runtimeObject



56
57
58
59
60
# File 'lib/ubalo/container_process.rb', line 56

def pretty_runtime
  if @runtime
    "%2.1f s" % @runtime
  end
end

#printable_resultObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ubalo/container_process.rb', line 44

def printable_result
  s = ""
  s << "status: #{exit_result}\n"
  s << "runtime: #{pretty_runtime}\n"

  if output and output.length > 0
    s << "stdout/stderr:\n"
    s << Util.indent(output)
  end
  s
end

#sshObject



28
29
30
31
32
33
34
# File 'lib/ubalo/container_process.rb', line 28

def ssh
  unless @ssh_uri
    raise Ubalo::Error, "Unable to ssh: no connection information available"
  end
  uri = URI.parse(@ssh_uri)
  system("ssh", "-o", "StrictHostKeyChecking=no", "-o", "CheckHostIp=no", "-p", uri.port.to_s, "#{uri.user}@#{uri.host}")
end

#tail(tailer, message) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/ubalo/container_process.rb', line 36

def tail(tailer, message)
  logger.poll do
    result = yield
    tailer.update(message, @output)
    result
  end
end

#update_attributes(attributes) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/ubalo/container_process.rb', line 17

def update_attributes(attributes)
  @state = attributes.fetch('state')
  @runtime = attributes.fetch('runtime')
  @started_at = parse_datetime(attributes.fetch('started_at'))
  @stopped_at = parse_datetime(attributes.fetch('stopped_at'))
  @exit_type = attributes.fetch('exit_type')
  @exit_result = attributes.fetch('exit_result')
  @output = attributes.fetch('output')
  @ssh_uri = attributes.fetch('ssh_uri')
end