Class: Raca::Servers

Inherits:
Object
  • Object
show all
Defined in:
lib/raca/servers.rb

Overview

Represents a collection of cloud servers within a single region.

There’s currently no methods that relate to the entire collection, this is primarily used to retrieve a single Raca::Server object.

You probably don’t want to instantiate this directly, see Raca::Account#servers

Instance Method Summary collapse

Constructor Details

#initialize(account, region) ⇒ Servers

Returns a new instance of Servers.



11
12
13
14
# File 'lib/raca/servers.rb', line 11

def initialize(, region)
  @account, @region = , region
  @servers_url = @account.public_endpoint("cloudServersOpenStack", region)
end

Instance Method Details

#create(server_name, flavor_name, image_name, files = {}) ⇒ Object

create a new server on Rackspace.

server_name is a free text name you want to assign the server.

flavor_name is a string that describes the amount of RAM. If you enter an invalid option a list of valid options will be raised.

image_name is a string that describes the OS image to use. If you enter an invalid option a list of valid options will be raised. I suggest starting with ‘Ubuntu 10.04 LTS’

files is an optional Hash of path to blobs. Use it to place a file on the disk of the new server.

Use it like this:

server.create("my-server", 512, "Ubuntu 10.04 LTS", "/root/.ssh/authorised_keys" => File.read("/foo"))


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/raca/servers.rb', line 43

def create(server_name, flavor_name, image_name, files = {})
  request = {
    "server" => {
      "name" => server_name,
      "imageRef" => image_name_to_id(image_name),
      "flavorRef" => flavor_name_to_id(flavor_name),
    }
  }
  files.each do |path, blob|
    request['server']['personality'] ||= []
    request['server']['personality'] << {
      'path' => path,
      'contents' => Base64.encode64(blob)
    }
  end

  response = servers_client.post(servers_path, JSON.dump(request), json_headers)
  data = JSON.parse(response.body)['server']
  Raca::Server.new(@account, @region, data['id'])
end

#get(server_name) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/raca/servers.rb', line 16

def get(server_name)
  server_id = find_server_id(server_name)
  if server_id
    Raca::Server.new(@account, @region, server_id)
  else
    nil
  end
end

#inspectObject



64
65
66
# File 'lib/raca/servers.rb', line 64

def inspect
  "#<Raca::Servers:#{__id__} region=#{@region}>"
end