Class: Bcome::Node::Kube::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/objects/node/kube/base.rb

Direct Known Subclasses

Container, Estate, Namespace, Pod

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kube_wrap, config = {}) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
# File 'lib/objects/node/kube/base.rb', line 9

def initialize(kube_wrap, config = {})
  @kube_wrap = kube_wrap
  @config = config
  @resources = []
end

Instance Attribute Details

#resourcesObject (readonly)

Returns the value of attribute resources.



7
8
9
# File 'lib/objects/node/kube/base.rb', line 7

def resources
  @resources
end

Instance Method Details

#buildObject



23
24
25
26
# File 'lib/objects/node/kube/base.rb', line 23

def build
  child_node_lookup_result = run(get_child_node_command)
  parse(child_node_lookup_result)
end

#get_child_config_from_line(*_params) ⇒ Object



46
47
48
# File 'lib/objects/node/kube/base.rb', line 46

def get_child_config_from_line(*_params)
  raise 'should be overidden'
end

#get_child_node_commandObject



42
43
44
# File 'lib/objects/node/kube/base.rb', line 42

def get_child_node_command
  raise 'should be overriden'
end

#parentObject



15
16
17
# File 'lib/objects/node/kube/base.rb', line 15

def parent
  @config[:parent]
end

#parse(child_node_lookup_result) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/objects/node/kube/base.rb', line 28

def parse(child_node_lookup_result)
  # Get the output
  output = child_node_lookup_result.stdout
  # Remove the title & form array
  data = output.remove_lines(1).split("\n")

  structured_data = {}
  data.each do |raw_namespace_line|
    child_config = get_child_config_from_line(raw_namespace_line)
    child_config.merge!(parent: self)
    @resources << child_node_klass.new(@kube_wrap, child_config)
  end
end

#run(command) ⇒ Object



19
20
21
# File 'lib/objects/node/kube/base.rb', line 19

def run(command)
  @kube_wrap.run(command)
end