Class Machine
In: lib/svengali/machine.rb
lib/svengali/plugins/eucalyptus.rb
lib/svengali/plugins/machine_config.rb
lib/svengali/plugins/package.rb
Parent: MachineMaster

Methods

Included Modules

Config FileIO

Attributes

ssh  [R] 

Public Class methods

[Source]

# File lib/svengali/machine.rb, line 27
    def initialize(host=nil)
      if host == nil  #substitute of constructor which has no argument
      else
        @host = host.to_s()
        initialize()
      end
    end

Public Instance methods

[Source]

# File lib/svengali/machine.rb, line 35
    def cleanup
      debug_p "start cleanup instance for " + @host
      @sftp_session.close_channel()
      @ssh.close()
      debug_p "finished cleanup instance for " + @host
      # @@group.list.each {|th| th.join }
    end

:ipaddr -> CLibIPAddr : IP address which assigned to interface :interface -> string : interface name :netmask -> string : netmask :gateway -> CLibIPAddr : IP address of gateway :onboot -> string : yes or no (you can omit) :hwaddr -> string : MAC address (you can omit)

[Source]

# File lib/svengali/plugins/machine_config.rb, line 9
  def config_nw_interface(params_hash)
    config_file = nil
    if interface_name_str = params_hash[:interface]
      #open or create target file
      target_path = ExtStr.path["network_configs"]+"ifcfg-" + interface_name_str
      config_file = self.get_config_file(target_path)
    else
      err_message_and_exit("please specify a value of :interface!")
    end

    if netmask = params_hash[:netmask]
      netmask_str = netmask.to_s()
      # remove_col_by_regexp should be used under normal condition
      config_file.remove_col_by_str("NETMASK")
      config_file.append_str("NETMASK=" + netmask_str + "\n")
    else
      err_message_and_exit("please specify a value of :netmask!")
    end

    if ipaddr = params_hash[:ipaddr]
      ipaddr_str = ipaddr.to_s()
      # remove_col_by_regexp should be used under normal condition
      config_file.remove_col_by_str("IPADDR")
      config_file.append_str("IPADDR=" + ipaddr_str + "\n")
    else
      err_message_and_exit("please specify a value of :ipaddr!")
    end

    if gateway = params_hash[:gateway]
      gateway_str = gateway.to_s()
      # remove_col_by_regexp should be used under normal condition
      config_file.remove_col_by_str("GATEWAY")
      config_file.append_str("GATEWAY=" + gateway_str + "\n")
    else
      err_message_and_exit("please specify a value of :gateway!")
    end

    if hwaddr = params_hash[:hwaddr]
      # remove_col_by_regexp should be used under normal condition
      config_file.remove_col_by_str("HWADDR")
      config_file.append_str("HWADDR=" + hwaddr + "\n")
    end

    onboot = params_hash[:onboot] || "yes" # default is "yes"
    # remove_col_by_regexp should be used under normal condition
    config_file.remove_col_by_str("ONBOOT")
    config_file.append_str("ONBOOT=" + onboot + "\n")

    config_file.remove_col_by_str("BOOTPROTO")
    config_file.append_str("BOOTRPROTO=static\n")

    config_file.save()
    lazy_inp()
  end

[Source]

# File lib/svengali/plugins/eucalyptus.rb, line 141
  def destroy_instance()
    unless @instance_id_str
      puts "set_cloud_info() should be called appropriately before destroying instance"
      puts "exit destroy_instance() without terminating"
      return
    end

    unless @@do_cache
      terminate_instance(@instance_id_str)
    end
    
  end

[Source]

# File lib/svengali/machine.rb, line 58
    def establish_session()
      debug_p "start establish_session to " + @host
      # Spawn worker threads

      th = Thread.new do
        debug_p "Initialization of Machine ##{@host} is started."
        if @private_key_path
          if @user_name && @passphrase
            @ssh = SSH.new(@host,@user_name,@passphrase)
          else
            debug_p "please set user name and password when you want to use public key authentication"
            exit()
          end
        elsif @user_name && @password
          @ssh = SSH.new(@host,@user_name,@password)
        elsif @user_name
          @ssh = SSH.new(@userneme)
        else
          debug_p "please set user name at leaset"
          exit()
        end
        debug_p "Initialization of Machine ##{@host} is finished."

        @sftp_session = @ssh.sftp_session
        @@group.add(th)
      end

      #wait until finishing initialize of @ssh object
      while @ssh == nil
        sleep(1)
      end

      debug_p "finished establish_session to " + @host
    end

[Source]

# File lib/svengali/machine.rb, line 93
    def exec(command_str)
      return @ssh.exec(command_str)
    end

[Source]

# File lib/svengali/machine.rb, line 97
    def exec!(command_str,timeout = nil)
      return @ssh.exec!(command_str,timeout)
    end

call exec!( command ) on specified path TODO: change function name to exec_on!

[Source]

# File lib/svengali/machine.rb, line 103
    def exec_on!(command_str,current_path_str)
      exec!("cd #{current_path_str};" + command_str)
    end

execute local script on remote current_path_str -> string: if change of directory is not needed, please pass "." use remote /tmp directory to store script file TODO: change function name to exec_script_on!

[Source]

# File lib/svengali/machine.rb, line 111
    def exec_script_on(script_path_str,arguments_str,current_path_str)
      fname_str = File.basename(script_path_str)
      rempte_path_str = "/tmp/" + fname_str
      push_a_file(script_path_str,rempte_path_str)
      exec_on!("sh #{rempte_path_str} " + arguments_str,current_path_str)
    end

return -> string: ID of vm instance

[Source]

# File lib/svengali/plugins/eucalyptus.rb, line 137
  def get_instance_info()
    return @instance_id_str
  end

[Source]

# File lib/svengali/plugins/package.rb, line 3
  def install_package(package_name_str)
    return @ssh.exec!(ExtStr.cmd["package_install"] + " " + package_name_str)
  end

def set_auth_info(user_name)

  @user_name = user_name

end

[Source]

# File lib/svengali/machine.rb, line 47
    def set_auth_info(user_name,password = nil)
      @user_name = user_name
      @password = password
    end

[Source]

# File lib/svengali/machine.rb, line 52
    def set_auth_info_pki(user_name,passphrase,private_key_path)
      @user_name = user_name
      @passphrase = passphrase
      @private_key_path = private_key_path
    end

[Source]

# File lib/svengali/plugins/eucalyptus.rb, line 132
  def set_instance_info(instance_id_str)
    @instance_id_str = instance_id_str
  end

!!!! Now, this method write resolver information !!!! !!!! to /etc/sysconfig/network-scripts/ifcfg-ethX !!!! !!!! due to baffling behavior of CentOS !!!!

:primary_ip -> CLibIPAddr : IP address of primary DNS :secondry_ip -> CLibIPAddr : IP address of secondly DNS :search_domain -> string : domain of search directive

:interface -> string : interface name (for CentOS)

[Source]

# File lib/svengali/plugins/machine_config.rb, line 73
  def set_resolver(params_hash)
    #open or create target file
    config_file = nil
    if interface_name_str = params_hash[:interface]
      target_path = ExtStr.path["network_configs"]+"ifcfg-" + interface_name_str
      config_file = self.get_config_file(target_path)
    else
      err_message_and_exit("please specify a value of :interface!")
    end


#    target_path = ExtStr.path["resolver_config"]
#    config_file = self.get_config_file(target_path)
#
#    if search_domain = params_hash[:search_domain]
#      # remove_col_by_regexp should be used under normal condition
#      config_file.append_str("search " + search_domain + "\n")
#    end
#
#    if primary_ip = params_hash[:primary_ip]
#      primary_ip_str = primary_ip.to_s()
#      # remove_col_by_regexp should be used under normal condition
#      config_file.remove_col_by_str("nameserver")
#      config_file.append_str("nameserver " + primary_ip_str + "\n")
#    else
#      err_message_and_exit("please specify a value of :primary_ip!")
#    end
#
#    if secondly_ip = params_hash[:secondly_ip]
#      secondly_ip_str = secondly_ip.to_s()
#      # remove_col_by_regexp should be used under normal condition
#      config_file.append_str("nameserver " + secondly_ip_str + "\n")
#    end

    
    if primary_ip = params_hash[:primary_ip]
      primary_ip_str = primary_ip.to_s()
      # remove_col_by_regexp should be used under normal condition
      config_file.remove_col_by_str("PEERDNS")
      config_file.append_str("PEERDNS=yes\n")
      
      config_file.remove_col_by_str("DNS1")
      config_file.append_str("DNS1=" + primary_ip_str + "\n")
    else
      err_message_and_exit("please specify a value of :primary_ip!")
    end

    config_file.save()
    
    lazy_inp()
  end

set whether cache and reuse guest instance on Eucalyptus if true value is set

    - destroy_instance(...) doesn't terminate instance

[Source]

# File lib/svengali/plugins/eucalyptus.rb, line 157
  def set_whether_do_cache(true_or_false)
    @@do_cache = true_or_false
  end

[Source]

# File lib/svengali/machine.rb, line 118
    def sftp()
      return @ssh.sftp_session
    end

[Validate]