Class: Fog::Compute::DigitalOcean::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/digitalocean/compute.rb,
lib/fog/digitalocean/requests/compute/get_ssh_key.rb,
lib/fog/digitalocean/requests/compute/list_images.rb,
lib/fog/digitalocean/requests/compute/list_flavors.rb,
lib/fog/digitalocean/requests/compute/list_regions.rb,
lib/fog/digitalocean/requests/compute/list_servers.rb,
lib/fog/digitalocean/requests/compute/create_server.rb,
lib/fog/digitalocean/requests/compute/list_ssh_keys.rb,
lib/fog/digitalocean/requests/compute/reboot_server.rb,
lib/fog/digitalocean/requests/compute/create_ssh_key.rb,
lib/fog/digitalocean/requests/compute/destroy_server.rb,
lib/fog/digitalocean/requests/compute/destroy_ssh_key.rb,
lib/fog/digitalocean/requests/compute/power_on_server.rb,
lib/fog/digitalocean/requests/compute/shutdown_server.rb,
lib/fog/digitalocean/requests/compute/power_off_server.rb,
lib/fog/digitalocean/requests/compute/get_server_details.rb,
lib/fog/digitalocean/requests/compute/power_cycle_server.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



71
72
73
74
75
76
77
# File 'lib/fog/digitalocean/compute.rb', line 71

def initialize(options={})
  @digitalocean_api_key   = options[:digitalocean_api_key]
  @digitalocean_client_id = options[:digitalocean_client_id]
  @digitalocean_api_url   = options[:digitalocean_api_url] || \
                                    "https://api.digitalocean.com"
  @connection             = Fog::XML::Connection.new(@digitalocean_api_url)
end

Instance Method Details

#create_server(name, size_id, image_id, region_id, options = {}) ⇒ Object

FIXME: missing ssh keys support



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/digitalocean/requests/compute/create_server.rb', line 8

def create_server( name,
                   size_id,
                   image_id,
                   region_id,
                   options = {} )

  query_hash = {
    :name        => name,
    :size_id     => size_id,
    :image_id    => image_id,
    :region_id   => region_id
  }

  if options[:ssh_key_ids]
    options[:ssh_key_ids]    = options[:ssh_key_ids].join(",") if options[:ssh_key_ids].is_a? Array
    query_hash[:ssh_key_ids] = options[:ssh_key_ids]
  end

  query_hash[:private_networking] = !!options[:private_networking]
  # backups are enabled using backups_enabled query parameter!
  query_hash[:backups_enabled] = !!options[:backups_active]

  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => 'droplets/new',
    :query    => query_hash
  )
end

#create_ssh_key(name, pub_key) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/digitalocean/requests/compute/create_ssh_key.rb', line 5

def create_ssh_key( name, pub_key )
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => 'ssh_keys/new',
    :query    => { 'name' => name, 'ssh_pub_key' => pub_key }
  )
end

#destroy_server(id) ⇒ Object

FIXME: missing ssh keys support



8
9
10
11
12
13
14
15
16
# File 'lib/fog/digitalocean/requests/compute/destroy_server.rb', line 8

def destroy_server( id )
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{id}/destroy",
    # We scrub data so future users can't read our disks.
    :query    => {:scrub_data => '1' }
  )
end

#destroy_ssh_key(id) ⇒ Object

Delete a SSH public key from your account



10
11
12
13
14
15
16
# File 'lib/fog/digitalocean/requests/compute/destroy_ssh_key.rb', line 10

def destroy_ssh_key(id)
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "ssh_keys/#{id}/destroy"
  )
end

#get_server_details(server_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/digitalocean/requests/compute/get_server_details.rb', line 5

def get_server_details(server_id)
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{server_id}"
  )
end

#get_ssh_key(id) ⇒ Object

This method shows a specific public SSH key in your account that can be added to a droplet.



11
12
13
14
15
16
17
# File 'lib/fog/digitalocean/requests/compute/get_ssh_key.rb', line 11

def get_ssh_key(id)
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "ssh_keys/#{id}"
  )
end

#list_flavors(options = {}) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/digitalocean/requests/compute/list_flavors.rb', line 5

def list_flavors(options = {})
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => 'sizes'
  )
end

#list_images(options = {}) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/digitalocean/requests/compute/list_images.rb', line 5

def list_images(options = {})
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => 'images'
  )
end

#list_regions(options = {}) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/digitalocean/requests/compute/list_regions.rb', line 5

def list_regions(options = {})
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => 'regions'
  )
end

#list_servers(options = {}) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/digitalocean/requests/compute/list_servers.rb', line 5

def list_servers(options = {})
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => 'droplets'
  )
end

#list_ssh_keys(options = {}) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/digitalocean/requests/compute/list_ssh_keys.rb', line 5

def list_ssh_keys(options = {})
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => 'ssh_keys'
  )
end

#power_cycle_server(id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/digitalocean/requests/compute/power_cycle_server.rb', line 5

def power_cycle_server( id )
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{id}/power_cycle"
  )
end

#power_off_server(id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/digitalocean/requests/compute/power_off_server.rb', line 5

def power_off_server( id )
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{id}/power_off"
  )
end

#power_on_server(id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/digitalocean/requests/compute/power_on_server.rb', line 5

def power_on_server( id )
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{id}/power_on"
  )
end

#reboot_server(id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/digitalocean/requests/compute/reboot_server.rb', line 5

def reboot_server( id )
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{id}/reboot"
  )
end

#reloadObject



79
80
81
# File 'lib/fog/digitalocean/compute.rb', line 79

def reload
  @connection.reset
end

#request(params) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/fog/digitalocean/compute.rb', line 83

def request(params)
  params[:query] ||= {}
  params[:query].merge!(:api_key   => @digitalocean_api_key)
  params[:query].merge!(:client_id => @digitalocean_client_id)

  response = retry_event_lock { parse @connection.request(params) }

  unless response.body.empty?
    if response.body['status'] != 'OK'
      case response.body['error_message']
      when /No Droplets Found/
        raise Fog::Errors::NotFound.new
      else
        raise Fog::Errors::Error.new response.body.to_s
      end
    end
  end
  response
end

#shutdown_server(id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/digitalocean/requests/compute/shutdown_server.rb', line 5

def shutdown_server( id )
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{id}/shutdown"
  )
end