This Project Has Not Released Any Files
We assume that there are machines organized like below.
Here, we perform operations below to all managed machines.
Code for above operations can be written like below.
- #! /bin/ruby
- require "rubygems"
- require "svengali"
- user_name = "bob"
- password = "bar"
- # use IP addres due to access by sequence number
- IPADDR_BASE = CLibIPAddr.new("192.168.2.1")
- MACHINE_NUM = 3
- nodes = Array.new(MACHINE_NUM)
- tmp_ipaddr = IPADDR_BASE.dup()
- MACHINE_NUM.times{ |n|
- # FQDN machine name can be also passed
- nodes[n] = Machine.new(tmp_ipaddr)
- nodes[n].set_auth_info(user_name,password)
- # establishes a transport for command execution via SSH
- nodes[n].establish_session()
- # install package
- # package system used is default one(yum)
- puts nodes[n].install_package("openmpi")
- tmp_ipaddr.inc!()
- }
- nodes.each{ |a_node|
- # edit configuration file( sshd_config )
- sshd_conf = a_node.get_config_file("/etc/ssh/sshd_config")
- sshd_conf.replace_col("X11Forwarding yes","X11Forwarding no")
- sshd_conf.save()
- }
- # start experiment
- nodes.each{ |a_node|
- # bonus
- puts a_node.exec!("uname -a")
- # executes experiment script
- puts a_node.exec_script_on("/home/taro/scenario.sh","","/home/taro")
- }
Execution result
$ruby test_svengali.rb ( --- omitted yum outputs --- ) Linux sunagimo01 2.6.32-22-generic #33-Ubuntu SMP Wed Jan 21 10:44:23 EST 2009 sunagimo01: Hello svengali!! Linux sunagimo02 2.6.32-22-generic #33-Ubuntu SMP Wed Jan 21 10:44:35 EST 2009 sunagimo02: Hello svengali!! Linux sunagimo03 2.6.32-22-generic #33-Ubuntu SMP Wed Jan 21 10:44:47 EST 2009 sunagimo03: Hello svengali!!
Operation of network configuration can be written like below.
- ( --- codes same as former sample code are omitted --- )
- gateway_addr = CLibIPAddr.new("xxx.xxx.xxx.xxx")
- dns_addr = CLibIPAddr.new("xxx.xxx.xxx.xxx")
- netmask_addr = CLibIPAddr.new("xxx.xxx.xxx.xxx")
- CHANGED_IPADDR_BASE = CLibIPAddr.new("xxx.xxx.xxx.xxx")
- tmp_ipaddr = CHANGED_IPADDR_BASE.dup()
- nodes.each{ |a_node|
- # set a IP address in sequence
- a_node.config_nw_interface(:ipaddr => tmp_ipaddr , :interface => "eth0", :netmask => netmask_addr, :gateway => gateway_addr, :onboot => "yes")
- a_node.set_resolver(:primary_ip => dns_addr)
- # reload network configuration of each machine
- # returns after 10 seconds ( use timeout due to avoid implementation problem of Machine class around SSH connection)
- a_node.exec!("/sbin/service network restart", 10)
- tmp_ipaddr.inc!()
- }
- # reestablish connection with using new addresses
- tmp_ipaddr = CHANGED_IPADDR_BASE.dup()
- nodes_changed = Array.new(MACHINE_NUM)
- nodes_changed.each{ |a_node|
- a_node = Machine.new(tmp_ipaddr.to_s)
- a_node.set_auth_info(user_name,password)
- a_node.establish_session()
- tmp_ipaddr.inc!()
- puts a_node.exec!("/sbin/ifconfig eth0")
- }