Module: BlackStack::Deployer::NodeModule

Includes:
Infrastructure::NodeModule
Included in:
Node
Defined in:
lib/my-ruby-deployer.rb

Overview

inherit BlackStack::Infrastructure::NodeModule, including features of deployer.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#deployment_routineObject

Returns the value of attribute deployment_routine.



25
26
27
# File 'lib/my-ruby-deployer.rb', line 25

def deployment_routine
  @deployment_routine
end

#parametersObject

Returns the value of attribute parameters.



25
26
27
# File 'lib/my-ruby-deployer.rb', line 25

def parameters
  @parameters
end

Class Method Details

.descriptor_errors(h) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/my-ruby-deployer.rb', line 53

def self.descriptor_errors(h)
  errors = BlackStack::Infrastructure::NodeModule.descriptor_errors(h)
 
  # validate: does not exist any other element in @@nodes with the same value for the parameter h[:name]
  errors << "The parameter h[:name] is not unique" if BlackStack::Deployer.nodes.select{|n| n.name == h[:name]}.length > 0 

  # validate: h[:deployment_routine] is not nil
  errors << "The parameter h[:deployment_routine] is required" if h[:deployment_routine].nil?

  # validate: h[:deployment_routine] is a string
  # This value is no longer mandatory
  #errors << "The parameter h[:deployment_routine] is not a string" unless h[:deployment_routine].is_a?(String)
  
  # return list of errors
  errors.uniq
end

.eth0_ip(insterface) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/my-ruby-deployer.rb', line 29

def self.eth0_ip(insterface)
  ret = nil
  a = `ip addr show dev #{insterface}`.scan(/inet [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/)
  if a.size > 0
    ret = a.last.to_s.gsub(/inet /, '')           
  else
    raise "Cannot get ip address of the interface #{insterface}"
  end
  ret
end

Instance Method Details

#deploy(routine_name = nil, l = nil) ⇒ Object

def to_hash



84
85
86
87
88
# File 'lib/my-ruby-deployer.rb', line 84

def deploy(routine_name=nil, l=nil)
  l = BlackStack::DummyLogger.new(nil) if l.nil?
  s = routine_name || self.deployment_routine
  BlackStack::Deployer::run_routine(self.name, s, l);
end

#eth0_ipObject

get the IP address for an interface using the ip addr command. this is a helper method for installing cockroachdb nodes.



42
43
44
45
46
47
48
49
50
51
# File 'lib/my-ruby-deployer.rb', line 42

def eth0_ip()
  ret = nil
  a = self.ssh.exec!("ip addr show dev #{parameters[:laninterface]}").scan(/inet [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/)
  if a.size > 0
    ret = a.last.to_s.gsub(/inet /, '')           
  else
    raise "Cannot get ip address of the interface #{parameters[:laninterface]}"
  end
  ret
end

#initialize(h, i_logger = nil) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/my-ruby-deployer.rb', line 70

def initialize(h, i_logger=nil)
  self.parameters = h
  errors = BlackStack::Deployer::NodeModule.descriptor_errors(h)
  raise "The node descriptor is not valid: #{errors.uniq.join(".\n")}" if errors.length > 0
  super(h, i_logger)
  self.deployment_routine = h[:deployment_routine]
end

#to_hashObject

def self.create(h)



78
79
80
81
82
# File 'lib/my-ruby-deployer.rb', line 78

def to_hash
  h = super
  h[:deployment_routine] = self.deployment_routine
  h
end