Class | Cloud |
In: |
lib/svengali/plugins/eucalyptus.rb
|
Parent: | Object |
DHCP_LEASE_RANGE | = | "xxx.xxx.xxx.xxx" | TODO: enabling lib to find newly booted node without pinging | |
CACHE_FILE_NAME | = | "./machine_cache_hash.yml" |
# File lib/svengali/plugins/eucalyptus.rb, line 176 def self.Cloud(default_user,default_pass) @@default_user = default_user @@default_pass = default_pass end
machine_cache_hash -> hash : {"xxx.xxx.xxx.xxx" => "i-xxxxxxx", … }
# File lib/svengali/plugins/eucalyptus.rb, line 310 def self.dump_machine_cache_info(machine_cache_hash) file = open(CACHE_FILE_NAME,"w") YAML.dump(machine_cache_hash,file) file.close() end
return -> Machine : Machine instance applied network configuration and establised session
# File lib/svengali/plugins/eucalyptus.rb, line 196 def self.get_a_machine(params_hash) # if @@do_cache true, Cloud class tries to reuse guest instance on Eucalyptus # whether exist appropriate instace is checked in terms of IP address if Cloud.is_exist_requested_machine(params_hash[:ipaddr]) && @@do_cache debug_p "reused a guset instance which has address #{params_hash[:ipaddr]}" # load instance ID corresponding to requested IP address from cache file machine_cache_hash = Cloud.load_machine_cache_info() instance_id = machine_cache_hash[params_hash[:ipaddr]] else # calling of this method isn't needed under normal conditions get_ipaddr_of_instance_pre() debug_p "executing euca-run-instance...." # ** Attention ** below is draft code instance_id = run_image(params_hash[:imageid]) debug_p "euca-run-instance finished." #get a CLibIPAddr insance ipaddr = get_ipaddr_of_instance(instance_id) debug_p "IP address of the kicked instance: " + ipaddr.to_s debug_p "configure network setting to the kicked instance." vanilla_machine = Machine.new(ipaddr) vanilla_machine.set_auth_info(DEFAULT_USER,DEFAULT_PASS) vanilla_machine.establish_session() vanilla_machine.config_nw_interface(:ipaddr => params_hash[:ipaddr], :interface => params_hash[:interface], :netmask => params_hash[:netmask], :gateway => params_hash[:gateway], :onboot => "yes") vanilla_machine.set_resolver(:primary_ip => params_hash[:dns],:interface => params_hash[:interface]) #reloads network configuration #10 seconds after, this will return with nil value # TODO: should eliminate assumption for platform debug_p "reload network configuration...." puts vanilla_machine.exec!("/sbin/service network restart", 10) debug_p "reloading of network configuration may have finished." # write machine info to cache file if @@do_cache machine_cache_hash = Cloud.load_machine_cache_info() debug_p "----------------loaded_hash------------------" debug_p machine_cache_hash.inspect() debug_p "class name of machine_cache_hash is #{machine_cache_hash.class}" debug_p "---------------------------------------------" machine_cache_hash[params_hash[:ipaddr]] = instance_id Cloud.dump_machine_cache_info(machine_cache_hash) end end configured_machine = Machine.new(params_hash[:ipaddr]) configured_machine.set_auth_info(DEFAULT_USER,DEFAULT_PASS) configured_machine.establish_session() configured_machine.set_instance_info(instance_id) if @@do_cache configured_machine.set_whether_do_cache(true) end return configured_machine end
return -> Machine : Machine instance applied network configuration and establised session
# File lib/svengali/plugins/eucalyptus.rb, line 182 def self.get_a_machine_with_imageup(params_hash) check_has_keys(params_hash,[:imagepath]) unless params_hash[:imageid] = upload_and_register_image(params_hash[image_path_str],120) puts "uploading and registration of image failed" err_message_and_exit("I wll exit") end not_tested() return self.get_a_machine(params_hash) end
** Attention ** this is quick-fix implementation
this method can't work on parallel kicking
return -> CLibIPAddr : xxx
# File lib/svengali/plugins/eucalyptus.rb, line 268 def self.get_ipaddr_of_instance(instance_id) unless @@pre_alived_hash err_message_and_exit("get_ipaddr_of_instance_pre() should be called on the eve of run_image(...)") end debug_p @@pre_alived_hash.inspect() while(true) alived_hash = find_machines_on_range_by_ping(DHCP_LEASE_RANGE) # find difference alived_hash.delete_if{ |key,value| @@pre_alived_hash.has_key?(key)} if alived_hash.size == 1 debug_p alived_hash.inspect() ret = alived_hash.shift()[0] debug_p "found #{ret}" return CLibIPAddr.new(ret) elsif alived_hash.size > 1 err_message_and_exit("There may be other booting machine!") end sleep 1 #leave a space end end
call of this method isn‘t needed under normal conditions this method should be called on the eve of run_image(…)
# File lib/svengali/plugins/eucalyptus.rb, line 296 def self.get_ipaddr_of_instance_pre() @@pre_alived_hash = find_machines_on_range_by_ping(DHCP_LEASE_RANGE) end
ipaddr -> CLibIPAddr whether exist appropriate instace is checked in terms of IP address
# File lib/svengali/plugins/eucalyptus.rb, line 260 def self.is_exist_requested_machine(ipaddr) return is_exist_by_ping(ipaddr) end
return -> hash: {"xxx.xxx.xxx.xxx" => "i-xxxxxxx", … } if chache file doesn‘t exist, return a empty hash
# File lib/svengali/plugins/eucalyptus.rb, line 318 def self.load_machine_cache_info() if File.exist?(CACHE_FILE_NAME) ret_hash = nil open(CACHE_FILE_NAME){ |file| ret_hash = YAML.load(file) } return ret_hash else return Hash.new() end end
set whether cache and reuse guest instance on Eucalyptus if true value is set
- get_a_machine(...) tries to reuse guest instance on Eucalyptus - destroy_instance(...) of Machine class doesn't terminate instance - write kicked machine info to cache file
# File lib/svengali/plugins/eucalyptus.rb, line 305 def self.set_whether_do_cache(true_or_false) @@do_cache = true_or_false end