Class: Ec2ServerArray
- Inherits:
-
Object
- Object
- Ec2ServerArray
- Extended by:
- RightScale::Api::BaseExtend, RightScale::Api::TaggableExtend
- Includes:
- RightScale::Api::Base, RightScale::Api::Taggable
- Defined in:
- lib/rest_connection/rightscale/ec2_server_array.rb
Overview
API 1.0
Instance Attribute Summary collapse
-
#internal ⇒ Object
Returns the value of attribute internal.
Attributes included from RightScale::Api::Base
Instance Method Summary collapse
-
#initialize(*args, &block) ⇒ Ec2ServerArray
constructor
A new instance of Ec2ServerArray.
- #instances ⇒ Object
- #launch ⇒ Object
-
#run_script_on_all(script, server_template_hrefs, inputs = nil) ⇒ Object
Example: right_script = @server_template.executables.first result = @my_array.run_script_on_all(right_script, [@server_template.href]).
-
#run_script_on_instances(script, ec2_instance_hrefs = [], opts = {}) ⇒ Object
Run a script on individual instances in a ServerArray.
- #terminate_all ⇒ Object
Methods included from RightScale::Api::BaseExtend
[], create, deny_methods, filters, find, find_all, find_by, find_by_cloud_id, find_by_id, find_by_nickname, find_by_nickname_speed, find_with_filter, resource_plural_name, resource_singular_name
Methods included from RightScale::Api::BaseConnection
Methods included from RightScale::Api::TaggableExtend
Methods included from RightScale::Api::Taggable
#add_tags, #clear_tags, #get_info_tags, #get_tags_by_namespace, #remove_info_tags, #remove_tags, #remove_tags_by_namespace, #set_info_tags, #set_tags_by_namespace, #set_tags_to, #tags
Methods included from RightScale::Api::Base
#[], #[]=, #destroy, #method_missing, #reload, #resource_plural_name, #resource_singular_name, #rs_id, #save
Constructor Details
#initialize(*args, &block) ⇒ Ec2ServerArray
Returns a new instance of Ec2ServerArray.
35 36 37 |
# File 'lib/rest_connection/rightscale/ec2_server_array.rb', line 35 def initialize(*args, &block) super(*args, &block) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RightScale::Api::Base
Instance Attribute Details
#internal ⇒ Object
Returns the value of attribute internal.
33 34 35 |
# File 'lib/rest_connection/rightscale/ec2_server_array.rb', line 33 def internal @internal end |
Instance Method Details
#instances ⇒ Object
84 85 86 87 88 89 |
# File 'lib/rest_connection/rightscale/ec2_server_array.rb', line 84 def instances serv_href = URI.parse(self.href) connection.get("#{serv_href.path}/instances") rescue [] # raise an error on self.href which we want, it'll just rescue on rackspace and return an empty array. end |
#launch ⇒ Object
96 97 98 99 |
# File 'lib/rest_connection/rightscale/ec2_server_array.rb', line 96 def launch serv_href = URI.parse(self.href) connection.post("#{serv_href.path}/launch") end |
#run_script_on_all(script, server_template_hrefs, inputs = nil) ⇒ Object
Example:
right_script = @server_template.executables.first
result = @my_array.run_script_on_all(right_script, [@server_template.href])
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rest_connection/rightscale/ec2_server_array.rb', line 42 def run_script_on_all(script, server_template_hrefs, inputs=nil) serv_href = URI.parse(self.href) = Hash.new [:ec2_server_array] = Hash.new [:ec2_server_array][:right_script_href] = script.href [:ec2_server_array][:parameters] = inputs unless inputs.nil? [:ec2_server_array][:server_template_hrefs] = server_template_hrefs # bug, this only returns work units if using xml, for json all we get is nil. scripts still run though .. connection.post("#{serv_href.path}/run_script_on_all", ) end |
#run_script_on_instances(script, ec2_instance_hrefs = [], opts = {}) ⇒ Object
Run a script on individual instances in a ServerArray
This was formerly located in Ec2ServerArrayInternal but has been moved here to Ec2ServerArray as the call has been ported from API 0.1 to API 1.0.
Example: array.run_script_on_instances(right_script, server_href, options_hash)
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rest_connection/rightscale/ec2_server_array.rb', line 62 def run_script_on_instances(script, ec2_instance_hrefs=[], opts={}) uri = URI.parse(self.href) case script when Executable then script = script.right_script when String then script = RightScript.new('href' => script) end params = {:right_script_href => script.href } unless ec2_instance_hrefs.nil? || ec2_instance_hrefs.empty? params[:ec2_instance_hrefs] = ec2_instance_hrefs end unless opts.nil? || opts.empty? params[:parameters] = opts end params = {:ec2_server_array => params} status_array=[] connection.post(uri.path + "/run_script_on_instances", params).map do |work_unit| status_array.push Status.new('href' => work_unit) end return(status_array) end |
#terminate_all ⇒ Object
91 92 93 94 |
# File 'lib/rest_connection/rightscale/ec2_server_array.rb', line 91 def terminate_all serv_href = URI.parse(self.href) connection.post("#{serv_href.path}/terminate_all") end |