Delete stuff

Delete compute v1

Change to V2

Compute
This commit is contained in:
Suraj Shirvankar 2016-01-19 12:27:36 +04:00
parent b7bdfce149
commit 14e9c4ef7e
52 changed files with 4 additions and 1749 deletions

View File

@ -3,7 +3,7 @@ class DigitalOcean < Fog::Bin
def class_for(key)
case key
when :compute
Fog::Compute::DigitalOcean
Fog::Compute::DigitalOceanV2
else
raise ArgumentError, "Unsupported #{self} service: #{key}"
end

View File

@ -1 +1 @@
require 'fog/digitalocean/compute'
require 'fog/digitalocean/compute_v2'

View File

@ -1,130 +0,0 @@
require 'fog/digitalocean/core'
module Fog
module Compute
class DigitalOcean < Fog::Service
requires :digitalocean_api_key
requires :digitalocean_client_id
recognizes :digitalocean_api_url
model_path 'fog/digitalocean/models/compute'
model :server
collection :servers
model :flavor
collection :flavors
model :image
collection :images
model :region
collection :regions
model :ssh_key
collection :ssh_keys
request_path 'fog/digitalocean/requests/compute'
request :list_servers
request :list_images
request :list_regions
request :list_flavors
request :get_server_details
request :create_server
request :destroy_server
request :reboot_server
request :power_cycle_server
request :power_off_server
request :power_on_server
request :shutdown_server
request :list_ssh_keys
request :create_ssh_key
request :get_ssh_key
request :destroy_ssh_key
# request :digitalocean_resize
class Mock
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {
:servers => [],
:ssh_keys => []
}
end
end
def self.reset
@data = nil
end
def initialize(options={})
@digitalocean_api_key = options[:digitalocean_api_key]
end
def data
self.class.data[@digitalocean_api_key]
end
def reset_data
self.class.data.delete(@digitalocean_api_key)
end
end
class Real
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
def reload
@connection.reset
end
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
private
def parse(response)
return response if response.body.empty?
response.body = Fog::JSON.decode(response.body)
response
end
def retry_event_lock
count = 0
response = nil
while count < 5
response = yield
if response.body && response.body['error_message'] =~ /There is already a pending event for the droplet/
count += 1
sleep count ** 3
else
break
end
end
response
end
end
end
end
end

View File

@ -4,6 +4,6 @@ require 'fog/json'
module Fog
module DigitalOcean
extend Fog::Provider
service(:compute, 'Compute')
service(:compute_v2, 'Compute')
end
end

View File

@ -1,12 +0,0 @@
require 'fog/core/model'
module Fog
module Compute
class DigitalOcean
class Flavor < Fog::Model
identity :id
attribute :name
end
end
end
end

View File

@ -1,22 +0,0 @@
require 'fog/core/collection'
require 'fog/digitalocean/models/compute/flavor'
module Fog
module Compute
class DigitalOcean
class Flavors < Fog::Collection
model Fog::Compute::DigitalOcean::Flavor
def all
load service.list_flavors.body['sizes']
end
def get(id)
all.find { |f| f.id == id }
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View File

@ -1,13 +0,0 @@
require 'fog/core/model'
module Fog
module Compute
class DigitalOcean
class Image < Fog::Model
identity :id
attribute :name
attribute :distribution
end
end
end
end

View File

@ -1,22 +0,0 @@
require 'fog/core/collection'
require 'fog/digitalocean/models/compute/image'
module Fog
module Compute
class DigitalOcean
class Images < Fog::Collection
model Fog::Compute::DigitalOcean::Image
def all
load service.list_images.body['images']
end
def get(id)
all.find { |f| f.id == id }
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View File

@ -1,12 +0,0 @@
require 'fog/core/model'
module Fog
module Compute
class DigitalOcean
class Region < Fog::Model
identity :id
attribute :name
end
end
end
end

View File

@ -1,22 +0,0 @@
require 'fog/core/collection'
require 'fog/digitalocean/models/compute/region'
module Fog
module Compute
class DigitalOcean
class Regions < Fog::Collection
model Fog::Compute::DigitalOcean::Region
def all
load service.list_regions.body['regions']
end
def get(id)
all.find { |f| f.id == id }
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View File

@ -1,202 +0,0 @@
require 'fog/compute/models/server'
module Fog
module Compute
class DigitalOcean
# A DigitalOcean Droplet
#
class Server < Fog::Compute::Server
identity :id
attribute :name
attribute :state, :aliases => 'status'
attribute :image_id
attribute :region_id
attribute :flavor_id, :aliases => 'size_id'
attribute :public_ip_address, :aliases => 'ip_address'
attribute :private_ip_address
attribute :private_networking
attribute :backups_active, :aliases => 'backups_enabled'
attribute :created_at
attr_writer :ssh_keys
# Deprecated: Use public_ip_address instead.
def ip_address
Fog::Logger.warning("ip_address has been deprecated. Use public_ip_address instead")
public_ip_address
end
# Reboot the server (soft reboot).
#
# The preferred method of rebooting a server.
def reboot
requires :id
service.reboot_server self.id
end
# Reboot the server (hard reboot).
#
# Powers the server off and then powers it on again.
def power_cycle
requires :id
service.power_cycle_server self.id
end
# Shutdown the server
#
# Sends a shutdown signal to the operating system.
# The server consumes resources while powered off
# so you are still charged.
#
# @see https://www.digitalocean.com/community/questions/am-i-charged-while-my-droplet-is-in-a-powered-off-state
def shutdown
requires :id
service.shutdown_server self.id
end
# Power off the server
#
# Works as a power switch.
# The server consumes resources while powered off
# so you are still charged.
#
# @see https://www.digitalocean.com/community/questions/am-i-charged-while-my-droplet-is-in-a-powered-off-state
def stop
requires :id
service.power_off_server self.id
end
# 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.
#
def start
requires :id
service.power_on_server self.id
end
def setup(credentials = {})
requires :ssh_ip_address
commands = [
%{mkdir .ssh},
%{passwd -l #{username}},
%{echo "#{Fog::JSON.encode(Fog::JSON.sanitize(attributes))}" >> ~/attributes.json}
]
if public_key
commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys}
end
# wait for DigitalOcean to be ready
wait_for { sshable?(credentials) }
Fog::SSH.new(ssh_ip_address, username, credentials).run(commands)
end
# Creates the server (not to be called directly).
#
# Usually called by Fog::Collection#create
#
# docean = Fog::Compute.new({
# :provider => 'DigitalOcean',
# :digitalocean_api_key => 'key-here', # your API key here
# :digitalocean_client_id => 'client-id-here' # your client key here
# })
# docean.servers.create :name => 'foobar',
# :image_id => image_id_here,
# :flavor_id => flavor_id_here,
# :region_id => region_id_here
#
# @return [Boolean]
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]
elsif @ssh_keys
options[:ssh_key_ids] = @ssh_keys.map(&:id)
end
options[:private_networking] = private_networking
options[:backups_active] = backups_active
data = service.create_server name,
flavor_id,
image_id,
region_id,
options
merge_attributes(data.body['droplet'])
true
end
# 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!
def destroy
requires :id
service.destroy_server id
end
# 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).
#
# @return [Boolean]
def ready?
state == 'active'
end
# DigitalOcean API does not support updating server state
def update
msg = 'DigitalOcean servers do not support updates'
raise NotImplementedError.new(msg)
end
# Helper method to get the flavor name
def flavor
requires :flavor_id
@flavor ||= service.flavors.get(flavor_id.to_i)
end
# Helper method to get the image name
def image
requires :image_id
@image ||= service.images.get(image_id.to_i)
end
# Helper method to get the region name
def region
requires :region_id
@region ||= service.regions.get(region_id.to_i)
end
# Helper method to get an array with all available IP addresses
def ip_addresses
[public_ip_address, private_ip_address].flatten.select(&:present?)
end
end
end
end
end

View File

@ -1,95 +0,0 @@
require 'fog/core/collection'
require 'fog/digitalocean/models/compute/server'
module Fog
module Compute
class DigitalOcean
class Servers < Fog::Collection
model Fog::Compute::DigitalOcean::Server
# Returns list of servers
# @return [Fog::Compute::DigitalOcean::Servers] Retrieves a list of servers.
# @raise [Fog::Compute::DigitalOcean::NotFound] - HTTP 404
# @raise [Fog::Compute::DigitalOcean::BadRequest] - HTTP 400
# @raise [Fog::Compute::DigitalOcean::InternalServerError] - HTTP 500
# @raise [Fog::Compute::DigitalOcean::ServiceError]
# @see https://developers.digitalocean.com/v1/droplets/
def all(filters = {})
data = service.list_servers.body['droplets']
load(data)
end
# Creates a new server and populates ssh keys
#
# @return [Fog::Compute::DigitalOcean::Server]
# @raise [Fog::Compute::DigitalOcean::NotFound] - HTTP 404
# @raise [Fog::Compute::DigitalOcean::BadRequest] - HTTP 400
# @raise [Fog::Compute::DigitalOcean::InternalServerError] - HTTP 500
# @raise [Fog::Compute::DigitalOcean::ServiceError]
# @note This creates an SSH public key object and assigns it to the server on creation
# @example
# 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'
#
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
# Retrieves server
# @param [String] id for server to be returned
# @return [Fog::Compute::DigitalOcean:Server]
# @raise [Fog::Compute::DigitalOcean::NotFound] - HTTP 404
# @raise [Fog::Compute::DigitalOcean::BadRequest] - HTTP 400
# @raise [Fog::Compute::DigitalOcean::InternalServerError] - HTTP 500
# @raise [Fog::Compute::DigitalOcean::ServiceError]
# @see https://developers.digitalocean.com/v1/droplets/
def get(id)
server = service.get_server_details(id).body['droplet']
new(server) if server
rescue Fog::Errors::NotFound
nil
end
protected
def check_keys(attributes)
check_key :public, attributes[:public_key], attributes[:public_key_path]
check_key :private, attributes[:private_key], attributes[:private_key_path]
end
def check_key(name, data, path)
if [data, path].all?(&:nil?)
raise ArgumentError, "either #{name}_key or #{name}_key_path is required to configure the server"
end
end
end
end
end
end

View File

@ -1,26 +0,0 @@
module Fog
module Compute
class DigitalOcean
class SshKey < Fog::Model
identity :id
attribute :name
attribute :ssh_pub_key
def save
requires :name, :ssh_pub_key
merge_attributes(service.create_ssh_key(name, ssh_pub_key).body['ssh_key'])
true
end
def destroy
requires :id
service.destroy_ssh_key id
true
end
end
end
end
end

View File

@ -1,25 +0,0 @@
require 'fog/digitalocean/models/compute/ssh_key'
module Fog
module Compute
class DigitalOcean
class SshKeys < Fog::Collection
identity :href
model Fog::Compute::DigitalOcean::SshKey
def all
data = service.list_ssh_keys.body['ssh_keys']
load(data)
end
def get(uri)
data = service.get_ssh_key(uri).body['ssh_key']
new(data)
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View File

@ -1,5 +1,5 @@
require 'fog/core/collection'
require 'fog/digitalocean/models/compute/server'
require 'fog/digitalocean/models/compute_v2/server'
module Fog
module Compute

View File

@ -1,77 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
#
# FIXME: missing ssh keys support
#
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
end
class Mock
def create_server( name,
size_id,
image_id,
region_id,
options = {} )
response = Excon::Response.new
response.status = 200
# New York 2 (region id 4) is currently the only region that supports
# private networking. The Digital Ocean IP will return a null
# private_ip_address for any other region
has_private_ip = !!options[:private_networking] && (region_id == 4)
mock_data = {
"id" => Fog::Mock.random_numbers(1).to_i,
"event_id" => Fog::Mock.random_numbers(2).to_i,
"name" => name,
"size_id" => size_id,
"image_id" => image_id,
"region_id" => region_id,
"ip_address" => "127.0.0.1",
"private_ip_address" => has_private_ip ? "10.0.0.1" : nil,
"status" => 'active',
"created_at" => Time.now.strftime("%FT%TZ")
}
response.body = {
"status" => "OK",
"droplet" => mock_data
}
self.data[:servers] << mock_data
response
end
end
end
end
end

View File

@ -1,34 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
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
end
class Mock
def create_ssh_key( name, pub_key )
response = Excon::Response.new
response.status = 200
mock_data = {
"id" => Fog::Mock.random_numbers(1).to_i,
"name" => name,
"ssh_pub_key" => pub_key
}
response.body = {
"status" => "OK",
"ssh_key" => mock_data
}
self.data[:ssh_keys] << mock_data
response
end
end
end
end
end

View File

@ -1,35 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
#
# FIXME: missing ssh keys support
#
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
end
class Mock
def destroy_server( id )
response = Excon::Response.new
response.status = 200
response.body = {
"event_id" => Fog::Mock.random_numbers(1).to_i,
"status" => "OK"
}
server = self.data[:servers].reject! { |s| s['id'] == id }
response
end
end
end
end
end

View File

@ -1,33 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
#
# Delete a SSH public key from your account
#
# @see https://developers.digitalocean.com/ssh-keys
#
def destroy_ssh_key(id)
request(
:expects => [200],
:method => 'GET',
:path => "ssh_keys/#{id}/destroy"
)
end
end
class Mock
def destroy_ssh_key(id)
response = Excon::Response.new
response.status = 200
if self.data[:ssh_keys].reject! { |k| k['id'] == id }
response.body = { "status" => "OK" }
else
response.body = { "status" => "ERROR" }
end
response
end
end
end
end
end

View File

@ -1,31 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
def get_server_details(server_id)
request(
:expects => [200],
:method => 'GET',
:path => "droplets/#{server_id}"
)
end
end
class Mock
def get_server_details(server_id)
response = Excon::Response.new
response.status = 200
server = self.data[:servers].find { |s| s['id'] == server_id }
response.body = {
"status" => "OK",
"droplet" => self.data[:servers].find { |s| s['id'] == server_id }
}
response
end
end
end
end
end

View File

@ -1,35 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
#
# This method shows a specific public SSH key in your account
# that can be added to a droplet.
#
# @see https://developers.digitalocean.com/ssh-keys
#
def get_ssh_key(id)
request(
:expects => [200],
:method => 'GET',
:path => "ssh_keys/#{id}"
)
end
end
class Mock
def get_ssh_key(id)
response = Excon::Response.new
response.status = 200
response.body = {
"status" => "OK",
# key listing does not return ssh_pub_key
# https://developers.digitalocean.com/ssh-keys
"ssh_key" => self.data[:ssh_keys].find { |k| k['id'] == id }
}
response
end
end
end
end
end

View File

@ -1,34 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
def list_flavors(options = {})
request(
:expects => [200],
:method => 'GET',
:path => 'sizes'
)
end
end
class Mock
def list_flavors
response = Excon::Response.new
response.status = 200
response.body = {
"status" => "OK",
"sizes" => [
{"id" => 33,"name" => "512MB"},
{"id" => 34,"name" => "1GB"},
{"id" => 35,"name" => "2GB"},
{"id" => 36,"name" => "4GB"},
{"id" => 37,"name" => "8GB"},
{"id" => 38,"name" => "16GB"}
]
}
response
end
end
end
end
end

View File

@ -1,45 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
def list_images(options = {})
request(
:expects => [200],
:method => 'GET',
:path => 'images'
)
end
end
class Mock
def list_images
response = Excon::Response.new
response.status = 200
response.body = {
"status" => "OK",
"images" => [
# Sample image
{
"id" => 1601,
"name" => "CentOS 5.8 x64",
"distribution" => "CentOS"
},
{
"id" => 1602,
"name" => "CentOS 5.8 x32",
"distribution" => "CentOS"
},
{
"id" => 2676,
"name" => "Ubuntu 12.04 x64",
"distribution" => "Ubuntu"
},
]
}
response
end
end
end
end
end

View File

@ -1,34 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
def list_regions(options = {})
request(
:expects => [200],
:method => 'GET',
:path => 'regions'
)
end
end
class Mock
def list_regions
response = Excon::Response.new
response.status = 200
response.body = {
"status" => "OK",
"regions" => [
{ "id" => 1, "name" => "New York 1" },
{ "id" => 2, "name" => "Amsterdam 1" },
{ "id" => 3, "name" => "San Francisco 1" },
{ "id" => 4, "name" => "New York 2" },
{ "id" => 5, "name" => "Amsterdam 2" },
{ "id" => 6, "name" => "Singapore 1" }
]
}
response
end
end
end
end
end

View File

@ -1,27 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
def list_servers(options = {})
request(
:expects => [200],
:method => 'GET',
:path => 'droplets'
)
end
end
class Mock
def list_servers
response = Excon::Response.new
response.status = 200
response.body = {
"status" => "OK",
"droplets" => self.data[:servers]
}
response
end
end
end
end
end

View File

@ -1,27 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
def list_ssh_keys(options = {})
request(
:expects => [200],
:method => 'GET',
:path => 'ssh_keys'
)
end
end
class Mock
def list_ssh_keys
response = Excon::Response.new
response.status = 200
response.body = {
"status" => "OK",
"ssh_keys" => self.data[:ssh_keys]
}
response
end
end
end
end
end

View File

@ -1,29 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
def power_cycle_server( id )
request(
:expects => [200],
:method => 'GET',
:path => "droplets/#{id}/power_cycle"
)
end
end
class Mock
def power_cycle_server( id )
response = Excon::Response.new
response.status = 200
server = self.data[:servers].find { |s| s['id'] == id }
server['status'] = 'off' if server
response.body = {
"event_id" => Fog::Mock.random_numbers(1).to_i,
"status" => "OK"
}
response
end
end
end
end
end

View File

@ -1,29 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
def power_off_server( id )
request(
:expects => [200],
:method => 'GET',
:path => "droplets/#{id}/power_off"
)
end
end
class Mock
def power_off_server( id )
response = Excon::Response.new
response.status = 200
server = self.data[:servers].find { |s| s['id'] }
server['status'] = 'off' if server
response.body = {
"event_id" => Fog::Mock.random_numbers(1).to_i,
"status" => "OK"
}
response
end
end
end
end
end

View File

@ -1,29 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
def power_on_server( id )
request(
:expects => [200],
:method => 'GET',
:path => "droplets/#{id}/power_on"
)
end
end
class Mock
def power_on_server( id )
response = Excon::Response.new
response.status = 200
server = self.data[:servers].find { |s| s['id'] }
server['status'] = 'active' if server
response.body = {
"event_id" => Fog::Mock.random_numbers(1).to_i,
"status" => "OK"
}
response
end
end
end
end
end

View File

@ -1,29 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
def reboot_server( id )
request(
:expects => [200],
:method => 'GET',
:path => "droplets/#{id}/reboot"
)
end
end
class Mock
def reboot_server( id )
response = Excon::Response.new
response.status = 200
server = self.data[:servers].find { |s| s['id'] == id }
server['status'] = 'off' if server
response.body = {
"event_id" => Fog::Mock.random_numbers(1).to_i,
"status" => "OK"
}
response
end
end
end
end
end

View File

@ -1,32 +0,0 @@
module Fog
module Compute
class DigitalOcean
class Real
def shutdown_server( id )
request(
:expects => [200],
:method => 'GET',
:path => "droplets/#{id}/shutdown"
)
end
end
class Mock
def shutdown_server( id )
response = Excon::Response.new
response.status = 200
server = self.data[:servers].find { |s| s['id'] == id }
# Simulate reboot
server['status'] = 'off' if server
response.body = {
"event_id" => Fog::Mock.random_numbers(1).to_i,
"status" => "OK"
}
response
end
end
end
end
end

View File

@ -1,29 +0,0 @@
Shindo.tests("Fog::Compute[:digitalocean] | flavor model", ['digitalocean', 'compute']) do
service = Fog::Compute[:digitalocean]
flavor = service.flavors.first
tests('The flavor model should') do
tests('have the action') do
test('reload') { flavor.respond_to? 'reload' }
end
tests('have attributes') do
model_attribute_hash = flavor.attributes
attributes = [
:id,
:name,
]
tests("The flavor model should respond to") do
attributes.each do |attribute|
test("#{attribute}") { flavor.respond_to? attribute }
end
end
tests("The attributes hash should have key") do
attributes.each do |attribute|
test("#{attribute}") { model_attribute_hash.key? attribute }
end
end
end
end
end

View File

@ -1,30 +0,0 @@
Shindo.tests("Fog::Compute[:digitalocean] | image model", ['digitalocean', 'compute']) do
service = Fog::Compute[:digitalocean]
image = service.images.first
tests('The image model should') do
tests('have the action') do
test('reload') { image.respond_to? 'reload' }
end
tests('have attributes') do
model_attribute_hash = image.attributes
attributes = [
:id,
:name,
:distribution
]
tests("The image model should respond to") do
attributes.each do |attribute|
test("#{attribute}") { image.respond_to? attribute }
end
end
tests("The attributes hash should have key") do
attributes.each do |attribute|
test("#{attribute}") { model_attribute_hash.key? attribute }
end
end
end
end
end

View File

@ -1,29 +0,0 @@
Shindo.tests("Fog::Compute[:digitalocean] | region model", ['digitalocean', 'compute']) do
service = Fog::Compute[:digitalocean]
region = service.regions.first
tests('The region model should') do
tests('have the action') do
test('reload') { region.respond_to? 'reload' }
end
tests('have attributes') do
model_attribute_hash = region.attributes
attributes = [
:id,
:name,
]
tests("The region model should respond to") do
attributes.each do |attribute|
test("#{attribute}") { region.respond_to? attribute }
end
end
tests("The attributes hash should have key") do
attributes.each do |attribute|
test("#{attribute}") { model_attribute_hash.key? attribute }
end
end
end
end
end

View File

@ -1,93 +0,0 @@
Shindo.tests("Fog::Compute[:digitalocean] | server model", ['digitalocean', 'compute']) do
server = fog_test_server
tests('The server model should') do
tests('have the action') do
test('reload') { server.respond_to? 'reload' }
%w{
shutdown
reboot
power_cycle
stop
start
}.each do |action|
test(action) { server.respond_to? action }
end
end
tests('have attributes') do
model_attribute_hash = server.attributes
attributes = [
:id,
:name,
:state,
:backups_active,
:public_ip_address,
:private_ip_address,
:flavor_id,
:region_id,
:image_id,
:created_at,
:ssh_keys=
]
tests("The server model should respond to") do
attributes.each do |attribute|
test("#{attribute}") { server.respond_to? attribute }
end
end
end
test('#reboot') do
pending if Fog.mocking?
server.reboot
server.wait_for { server.state == 'off' }
server.state == 'off'
end
test('#power_cycle') do
pending if Fog.mocking?
server.wait_for { server.ready? }
server.power_cycle
server.wait_for { server.state == 'off' }
server.state == 'off'
end
test('#stop') do
server.stop
server.wait_for { server.state == 'off' }
server.state == 'off'
end
test('#start') do
server.start
server.wait_for { ready? }
server.ready?
end
# DigitalOcean shutdown is unreliable
# so disable it in real mode for now
test('#shutdown') do
pending unless Fog.mocking?
server.start
server.wait_for { server.ready? }
server.shutdown
server.wait_for { server.state == 'off' }
server.state == 'off'
end
test('#update') do
begin
server.update
rescue NotImplementedError => e
true
end
end
end
# restore server state
server.start
server.wait_for { ready? }
end

View File

@ -1,39 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | servers collection', ['digitalocean']) do
service = Fog::Compute[:digitalocean]
options = {
:name => "#{fog_server_name}-#{Time.now.to_i.to_s}"
}.merge fog_test_server_attributes
public_key_path = File.join(File.dirname(__FILE__), '../../fixtures/id_rsa.pub')
private_key_path = File.join(File.dirname(__FILE__), '../../fixtures/id_rsa')
# Collection tests are consistently timing out on Travis wasting people's time and resources
pending if Fog.mocking?
collection_tests(service.servers, options, true) do
@instance.wait_for { ready? }
end
tests("#bootstrap with public/private_key_path").succeeds do
pending if Fog.mocking?
@server = service.servers.bootstrap({
:public_key_path => public_key_path,
:private_key_path => private_key_path
}.merge(options))
@server.destroy
end
tests("#bootstrap with public/private_key").succeeds do
pending if Fog.mocking?
@server = service.servers.bootstrap({
:public_key => File.read(public_key_path),
:private_key => File.read(private_key_path)
}.merge(options))
@server.destroy
end
tests("#bootstrap with no public/private keys") do
raises(ArgumentError, 'raises ArgumentError') { service.servers.bootstrap(options) }
end
end

View File

@ -1,43 +0,0 @@
Shindo.tests("Fog::Compute[:digitalocean] | ssh_key model", ['digitalocean', 'compute']) do
service = Fog::Compute[:digitalocean]
tests('The ssh_key model should') do
test('#save') do
@key = service.ssh_keys.create :name => 'fookey',
:ssh_pub_key => 'fookey'
@key.is_a? Fog::Compute::DigitalOcean::SshKey
end
tests('have the action') do
test('reload') { @key.respond_to? 'reload' }
%w{
save
destroy
}.each do |action|
test(action) { @key.respond_to? action }
end
end
tests('have attributes') do
attributes = [
:id,
:name,
:ssh_pub_key
]
tests("The key model should respond to") do
attributes.each do |attribute|
test("#{attribute}") { @key.respond_to? attribute }
end
end
end
test('#destroy') do
@key.destroy
end
end
end

View File

@ -1,32 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | ssh_keys collection', ['digitalocean']) do
service = Fog::Compute[:digitalocean]
tests('The ssh_keys collection') do
key = service.ssh_keys.create :name => 'fookey',
:ssh_pub_key => 'fookey'
[:all, :get].each do |method|
test("should respond to #{method}") do
service.ssh_keys.respond_to? method
end
end
tests('should have Fog::Compute::DigitalOcean::SshKey inside') do
service.ssh_keys.each do |s|
test { s.kind_of? Fog::Compute::DigitalOcean::SshKey }
end
end
tests('should be able to get a model') do
test('by instance id') do
retrieved_key = service.ssh_keys.get(key.id)
test { retrieved_key.kind_of? Fog::Compute::DigitalOcean::SshKey }
test { retrieved_key.name == key.name }
end
end
key.destroy
end
end

View File

@ -1,32 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | create_server request', ['digitalocean', 'compute']) do
@server_format = {
'id' => Integer,
'name' => String,
'image_id' => Integer,
'size_id' => Integer,
'event_id' => Integer
}
service = Fog::Compute[:digitalocean]
tests('success') do
tests('#create_server').formats({'status' => 'OK', 'droplet' => @server_format}) do
image = service.images.find { |i| i.name == 'Ubuntu 13.10 x64' }
image_id = image.nil? ? 1505447 : image.id
region = service.regions.find { |r| r.name == 'New York 1' }
region_id = region.nil? ? 4 : region.id
flavor = service.flavors.find { |r| r.name == '512MB' }
flavor_id = flavor.nil? ? 66 : flavor.id
data = Fog::Compute[:digitalocean].create_server(
fog_server_name,
flavor_id,
image_id,
region_id
)
data.body
end
end
end

View File

@ -1,22 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | create_ssh_key request', ['digitalocean', 'compute']) do
@key_format = {
'id' => Integer,
'name' => String,
'ssh_pub_key' => String
}
service = Fog::Compute[:digitalocean]
tests('success') do
tests('#create_ssh_key').formats({'status' => 'OK', 'ssh_key' => @key_format}) do
@key = Fog::Compute[:digitalocean].create_ssh_key 'fookey', 'fookey'
@key.body
end
end
service.destroy_ssh_key @key.body['ssh_key']['id']
end

View File

@ -1,14 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | destroy_server request', ['digitalocean', 'compute']) do
service = Fog::Compute[:digitalocean]
server = fog_test_server
tests('success') do
test('#destroy_server') do
service.destroy_server(server.id).body['status'] == 'OK'
service.servers.get(server.id) == nil
end
end
end

View File

@ -1,23 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | destroy_ssh_key request', ['digitalocean', 'compute']) do
service = Fog::Compute[:digitalocean]
tests('success') do
test('#destroy_ssh_key') do
key = service.create_ssh_key 'fookey', 'fookey'
service.destroy_ssh_key(key.body['ssh_key']['id']).body['status'] == 'OK'
end
end
tests('failures') do
test 'delete invalid key' do
# DigitalOcean API returns 500 with this sometimes
# so mark it as pending in real mode
pending unless Fog.mocking?
service.destroy_ssh_key('00000000000').body['status'] == 'ERROR'
end
end
end

View File

@ -1,13 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | get_server_details request', ['digitalocean', 'compute']) do
tests('success') do
test('#get_server_details') do
server = fog_test_server
body = Fog::Compute[:digitalocean].get_server_details(server.id).body
body['droplet']['name'] == fog_server_name
end
end
end

View File

@ -1,25 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | get_ssh_keys request', ['digitalocean', 'compute']) do
@ssh_key_format = {
'id' => Integer,
'name' => String,
'ssh_pub_key' => String,
}
service = Fog::Compute[:digitalocean]
tests('success') do
tests('#get_ssh_key') do
key = service.create_ssh_key 'fookey', 'ssh-dss FOO'
tests('format').data_matches_schema(@ssh_key_format) do
service.get_ssh_key(key.body['ssh_key']['id']).body['ssh_key']
end
service.destroy_ssh_key(key.body['ssh_key']['id'])
end
end
end

View File

@ -1,23 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | list_flavors request', ['digitalocean', 'compute']) do
# {"id":2,"name":"Amsterdam 1"}
@flavor_format = {
'id' => Integer,
'name' => String,
}
tests('success') do
tests('#list_flavor') do
flavors = Fog::Compute[:digitalocean].list_flavors.body
test 'returns a Hash' do
flavors.is_a? Hash
end
tests('flavor').formats(@flavor_format, false) do
flavors['sizes'].first
end
end
end
end

View File

@ -1,24 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | list_images request', ['digitalocean', 'compute']) do
# {"id"=>1601, "name"=>"CentOS 5.8 x64", "distribution"=>"CentOS"}
@image_format = {
'id' => Integer,
'name' => String,
'distribution' => String
}
tests('success') do
tests('#list_images') do
images = Fog::Compute[:digitalocean].list_images.body
test 'returns a Hash' do
images.is_a? Hash
end
tests('image').formats(@image_format, false) do
images['images'].first
end
end
end
end

View File

@ -1,23 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | list_regions request', ['digitalocean', 'compute']) do
# {"id":2,"name":"Amsterdam 1"}
@region_format = {
'id' => Integer,
'name' => String,
}
tests('success') do
tests('#list_regions') do
regions = Fog::Compute[:digitalocean].list_regions.body
test 'returns a Hash' do
regions.is_a? Hash
end
tests('region').formats(@region_format, false) do
regions['regions'].first
end
end
end
end

View File

@ -1,27 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | list_servers request', ['digitalocean', 'compute']) do
@server_format = {
'id' => Integer,
'name' => String,
'image_id' => Integer,
'size_id' => Integer,
'region_id' => Integer,
'backups_active' => Fog::Nullable::Boolean,
'ip_address' => Fog::Nullable::String,
'status' => String,
'created_at' => String
}
tests('success') do
tests('#list_servers') do
Fog::Compute[:digitalocean].list_servers.body['droplets'].each do |server|
tests('format').data_matches_schema(@server_format) do
server
end
end
end
end
end

View File

@ -1,24 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | list_ssh_keys request', ['digitalocean', 'compute']) do
@ssh_key_format = {
'id' => Integer,
'name' => String
}
tests('success') do
ssh_key = service.create_ssh_key 'fookey', 'ssh-dss FOO'
tests('#list_ssh_keys') do
service.list_ssh_keys.body['ssh_keys'].each do |key|
tests('format').data_matches_schema(@ssh_key_format) do
key
end
end
end
service.destroy_ssh_key(ssh_key.body['ssh_key']['id'])
end
end

View File

@ -1,20 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | power_cycle_server request', ['digitalocean', 'compute']) do
server = fog_test_server
tests('success') do
tests('#power_cycle_server') do
test('returns 200') do
service.power_cycle_server(server.id).status == 200
end
test('state is off') do
server.wait_for { server.state == 'off' }
server.state == 'off'
end
end
end
end

View File

@ -1,25 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | power on/off/shutdown requests',
['digitalocean', 'compute']) do
service = Fog::Compute[:digitalocean]
server = fog_test_server
tests('success') do
test('#power_off_server') do
service.power_off_server(server.id).body['status'] == 'OK'
end
test('#power_on_server') do
service.power_on_server(server.id).body['status'] == 'OK'
end
test('#shutdown_server') do
service.shutdown_server(server.id).body['status'] == 'OK'
end
server.start
end
end

View File

@ -1,14 +0,0 @@
Shindo.tests('Fog::Compute[:digitalocean] | reboot_server request', ['digitalocean', 'compute']) do
server = fog_test_server
tests('success') do
tests('#reboot_server').succeeds do
service.reboot_server(server.id).body['status'] == 'OK'
end
end
end