Class: Server

Inherits:
RightResource::Base show all
Defined in:
lib/right_resource/server.rb

Overview

define_methods 1

Server Action

  • start

  • stop

  • restart

Parameters

Examples

server_id = Server.index(:filter => "nickname=dev001").first.id
Server.start(server_id)

define_methods 2

Server and other resource action

  • run_script

  • attach_volume

Parameters

Examples

server_id = 1
params = {:ec2_ebs_volume_href => "https://my.rightscale.com/api/acct/##/ec2_ebs_volumes/1", :device => "/dev/sdj"}
Server.attach_volume(server_id, params) # => 204 No Content

Instance Attribute Summary

Attributes inherited from RightResource::Base

#attributes, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RightResource::Base

action, #clone, collection_path, connection, connection=, correct_attributes, create, destory, #destory, #dup, element_path, format, format=, headers, index, #initialize, #known_attributes, #loads, logger, logger=, #new?, #reload, resource_id, resource_name, #respond_to?, #respond_to_without_attributes?, #save, #schema, show, status_code, update, #update_attribute, #update_attributes

Constructor Details

This class inherits a constructor from RightResource::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RightResource::Base

Class Method Details

.get_sketchy_data(id, params) ⇒ Object

Get sampleing data

Return

Hash (keys # => [:cf, :start, :vars, :lag_time, :end, :data :avg_lag_time])

Examples

server_id = 848422
params = {:start => -180, :end => -20, :plugin_name => "cpu-0", :plugin_type => "cpu-idle"}
Server.get_sketchy_data(server_id, params)


69
70
71
72
# File 'lib/right_resource/server.rb', line 69

def get_sketchy_data(id, params)
  path = element_path(id, :get_sketchy_data, params)
  format.decode(action(:get, path)).tap {|resource| correct_attributes(resource)}
end

.monitoring(id, params = {}) ⇒ Object

Get URL of Server monitoring graph

Examples

* General Graph
  Server.monitoring(1)

* Custumize Graph
  server_id = 1
  params = {:graph_name => "cpu-0/cpu-idle", :size => "small", :period => "day", :title => "MyCpuGraph", :tz => "JST"}
  Server.monitoring(server_id, params)


83
84
85
86
87
88
89
90
91
92
# File 'lib/right_resource/server.rb', line 83

def monitoring(id, params={})
  if params[:graph_name]
    prefix_options = params[:graph_name]
    params.delete(:graph_name)
    path = element_path(id, :monitoring => prefix_options)
  else
    path = element_path(id, :monitoring)
  end
  format.decode(action(:get, path, params)).tap {|resource| correct_attributes(resource)}
end

.settings(id) ⇒ Object

Get Server settings(Subresource)

Examples

server_id = Server.index(:filter => "nickname=dev-001").first.id
settings = Server.settings(server_id)


98
99
100
101
# File 'lib/right_resource/server.rb', line 98

def settings(id)
  path = element_path(id, :settings)
  format.decode(action(:get, path)).tap {|resource| correct_attributes(resource)}
end

.show_current(id, params = {}) ⇒ Object

Get Current instance of server



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/right_resource/server.rb', line 45

def show_current(id, params={})
  path = element_path(id, :current, params)
  connection.clear
  result = format.decode(connection.get(path)).tap do |resource|
    correct_attributes(resource)
  end
  instantiate_record(result).tap do |resource|
    resource.id = resource.href.sub(/\/current$/, "").match(/[0-9]+$/).to_s.to_i
  end
rescue => e
  logger.error("#{e.class}: #{e.pretty_inspect}")
  logger.debug {"Backtrace:\n#{e.backtrace.pretty_inspect}"}
  nil
ensure
  logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
end

.tags(resource_href) ⇒ Object

Get Server tags(server or ec2_current_instance)

Parameters

  • resource_href - server.href or server.ec2_current_href

Examples

server = Server.show(1)
tags = Server.tags(server.ec2_current_href)
# => [{"rs_login:state" => "active"}, {"name"=>"rs_logging:state=active"}, {"name"=>"rs_monitoring:state=active"}]


110
111
112
113
114
115
116
# File 'lib/right_resource/server.rb', line 110

def tags(resource_href)
  query_options = {:resource_href => resource_href}
  path = "tags/search.#{format.extension}#{query_string(query_options)}"
  Hash[*format.decode(action(:get, path)).collect {|tag|
    tag['name'].split('=')
  }.flatten]
end

Instance Method Details

#settingsObject

Get Server settings with merge to instance(attributes)

Examples

server = Server.index(:filter => "nickname=dev-001").first
Server.settings
# => Server#attributes[:settings]
# {:dns_name => "ec2-175-...", :aws_id => "i-12345", ..., :ip_address => "175...."}


125
126
127
128
129
130
131
132
# File 'lib/right_resource/server.rb', line 125

def settings
  # first access
  if self.attributes[:settings].nil?
    self.attributes[:settings] = _settings
  end

  self.attributes[:settings]
end

#settings!Object

Get Server settings with merge to instance(destructive)

Examples

server = Server.index(:filter => "nickname=dev-001").first
Server.settings!
# => self
#
# > Server.attributes
# => [:nickname => "server1", :aws_id => "i-12345", ..., :ip_address => "175..."]


142
143
144
145
146
# File 'lib/right_resource/server.rb', line 142

def settings!
  self.loads(_settings)

  self
end