class Ec2ServerArray

API 1.0

Attributes

internal[RW]

Public Class Methods

new(*args, &block) click to toggle source
Calls superclass method RightScale::Api::Base::new
# File lib/rest_connection/rightscale/ec2_server_array.rb, line 35
def initialize(*args, &block)
  super(*args, &block)
end

Public Instance Methods

instances() click to toggle source
# 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() click to toggle source
# 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) click to toggle source

Example:

right_script = @server_template.executables.first
result = @my_array.run_script_on_all(right_script, [@server_template.href])
# 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)
     options = Hash.new
     options[:ec2_server_array] = Hash.new
     options[:ec2_server_array][:right_script_href] = script.href
     options[:ec2_server_array][:parameters] = inputs unless inputs.nil?
     options[: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", options)
  end
run_script_on_instances(script, ec2_instance_hrefs=[], opts={}) click to toggle source

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)

# 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() click to toggle source
# 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