Class: Fog::Compute::DigitalOcean::Server

Inherits:
Server
  • Object
show all
Defined in:
lib/fog/digitalocean/models/compute/server.rb

Overview

A DigitalOcean Droplet

Instance Attribute Summary

Attributes inherited from Server

#private_key, #private_key_path, #public_key, #public_key_path, #ssh_port, #username

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Server

#scp, #scp_download, #ssh, #sshable?

Methods inherited from Model

#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#destroyObject

Destroy the server, freeing up the resources.

DigitalOcean will stop charging you for the resources the server was using.

Once the server has been destroyed, there’s no way to recover it so the data is irrecoverably lost.

IMPORTANT: As of 2013/01/31, you should wait some time to destroy the server after creating it. If you try to destroy the server too fast, the destroy event may be lost and the server will remain running and consuming resources, so DigitalOcean will keep charging you. Double checked this with DigitalOcean staff and confirmed that it’s the way it works right now.

Double check the server has been destroyed!



124
125
126
127
# File 'lib/fog/digitalocean/models/compute/server.rb', line 124

def destroy
  requires :id
  service.destroy_server id
end

#power_cycleObject

Reboot the server (hard reboot).

Powers the server off and then powers it on again.



33
34
35
36
# File 'lib/fog/digitalocean/models/compute/server.rb', line 33

def power_cycle
  requires :id
  service.power_cycle_server self.id
end

#ready?Boolean

Checks whether the server status is ‘active’.

The server transitions from ‘new’ to ‘active’ sixty to ninety seconds after creating it (time varies and may take more than 90 secs).

Returns:

  • (Boolean)


136
137
138
# File 'lib/fog/digitalocean/models/compute/server.rb', line 136

def ready?
  state == 'active'
end

#rebootObject

Reboot the server (soft reboot).

The preferred method of rebooting a server.



25
26
27
28
# File 'lib/fog/digitalocean/models/compute/server.rb', line 25

def reboot
  requires :id
  service.reboot_server self.id
end

#saveBoolean

Creates the server (not to be called directly).

Usually called by Fog::Collection#create

do = Fog::Compute.new({
  :provider => 'DigitalOcean',
  :digitalocean_api_key   => 'key-here',      # your API key here
  :digitalocean_client_id => 'client-id-here' # your client key here
})
do.servers.create :name => 'foobar',
                  :image_id  => image_id_here,
                  :flavor_id => flavor_id_here,
                  :region_id => region_id_here

Returns:

  • (Boolean)

Raises:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fog/digitalocean/models/compute/server.rb', line 90

def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
  requires :name, :flavor_id, :image_id, :region_id

  options = {}
  if attributes[:ssh_key_ids]
    options[:ssh_key_ids] = attributes[:ssh_key_ids] 
  end
  data = service.create_server name, 
                               flavor_id, 
                               image_id, 
                               region_id,
                               options
  merge_attributes(data.body['droplet'])
  true
end

#shutdownObject

Shutdown the server

Sends a shutdown signal to the operating system. The server consumes resources while powered off so you are still charged.



45
46
47
48
# File 'lib/fog/digitalocean/models/compute/server.rb', line 45

def shutdown
  requires :id
  service.shutdown_server self.id
end

#startObject

Power on the server.

The server consumes resources while powered on so you will be charged.

Each time a server is spun up, even if for a few seconds, it is charged for an hour.



70
71
72
73
# File 'lib/fog/digitalocean/models/compute/server.rb', line 70

def start
  requires :id
  service.power_on_server self.id
end

#stopObject

Power off the server

Works as a power switch. The server consumes resources while powered off so you are still charged.



57
58
59
60
# File 'lib/fog/digitalocean/models/compute/server.rb', line 57

def stop
  requires :id
  service.power_off_server self.id
end

#updateObject

DigitalOcean API does not support updating server state

Raises:

  • (NotImplementedError)


141
142
143
144
# File 'lib/fog/digitalocean/models/compute/server.rb', line 141

def update
  msg = 'DigitalOcean servers do not support updates'
  raise NotImplementedError.new(msg)
end