Commit 3467bb72 authored by Gaetan SIMO's avatar Gaetan SIMO
Browse files

[orsay] DNS over SSH.

parent 701ec9bd
source :rubygems
gem 'json_pure', '~> 1.5'
gem 'net-ssh'
\ No newline at end of file
gem 'net-ssh'
{
"description": "",
"email_contact": null,
"latitude": 48.7,
"location": "Orsay, France",
"longitude": 2.2,
"name": "Orsay",
"security_contact": null,
"sys_admin_contact": null,
"type": "site",
"uid": "orsay"
"uid": "orsay",
"user_support_contact": null,
"web": null
}
\ No newline at end of file
......@@ -10,9 +10,8 @@ def get_switch_for_node(switches,id)
lookup('orsay-network',"switch-nil").merge({:nodes=>[0,0]})
end
site :orsay do |site_uid|
site :orsay, {:discard_content => true} do |site_uid|
ssh = Net::SSH.start("frontend.#{site_uid}.grid5000.fr","g5kadmin")
cluster :gdx do |cluster_uid|
model "IBM eServer 326m"
created_at nil
......
require 'net/ssh'
site :orsay do |site_uid|
def switch_match_node(switch,id); switch != nil and (switch[:nodes][0] <= id and id <= switch[:nodes][1]); end
def get_switch_for_node(switches,id)
switches.each{|k,v|
arr = v.split(",").map{|s| s.to_i}
next if id < arr[0] or arr[1] < id
return lookup('orsay-network',k).merge({:nodes=>arr})
}
lookup('orsay-network',"switch-nil").merge({:nodes=>[0,0]})
end
site :orsay, {:discard_content => true} do |site_uid|
ssh = Net::SSH.start("frontend.#{site_uid}.grid5000.fr","g5kadmin")
cluster :netgdx do |cluster_uid|
......
site :orsay do |site_uid|
name "Orsay"
location "Orsay, France"
location "Orsay, France"
web
description ""
latitude 48.7000
......
......@@ -59,6 +59,48 @@ module G5K
def method_missing(method, *args)
@context.recursive_merge!(method.to_sym => args.first)
end
# Remotly execute commands, and retrieve stdout, stderr, exit code and exit signal.
def ssh_exec!(ssh, command)
stdout_data = ""
stderr_data = ""
exit_code = nil
exit_signal = nil
ssh.open_channel do |channel|
channel.exec(command) do |ch, success|
unless success
abort "FAILED: couldn't execute command (ssh.channel.exec)"
end
channel.on_data do |ch,data|
stdout_data+=data
end
channel.on_extended_data do |ch,type,data|
stderr_data+=data
end
channel.on_request("exit-status") do |ch,data|
exit_code = data.read_long
end
channel.on_request("exit-signal") do |ch, data|
exit_signal = data.read_long
end
end
end
ssh.loop
[stdout_data, stderr_data, exit_code, exit_signal]
end
# Get the IP address corresponding to the host fqdn throught ssh channel
def dns_lookup_through_ssh(ssh,fqdn)
results = ssh_exec! ssh, "host #{fqdn}"
if results[2] == 0
results[0].split(" ").reverse[0]
else
fail "Failed to get ip address of '#{fqdn}' : #{results[1]}"
end
end
def dns_lookup(network_address)
Resolv.getaddress(network_address)
......@@ -93,6 +135,22 @@ module G5K
raise ArgumentError, "Cannot fetch the values for '#{keys.inspect}' in the input file '#{filename}'. The config files you gave to me are: '#{config.keys.inspect}'."
end
end
# This method is used exclusivly for environments. Example:
# environment 'squeeze-x64-xen-0.8' do
# available_on %w{bordeaux grenoble lille lyon nancy orsay rennes sophia toulouse}
# end
def available_on(sites_uid)
env_uid = @context[:uid]
old_context = @context
@context = @data
sites_uid.each{|site_uid|
site site_uid.to_sym, {:discard_content => true} do
environment "#{env_uid}", :refer_to => "grid5000/environments/#{env_uid}"
end
}
@context = old_context
end
# This doesn't work with Ruby < 1.8.7. Replaced by a call to build_context (see below).
#
# %w{site cluster environment node service}.each do |method|
......@@ -136,17 +194,6 @@ module G5K
def service(uid, *options, &block)
build_context(:services, uid, *options, &block)
end
def available_on(sites_uid)
env_uid = @context[:uid]
old_context = @context
@context = @data
sites_uid.each{|site_uid|
site site_uid.to_sym, {:discard_content => true} do
environment "#{env_uid}", :refer_to => "grid5000/environments/#{env_uid}"
end
}
@context = old_context
end
def build_context(key, uid, *options, &block)
type = key.to_s.chop
uid = uid.to_s
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment