Top Level Namespace

Defined Under Namespace

Modules: Zygote

Instance Method Summary collapse

Instance Method Details

#clean_params(params) ⇒ Object



27
28
29
30
31
# File 'lib/zygote/util.rb', line 27

def clean_params(params)
  params.delete_if { |x, _| x == 'splat' || x == 'captures' }
  params = params.map { |k, v| [k, v.is_a?(Hash) ? encode64(v) : v] }.to_h
  params
end

#compute_sku(vendor, serial, board_serial) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/zygote/util.rb', line 5

def compute_sku(vendor, serial, board_serial)
  # Sanitize params
  strip_pattern = /[^-^:\p{Alnum}]/
  serial        = (serial || '').gsub(strip_pattern, '')
  vendor        = (vendor || '').gsub(strip_pattern, '')
  board_serial  = (board_serial || '').gsub(strip_pattern, '')

  serial = board_serial unless board_serial.empty?

  sku = case vendor
        when 'DellInc'
          'DEL'
        when 'Supermicro'
          'SPM'
        else
          'UKN' # unknown manufacturer
        end

  sku = "#{sku}-#{serial}"
  sku
end

#decode64(content) ⇒ Object



37
38
39
# File 'lib/zygote/util.rb', line 37

def decode64(content)
  JSON.load(Base64.decode64(content))
end

#discover_domainObject



45
46
47
# File 'lib/zygote/util.rb', line 45

def discover_domain
  Socket.gethostname.split('.')[1..-1].join('.')
end

#encode64(content) ⇒ Object



33
34
35
# File 'lib/zygote/util.rb', line 33

def encode64(content)
  Base64.encode64(JSON.pretty_generate(content)).gsub(/\n|=/, '')
end

#init_sighandlersObject



45
46
47
48
49
50
51
52
53
# File 'lib/zygote/server.rb', line 45

def init_sighandlers
  clean_quit = lambda do
    EM.stop
    exit
  end

  Signal.trap('INT') { clean_quit.call }
  Signal.trap('TERM') { clean_quit.call }
end

#kernel_params(hash) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/zygote/util.rb', line 49

def kernel_params(hash)
  hash.map do |k, v|
    if v.is_a? Array
      v.map { |x| "#{k}=#{x}" }
    else
      "#{k}=#{v}"
    end
  end.join(' ')
end

#my_ipObject



41
42
43
# File 'lib/zygote/util.rb', line 41

def my_ip
  Socket.ip_address_list.find { |x| x.ipv4? && !x.ipv4_loopback? }.ip_address
end