mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Fog calls drives "images", rename for consistency.
This commit is contained in:
parent
87c2a09a73
commit
a809a07178
9 changed files with 112 additions and 40 deletions
|
@ -9,14 +9,14 @@ module Fog
|
|||
recognizes :serverlove_api_url
|
||||
|
||||
request_path 'fog/serverlove/requests/compute'
|
||||
request :get_drives
|
||||
request :destroy_drive
|
||||
request :create_drive
|
||||
request :update_drive
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
|
@ -4,9 +4,9 @@ module Fog
|
|||
module Compute
|
||||
class Serverlove
|
||||
|
||||
class Drive < Fog::Model
|
||||
class Image < Fog::Model
|
||||
|
||||
identity :drive
|
||||
identity :id, :aliases => 'drive'
|
||||
|
||||
attribute :name
|
||||
attribute :user
|
||||
|
@ -19,20 +19,24 @@ module Fog
|
|||
attributes = {}
|
||||
|
||||
if(identity)
|
||||
attributes = connection.update_drive(identity, allowed_attributes).body
|
||||
attributes = connection.update_image(identity, allowed_attributes).body
|
||||
else
|
||||
requires :name
|
||||
requires :size
|
||||
attributes = connection.create_drive(allowed_attributes).body
|
||||
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_drive(identity)
|
||||
connection.destroy_image(identity)
|
||||
self
|
||||
end
|
||||
|
25
lib/fog/serverlove/models/compute/images.rb
Normal file
25
lib/fog/serverlove/models/compute/images.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
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)
|
||||
connection.get_image(image_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,7 +3,7 @@ module Fog
|
|||
class Serverlove
|
||||
class Real
|
||||
|
||||
def create_drive(options)
|
||||
def create_image(options)
|
||||
return nil if options.empty? || options.nil?
|
||||
request(:method => "post", :path => "/drives/create", :expects => 200, :options => options)
|
||||
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
|
||||
|
|
@ -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
|
||||
|
|
@ -3,7 +3,7 @@ module Fog
|
|||
class Serverlove
|
||||
class Real
|
||||
|
||||
def update_drive(identifier, options)
|
||||
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)
|
68
tests/serverlove/requests/compute/drive_tests.rb
Normal file
68
tests/serverlove/requests/compute/drive_tests.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
Shindo.tests('Fog::Compute[:serverlove] | drive requests', ['serverlove']) do
|
||||
|
||||
@image_format = {
|
||||
'created' => Fog::Nullable::String,
|
||||
'id' => Integer,
|
||||
'name' => String,
|
||||
'progress' => Fog::Nullable::Integer,
|
||||
'serverId' => Fog::Nullable::Integer,
|
||||
'status' => String,
|
||||
'updated' => String
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
@server = Fog::Compute[:serverlove].servers.create(:flavor_id => 1, :image_id => 19)
|
||||
@server.wait_for { ready? }
|
||||
@image_id = nil
|
||||
|
||||
tests("#create_image(#{@server.id})").formats(@image_format) do
|
||||
data = Fog::Compute[:serverlove].create_image(@server.id).body['image']
|
||||
@image_id = data['id']
|
||||
data
|
||||
end
|
||||
|
||||
unless Fog.mocking?
|
||||
Fog::Compute[:serverlove].images.get(@image_id).wait_for { ready? }
|
||||
end
|
||||
|
||||
tests("#get_image_details(#{@image_id})").formats(@image_format) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Compute[:serverlove].get_image_details(@image_id).body['image']
|
||||
end
|
||||
|
||||
tests('#list_images').formats({'images' => [serverlove::Compute::Formats::SUMMARY]}) do
|
||||
Fog::Compute[:serverlove].list_images.body
|
||||
end
|
||||
|
||||
tests('#list_images_detail').formats({'images' => [@image_format]}) do
|
||||
Fog::Compute[:serverlove].list_images_detail.body
|
||||
end
|
||||
|
||||
unless Fog.mocking?
|
||||
Fog::Compute[:serverlove].images.get(@image_id).wait_for { ready? }
|
||||
end
|
||||
|
||||
tests("#delete_image(#{@image_id})").succeeds do
|
||||
pending if Fog.mocking? # because it will fail without the wait just above here, which won't work
|
||||
Fog::Compute[:serverlove].delete_image(@image_id)
|
||||
end
|
||||
|
||||
@server.destroy
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests('#delete_image(0)').raises(Excon::Errors::BadRequest) do
|
||||
Fog::Compute[:serverlove].delete_image(0)
|
||||
end
|
||||
|
||||
tests('#get_image_details(0)').raises(Fog::Compute::serverlove::NotFound) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Compute[:serverlove].get_image_details(0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue