mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Remove digitalocean
This commit is contained in:
parent
e1a9c6237e
commit
1e94d2457a
56 changed files with 2 additions and 2626 deletions
|
@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|||
## the sub! line in the Rakefile
|
||||
s.name = "fog"
|
||||
s.version = "1.38.0"
|
||||
s.date = "2016-03-28"
|
||||
s.date = "2016-08-03"
|
||||
s.rubyforge_project = "fog"
|
||||
|
||||
## Make sure your summary is short. The description may be as long
|
||||
|
@ -75,6 +75,7 @@ Gem::Specification.new do |s|
|
|||
s.add_dependency("fog-voxel")
|
||||
s.add_dependency("fog-vsphere", ">= 0.4.0")
|
||||
s.add_dependency("fog-xenserver")
|
||||
s.add_dependency("fog-digitalocean")
|
||||
|
||||
s.add_development_dependency("docker-api", ">= 1.13.6")
|
||||
s.add_development_dependency("fission")
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
# 1.10.1 2013/04/04
|
||||
|
||||
* Initial release
|
||||
|
||||
Getting started example: https://github.com/fog/fog/blob/master/lib/fog/digitalocean/examples/getting_started.md
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
require 'fog/digitalocean/core'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2 < Fog::Service
|
||||
requires :digitalocean_token
|
||||
|
||||
model_path 'fog/digitalocean/models/compute_v2'
|
||||
model :server
|
||||
collection :servers
|
||||
model :image
|
||||
collection :images
|
||||
model :region
|
||||
collection :regions
|
||||
model :flavor
|
||||
collection :flavors
|
||||
model :ssh_key
|
||||
collection :ssh_keys
|
||||
|
||||
request_path 'fog/digitalocean/requests/compute_v2'
|
||||
request :change_kernel
|
||||
request :create_server
|
||||
request :create_ssh_key
|
||||
request :destroy_server
|
||||
request :delete_ssh_key
|
||||
request :disable_backups
|
||||
request :enable_ipv6
|
||||
request :enable_private_networking
|
||||
request :get_droplet_action
|
||||
request :get_image_details
|
||||
request :get_server_details
|
||||
request :get_ssh_key
|
||||
request :list_droplet_actions
|
||||
request :list_flavors
|
||||
request :list_images
|
||||
request :list_regions
|
||||
request :list_servers
|
||||
request :list_ssh_keys
|
||||
request :password_reset
|
||||
request :power_cycle
|
||||
request :power_off
|
||||
request :power_on
|
||||
request :reboot_server
|
||||
request :rebuild
|
||||
request :rename
|
||||
request :resize
|
||||
request :restore
|
||||
request :shutdown
|
||||
request :snapshot
|
||||
request :update_ssh_key
|
||||
request :upgrade
|
||||
|
||||
|
||||
class Mock
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {
|
||||
:servers => [],
|
||||
:ssh_keys => []
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@digitalocean_token = options[:digitalocean_token]
|
||||
end
|
||||
|
||||
def data
|
||||
self.class.data[@digitalocean_token]
|
||||
end
|
||||
|
||||
def reset_data
|
||||
self.class.data.delete(@digitalocean_token)
|
||||
end
|
||||
end
|
||||
|
||||
class Real
|
||||
def initialize(options={})
|
||||
digitalocean_token = options[:digitalocean_token]
|
||||
persistent = false
|
||||
options = {
|
||||
headers: {
|
||||
'Authorization' => "Bearer #{digitalocean_token}",
|
||||
}
|
||||
}
|
||||
@connection = Fog::Core::Connection.new 'https://api.digitalocean.com', persistent, options
|
||||
end
|
||||
|
||||
def request(params)
|
||||
params[:headers] ||= {}
|
||||
begin
|
||||
response = @connection.request(params)
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise case error
|
||||
when Excon::Errors::NotFound
|
||||
NotFound.slurp(error)
|
||||
else
|
||||
error
|
||||
end
|
||||
end
|
||||
unless response.body.empty?
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
end
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
require 'fog/core'
|
||||
require 'fog/json'
|
||||
|
||||
module Fog
|
||||
module DigitalOcean
|
||||
extend Fog::Provider
|
||||
service(:compute_v2, 'Compute')
|
||||
end
|
||||
end
|
|
@ -1,124 +0,0 @@
|
|||
# Getting started: the compute service
|
||||
|
||||
You'll need a DigitalOcean account and an API token to use this provider.
|
||||
|
||||
Get one from https://cloud.digitalocean.com/settings/tokens/new
|
||||
|
||||
Write down the Access Token.
|
||||
|
||||
## Connecting, retrieving and managing server objects
|
||||
|
||||
Before we start, I guess it will be useful to the reader to know
|
||||
that Fog servers are 'droplets' in DigitalOcean's parlance.
|
||||
'Server' is the Fog way to name VMs, and we have
|
||||
respected that in the DigitalOcean's Fog provider.
|
||||
|
||||
First, create a connection to the host:
|
||||
|
||||
```ruby
|
||||
require 'fog'
|
||||
|
||||
docean = Fog::Compute.new({
|
||||
:provider => 'DigitalOcean',
|
||||
:version => 'V2',
|
||||
:digitalocean_token => 'poiuweoruwoeiuroiwuer', # your Access Token here
|
||||
})
|
||||
```
|
||||
|
||||
## SSH Key Management
|
||||
|
||||
Access to DigitalOcean servers can be managed with SSH keys. These can be assigned to servers at creation time so you can access them without having to use a password.
|
||||
|
||||
Creating a key:
|
||||
|
||||
```ruby
|
||||
docean.ssh_keys.create(
|
||||
:name => 'Default SSH Key',
|
||||
:ssh_pub_key => File.read('~/.ssh/id_rsa.pub'))
|
||||
)
|
||||
```
|
||||
|
||||
Listing all keys:
|
||||
|
||||
```ruby
|
||||
docean.ssh_keys.each do | key |
|
||||
puts key.name
|
||||
puts key.public_key
|
||||
puts key.id
|
||||
end
|
||||
```
|
||||
|
||||
Destroying a key:
|
||||
|
||||
```ruby
|
||||
docean.ssh_keys.destroy(:id => '27100')
|
||||
```
|
||||
## Listing servers
|
||||
|
||||
Listing servers and attributes:
|
||||
|
||||
```ruby
|
||||
docean.servers.each do |server|
|
||||
# remember, servers are droplets
|
||||
puts server.id
|
||||
puts server.name
|
||||
puts server.status
|
||||
puts (server.image['slug'] || server.image['name']) # slug is only for public images, private images use name
|
||||
puts server.size['slug']
|
||||
puts server.region['slug']
|
||||
end
|
||||
```
|
||||
|
||||
## Server creation and life-cycle management
|
||||
|
||||
Creating a new server (droplet):
|
||||
|
||||
```ruby
|
||||
server = docean.servers.create :name => 'foobar',
|
||||
# use the last image listed
|
||||
:image => docean.images.last.id,
|
||||
# use the first flavor (aka size) listed
|
||||
:size => docean.flavors.first.slug,
|
||||
# use the first region listed
|
||||
:region => docean.regions.first.slug
|
||||
```
|
||||
|
||||
The server is automatically started after that.
|
||||
|
||||
We didn't pay attention when choosing the flavor, image and region used
|
||||
but you can easily list them too, and then decide:
|
||||
|
||||
```ruby
|
||||
docean.images.each do |image|
|
||||
puts image.id
|
||||
puts image.name
|
||||
puts image.distribution
|
||||
end
|
||||
|
||||
docean.flavors.each do |flavor|
|
||||
puts flavor.slug
|
||||
end
|
||||
|
||||
docean.regions.each do |region|
|
||||
puts region.slug
|
||||
end
|
||||
```
|
||||
|
||||
Rebooting a server:
|
||||
|
||||
```ruby
|
||||
server = docean.servers.first
|
||||
server.reboot
|
||||
```
|
||||
|
||||
Power cycle a server:
|
||||
|
||||
```ruby
|
||||
server.power_cycle
|
||||
```
|
||||
|
||||
Destroying the server:
|
||||
|
||||
```ruby
|
||||
server.destroy
|
||||
```
|
|
@ -1,17 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Flavor < Fog::Model
|
||||
identity :slug
|
||||
attribute :available
|
||||
attribute :transfer
|
||||
attribute :price_monthly
|
||||
attribute :price_hourly
|
||||
attribute :memory
|
||||
attribute :vcpus
|
||||
attribute :disk
|
||||
attribute :regions
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Flavors < Fog::Collection
|
||||
model Fog::Compute::DigitalOceanV2::Flavor
|
||||
|
||||
# Retrieves flavours (aka. sizes)
|
||||
# @return [Fog::Compute::DigitalOceanV2:Flavor]
|
||||
# @raise [Fog::Compute::DigitalOceanV2::NotFound] - HTTP 404
|
||||
# @raise [Fog::Compute::DigitalOceanV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::DigitalOceanV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::DigitalOceanV2::ServiceError]
|
||||
# @see https://developers.digitalocean.com/documentation/v2/#list-all-sizes
|
||||
def all(filters = {})
|
||||
data = service.list_flavors(filters).body["sizes"]
|
||||
load(data)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,25 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Image < Fog::Model
|
||||
identity :id
|
||||
attribute :name
|
||||
attribute :type
|
||||
attribute :distribution
|
||||
attribute :slug
|
||||
attribute :public
|
||||
attribute :regions
|
||||
attribute :min_disk_size
|
||||
attribute :created_at
|
||||
end
|
||||
|
||||
def transfer
|
||||
perform_action :transfer_image
|
||||
end
|
||||
|
||||
def convert_to_snapshot
|
||||
perform_action :convert_image_to_snapshot
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
require 'fog/digitalocean/models/paging_collection'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Images < Fog::Compute::DigitalOceanV2::PagingCollection
|
||||
model Fog::Compute::DigitalOceanV2::Image
|
||||
|
||||
# Retrieves images
|
||||
# @return [Fog::Compute::DigitalOceanV2:Image]
|
||||
# @raise [Fog::Compute::DigitalOceanV2::NotFound] - HTTP 404
|
||||
# @raise [Fog::Compute::DigitalOceanV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::DigitalOceanV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::DigitalOceanV2::ServiceError]
|
||||
# @see https://developers.digitalocean.com/documentation/v2/#list-all-images
|
||||
def all(filters = {})
|
||||
data = service.list_images(filters)
|
||||
links = data.body["links"]
|
||||
get_paged_links(links)
|
||||
images = data.body["images"]
|
||||
load(images)
|
||||
end
|
||||
|
||||
# Retrieves image
|
||||
# @param [String] id for image to be returned
|
||||
# @return [Fog::Compute::DigitalOceanV2:Image]
|
||||
# @raise [Fog::Compute::DigitalOceanV2::NotFound] - HTTP 404
|
||||
# @raise [Fog::Compute::DigitalOceanV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::DigitalOceanV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::DigitalOceanV2::ServiceError]
|
||||
# @see https://developers.digitalocean.com/documentation/v2/#retrieve-an-existing-image-by-id
|
||||
def get(id)
|
||||
image = service.get_image_details(id).body['image']
|
||||
new(image) if image
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,13 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Region < Fog::Model
|
||||
identity :slug
|
||||
attribute :name
|
||||
attribute :sizes
|
||||
attribute :available
|
||||
attribute :features
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Regions < Fog::Collection
|
||||
model Fog::Compute::DigitalOceanV2::Region
|
||||
|
||||
# Retrieves regions
|
||||
# @return [Fog::Compute::DigitalOceanV2:Regions]
|
||||
# @raise [Fog::Compute::DigitalOceanV2::NotFound] - HTTP 404
|
||||
# @raise [Fog::Compute::DigitalOceanV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::DigitalOceanV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::DigitalOceanV2::ServiceError]
|
||||
# @see https://developers.digitalocean.com/documentation/v2/#list-all-regions
|
||||
def all(filters = {})
|
||||
data = service.list_regions(filters).body["regions"]
|
||||
load(data)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,170 +0,0 @@
|
|||
require 'fog/compute/models/server'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
# A DigitalOcean Droplet
|
||||
#
|
||||
class Server < Fog::Compute::Server
|
||||
identity :id
|
||||
attribute :name
|
||||
attribute :memory
|
||||
attribute :vcpus
|
||||
attribute :disk
|
||||
attribute :locked
|
||||
attribute :created_at
|
||||
attribute :status, :aliases => 'state'
|
||||
attribute :backup_ids
|
||||
attribute :snapshot_ids
|
||||
attribute :features
|
||||
attribute :region
|
||||
attribute :image
|
||||
attribute :size
|
||||
attribute :size_slug
|
||||
attribute :networks
|
||||
attribute :kernel
|
||||
attribute :next_backup_window
|
||||
attribute :private_networking
|
||||
attribute :backups
|
||||
attribute :ipv6
|
||||
attribute :ssh_keys
|
||||
|
||||
def public_ip_address
|
||||
ipv4_address
|
||||
end
|
||||
|
||||
def ipv6_address
|
||||
if (net = networks['v6'].find { |n| n['type'] == 'public' })
|
||||
net['ip_address']
|
||||
end
|
||||
end
|
||||
|
||||
def ipv4_address
|
||||
if (net = networks['v4'].find { |n| n['type'] == 'public' })
|
||||
net['ip_address']
|
||||
end
|
||||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Re-saving an existing object may create a duplicate') if persisted?
|
||||
requires :name, :region, :size, :image
|
||||
|
||||
options = {}
|
||||
if attributes[:ssh_keys]
|
||||
options[:ssh_keys] = attributes[:ssh_keys]
|
||||
elsif @ssh_keys
|
||||
options[:ssh_keys] = @ssh_keys.map(&:id)
|
||||
end
|
||||
|
||||
options[:private_networking] = private_networking
|
||||
options[:backups] = backups
|
||||
options[:ipv6] = ipv6
|
||||
|
||||
data = service.create_server(name, size, image, region, options)
|
||||
|
||||
merge_attributes(data.body['droplet'])
|
||||
true
|
||||
end
|
||||
|
||||
def delete
|
||||
requires :id
|
||||
response = service.delete_server id
|
||||
response.body
|
||||
end
|
||||
|
||||
def ready?
|
||||
status == 'active'
|
||||
end
|
||||
|
||||
def locked?
|
||||
locked
|
||||
end
|
||||
|
||||
def actions
|
||||
requires :id
|
||||
response = service.list_droplet_actions id
|
||||
response.body
|
||||
end
|
||||
|
||||
def action(action_id)
|
||||
requires :id
|
||||
response = service.get_droplet_action(id, action_id)
|
||||
response.body
|
||||
end
|
||||
|
||||
def reboot
|
||||
perform_action :reboot_server
|
||||
end
|
||||
|
||||
def disable_backups
|
||||
perform_action :disable_backups
|
||||
end
|
||||
|
||||
def power_cycle
|
||||
perform_action :power_cycle
|
||||
end
|
||||
|
||||
def shutdown
|
||||
perform_action :shutdown
|
||||
end
|
||||
|
||||
def power_off
|
||||
perform_action :power_off
|
||||
end
|
||||
|
||||
def power_on
|
||||
perform_action :power_on
|
||||
end
|
||||
|
||||
def restore(image)
|
||||
perform_action :restore, image
|
||||
end
|
||||
|
||||
def password_reset
|
||||
perform_action :password_reset
|
||||
end
|
||||
|
||||
def resize(resize_disk, size)
|
||||
perform_action :resize, resize_disk, size
|
||||
end
|
||||
|
||||
def rebuild(image)
|
||||
perform_action :rebuild, image
|
||||
end
|
||||
|
||||
def rename(name)
|
||||
perform_action :rename, name
|
||||
end
|
||||
|
||||
def change_kernel(kernel)
|
||||
perform_action :change_kernel, kernel
|
||||
end
|
||||
|
||||
def enable_ipv6
|
||||
perform_action :enable_ipv6
|
||||
end
|
||||
|
||||
def enable_private_networking
|
||||
perform_action :enable_private_networking
|
||||
end
|
||||
|
||||
def snapshot(name)
|
||||
perform_action :snapshot, name
|
||||
end
|
||||
|
||||
def upgrade
|
||||
perform_action :upgrade
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Performs a droplet action with the given set of arguments.
|
||||
def perform_action(action, *args)
|
||||
requires :id
|
||||
response = service.send(action, id, *args)
|
||||
response.body
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,43 +0,0 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/digitalocean/models/compute_v2/server'
|
||||
require 'fog/digitalocean/models/paging_collection'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Servers < Fog::Compute::DigitalOceanV2::PagingCollection
|
||||
model Fog::Compute::DigitalOceanV2::Server
|
||||
|
||||
# Returns list of servers
|
||||
# @return [Fog::Compute::DigitalOceanV2::Servers]
|
||||
# @raise [Fog::Compute::DigitalOceanV2::NotFound] - HTTP 404
|
||||
# @raise [Fog::Compute::DigitalOceanV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::DigitalOceanV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::DigitalOceanV2::ServiceError]
|
||||
# @see https://developers.digitalocean.com/documentation/v2/#droplets
|
||||
def all(filters = {})
|
||||
data = service.list_servers(filters)
|
||||
links = data.body["links"]
|
||||
get_paged_links(links)
|
||||
droplets = data.body["droplets"]
|
||||
load(droplets)
|
||||
end
|
||||
|
||||
# Retrieves server
|
||||
# @param [String] id for server to be returned
|
||||
# @return [Fog::Compute::DigitalOceanV2:Server]
|
||||
# @raise [Fog::Compute::DigitalOceanV2::NotFound] - HTTP 404
|
||||
# @raise [Fog::Compute::DigitalOceanV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::DigitalOceanV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::DigitalOceanV2::ServiceError]
|
||||
# @see https://developers.digitalocean.com/documentation/v2/#retrieve-an-existing-droplet-by-id
|
||||
def get(id)
|
||||
server = service.get_server_details(id).body['droplet']
|
||||
new(server) if server
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,31 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class SshKey < Fog::Model
|
||||
identity :id
|
||||
attribute :fingerprint
|
||||
attribute :public_key
|
||||
attribute :name
|
||||
|
||||
def save
|
||||
requires :name, :public_key
|
||||
merge_attributes(service.create_ssh_key(name, public_key).body['ssh_key'])
|
||||
true
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
service.delete_ssh_key id
|
||||
end
|
||||
|
||||
def update
|
||||
requires :id, :name
|
||||
data = service.update_server(id, name)
|
||||
merge_attributes(data.body['ssh_key'])
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
require 'fog/digitalocean/models/paging_collection'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class SshKeys < Fog::Compute::DigitalOceanV2::PagingCollection
|
||||
model Fog::Compute::DigitalOceanV2::SshKey
|
||||
|
||||
# Returns list of ssh keys
|
||||
# @return [Fog::Compute::DigitalOceanV2::Sshkeys] Retrieves a list of ssh keys.
|
||||
# @raise [Fog::Compute::DigitalOceanV2::NotFound] - HTTP 404
|
||||
# @raise [Fog::Compute::DigitalOceanV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::DigitalOceanV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::DigitalOceanV2::ServiceError]
|
||||
# @see https://developers.digitalocean.com/documentation/v2/#list-all-keys
|
||||
def all(filters = {})
|
||||
data = service.list_ssh_keys(filters)
|
||||
links = data.body["links"]
|
||||
get_paged_links(links)
|
||||
keys = data.body["ssh_keys"]
|
||||
load(keys)
|
||||
end
|
||||
|
||||
# Returns ssh key
|
||||
# @return [Fog::Compute::DigitalOceanV2::Sshkeys] Retrieves a list of ssh keys.
|
||||
# @raise [Fog::Compute::DigitalOceanV2::NotFound] - HTTP 404
|
||||
# @raise [Fog::Compute::DigitalOceanV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::DigitalOceanV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::DigitalOceanV2::ServiceError]
|
||||
# @see https://developers.digitalocean.com/documentation/v2/#retrieve-an-existing-key
|
||||
def get(id)
|
||||
key = service.get_ssh_key(id).body['ssh_key']
|
||||
new(key) if key
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,41 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class PagingCollection < Fog::Collection
|
||||
|
||||
attribute :next
|
||||
attribute :last
|
||||
|
||||
def next_page
|
||||
all(page: @next) if @next != @last
|
||||
end
|
||||
|
||||
def previous_page
|
||||
if @next.to_i > 2
|
||||
all(page: @next.to_i - 2)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def deep_fetch(hash, *path)
|
||||
path.inject(hash) do |acc, key|
|
||||
acc.respond_to?(:keys) ? acc[key] : nil
|
||||
end
|
||||
end
|
||||
|
||||
def get_page(link)
|
||||
if match = link.match(/page=(?<page>\d+)/)
|
||||
match.captures.last
|
||||
end
|
||||
end
|
||||
|
||||
def get_paged_links(links)
|
||||
next_link = deep_fetch(links, "pages", "next").to_s
|
||||
last_link = deep_fetch(links, "pages", "last").to_s
|
||||
@next = get_page(next_link) || @next
|
||||
@last = get_page(last_link) || @last
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def change_kernel(id, kernel)
|
||||
body = { :type => "change_kernel", :kernel => kernel }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def change_kernel(id, kernel)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "change_kernel",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def convert_to_snapshot(id)
|
||||
body = { :type => 'convert',}
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/images/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def convert_to_snapshot(id, name)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => 46592838,
|
||||
'status' => 'completed',
|
||||
'type' => 'convert_to_snapshot',
|
||||
'started_at' => '2015-03-24T19:02:47Z',
|
||||
'completed_at' => '2015-03-24T19:02:47Z',
|
||||
'resource_id' => 11060029,
|
||||
'resource_type' => 'image',
|
||||
'region' => null,
|
||||
'region_slug' => null
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,93 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Real
|
||||
|
||||
def create_server(name,
|
||||
size,
|
||||
image,
|
||||
region,
|
||||
options = {})
|
||||
|
||||
create_options = {
|
||||
:name => name,
|
||||
:region => region,
|
||||
:size => size,
|
||||
:image => image,
|
||||
}
|
||||
|
||||
[:backups, :ipv6, :private_networking].each do |opt|
|
||||
create_options[opt] = !!options[opt] if options[opt]
|
||||
end
|
||||
|
||||
[:user_data, :ssh_keys].each do |opt|
|
||||
create_options[opt] = options[opt] if options[opt]
|
||||
end
|
||||
|
||||
encoded_body = Fog::JSON.encode(create_options)
|
||||
|
||||
request(
|
||||
:expects => [202],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => '/v2/droplets',
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Mock
|
||||
def create_server(name,
|
||||
size,
|
||||
image,
|
||||
region,
|
||||
options = {})
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
|
||||
response.body = {
|
||||
'droplet' => {
|
||||
'id' => 3164494,
|
||||
'name' => name,
|
||||
'memory' => 512,
|
||||
'vcpus' => 1,
|
||||
'disk' => 20,
|
||||
'locked' => true,
|
||||
'status' => 'new',
|
||||
'kernel' => {
|
||||
'id' => 2233,
|
||||
'name' => 'Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic',
|
||||
'version' => '3.13.0-37-generic'
|
||||
},
|
||||
'created_at' => '2014-11-14T16:36:31Z',
|
||||
'features' => %w(virtio),
|
||||
'backup_ids' => [],
|
||||
'snapshot_ids' => [],
|
||||
'image' => {},
|
||||
'size' => {},
|
||||
'size_slug' => '512mb',
|
||||
'networks' => {},
|
||||
'region' => {}
|
||||
},
|
||||
'links' => {
|
||||
'actions' => [
|
||||
{
|
||||
'id' => 36805096,
|
||||
'rel' => "create",
|
||||
'href' => "https://api.digitalocean.com/v2/actions/36805096"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,49 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Real
|
||||
|
||||
def create_ssh_key(name, public_key)
|
||||
create_options = {
|
||||
:name => name,
|
||||
:public_key => public_key,
|
||||
}
|
||||
|
||||
encoded_body = Fog::JSON.encode(create_options)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => '/v2/account/keys',
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Mock
|
||||
def create_ssh_key(name, public_key)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
|
||||
data[:ssh_keys] << {
|
||||
"id" => Fog::Mock.random_numbers(6).to_i,
|
||||
"fingerprint" => (["00"] * 16).join(':'),
|
||||
"public_key" => public_key,
|
||||
"name" => name
|
||||
}
|
||||
|
||||
response.body ={
|
||||
'ssh_key' => data[:ssh_keys].last
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,32 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Real
|
||||
def delete_ssh_key(id)
|
||||
request(
|
||||
:expects => [204],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'DELETE',
|
||||
:path => "/v2/account/keys/#{id}",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Mock
|
||||
def delete_ssh_key(id)
|
||||
self.data[:ssh_keys].select! do |key|
|
||||
key["id"] != id
|
||||
end
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 204
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,35 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Real
|
||||
def delete_server(server_id)
|
||||
Fog::Logger.warning("delete_server method has been deprecated, use destroy_server instead")
|
||||
destroy_server(server_id)
|
||||
end
|
||||
def destroy_server(server_id)
|
||||
request(
|
||||
:expects => [204],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'DELETE',
|
||||
:path => "/v2/droplets/#{server_id}",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Mock
|
||||
def delete_server(server_id)
|
||||
destroy_server(server_id)
|
||||
end
|
||||
def destroy_server(_)
|
||||
response = Excon::Response.new
|
||||
response.status = 204
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,45 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def disable_backups(id)
|
||||
body = { :type => "disable_backups" }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def disable_backups(id)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "disable_backups",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def enable_ipv6(id)
|
||||
body = { :type => "enable_ipv6" }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def enable_ipv6(id)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "enable_ipv6",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def enable_private_networking(id)
|
||||
body = { :type => "enable_private_networking" }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def enable_private_networking(id)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "enable_private_networking",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,36 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def get_droplet_action(droplet_id, action_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "v2/droplets/#{droplet_id}/actions/#{action_id}",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_droplet_action(droplet_id, action)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "change_kernel",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def get_image_details(image_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "/v2/images/#{image_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Mock
|
||||
def get_server_details(_)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
response.body = {
|
||||
'image' =>
|
||||
{
|
||||
'id' => 7555620,
|
||||
'name' => 'Nifty New Snapshot',
|
||||
'distribution' => 'Ubuntu',
|
||||
'slug' => null,
|
||||
'public' => false,
|
||||
'regions' => [
|
||||
'nyc2',
|
||||
'nyc2'
|
||||
],
|
||||
'created_at' => '2014-11-04T22:23:02Z',
|
||||
'min_disk_size' => 20
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,84 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def get_server_details(server_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "/v2/droplets/#{server_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Mock
|
||||
def get_server_details(_)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
response.body = {
|
||||
'droplet' => {
|
||||
'id' => 3164494,
|
||||
'name' => 'example.com',
|
||||
'memory' => 512,
|
||||
'vcpus' => 1,
|
||||
'disk' => 20,
|
||||
'locked' => false,
|
||||
'status' => 'active',
|
||||
'kernel' => {
|
||||
'id' => 2233,
|
||||
'name' => 'Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic',
|
||||
'version' => '3.13.0-37-generic'
|
||||
},
|
||||
'created_at' => '2014-11-14T16:36:31Z',
|
||||
'features' => %w(ipv6 virtio),
|
||||
'backup_ids' => [],
|
||||
'snapshot_ids' => [7938206],
|
||||
'image' => {
|
||||
'id' => 6918990,
|
||||
'name' => '14.04 x64',
|
||||
'distribution' => 'Ubuntu',
|
||||
'slug' => 'ubuntu-14-04-x64',
|
||||
'public' => true,
|
||||
'regions' => %w(nyc1 ams1 sfo1 nyc2 ams2 sgp1 lon1 nyc3 ams3 nyc3),
|
||||
'created_at' => '2014-10-17T20:24:33Z',
|
||||
'type' => 'snapshot',
|
||||
'min_disk_size' => 20
|
||||
},
|
||||
'size' => {},
|
||||
'size_slug' => '512mb',
|
||||
'networks' => {
|
||||
'v4' => [
|
||||
{
|
||||
'ip_address' => '104.131.186.241',
|
||||
'netmask' => '255.255.240.0',
|
||||
'gateway' => '104.131.176.1',
|
||||
'type' => 'public'
|
||||
}
|
||||
],
|
||||
'v6' => [
|
||||
{
|
||||
'ip_address' => '2604:A880:0800:0010:0000:0000:031D:2001',
|
||||
'netmask' => 64,
|
||||
'gateway' => '2604:A880:0800:0010:0000:0000:0000:0001',
|
||||
'type' => 'public'
|
||||
}
|
||||
]
|
||||
},
|
||||
'region' => {
|
||||
'name' => 'New York 3',
|
||||
'slug' => 'nyc3',
|
||||
'sizes' => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
|
||||
'features' => %w(virtio private_networking backups ipv6 metadata),
|
||||
'available' => true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,34 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def get_ssh_key(key_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "/v2/account/keys/#{key_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Mock
|
||||
def get_ssh_key(_)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
response.body = {
|
||||
'ssh_key' => {
|
||||
'id' => 512190,
|
||||
'fingerprint' => '3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa',
|
||||
'public_key' => 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDDHr/jh2Jy4yALcK4JyWbVkPRaWmhck3IgCoeOO3z1e2dBowLh64QAM+Qb72pxekALga2oi4GvT+TlWNhzPH4V example',
|
||||
'name' => 'My SSH Public Key'
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,38 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def list_droplet_actions(id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_droplet_actions(id)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'actions' => [
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "change_kernel",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
]
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,132 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def list_flavors(filters = {})
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "/v2/sizes",
|
||||
:query => filters
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Mock
|
||||
def list_flavors(filters = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
|
||||
'sizes' => [
|
||||
{
|
||||
'slug' => '512mb',
|
||||
'memory' => 512,
|
||||
'vcpus' => 1,
|
||||
'disk' => 20,
|
||||
'transfer' => 1.0,
|
||||
'price_monthly' => 5.0,
|
||||
'price_hourly' => 0.00744,
|
||||
'regions' => %w(nyc1 sgp1 ams1 ams2 sfo1 nyc2 lon1 nyc3 ams3),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'slug' => '1gb',
|
||||
'memory' => 1024,
|
||||
'vcpus' => 1,
|
||||
'disk' => 30,
|
||||
'transfer' => 2.0,
|
||||
'price_monthly' => 10.0,
|
||||
'price_hourly' => 0.01488,
|
||||
'regions' => %w(nyc2 sgp1 ams1 sfo1 lon1 nyc3 ams3 ams2 nyc1),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'slug' => '2gb',
|
||||
'memory' => 2048,
|
||||
'vcpus' => 2,
|
||||
'disk' => 40,
|
||||
'transfer' => 3.0,
|
||||
'price_monthly' => 20.0,
|
||||
'price_hourly' => 0.02976,
|
||||
'regions' => %w(nyc2 sfo1 ams1 sgp1 ams2 lon1 nyc3 ams3 nyc1),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'slug' => '4gb',
|
||||
'memory' => 4096,
|
||||
'vcpus' => 2,
|
||||
'disk' => 60,
|
||||
'transfer' => 4.0,
|
||||
'price_monthly' => 40.0,
|
||||
'price_hourly' => 0.05952,
|
||||
'regions' => %w(nyc2 sfo1 ams1 sgp1 ams2 lon1 nyc3 ams3 nyc1),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'slug' => '8gb',
|
||||
'memory' => 8192,
|
||||
'vcpus' => 4,
|
||||
'disk' => 80,
|
||||
'transfer' => 5.0,
|
||||
'price_monthly' => 80.0,
|
||||
'price_hourly' => 0.11905,
|
||||
'regions' => %w(nyc2 sfo1 sgp1 ams1 ams2 nyc1 lon1 nyc3 ams3),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'slug' => '16gb',
|
||||
'memory' => 16384,
|
||||
'vcpus' => 8,
|
||||
'disk' => 160,
|
||||
'transfer' => 6.0,
|
||||
'price_monthly' => 160.0,
|
||||
'price_hourly' => 0.2381,
|
||||
'regions' => %w(sgp1 nyc1 sfo1 ams2 nyc3 lon1 nyc2 ams1 ams3),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'slug' => '32gb',
|
||||
'memory' => 32768,
|
||||
'vcpus' => 12,
|
||||
'disk' => 320,
|
||||
'transfer' => 7.0,
|
||||
'price_monthly' => 320.0,
|
||||
'price_hourly' => 0.47619,
|
||||
'regions' => %w(nyc2 sgp1 ams2 nyc1 sfo1 lon1 ams3 nyc3),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'slug' => '48gb',
|
||||
'memory' => 49152,
|
||||
'vcpus' => 16,
|
||||
'disk' => 480,
|
||||
'transfer' => 8.0,
|
||||
'price_monthly' => 480.0,
|
||||
'price_hourly' => 0.71429,
|
||||
'regions' => %w(sgp1 ams2 sfo1 nyc1 lon1 nyc2 ams3 nyc3),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'slug' => '64gb',
|
||||
'memory' => 65536,
|
||||
'vcpus' => 20,
|
||||
'disk' => 640,
|
||||
'transfer' => 9.0,
|
||||
'price_monthly' => 640.0,
|
||||
'price_hourly' => 0.95238,
|
||||
'regions' => %w(sgp1 nyc1 nyc2 sfo1 lon1 ams3 ams2 nyc3),
|
||||
'available' => true
|
||||
}
|
||||
],
|
||||
'links' => {},
|
||||
'meta' => {'total' => 9}
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,51 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def list_images(filters = {})
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "/v2/images",
|
||||
:query => filters
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Mock
|
||||
def list_images(filters = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
|
||||
'images' => [
|
||||
{
|
||||
'id' => 7555620,
|
||||
'name' => 'Nifty New Snapshot',
|
||||
'distribution' => 'Ubuntu',
|
||||
'slug' => nil,
|
||||
'public' => false,
|
||||
'regions' => %w(nyc2 nyc3),
|
||||
'created_at' => '2014-11-04T22:23:02Z',
|
||||
'type' => 'snapshot',
|
||||
'min_disk_size' => 20,
|
||||
}
|
||||
],
|
||||
'links' => {
|
||||
'pages' => {
|
||||
'last' => 'https://api.digitalocean.com/v2/images?page=56&per_page=1',
|
||||
'next' => 'https://api.digitalocean.com/v2/images?page=2&per_page=1'
|
||||
}
|
||||
},
|
||||
'meta' => {
|
||||
'total' => 56
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,95 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def list_regions(filters = {})
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "/v2/regions",
|
||||
:query => filters
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Mock
|
||||
def list_regions(filters = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'regions' => [
|
||||
{
|
||||
'name' => 'New York 1',
|
||||
'slug' => 'nyc1',
|
||||
'sizes' => [],
|
||||
'features' => %w(virtio backups),
|
||||
'available' => false
|
||||
},
|
||||
{
|
||||
'name' => 'Amsterdam 1',
|
||||
'slug' => 'ams1',
|
||||
'sizes' => [],
|
||||
'features' => %w(virtio backups),
|
||||
'available' => false
|
||||
},
|
||||
{
|
||||
'name' => 'San Francisco 1',
|
||||
'slug' => 'sfo1',
|
||||
'sizes' => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
|
||||
'features' => %w(virtio backups metadata),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'name' => 'New York 2',
|
||||
'slug' => 'nyc2',
|
||||
'sizes' => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
|
||||
'features' => %w(virtio private_networking backups),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'name' => 'Amsterdam 2',
|
||||
'slug' => 'ams2',
|
||||
'sizes' => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
|
||||
'features' => %w(virtio private_networking backups metadata),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'name' => 'Singapore 1',
|
||||
'slug' => 'sgp1',
|
||||
'sizes' => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
|
||||
'features' => %w(virtio private_networking backups ipv6 metadata),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'name' => 'London 1',
|
||||
'slug' => 'lon1',
|
||||
'sizes' => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
|
||||
'features' => %w(virtio private_networking backups ipv6 metadata),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'name' => 'New York 3',
|
||||
'slug' => 'nyc3',
|
||||
'sizes' => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
|
||||
'features' => %w(virtio private_networking backups ipv6 metadata),
|
||||
'available' => true
|
||||
},
|
||||
{
|
||||
'name' => 'Amsterdam 3',
|
||||
'slug' => 'ams3',
|
||||
'sizes' => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
|
||||
'features' => %w(virtio private_networking backups ipv6 metadata),
|
||||
'available' => true
|
||||
}
|
||||
],
|
||||
'links' => {},
|
||||
'meta' => {'total' => 9}
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,33 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def list_servers(filters = {})
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "/v2/droplets",
|
||||
:query => filters
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Mock
|
||||
def list_servers(filters = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"status" => "OK",
|
||||
"droplets" => self.data[:servers],
|
||||
"links" => {},
|
||||
"meta" => {
|
||||
"total" => data[:servers].count
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,41 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def list_ssh_keys(filters = {})
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "v2/account/keys",
|
||||
:query => filters
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Mock
|
||||
def list_ssh_keys(filters = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"ssh_keys" => data[:ssh_keys] ||
|
||||
[
|
||||
{
|
||||
"id" => 512189,
|
||||
"fingerprint" => "3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa",
|
||||
"public_key" => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDDHr/jh2Jy4yALcK4JyWbVkPRaWmhck3IgCoeOO3z1e2dBowLh64QAM+Qb72pxekALga2oi4GvT+TlWNhzPH4V example",
|
||||
"name" => "My SSH Public Key"
|
||||
}
|
||||
],
|
||||
"links" => {
|
||||
},
|
||||
"meta" => {
|
||||
"total" => data[:ssh_keys].count || 1
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def password_reset(id)
|
||||
body = { :type => "password_reset" }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def password_reset(id)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "password_reset",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def power_cycle(id)
|
||||
body = { :type => "power_cycle" }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def power_cycle(id)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "power_cycle",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def power_off(id)
|
||||
body = { :type => "power_off" }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def power_off(id)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "power_off",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def power_on(id)
|
||||
body = { :type => "power_on" }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def power_on(id)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "power_on",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def reboot_server(id)
|
||||
body = { :type => "reboot" }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def reboot_server(id)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "reboot",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def rebuild(id, image)
|
||||
body = { :type => "rebuild", :image => image }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def rebuild(id, image)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "rebuild",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def rename(id, name)
|
||||
body = { :type => "rename", :name => name }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def rename(id, name)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "rename",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,48 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def resize(id, resize_disk, size)
|
||||
body = {
|
||||
:type => "resize",
|
||||
:disk => resize_disk,
|
||||
:size => size
|
||||
}
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def resize(id, resize_disk, size)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "resize",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def restore(id, image)
|
||||
body = { :type => "restore", :image => image }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def restore(id, image)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "restore",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def shutdown(id)
|
||||
body = { :type => "shutdown" }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def shutdown(id)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "shutdown",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def snapshot(id, name)
|
||||
body = { :type => "snapshot", :name => name }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def snapshot(id, name)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "snapshot",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def transfer_image(id, region)
|
||||
body = { :type => 'transfer', :region => region }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/images/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def transfer_image(id, name)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => 36805527,
|
||||
'status' => 'in-progress',
|
||||
'type' => 'transfer',
|
||||
'started_at' => '2014-11-14T16:42:45Z',
|
||||
'completed_at' => null,
|
||||
'resource_id' => 7938269,
|
||||
'resource_type' => 'image',
|
||||
'region' => 'nyc3',
|
||||
'region_slug' => 'nyc3'
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,46 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Real
|
||||
|
||||
def update_ssh_key(key_id, name)
|
||||
update_options = {
|
||||
:name => name,
|
||||
}
|
||||
|
||||
encoded_body = Fog::JSON.encode(update_options)
|
||||
|
||||
request(
|
||||
:expects => [200],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'PUT',
|
||||
:path => "/v2/account/keys/#{key_id}",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# noinspection RubyStringKeysInHashInspection
|
||||
class Mock
|
||||
def update_ssh_key(key_id, name)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
response.body ={
|
||||
'ssh_key' => {
|
||||
'id' => 512190,
|
||||
'fingerprint' => "3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa",
|
||||
'public_key' => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDDHr/jh2Jy4yALcK4JyWbVkPRaWmhck3IgCoeOO3z1e2dBowLh64QAM+Qb72pxekALga2oi4GvT+TlWNhzPH4V example",
|
||||
'name' => "My SSH Public Key"
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOceanV2
|
||||
class Real
|
||||
def upgrade(id)
|
||||
body = { :type => "upgrade" }
|
||||
|
||||
encoded_body = Fog::JSON.encode(body)
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:headers => {
|
||||
'Content-Type' => "application/json; charset=UTF-8",
|
||||
},
|
||||
:method => 'POST',
|
||||
:path => "v2/droplets/#{id}/actions",
|
||||
:body => encoded_body,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def upgrade(id)
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = {
|
||||
'action' => {
|
||||
'id' => Fog::Mock.random_numbers(1).to_i,
|
||||
'status' => "in-progress",
|
||||
'type' => "upgrade",
|
||||
'started_at' => "2014-11-14T16:31:00Z",
|
||||
'completed_at' => null,
|
||||
'resource_id' => id,
|
||||
'resource_type' => "droplet",
|
||||
'region' => "nyc3",
|
||||
'region_slug' => "nyc3"
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,51 +0,0 @@
|
|||
module Fog
|
||||
module DigitalOcean
|
||||
class Service
|
||||
|
||||
def request(params, parse_json = true)
|
||||
first_attempt = true
|
||||
begin
|
||||
response = @connection.request(request_params(params))
|
||||
rescue Excon::Errors::Unauthorized => error
|
||||
raise error unless first_attempt
|
||||
first_attempt = false
|
||||
authenticate
|
||||
retry
|
||||
end
|
||||
|
||||
process_response(response) if parse_json
|
||||
response
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def process_response(response)
|
||||
if response &&
|
||||
response.body &&
|
||||
response.body.is_a?(String) &&
|
||||
!response.body.strip.empty?
|
||||
begin
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
rescue Fog::JSON::DecodeError => e
|
||||
Fog::Logger.warning("Error Parsing response json - #{e}")
|
||||
response.body = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def headers(options={})
|
||||
{'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
}.merge(options[:headers] || {})
|
||||
end
|
||||
|
||||
def request_params(params)
|
||||
params.merge({
|
||||
:headers => headers(params),
|
||||
:path => "#{params[:path]}"
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,56 +0,0 @@
|
|||
|
||||
# Shortcut for Fog::Compute[:digitalocean]
|
||||
def service
|
||||
Fog::Compute[:digitalocean]
|
||||
end
|
||||
|
||||
def fog_test_server_attributes
|
||||
# Hard coding numbers because requests from tests are sometimes failing.
|
||||
# TODO: Mock properly instead
|
||||
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
|
||||
|
||||
{
|
||||
:image_id => image_id,
|
||||
:region_id => region_id,
|
||||
:flavor_id => flavor_id
|
||||
}
|
||||
end
|
||||
|
||||
def fog_server_name
|
||||
"fog-server-test"
|
||||
end
|
||||
|
||||
# Create a long lived server for the tests
|
||||
def fog_test_server
|
||||
server = service.servers.find { |s| s.name == fog_server_name }
|
||||
unless server
|
||||
server = service.servers.create({
|
||||
:name => fog_server_name
|
||||
}.merge(fog_test_server_attributes))
|
||||
server.wait_for { ready? }
|
||||
end
|
||||
server
|
||||
end
|
||||
|
||||
# Destroy the long lived server
|
||||
def fog_test_server_destroy
|
||||
server = service.servers.find { |s| s.name == fog_server_name }
|
||||
server.destroy if server
|
||||
end
|
||||
|
||||
at_exit do
|
||||
unless Fog.mocking? || Fog.credentials[:digitalocean_api_key].nil?
|
||||
server = service.servers.find { |s| s.name == fog_server_name }
|
||||
if server
|
||||
server.wait_for(120) do
|
||||
reload rescue nil; ready?
|
||||
end
|
||||
end
|
||||
fog_test_server_destroy
|
||||
end
|
||||
end
|
|
@ -1,25 +0,0 @@
|
|||
Shindo.tests('Fog::Compute::DigitalOceanV2 | list_flavors request', ['digitalocean', 'compute']) do
|
||||
service = Fog::Compute.new(:provider => 'DigitalOcean', :version => 'V2')
|
||||
|
||||
size_format = {
|
||||
'slug' => String,
|
||||
'memory' => Integer,
|
||||
'vcpus' => Integer,
|
||||
'disk' => Integer,
|
||||
'transfer' => Float,
|
||||
'price_monthly' => Float,
|
||||
'price_hourly' => Float,
|
||||
'regions' => Array,
|
||||
'available' => Fog::Boolean,
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
tests('#list_flavors') do
|
||||
service.list_flavors.body['sizes'].each do |size|
|
||||
tests('format').data_matches_schema(size_format) do
|
||||
size
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,25 +0,0 @@
|
|||
Shindo.tests('Fog::Compute::DigitalOceanV2 | list_images request', ['digitalocean', 'compute']) do
|
||||
service = Fog::Compute.new(:provider => 'DigitalOcean', :version => 'V2')
|
||||
|
||||
image_format = {
|
||||
'id' => Integer,
|
||||
'name' => String,
|
||||
'type' => String,
|
||||
'distribution' => String,
|
||||
'slug' => Fog::Nullable::String,
|
||||
'public' => Fog::Boolean,
|
||||
'regions' => Array,
|
||||
'min_disk_size' => Fog::Nullable::Integer,
|
||||
'created_at' => String,
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
tests('#list_images') do
|
||||
service.list_images.body['images'].each do |image|
|
||||
tests('format').data_matches_schema(image_format) do
|
||||
image
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
Shindo.tests('Fog::Compute::DigitalOceanV2 | list_regions request', ['digitalocean', 'compute']) do
|
||||
service = Fog::Compute.new(:provider => 'DigitalOcean', :version => 'V2')
|
||||
|
||||
region_format = {
|
||||
'slug' => String,
|
||||
'name' => String,
|
||||
'sizes' => Array,
|
||||
'available' => Fog::Boolean,
|
||||
'features' => Array,
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
tests('#list_regions') do
|
||||
service.list_regions.body['regions'].each do |region|
|
||||
tests('format').data_matches_schema(region_format) do
|
||||
region
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
Shindo.tests('Fog::Compute::DigitalOceanV2 | list_ssh_keys request', ['digitalocean', 'compute']) do
|
||||
service = Fog::Compute.new(:provider => 'DigitalOcean', :version => 'V2')
|
||||
|
||||
ssh_key_format = {
|
||||
'id' => Integer,
|
||||
'fingerprint' => String,
|
||||
'public_key' => String,
|
||||
'name' => String,
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
tests('#list_ssh_keys') do
|
||||
service.list_ssh_keys.body['ssh_keys'].each do |ssh_key|
|
||||
tests('format').data_matches_schema(ssh_key_format) do
|
||||
ssh_key
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,77 +0,0 @@
|
|||
Shindo.tests('Fog::Compute::DigitalOceanV2 | create_server request', ['digitalocean', 'compute']) do
|
||||
service = Fog::Compute.new(:provider => 'DigitalOcean', :version => 'V2')
|
||||
|
||||
server_format = {
|
||||
'id' => Integer,
|
||||
'name' => String,
|
||||
'memory' => Integer,
|
||||
'vcpus' => Integer,
|
||||
'disk' => Integer,
|
||||
'locked' => Fog::Boolean,
|
||||
'created_at' => String,
|
||||
}
|
||||
|
||||
create_server_format = {
|
||||
'droplet' => {
|
||||
'id' => Integer,
|
||||
'name' => String,
|
||||
'memory' => Integer,
|
||||
'vcpus' => Integer,
|
||||
'disk' => Integer,
|
||||
'locked' => Fog::Boolean,
|
||||
'status' => String,
|
||||
'kernel' => Hash,
|
||||
"created_at" => String,
|
||||
"features" => Array,
|
||||
"backup_ids" => Array,
|
||||
"snapshot_ids" => Array,
|
||||
"image" => Hash,
|
||||
"size" => Hash,
|
||||
"size_slug" => String,
|
||||
"networks" => Hash,
|
||||
"region" => Hash,
|
||||
},
|
||||
|
||||
'links' => {
|
||||
"actions" => Array,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
server_id = nil
|
||||
server_name = "fog-#{Time.now.to_i.to_s}"
|
||||
image = "ubuntu-14-04-x64"
|
||||
region = "nyc3"
|
||||
size = "512mb"
|
||||
|
||||
tests("#create_server(#{server_name}, #{size}, #{image}, #{region})").formats(create_server_format) do
|
||||
body = service.create_server(server_name, size, image, region).body
|
||||
server_id = body['droplet']['id']
|
||||
body
|
||||
end
|
||||
|
||||
test('#get_server_details can retrieve by id') do
|
||||
body = service.get_server_details(server_id).body
|
||||
tests('format').data_matches_schema(server_format) do
|
||||
body['droplet']
|
||||
end
|
||||
end
|
||||
|
||||
server = service.servers.get(server_id)
|
||||
server.wait_for { ready? }
|
||||
|
||||
tests('#delete_server').succeeds do
|
||||
server.delete
|
||||
end
|
||||
|
||||
tests('#list_servers') do
|
||||
service.list_servers.body['droplets'].each do |droplet|
|
||||
tests('format').data_matches_schema(server_format) do
|
||||
droplet
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue