Class: Fog::Compute::DigitalOcean::Servers

Inherits:
Fog::Collection
  • Object
show all
Defined in:
lib/fog/digitalocean/models/compute/servers.rb

Instance Method Summary collapse

Instance Method Details

#all(filters = {}) ⇒ Fog::Compute::DigitalOcean::Servers

Returns list of servers

Returns:

Raises:

  • (Fog::Compute::DigitalOcean::NotFound)
    • HTTP 404

  • (Fog::Compute::DigitalOcean::BadRequest)
    • HTTP 400

  • (Fog::Compute::DigitalOcean::InternalServerError)
    • HTTP 500

  • (Fog::Compute::DigitalOcean::ServiceError)

See Also:



17
18
19
20
# File 'lib/fog/digitalocean/models/compute/servers.rb', line 17

def all(filters = {})
  data = service.list_servers.body['droplets']
  load(data)
end

#bootstrap(new_attributes = {}) ⇒ Fog::Compute::DigitalOcean::Server

Note:

This creates an SSH public key object and assigns it to the server on creation

Creates a new server and populates ssh keys

Examples:

service.servers.bootstrap :name => 'bootstrap-server',
                          :flavor_ref => service.flavors.first.id,
                          :image_ref => service.images.find {|img| img.name =~ /Ubuntu/}.id,
                          :public_key_path => '~/.ssh/fog_rsa.pub',
                          :private_key_path => '~/.ssh/fog_rsa'

Returns:

Raises:

  • (Fog::Compute::DigitalOcean::NotFound)
    • HTTP 404

  • (Fog::Compute::DigitalOcean::BadRequest)
    • HTTP 400

  • (Fog::Compute::DigitalOcean::InternalServerError)
    • HTTP 500

  • (Fog::Compute::DigitalOcean::ServiceError)


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
# File 'lib/fog/digitalocean/models/compute/servers.rb', line 37

def bootstrap(new_attributes = {})
  server = new(new_attributes)

  check_keys(new_attributes)

  credential = Fog.respond_to?(:credential) && Fog.credential || :default
  name       = "fog_#{credential}"
  ssh_key    = service.ssh_keys.find { |key| key.name == name }
  if ssh_key.nil?
    ssh_key = service.ssh_keys.create(
      :name        => name,
      :ssh_pub_key => (new_attributes[:public_key] || File.read(new_attributes[:public_key_path]))
    )
  end
  server.ssh_keys = [ssh_key]

  server.save
  server.wait_for { ready? }

  if new_attributes[:private_key]
    server.setup :key_data => [new_attributes[:private_key]]
  else
    server.setup :keys => [new_attributes[:private_key_path]]
  end

  server
end

#get(id) ⇒ Fog::Compute::DigitalOcean:Server

Retrieves server

Parameters:

  • id (String)

    for server to be returned

Returns:

  • (Fog::Compute::DigitalOcean:Server)

Raises:

  • (Fog::Compute::DigitalOcean::NotFound)
    • HTTP 404

  • (Fog::Compute::DigitalOcean::BadRequest)
    • HTTP 400

  • (Fog::Compute::DigitalOcean::InternalServerError)
    • HTTP 500

  • (Fog::Compute::DigitalOcean::ServiceError)

See Also:



73
74
75
76
77
78
# File 'lib/fog/digitalocean/models/compute/servers.rb', line 73

def get(id)
  server = service.get_server_details(id).body['droplet']
  new(server) if server
rescue Fog::Errors::NotFound
  nil
end