class McInstance

API 1.5

Attributes

monitoring_metrics[RW]

Public Class Methods

filters() click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 57
def self.filters
  [
    :datacenter_href,
    :deployment_href,
    :name,
    :os_platform,
    :parent_href,
    :private_dns_name,
    :private_ip_address,
    :public_dns_name,
    :public_ip_address,
    :resource_uid,
    :server_template_href,
    :state
  ]
end
parse_args(cloud_id) click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 53
def self.parse_args(cloud_id)
  "clouds/#{cloud_id}/"
end
resource_plural_name() click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 45
def self.resource_plural_name
  "instances"
end
resource_singular_name() click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 49
def self.resource_singular_name
  "instance"
end

Public Instance Methods

fetch_monitoring_metrics() click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 181
def fetch_monitoring_metrics
  @monitoring_metrics = []
  return @monitoring_metrics if self.state != "operational"
  connection.get(URI.parse(self.href).path + '/monitoring_metrics').each { |mm|
    @monitoring_metrics << MonitoringMetric.new(mm)
  }
  @monitoring_metrics
end
get_data(params) click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 196
def get_data(params)
  get_sketchy_data(params)
end
get_sketchy_data(params) click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 190
def get_sketchy_data(params)
  metric = fetch_monitoring_metrics.detect { |mm| mm.plugin == params['plugin_name'] and mm.view == params['plugin_type'] }
  raise "Metric not found!" unless metric
  metric.data(params['start'], params['end'])
end
launch() click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 120
def launch
  inst_href = URI.parse(self.href)
  connection.post(inst_href.path + '/launch')
end
map_security_groups(to, sg_ary) click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 83
def map_security_groups(to, sg_ary)
  sg_ary.map { |hsh| hsh["href"] }
end
map_user_data(to, user_data) click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 87
def map_user_data(to, user_data)
  user_data
end
multi_update(input_ary) click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 130
def multi_update(input_ary)
  inst_href = URI.parse(self.href)
  connection.put(inst_href.path + '/inputs/multi_update', {'inputs' => input_ary})
end
reboot() click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 200
def reboot
  self.show
  connection.post(URI.parse(self.href).path + '/reboot')
end
resource_plural_name() click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 37
def resource_plural_name
  "instances"
end
resource_singular_name() click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 41
def resource_singular_name
  "instance"
end
run_executable(executable, opts=nil, ignore_lock=false) click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 154
def run_executable(executable, opts=nil, ignore_lock=false)
  run_options = Hash.new
  if executable.is_a?(Executable)
    if executable.recipe?
      run_options[:recipe_name] = executable.recipe
    else
      run_options[:right_script_href] = translate_href(executable.right_script.href)
    end
  elsif executable.is_a?(RightScript)
    run_options[:right_script_href] = translate_href(executable.href)
  else
    raise "Invalid class passed to run_executable, needs Executable or RightScript, was:#{executable.class}"
  end

  if not opts.nil? and opts.has_key?(:ignore_lock)
    run_options[:ignore_lock] = "true"
    opts.delete(:ignore_lock)
    opts = nil if opts.empty?
  end

  inst_href = URI.parse(self.href)
  run_options[:inputs] = transform_inputs(:to_a, opts) unless opts.nil?
  run_options[:ignore_lock] = "true" if ignore_lock
  location = connection.post(inst_href.path + '/run_executable', run_options)
  Task.new('href' => location)
end
save() click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 79
def save
  update
end
show() click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 74
def show
  inst_href = URI.parse(self.href)
  @params.merge! connection.get(inst_href.path, 'view' => "full")
end
terminate() click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 125
def terminate
  inst_href = URI.parse(self.href)
  connection.post(inst_href.path + '/terminate')
end
transform_inputs(sym, parameters) click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 135
def transform_inputs(sym, parameters)
  ret = nil
  if parameters.is_a?(Array) and sym == :to_h
    ret = {}
    parameters.each { |hash| ret[hash['name']] = hash['value'] }
  elsif parameters.is_a?(Hash) and sym == :to_a
    ret = []
    parameters.each { |key,val| ret << {'name' => key, 'value' => val} }
  end
  ret
end
translate_href(old_href) click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 147
def translate_href(old_href)
  href = old_href.dup
  href.gsub!(/ec2_/,'')
  href.gsub!(/\/acct\/[0-9]*/,'')
  return href
end
update() click to toggle source
# File lib/rest_connection/rightscale/mc_instance.rb, line 91
def update
  fields = [{"attr" => :datacenter,                                       "api" => :datacenter_href},
            {"attr" => :image,                                            "api" => :image_href},
            {"attr" => :instance_type,                                    "api" => :instance_type_href},
            {                                                             "api" => :kernel_image_href},
            {"attr" => :multi_cloud_image,                                "api" => :multi_cloud_image_href},
            {                                                             "api" => :ramdisk_image_href},
            {"attr" => :security_groups,    "fn" => :map_security_groups, "api" => :security_group_hrefs},
            {"attr" => :server_template,                                  "api" => :server_template_href},
            {"attr" => :ssh_key,                                          "api" => :ssh_key_href},
            {"attr" => :user_data,          "fn" => :map_user_data,       "api" => :user_data}]

  opts = {"instance" => {}}
  instance = opts["instance"]
  to = "api"
  from = "attr"
  fields.each { |hsh|
    next unless hsh[from]
    val = self[hsh[from]]
    if hsh["fn"]
      instance[hsh[to].to_s] = __send__(hsh["fn"], to, val) unless val.nil? || val.empty?
    else
      instance[hsh[to].to_s] = val unless val.nil? || val.empty?
    end
  }
  inst_href = URI.parse(self.href)
  connection.put(inst_href.path, opts)
end