Class: Fog::Rackspace::Compute::Real
- Inherits:
-
Object
- Object
- Fog::Rackspace::Compute::Real
- Defined in:
- lib/fog/compute/rackspace.rb,
lib/fog/compute/requests/rackspace/list_images.rb,
lib/fog/compute/requests/rackspace/create_image.rb,
lib/fog/compute/requests/rackspace/delete_image.rb,
lib/fog/compute/requests/rackspace/list_flavors.rb,
lib/fog/compute/requests/rackspace/list_servers.rb,
lib/fog/compute/requests/rackspace/create_server.rb,
lib/fog/compute/requests/rackspace/delete_server.rb,
lib/fog/compute/requests/rackspace/reboot_server.rb,
lib/fog/compute/requests/rackspace/resize_server.rb,
lib/fog/compute/requests/rackspace/server_action.rb,
lib/fog/compute/requests/rackspace/update_server.rb,
lib/fog/compute/requests/rackspace/list_addresses.rb,
lib/fog/compute/requests/rackspace/get_image_details.rb,
lib/fog/compute/requests/rackspace/get_flavor_details.rb,
lib/fog/compute/requests/rackspace/get_server_details.rb,
lib/fog/compute/requests/rackspace/list_images_detail.rb,
lib/fog/compute/requests/rackspace/list_flavors_detail.rb,
lib/fog/compute/requests/rackspace/list_servers_detail.rb,
lib/fog/compute/requests/rackspace/list_public_addresses.rb,
lib/fog/compute/requests/rackspace/revert_resized_server.rb,
lib/fog/compute/requests/rackspace/confirm_resized_server.rb,
lib/fog/compute/requests/rackspace/list_private_addresses.rb
Instance Method Summary collapse
-
#confirm_resized_server(server_id) ⇒ Object
Confirm resizing.
-
#create_image(server_id, options = {}) ⇒ Object
Create an image from a running server.
-
#create_server(flavor_id, image_id, options = {}) ⇒ Object
Create a new server.
-
#delete_image(image_id) ⇒ Object
Delete an image.
-
#delete_server(server_id) ⇒ Object
Delete an existing server.
-
#get_flavor_details(flavor_id) ⇒ Object
Get details for flavor by id.
-
#get_image_details(image_id) ⇒ Object
Get details for image by id.
-
#get_server_details(server_id) ⇒ Object
Get details about a server.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#list_addresses(server_id) ⇒ Object
List all server addresses.
-
#list_flavors ⇒ Object
List all flavors (IDs and names only).
-
#list_flavors_detail ⇒ Object
List all flavors.
-
#list_images ⇒ Object
List all images (IDs and names only).
-
#list_images_detail ⇒ Object
List all images.
-
#list_private_addresses(server_id) ⇒ Object
List private server addresses.
-
#list_public_addresses(server_id) ⇒ Object
List public server addresses.
-
#list_servers ⇒ Object
List all servers (IDs and names only).
-
#list_servers_detail ⇒ Object
List all servers details.
-
#reboot_server(server_id, type = 'SOFT') ⇒ Object
Reboot an existing server.
- #reload ⇒ Object
- #request(params) ⇒ Object
-
#resize_server(server_id, flavor_id) ⇒ Object
Reboot an existing server.
-
#revert_resized_server(server_id) ⇒ Object
Revert resizing.
-
#server_action(server_id, body, expects = 202) ⇒ Object
Reboot an existing server.
-
#update_server(server_id, options = {}) ⇒ Object
Update an existing server.
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/fog/compute/rackspace.rb', line 94 def initialize(={}) unless .delete(:provider) location = caller.first warning = "[yellow][WARN] Fog::Rackspace::Compute.new is deprecated, use Fog::Compute.new(:provider => 'Rackspace') instead[/]" warning << " [light_black](" << location << ")[/] " Formatador.display_line(warning) end require 'json' @rackspace_api_key = [:rackspace_api_key] @rackspace_username = [:rackspace_username] @rackspace_auth_url = [:rackspace_auth_url] authenticate @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", [:persistent]) end |
Instance Method Details
#confirm_resized_server(server_id) ⇒ Object
Confirm resizing
Parameters
-
server_id<~Integer> - Id of server to confirm
11 12 13 14 |
# File 'lib/fog/compute/requests/rackspace/confirm_resized_server.rb', line 11 def confirm_resized_server(server_id) body = { 'confirmResize' => nil } server_action(server_id, body, 204) end |
#create_image(server_id, options = {}) ⇒ Object
Create an image from a running server
Parameters
-
server_id<~Integer> - Id of server to create image from
-
options<~Hash> - Name
Returns
-
response<~Excon::Response>:
-
‘image’<~Hash>:
-
‘id’<~Integer> - Id of image
-
‘name’<~String> - Name of image
-
‘serverId’<~Integer> - Id of server
-
-
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fog/compute/requests/rackspace/create_image.rb', line 18 def create_image(server_id, = {}) data = { 'image' => { 'serverId' => server_id } } if ['name'] data['image']['name'] = ['name'] end request( :body => data.to_json, :expects => 202, :method => 'POST', :path => "images" ) end |
#create_server(flavor_id, image_id, options = {}) ⇒ Object
Create a new server
Parameters
-
flavor_id<~Integer> - Id of flavor for server
-
image_id<~Integer> - Id of image for server
-
name<~String> - Name of server
-
options<~Hash>:
-
‘metadata’<~Hash> - Up to 5 key value pairs containing 255 bytes of info
-
‘name’<~String> - Name of server, defaults to “slice#id”
-
‘personality’<~Array>: Up to 5 files to customize server
-
file<~Hash>:
-
‘contents’<~String> - Contents of file (10kb total of contents)
-
‘path’<~String> - Path to file (255 bytes total of path strings)
-
-
-
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘server’<~Hash>:
-
‘addresses’<~Hash>:
-
‘public’<~Array> - public address strings
-
‘private’<~Array> - private address strings
-
-
‘adminPass’<~String> - Admin password for server
-
‘flavorId’<~Integer> - Id of servers current flavor
-
‘hostId’<~String>
-
‘id’<~Integer> - Id of server
-
‘imageId’<~Integer> - Id of image used to boot server
-
‘metadata’<~Hash> - metadata
-
‘name<~String> - Name of server
-
‘progress’<~Integer> - Progress through current status
-
‘status’<~String> - Current server status
-
-
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fog/compute/requests/rackspace/create_server.rb', line 36 def create_server(flavor_id, image_id, = {}) data = { 'server' => { 'flavorId' => flavor_id, 'imageId' => image_id } } if ['metadata'] data['server']['metadata'] = ['metadata'] end if ['name'] data['server']['name'] = ['name'] end if ['personality'] data['server']['personality'] = [] for file in ['personality'] data['server']['personality'] << { 'contents' => Base64.encode64(file['contents']), 'path' => file['path'] } end end request( :body => data.to_json, :expects => 202, :method => 'POST', :path => 'servers.json' ) end |
#delete_image(image_id) ⇒ Object
Delete an image
Parameters
-
image_id<~Integer> - Id of image to delete
11 12 13 14 15 16 17 |
# File 'lib/fog/compute/requests/rackspace/delete_image.rb', line 11 def delete_image(image_id) request( :expects => 204, :method => 'DELETE', :path => "images/#{image_id}" ) end |
#delete_server(server_id) ⇒ Object
Delete an existing server
Parameters
-
id<~Integer> - Id of server to delete
11 12 13 14 15 16 17 |
# File 'lib/fog/compute/requests/rackspace/delete_server.rb', line 11 def delete_server(server_id) request( :expects => 202, :method => 'DELETE', :path => "servers/#{server_id}" ) end |
#get_flavor_details(flavor_id) ⇒ Object
Get details for flavor by id
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘id’<~Integer> - Id of the flavor
-
‘name’<~String> - Name of the flavor
-
‘ram’<~Integer> - Amount of ram for the flavor
-
‘disk’<~Integer> - Amount of diskspace for the flavor
-
-
15 16 17 18 19 20 21 |
# File 'lib/fog/compute/requests/rackspace/get_flavor_details.rb', line 15 def get_flavor_details(flavor_id) request( :expects => [200, 203], :method => 'GET', :path => "flavors/#{flavor_id}.json" ) end |
#get_image_details(image_id) ⇒ Object
Get details for image by id
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘id’<~Integer> - Id of the image
-
‘name’<~String> - Name of the image
-
‘serverId’<~Integer> - Id of server image was created from
-
‘status’<~Integer> - Status of image
-
‘updated’<~String> - Timestamp of last update
-
-
16 17 18 19 20 21 22 |
# File 'lib/fog/compute/requests/rackspace/get_image_details.rb', line 16 def get_image_details(image_id) request( :expects => [200, 203], :method => 'GET', :path => "images/#{image_id}.json" ) end |
#get_server_details(server_id) ⇒ Object
Get details about a server
Parameters
-
server_id<~Integer> - Id of server to get details for
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘server’<~Hash>:
-
‘addresses’<~Hash>:
-
‘public’<~Array> - public address strings
-
‘private’<~Array> - private address strings
-
-
‘flavorId’<~Integer> - Id of servers current flavor
-
‘hostId’<~String>
-
‘id’<~Integer> - Id of server
-
‘imageId’<~Integer> - Id of image used to boot server
-
‘metadata’<~Hash> - metadata
-
‘name<~String> - Name of server
-
‘progress’<~Integer> - Progress through current status
-
‘status’<~String> - Current server status
-
-
26 27 28 29 30 31 32 |
# File 'lib/fog/compute/requests/rackspace/get_server_details.rb', line 26 def get_server_details(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}.json" ) end |
#list_addresses(server_id) ⇒ Object
List all server addresses
Parameters
-
server_id<~Integer> - Id of server to list addresses for
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘addresses’<~Array>:
-
‘public’<~Array> - Public ip addresses
-
‘private’<~Array> - Private ip addresses
-
-
17 18 19 20 21 22 23 |
# File 'lib/fog/compute/requests/rackspace/list_addresses.rb', line 17 def list_addresses(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}/ips.json" ) end |
#list_flavors ⇒ Object
List all flavors (IDs and names only)
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘id’<~Integer> - Id of the flavor
-
‘name’<~String> - Name of the flavor
-
-
13 14 15 16 17 18 19 |
# File 'lib/fog/compute/requests/rackspace/list_flavors.rb', line 13 def list_flavors request( :expects => [200, 203], :method => 'GET', :path => 'flavors.json' ) end |
#list_flavors_detail ⇒ Object
List all flavors
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘id’<~Integer> - Id of the flavor
-
‘name’<~String> - Name of the flavor
-
‘ram’<~Integer> - Amount of ram for the flavor
-
‘disk’<~Integer> - Amount of diskspace for the flavor
-
-
15 16 17 18 19 20 21 |
# File 'lib/fog/compute/requests/rackspace/list_flavors_detail.rb', line 15 def list_flavors_detail request( :expects => [200, 203], :method => 'GET', :path => 'flavors/detail.json' ) end |
#list_images ⇒ Object
List all images (IDs and names only)
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘id’<~Integer> - Id of the image
-
‘name’<~String> - Name of the image
-
-
13 14 15 16 17 18 19 |
# File 'lib/fog/compute/requests/rackspace/list_images.rb', line 13 def list_images request( :expects => [200, 203], :method => 'GET', :path => 'images.json' ) end |
#list_images_detail ⇒ Object
List all images
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘id’<~Integer> - Id of the image
-
‘name’<~String> - Name of the image
-
‘updated’<~String> - Last update timestamp for image
-
‘created’<~String> - Creation timestamp for image
-
‘status’<~String> - Status of image
-
-
16 17 18 19 20 21 22 |
# File 'lib/fog/compute/requests/rackspace/list_images_detail.rb', line 16 def list_images_detail request( :expects => [200, 203], :method => 'GET', :path => 'images/detail.json' ) end |
#list_private_addresses(server_id) ⇒ Object
List private server addresses
Parameters
-
server_id<~Integer> - Id of server to list addresses for
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘private’<~Array> - Public ip addresses
-
-
15 16 17 18 19 20 21 |
# File 'lib/fog/compute/requests/rackspace/list_private_addresses.rb', line 15 def list_private_addresses(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}/ips/private.json" ) end |
#list_public_addresses(server_id) ⇒ Object
List public server addresses
Parameters
-
server_id<~Integer> - Id of server to list addresses for
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘public’<~Array> - Public ip addresses
-
-
15 16 17 18 19 20 21 |
# File 'lib/fog/compute/requests/rackspace/list_public_addresses.rb', line 15 def list_public_addresses(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}/ips/public.json" ) end |
#list_servers ⇒ Object
List all servers (IDs and names only)
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘servers’<~Array>:
-
‘id’<~Integer> - Id of server
-
‘name<~String> - Name of server
-
-
14 15 16 17 18 19 20 |
# File 'lib/fog/compute/requests/rackspace/list_servers.rb', line 14 def list_servers request( :expects => [200, 203], :method => 'GET', :path => 'servers.json' ) end |
#list_servers_detail ⇒ Object
List all servers details
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘servers’<~Array>:
-
‘id’<~Integer> - Id of server
-
‘name<~String> - Name of server
-
‘imageId’<~Integer> - Id of image used to boot server
-
‘flavorId’<~Integer> - Id of servers current flavor
-
‘hostId’<~String>
-
‘status’<~String> - Current server status
-
‘progress’<~Integer> - Progress through current status
-
‘addresses’<~Hash>:
-
‘public’<~Array> - public address strings
-
‘private’<~Array> - private address strings
-
-
‘metadata’<~Hash> - metadata
-
-
23 24 25 26 27 28 29 |
# File 'lib/fog/compute/requests/rackspace/list_servers_detail.rb', line 23 def list_servers_detail request( :expects => [200, 203], :method => 'GET', :path => 'servers/detail.json' ) end |
#reboot_server(server_id, type = 'SOFT') ⇒ Object
Reboot an existing server
Parameters
-
server_id<~Integer> - Id of server to reboot
-
type<~String> - Type of reboot, must be in [‘HARD’, ‘SOFT’]
12 13 14 15 |
# File 'lib/fog/compute/requests/rackspace/reboot_server.rb', line 12 def reboot_server(server_id, type = 'SOFT') body = { 'reboot' => { 'type' => type }} server_action(server_id, body) end |
#reload ⇒ Object
110 111 112 |
# File 'lib/fog/compute/rackspace.rb', line 110 def reload @connection.reset end |
#request(params) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/fog/compute/rackspace.rb', line 114 def request(params) begin response = @connection.request(params.merge!({ :headers => { 'Content-Type' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :host => @host, :path => "#{@path}/#{params[:path]}" })) rescue Excon::Errors::Unauthorized => error if JSON.parse(response.body)['unauthorized']['message'] == 'Invalid authentication token. Please renew.' authenticate retry else raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Rackspace::Compute::NotFound.slurp(error) else error end end unless response.body.empty? response.body = JSON.parse(response.body) end response end |
#resize_server(server_id, flavor_id) ⇒ Object
Reboot an existing server
Parameters
-
server_id<~Integer> - Id of server to resize
-
size<~String> - new size. call list_flavors to get available flavors
12 13 14 15 |
# File 'lib/fog/compute/requests/rackspace/resize_server.rb', line 12 def resize_server(server_id, flavor_id) body = { 'resize' => { 'flavorId' => flavor_id }} server_action(server_id, body) end |
#revert_resized_server(server_id) ⇒ Object
Revert resizing
Parameters
-
server_id<~Integer> - Id of server to revert
11 12 13 14 |
# File 'lib/fog/compute/requests/rackspace/revert_resized_server.rb', line 11 def revert_resized_server(server_id) body = { 'revertResize' => nil } server_action(server_id, body) end |
#server_action(server_id, body, expects = 202) ⇒ Object
Reboot an existing server
Parameters
-
server_id<~Integer> - Id of server to reboot
-
body<~.to_json object> - Body of the request, describes the action (see reboot_server as an example)
-
expect<~Integer> - expected return, 202 except for confirm resize (204)
13 14 15 16 17 18 19 20 |
# File 'lib/fog/compute/requests/rackspace/server_action.rb', line 13 def server_action(server_id, body, expects=202) request( :body => body.to_json, :expects => expects, :method => 'POST', :path => "servers/#{server_id}/action.json" ) end |
#update_server(server_id, options = {}) ⇒ Object
Update an existing server
Parameters
# server_id<~Integer> - Id of server to update
-
options<~Hash>:
-
adminPass<~String> - New admin password for server
-
name<~String> - New name for server
-
13 14 15 16 17 18 19 20 |
# File 'lib/fog/compute/requests/rackspace/update_server.rb', line 13 def update_server(server_id, = {}) request( :body => { 'server' => }.to_json, :expects => 204, :method => 'PUT', :path => "servers/#{server_id}.json" ) end |