Class: Distem::Daemon::Admin

Inherits:
Object
  • Object
show all
Defined in:
lib/distem/daemon/admin.rb

Overview

Class that allow to manage daemon administration methods such as initializing another physical node

Constant Summary

PATH_DISTEMD_LOG =

The file used to store the stdout and stderr logs for the launched daemons

File.join(Node::Admin::PATH_DISTEM_LOGS,"distemd-pnode.log")
SSH_USER =

Default SSH user

ENV['USER']
PATH_SSH =

Paths to the SSH key files

File.join(File.expand_path("~#{SSH_USER}"),'.ssh')

Class Method Summary (collapse)

Class Method Details

+ (Object) get_vnetwork_addr(vnetwork)

Get the address to use on a virtual network for the ssh tasks (the last address of each virtual network is allocated to the main daemon to contact the virtual nodes (i.e. to use vnode_run)

Attributes

  • vnetwork The VNetwork object



101
102
103
# File 'lib/distem/daemon/admin.rb', line 101

def self.get_vnetwork_addr(vnetwork)
  vnetwork.address.last.to_string
end

+ (Object) pnode_run_server(pnode)

Run a daemon on a distant server (physical node)

Attributes

  • pnode The PNode object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/distem/daemon/admin.rb', line 46

def self.pnode_run_server(pnode)
  raise unless pnode.is_a?(Resource::PNode)

  if pnode.status == Resource::Status::INIT
    begin
      Net::SSH.start(pnode.address.to_s, pnode.ssh_user, :keys => ssh_keys_priv, :password => pnode.ssh_password) do |ssh|
        ssh.exec!("mkdir -p #{Node::Admin::PATH_DISTEM_LOGS}")
        ssh.exec!("echo '' > #{Lib::Shell::PATH_DISTEMD_LOG_CMD}")
        str = ssh.exec!("lsof -Pnl -i4 | grep ':4568 '")
        if !str || (str == "")
          ssh.exec!("LANG=C distemd &>#{PATH_DISTEMD_LOG} &")
          launched = []
          until launched and !launched.empty?
            launched = ssh.exec!("lsof -Pnl -i4 | grep ':4568 '")
            sleep(0.1)
          end
          retries = 20
          cl = NetAPI::Client.new(pnode.address, 4568)
          begin
            cl.pnode_info()
          rescue Lib::UnavailableResourceError
            sleep(0.2)
            retries -= 1
            retry if retries >= 0
          end
        end
      end
    rescue Net::SSH::AuthenticationFailed, Errno::ENETUNREACH
      raise Lib::UnreachableResourceError, pnode.address.to_s
    end
  end
end

+ (Object) ssh_keys_priv

Get current user SSH private keys paths (looking in PATH_SSH directory)

Returns

Array of String object



31
32
33
34
35
36
37
38
39
40
# File 'lib/distem/daemon/admin.rb', line 31

def self.ssh_keys_priv
  ret = []
  begin
    ret = Dir.entries(PATH_SSH).select do |v|
      v =~ /^id.*$/ and File.extname(v) =~  /^(?!\.pub)$/
    end if File.directory?(PATH_SSH)
  rescue ArgumentError
  end
  return ret.collect!{|v| File.join(PATH_SSH,v)}
end

+ (Object) ssh_keys_pub

Get current user SSH public keys paths (looking in PATH_SSH directory)

Returns

Array of String object



18
19
20
21
22
23
24
25
26
# File 'lib/distem/daemon/admin.rb', line 18

def self.ssh_keys_pub
  ret = []
  begin
    ret = Dir.entries(PATH_SSH).select {|v| v =~ /^id.*\.pub$/} \
      if File.directory?(PATH_SSH)
  rescue ArgumentError
  end
  return ret.collect!{|v| File.join(PATH_SSH,v)}
end

+ (Object) vnode_run(vnode, command)

Execute a specific command on a (runned) virtual node using ssh

Attributes

  • vnode The VNode object

  • command The command (String)



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/distem/daemon/admin.rb', line 84

def self.vnode_run(vnode,command)
  raise unless vnode.is_a?(Resource::VNode)
  raise unless vnode.vifaces[0].is_a?(Resource::VIface)
  raise unless vnode.vifaces[0].attached?

  ret = ""
  Net::SSH.start(vnode.vifaces[0].address.to_s, 'root', :keys => ssh_keys_priv, :password => 'root') do |ssh|
    ret = ssh.exec!(command)
  end

  return ret
end