class McServer
API 1.5
Attributes
current_instance[RW]
inputs[RW]
next_instance[RW]
Public Class Methods
filters()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 53 def self.filters [:deployment_href, :name] end
parse_args(deployment_id=nil)
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 49 def self.parse_args(deployment_id=nil) deployment_id ? "deployments/#{deployment_id}/" : "" end
resource_plural_name()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 41 def self.resource_plural_name "servers" end
resource_singular_name()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 45 def self.resource_singular_name "server" end
Public Instance Methods
cloud_id()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 254 def cloud_id settings unless @next_instance cloud_href = @current_instance.hash_of_links["cloud"] if @current_instance cloud_href = @next_instance.hash_of_links["cloud"] unless cloud_href return cloud_href.split("/").last.to_i end
current_instance_href()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 250 def current_instance_href hash_of_links["current_instance"] end
deployment_href()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 246 def deployment_href hash_of_links["deployment"] end
dns_name()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 261 def dns_name self.settings ret = nil if @current_instance ret ||= @current_instance.public_ip_addresses.first ret ||= @current_instance.public_dns_names.first ret ||= get_tags_by_namespace("server")["current_instance"]["public_ip_0"] end ret end
force_terminate()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 149 def force_terminate t = URI.parse(self.href) connection.post(t.path + '/terminate') connection.post(t.path + '/terminate') @current_instance = nil end
get_sketchy_data(params)
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 300 def get_sketchy_data(params) settings raise "No current instance found!" unless @current_instance @current_instance.get_sketchy_data(params) end
launch()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 57 def launch if actions.include?("launch") t = URI.parse(self.href) begin connection.post(t.path + '/launch') rescue Exception => e if connection.settings[:azure_hack_on] puts "**** [AZURE_HACK is ON] - McServer.launch() nickname: #{nickname}, caught exception #{e.message}" puts "**** connection.settings[:azure_hack_retry_count] = #{connection.settings[:azure_hack_retry_count]}" puts "**** connection.settings[:azure_hack_sleep_seconds] = #{connection.settings[:azure_hack_sleep_seconds]}" # 504 Gateway should always be treated as a successful launch target_504_gateway_timeout_error_message = "504 Gateway Time-out" # All 422 exceptions should be retried target_422_error_message = "Invalid response HTTP code: 422:" if e.message =~ /#{target_504_gateway_timeout_error_message}/ exception_matched_message = "**** McServer.launch(): Caught #{e.message}, treating as a successful launch..." puts(exception_matched_message) connection.logger(exception_matched_message) true elsif e.message =~ /#{target_422_error_message}/ azure_hack_retry_count = connection.settings[:azure_hack_retry_count] exception_matched_message = "**** McServer.launch(): Caught #{e.message}, retrying launch..." puts(exception_matched_message) connection.logger(exception_matched_message) retry_count = 1 loop do # sleep for azure_hack_sleep_seconds seconds sleep_message = "**** McServer.launch(): Sleeping for #{connection.settings[:azure_hack_sleep_seconds]} seconds and then retrying (#{retry_count}) launch..." puts(sleep_message) connection.logger(sleep_message) sleep(connection.settings[:azure_hack_sleep_seconds]) # retry the launch begin connection.post(t.path + '/launch') rescue Exception => e2 exception_caught_message = "**** McServer.launch(): Retry caught #{e2.message}..." puts(exception_caught_message) connection.logger(exception_caught_message) if e2.message =~ /#{target_422_error_message}/ azure_hack_retry_count -= 1 if azure_hack_retry_count > 0 retry_count += 1 # Try again on next iteration next else # Azure Hack maximum retries exceeded so rethrow the new 422 exception raise end else # On this re-launch we got some other exception so rethrow it raise end end # Fell through so launch worked and we need to break out of the retry do loop break end else # Didn't match on any target exception so rethrow the original exception raise end else # Azure Hack isn't enabled so rethrow the original exception raise end end elsif self.state == "inactive" raise "FATAL: Server is in an unlaunchable state!" else connection.logger("WARNING: was in #{self.state} so skipping launch call") end end
monitoring()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 220 def monitoring ret = @current_instance.fetch_monitoring_metrics raise "FATAL: Monitoring not available!" if ret.empty? ret end
private_ip()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 272 def private_ip self.settings ret = nil if @current_instance ret ||= @current_instance.private_ip_addresses.first ret ||= @current_instance.private_dns_names.first ret ||= get_tags_by_namespace("server")["current_instance"]["private_ip_0"] end ret end
relaunch(timeout=1200)
click to toggle source
*timeout <~Integer> optional, how long to wait for the inactive state before declare failure (in seconds).
# File lib/rest_connection/rightscale/mc_server.rb, line 227 def relaunch(timeout=1200) self.terminate self.wait_for_state("inactive", timeout) self.launch end
reload_as_current()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 292 def reload_as_current settings # Gets all instance (including current) information end
reload_as_next()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 296 def reload_as_next settings # Gets all instance (including current) information end
resource_plural_name()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 33 def resource_plural_name "servers" end
resource_singular_name()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 37 def resource_singular_name "server" end
run_executable(executable, opts=nil, ignore_lock=false)
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 164 def run_executable(executable, opts=nil, ignore_lock=false) raise "Instance isn't running; Can't run executable" unless @current_instance @current_instance.run_executable(executable, opts, ignore_lock) end
save()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 283 def save update end
server_template_href()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 238 def server_template_href if @current_instance return @current_instance.server_template end self.settings unless @next_instance return @next_instance.server_template end
server_type()
click to toggle source
Attributes taken for granted in API 1.0
# File lib/rest_connection/rightscale/mc_server.rb, line 234 def server_type "gateway" end
set_current_inputs(hash = {})
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 197 def set_current_inputs(hash = {}) settings unless @next_instance @current_instance.multi_update(transform_inputs(:to_a, hash)) if @current_instance end
set_input(name, value)
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 191 def set_input(name, value) settings unless @next_instance @current_instance.multi_update([{'name' => name, 'value' => value}]) if @current_instance @next_instance.multi_update([{'name' => name, 'value' => value}]) end
set_next_inputs(hash = {})
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 202 def set_next_inputs(hash = {}) settings unless @next_instance @next_instance.multi_update(transform_inputs(:to_a, hash)) end
settings()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 208 def settings #show serv_href = URI.parse(self.href) @params = connection.get(serv_href.path, 'view' => 'instance_detail') if self['current_instance'] @current_instance = McInstance.new(self['current_instance']) @current_instance.show end @next_instance = McInstance.new(self['next_instance']) @next_instance.show @params end
start()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 156 def start #start_ebs raise "You shouldn't be here." end
stop()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 160 def stop #stop_ebs raise "You shouldn't be here." end
terminate()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 137 def terminate if actions.include?("terminate") t = URI.parse(self.href) connection.post(t.path + '/terminate') @current_instance = nil # elsif self.state != "inactive" # raise "FATAL: Server is in an interminable state!" else connection.logger("WARNING: was in #{self.state} so skipping terminate call") end end
transform_inputs(sym, parameters)
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 169 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
update()
click to toggle source
# File lib/rest_connection/rightscale/mc_server.rb, line 287 def update @next_instance.update @current_instance.update if @current_instance end