Class: RightScaleAPI::Server

Inherits:
Account::SubResource show all
Defined in:
lib/right-scale-api/server.rb

Constant Summary collapse

SETTINGS =
%w(
      ec2_ssh_key_href
      ec2_security_groups_href
      ec2_instance_type
      aki_image_href
      ari_image_href
      ec2_image_href
      vpc_subnet_href
      pricing
      max_spot_price
      locked
      ec2_availability_zone
      aws_platform
      dns_name
      private_dns_name
      ip_address
      private_ip_address
      aws_id
      cloud_id
      aws_product_codes
)

Instance Attribute Summary

Attributes inherited from Account::SubResource

#account

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Account::SubResource

#collection_uri

Methods inherited from Base

api_name, attributes, #collection_uri, create, #delete, #destroy, get, #get, #head, #initialize, #path, #post, #put, #send_request, #update, #uri

Constructor Details

This class inherits a constructor from RightScaleAPI::Base

Class Method Details

.opts_to_query_opts(opts) ⇒ Object


131
132
133
134
135
136
137
# File 'lib/right-scale-api/server.rb', line 131

def self.opts_to_query_opts opts
  assoc_ip = opts.delete :associate_eip_at_launch
  if !assoc_ip.nil?
    opts[:associate_eip_at_launch] = assoc_ip ? 1 : 0
  end
  super opts
end

Instance Method Details

#attach_blank_volume(opts) ⇒ Object

creates a blank volume and attaches it to the server

Parameters:

  • opts (Hash)

    Account#create_ec2_ebs_volume’s opts +

Options Hash (opts):

  • :device (String)

    device mount point, e.g. /dev/sdk

  • :ec2_availability_zone (String) — default: server's

    availability zone to create the volume in.


124
125
126
127
128
129
# File 'lib/right-scale-api/server.rb', line 124

def attach_blank_volume opts
  device = opts.delete :device
  opts = {:ec2_availability_zone => ec2_availability_zone }.merge opts
  volume = .create_ec2_ebs_volume opts
  attach_volume volume, device
end

#attach_volume(volume, device) ⇒ Object

Attach a volume to the server

Parameters:


106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/right-scale-api/server.rb', line 106

def attach_volume volume, device
  if running?
    post '/attach_volume', :query => {
      :server => {
        :ec2_ebs_volume_href => volume.uri,
        :device => device
      }
    }
  else
    volume.attach_to_server self, device, 'boot'
  end
end

#operational?Boolean Also known as: running?

Is the server operational

Returns:

  • (Boolean)

97
98
99
# File 'lib/right-scale-api/server.rb', line 97

def operational?
  state == 'operational'
end

#rebootObject

Reboots the server


71
72
73
# File 'lib/right-scale-api/server.rb', line 71

def reboot
  post '/reboot'
end

#regionObject

returns the cloud region the server is in (:us_east,:us_west,:eu,:ap)


56
57
58
# File 'lib/right-scale-api/server.rb', line 56

def region
  RightScaleAPI::CLOUD_REGIONS.find{|k,v|v == cloud_id}.first
end

#reload!Object


91
92
93
94
# File 'lib/right-scale-api/server.rb', line 91

def reload!
  super
  reload_settings
end

#reload_settingsObject


86
87
88
89
# File 'lib/right-scale-api/server.rb', line 86

def reload_settings
  reset_settings
  settings
end

#reset_settingsObject


82
83
84
# File 'lib/right-scale-api/server.rb', line 82

def reset_settings
  @settings = nil
end

#settingsObject


78
79
80
# File 'lib/right-scale-api/server.rb', line 78

def settings
  @settings ||= get('/settings')['settings']
end

#startObject

Starts the server


61
62
63
# File 'lib/right-scale-api/server.rb', line 61

def start
  post '/start'
end

#stopObject

Stops the server


66
67
68
# File 'lib/right-scale-api/server.rb', line 66

def stop
  post '/stop'
end