Parent

Class/Module Index [+]

Quicksearch

Fog::Compute::DigitalOcean::Real

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/digitalocean/compute.rb, line 76
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::Connection.new(@digitalocean_api_url)
end

Public Instance Methods

create_server( name, size_id, image_id, region_id, options = {} ) click to toggle source

FIXME: missing ssh keys support

# File lib/fog/digitalocean/requests/compute/create_server.rb, line 9
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]
    query_hash[:ssh_key_ids] = options[:ssh_key_ids]
  end
  
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => 'droplets/new',
    :query    => query_hash
  )
end
create_ssh_key( name, pub_key ) click to toggle source
# File lib/fog/digitalocean/requests/compute/create_ssh_key.rb, line 6
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 ) click to toggle source

FIXME: missing ssh keys support

# File lib/fog/digitalocean/requests/compute/destroy_server.rb, line 9
def destroy_server( id )
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{id}/destroy"
  )
end
destroy_ssh_key(id) click to toggle source

Delete a SSH public key from your account

@see www.digitalocean.com/api#ssh_keys

# File lib/fog/digitalocean/requests/compute/destroy_ssh_key.rb, line 11
def destroy_ssh_key(id)
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "ssh_keys/#{id}/destroy"
  )
end
get_server_details(server_id) click to toggle source
# File lib/fog/digitalocean/requests/compute/get_server_details.rb, line 6
def get_server_details(server_id)
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{server_id}"
  )
end
get_ssh_key(id) click to toggle source

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

@see www.digitalocean.com/api#ssh_keys

# File lib/fog/digitalocean/requests/compute/get_ssh_key.rb, line 12
def get_ssh_key(id)
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "ssh_keys/#{id}"
  )
end
list_flavors(options = {}) click to toggle source
# File lib/fog/digitalocean/requests/compute/list_flavors.rb, line 6
def list_flavors(options = {})
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => 'sizes'
  )
end
list_images(options = {}) click to toggle source
# File lib/fog/digitalocean/requests/compute/list_images.rb, line 6
def list_images(options = {})
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => 'images'
  )
end
list_regions(options = {}) click to toggle source
# File lib/fog/digitalocean/requests/compute/list_regions.rb, line 6
def list_regions(options = {})
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => 'regions'
  )
end
list_servers(options = {}) click to toggle source
# File lib/fog/digitalocean/requests/compute/list_servers.rb, line 6
def list_servers(options = {})
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => 'droplets'
  )
end
list_ssh_keys(options = {}) click to toggle source
# File lib/fog/digitalocean/requests/compute/list_ssh_keys.rb, line 6
def list_ssh_keys(options = {})
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => 'ssh_keys'
  )
end
power_cycle_server( id ) click to toggle source
# File lib/fog/digitalocean/requests/compute/power_cycle_server.rb, line 6
def power_cycle_server( id )
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{id}/power_cycle"
  )
end
power_off_server( id ) click to toggle source
# File lib/fog/digitalocean/requests/compute/power_off_server.rb, line 6
def power_off_server( id )
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{id}/power_off"
  )
end
power_on_server( id ) click to toggle source
# File lib/fog/digitalocean/requests/compute/power_on_server.rb, line 6
def power_on_server( id )
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{id}/power_on"
  )
end
reboot_server( id ) click to toggle source
# File lib/fog/digitalocean/requests/compute/reboot_server.rb, line 6
def reboot_server( id )
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{id}/reboot"
  )
end
reload() click to toggle source
# File lib/fog/digitalocean/compute.rb, line 84
def reload
  @connection.reset
end
request(params) click to toggle source
# File lib/fog/digitalocean/compute.rb, line 88
def request(params)
  params[:query] ||= {}
  params[:query].merge!(:api_key   => @digitalocean_api_key)
  params[:query].merge!(:client_id => @digitalocean_client_id)

  response = @connection.request(params)

  unless response.body.empty?
    response.body = Fog::JSON.decode(response.body)
    if response.body['status'] != 'OK'
      raise Fog::Errors::Error.new response.body.to_s
    end
  end
  response
end
shutdown_server( id ) click to toggle source
# File lib/fog/digitalocean/requests/compute/shutdown_server.rb, line 6
def shutdown_server( id )
  request(
    :expects  => [200],
    :method   => 'GET',
    :path     => "droplets/#{id}/shutdown"
  )
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.