mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge branch 'master' of github.com:jamesrose/fog
Conflicts: lib/fog/providers.rb lib/fog/serverlove/models/compute/drive.rb
This commit is contained in:
commit
8fcee51407
13 changed files with 229 additions and 34 deletions
|
@ -75,6 +75,7 @@ require 'fog/bin/ninefold'
|
|||
require 'fog/bin/rackspace'
|
||||
require 'fog/bin/openstack'
|
||||
require 'fog/bin/ovirt'
|
||||
require 'fog/bin/serverlove'
|
||||
require 'fog/bin/stormondemand'
|
||||
require 'fog/bin/terremark'
|
||||
require 'fog/bin/vcloud'
|
||||
|
|
31
lib/fog/bin/serverlove.rb
Normal file
31
lib/fog/bin/serverlove.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
class Serverlove < Fog::Bin
|
||||
class << self
|
||||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :compute
|
||||
Fog::Compute::Serverlove
|
||||
else
|
||||
raise ArgumentError, "Unrecognized service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :compute
|
||||
Fog::Logger.warning("Serverlove[:compute] is not recommended, use Compute[:serverlove] for portability")
|
||||
Fog::Compute.new(:provider => 'Serverlove')
|
||||
else
|
||||
raise ArgumentError, "Unrecognized service: #{key.inspect}"
|
||||
end
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
||||
def services
|
||||
Fog::Serverlove.services
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -9,12 +9,15 @@ module Fog
|
|||
recognizes :serverlove_api_url
|
||||
|
||||
request_path 'fog/serverlove/requests/compute'
|
||||
request :get_drives
|
||||
request :destroy_drive
|
||||
request :get_image
|
||||
request :get_images
|
||||
request :destroy_image
|
||||
request :create_image
|
||||
request :update_image
|
||||
|
||||
model_path 'fog/serverlove/models/compute'
|
||||
model :drive
|
||||
collection :drives
|
||||
model :image
|
||||
collection :images
|
||||
|
||||
class Mock
|
||||
|
||||
|
@ -45,6 +48,7 @@ module Fog
|
|||
"Accept" => "application/json"
|
||||
}
|
||||
)
|
||||
params[:body] = encode_pairs(params[:options]) unless params[:options].nil?
|
||||
response = @connection.request(params)
|
||||
|
||||
raise_if_error!(response)
|
||||
|
@ -54,7 +58,12 @@ module Fog
|
|||
response
|
||||
end
|
||||
|
||||
|
||||
def encode_pairs(params)
|
||||
params.keys.collect do |key|
|
||||
"#{key} #{params[key]}"
|
||||
end.join("\n")
|
||||
end
|
||||
|
||||
def raise_if_error!(response)
|
||||
case response.status
|
||||
when 400 then
|
||||
|
@ -66,4 +75,4 @@ module Fog
|
|||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/serverlove/models/compute/drive'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Serverlove
|
||||
|
||||
class Drives < Fog::Collection
|
||||
|
||||
model Fog::Compute::Serverlove::Drive
|
||||
|
||||
def all
|
||||
data = connection.get_drives.body
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(drive_id)
|
||||
connection.get_drive(drive_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
51
lib/fog/serverlove/models/compute/image.rb
Normal file
51
lib/fog/serverlove/models/compute/image.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Serverlove
|
||||
|
||||
class Image < Fog::Model
|
||||
|
||||
identity :id, :aliases => 'drive'
|
||||
|
||||
attribute :name
|
||||
attribute :user
|
||||
attribute :size
|
||||
attribute :claimed
|
||||
attribute :status
|
||||
attribute :encryption_cipher, :aliases => 'encryption:cipher'
|
||||
|
||||
def save
|
||||
attributes = {}
|
||||
|
||||
if(identity)
|
||||
attributes = connection.update_image(identity, allowed_attributes).body
|
||||
else
|
||||
requires :name
|
||||
requires :size
|
||||
attributes = connection.create_image(allowed_attributes).body
|
||||
end
|
||||
|
||||
merge_attributes(attributes)
|
||||
self
|
||||
end
|
||||
|
||||
def ready?
|
||||
status.upcase == 'ACTIVE'
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :identity
|
||||
connection.destroy_image(identity)
|
||||
self
|
||||
end
|
||||
|
||||
def allowed_attributes
|
||||
allowed = [:name, :size]
|
||||
attributes.select {|k,v| allowed.include? k}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fog/serverlove/models/compute/images.rb
Normal file
26
lib/fog/serverlove/models/compute/images.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/serverlove/models/compute/image'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Serverlove
|
||||
|
||||
class Images < Fog::Collection
|
||||
|
||||
model Fog::Compute::Serverlove::Image
|
||||
|
||||
def all
|
||||
data = connection.get_images.body
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(image_id)
|
||||
data = connection.get_image(image_id).body
|
||||
new(data)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
32
lib/fog/serverlove/requests/compute/create_image.rb
Normal file
32
lib/fog/serverlove/requests/compute/create_image.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Serverlove
|
||||
class Real
|
||||
|
||||
def create_image(options)
|
||||
return nil if options.empty? || options.nil?
|
||||
request(:method => "post", :path => "/drives/create", :expects => 200, :options => options)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def create_image(options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
data = {
|
||||
'drive' => Fog::Mock.random_numbers(1000000).to_s,
|
||||
'name' => options['name'] || 'Test',
|
||||
'size' => options['size'] || 12345
|
||||
}
|
||||
|
||||
response.body = data
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,7 +3,7 @@ module Fog
|
|||
class Serverlove
|
||||
class Real
|
||||
|
||||
def destroy_drive(drive_id)
|
||||
def destroy_image(drive_id)
|
||||
request(:method => "post", :path => "/drives/#{drive_id}/destroy", :expects => 204)
|
||||
end
|
||||
|
13
lib/fog/serverlove/requests/compute/get_image.rb
Normal file
13
lib/fog/serverlove/requests/compute/get_image.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Serverlove
|
||||
class Real
|
||||
|
||||
def get_image(image_id)
|
||||
request(:method => "get", :path => "/drives/#{image_id}/info", :expects => 200)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,7 +3,7 @@ module Fog
|
|||
class Serverlove
|
||||
class Real
|
||||
|
||||
def get_drives
|
||||
def get_images
|
||||
request(:method => "get", :path => "/drives/info", :expects => 200)
|
||||
end
|
||||
|
15
lib/fog/serverlove/requests/compute/update_image.rb
Normal file
15
lib/fog/serverlove/requests/compute/update_image.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Serverlove
|
||||
class Real
|
||||
|
||||
def update_image(identifier, options)
|
||||
return nil if identifier.nil? || identifier == ""
|
||||
return nil if options.empty? || options.nil?
|
||||
request(:method => "post", :path => "/drives/#{identifier}/set", :expects => 200, :options => options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -12,7 +12,8 @@ def array_differences(array_a, array_b)
|
|||
end
|
||||
|
||||
# check to see which credentials are available and add others to the skipped tags list
|
||||
all_providers = ['aws', 'bluebox', 'brightbox', 'cloudstack', 'dnsimple', 'dnsmadeeasy', 'dynect', 'ecloud', 'glesys', 'gogrid', 'google', 'hp', 'linode', 'local', 'ninefold', 'newservers', 'openstack', 'rackspace', 'stormondemand', 'voxel', 'xenserver', 'zerigo']
|
||||
|
||||
all_providers = ['aws', 'bluebox', 'brightbox', 'cloudstack', 'dnsimple', 'dnsmadeeasy', 'dynect', 'ecloud', 'glesys', 'gogrid', 'google', 'hp', 'linode', 'local', 'ninefold', 'newservers', 'openstack', 'rackspace', 'serverlove', 'stormondemand', 'voxel', 'xenserver', 'zerigo']
|
||||
available_providers = Fog.available_providers.map {|provider| provider.downcase}
|
||||
for provider in (all_providers - available_providers)
|
||||
Formatador.display_line("[yellow]Skipping tests for [bold]#{provider}[/] [yellow]due to lacking credentials (add some to '~/.fog' to run them)[/]")
|
||||
|
|
41
tests/serverlove/requests/compute/image_tests.rb
Normal file
41
tests/serverlove/requests/compute/image_tests.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
Shindo.tests('Fog::Compute[:serverlove] | drive requests', ['serverlove']) do
|
||||
|
||||
@image_format = {
|
||||
'drive' => String,
|
||||
'name' => String,
|
||||
'user' => String,
|
||||
'size' => Integer,
|
||||
'claimed' => Fog::Nullable::String,
|
||||
'status' => String,
|
||||
'encryption:cipher' => String,
|
||||
'read:bytes' => String,
|
||||
'write:bytes' => String,
|
||||
'read:requests' => String,
|
||||
'write:requests' => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
attributes = { name: 'Test', size: 12345 }
|
||||
|
||||
tests("#create_image").formats(@image_format) do
|
||||
@image = Fog::Compute[:serverlove].create_image(attributes).body
|
||||
end
|
||||
|
||||
tests("#list_images").succeeds do
|
||||
Fog::Compute[:serverlove].images
|
||||
end
|
||||
|
||||
tests("#update_image").returns(true) do
|
||||
@image['name'] = "Diff"
|
||||
Fog::Compute[:serverlove].update_image(@image['drive'], { name: @image['name'], size: @image['size']})
|
||||
Fog::Compute[:serverlove].images.get(@image['drive']).name == "Diff"
|
||||
end
|
||||
|
||||
tests("#destroy_image").succeeds do
|
||||
Fog::Compute[:serverlove].destroy_image(@image['drive'])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue