1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[slicehost] cleaner mocking/dependencies

This commit is contained in:
geemus (Wesley Beary) 2010-03-17 20:51:55 -07:00
parent e7b8d6f76e
commit 10db608eb1
17 changed files with 149 additions and 171 deletions

View file

@ -1,55 +1,63 @@
require 'fog/slicehost/models/flavor'
require 'fog/slicehost/models/flavors'
require 'fog/slicehost/models/image'
require 'fog/slicehost/models/images'
require 'fog/slicehost/models/server'
require 'fog/slicehost/models/servers'
require 'fog/slicehost/requests/create_slice'
require 'fog/slicehost/requests/delete_slice'
require 'fog/slicehost/requests/get_backups'
require 'fog/slicehost/requests/get_flavor'
require 'fog/slicehost/requests/get_flavors'
require 'fog/slicehost/requests/get_image'
require 'fog/slicehost/requests/get_images'
require 'fog/slicehost/requests/get_slice'
require 'fog/slicehost/requests/get_slices'
require 'fog/slicehost/requests/reboot_slice'
module Fog
class Slicehost
module Slicehost
def self.new(options={})
unless options[:slicehost_password]
raise ArgumentError.new('slicehost_password is required to access slicehost')
end
if Fog.mocking?
Fog::Slicehost::Mock.new(options)
else
Fog::Slicehost::Real.new(options)
end
end
def self.reset_data(keys=Mock.data.keys)
Mock.reset_data(keys)
end
class Mock
def self.data
@data
end
def self.reset_data
@data = {}
@data ||= Hash.new do |hash, key|
hash[key] = {}
end
end
def self.dependencies
[
"fog/slicehost/models/flavor.rb",
"fog/slicehost/models/flavors.rb",
"fog/slicehost/models/image.rb",
"fog/slicehost/models/images.rb",
"fog/slicehost/models/server.rb",
"fog/slicehost/models/servers.rb",
"fog/slicehost/parsers/create_slice.rb",
"fog/slicehost/parsers/get_backups.rb",
"fog/slicehost/parsers/get_flavor.rb",
"fog/slicehost/parsers/get_flavors.rb",
"fog/slicehost/parsers/get_image.rb",
"fog/slicehost/parsers/get_images.rb",
"fog/slicehost/parsers/get_slice.rb",
"fog/slicehost/parsers/get_slices.rb",
"fog/slicehost/requests/create_slice.rb",
"fog/slicehost/requests/delete_slice.rb",
"fog/slicehost/requests/get_backups.rb",
"fog/slicehost/requests/get_flavor.rb",
"fog/slicehost/requests/get_flavors.rb",
"fog/slicehost/requests/get_image.rb",
"fog/slicehost/requests/get_images.rb",
"fog/slicehost/requests/get_slice.rb",
"fog/slicehost/requests/get_slices.rb",
"fog/slicehost/requests/reboot_slice.rb"
]
end
def self.reload
self.dependencies.each {|dependency| load(dependency)}
if Fog.mocking?
reset_data
def self.reset_data(keys=data.keys)
for key in [*keys]
data.delete(key)
end
end
def initialize(options={})
unless @slicehost_password = options[:slicehost_password]
raise ArgumentError.new('slicehost_password is required to access slicehost')
@slicehost_password = options[:slicehost_password]
@data = self.class.data[@slicehost_password]
end
end
class Real
def initialize(options={})
@slicehost_password = options[:slicehost_password]
@host = options[:host] || "api.slicehost.com"
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@ -82,5 +90,4 @@ module Fog
end
end
Fog::Slicehost.reload
end

View file

@ -1,5 +1,7 @@
require 'fog/model'
module Fog
class Slicehost
module Slicehost
class Flavor < Fog::Model

View file

@ -1,5 +1,8 @@
require 'fog/collection'
require 'fog/slicehost/models/flavor'
module Fog
class Slicehost
module Slicehost
def flavors
Fog::Slicehost::Flavors.new(:connection => self)

View file

@ -1,5 +1,7 @@
require 'fog/model'
module Fog
class Slicehost
module Slicehost
class Image < Fog::Model

View file

@ -1,5 +1,8 @@
require 'fog/collection'
require 'fog/slicehost/models/image'
module Fog
class Slicehost
module Slicehost
def images(attributes = {})
Fog::Slicehost::Images.new({

View file

@ -1,5 +1,7 @@
require 'fog/model'
module Fog
class Slicehost
module Slicehost
class Server < Fog::Model

View file

@ -1,5 +1,8 @@
require 'fog/collection'
require 'fog/slicehost/models/server'
module Fog
class Slicehost
module Slicehost
def servers
Fog::Slicehost::Servers.new(:connection => self)

View file

@ -1,7 +1,8 @@
unless Fog.mocking?
module Fog
class Slicehost
module Slicehost
class Real
require 'fog/slicehost/parsers/create_slice'
# Get list of slices
# ==== Parameters
@ -34,12 +35,8 @@ unless Fog.mocking?
end
end
end
else
module Fog
class Slicehost
class Mock
def create_slice(flavor_id, image_id, name)
raise MockNotImplemented.new("Contributions welcome!")
@ -47,5 +44,4 @@ else
end
end
end

View file

@ -1,7 +1,6 @@
unless Fog.mocking?
module Fog
class Slicehost
module Slicehost
class Real
# Get list of slices
# ==== Parameters
@ -32,12 +31,8 @@ unless Fog.mocking?
end
end
end
else
module Fog
class Slicehost
class Mock
def delete_slice(slice_id)
raise MockNotImplemented.new("Contributions welcome!")
@ -45,5 +40,4 @@ else
end
end
end

View file

@ -1,7 +1,8 @@
unless Fog.mocking?
module Fog
class Slicehost
module Slicehost
class Real
require 'fog/slicehost/parsers/get_backups'
# Get list of backups
#
@ -22,12 +23,8 @@ unless Fog.mocking?
end
end
end
else
module Fog
class Slicehost
class Mock
def get_backups
raise MockNotImplemented.new("Contributions welcome!")
@ -35,5 +32,4 @@ else
end
end
end

View file

@ -1,7 +1,8 @@
unless Fog.mocking?
module Fog
class Slicehost
module Slicehost
class Real
require 'fog/slicehost/parsers/get_flavor'
# Get details of a flavor
#
@ -25,12 +26,8 @@ unless Fog.mocking?
end
end
end
else
module Fog
class Slicehost
class Mock
def get_flavor(flavor_id)
raise MockNotImplemented.new("Contributions welcome!")
@ -38,5 +35,4 @@ else
end
end
end

View file

@ -1,7 +1,8 @@
unless Fog.mocking?
module Fog
class Slicehost
module Slicehost
class Real
require 'fog/slicehost/parsers/get_flavors'
# Get list of flavors
#
@ -22,12 +23,8 @@ unless Fog.mocking?
end
end
end
else
module Fog
class Slicehost
class Mock
def get_flavors
raise MockNotImplemented.new("Contributions welcome!")
@ -35,5 +32,4 @@ else
end
end
end

View file

@ -1,7 +1,8 @@
unless Fog.mocking?
module Fog
class Slicehost
module Slicehost
class Real
require 'fog/slicehost/parsers/get_image'
# Get details of an image
#
@ -23,12 +24,8 @@ unless Fog.mocking?
end
end
end
else
module Fog
class Slicehost
class Mock
def get_image(image_id)
raise MockNotImplemented.new("Contributions welcome!")
@ -36,5 +33,4 @@ else
end
end
end

View file

@ -1,7 +1,8 @@
unless Fog.mocking?
module Fog
class Slicehost
module Slicehost
class Real
require 'fog/slicehost/parsers/get_images'
# Get list of images
#
@ -20,12 +21,8 @@ unless Fog.mocking?
end
end
end
else
module Fog
class Slicehost
class Mock
def get_images
raise MockNotImplemented.new("Contributions welcome!")
@ -33,5 +30,4 @@ else
end
end
end

View file

@ -1,7 +1,8 @@
unless Fog.mocking?
module Fog
class Slicehost
module Slicehost
class Real
require 'fog/slicehost/parsers/get_slice'
# Get details of a slice
#
@ -31,12 +32,8 @@ unless Fog.mocking?
end
end
end
else
module Fog
class Slicehost
class Mock
def get_slice(id)
raise MockNotImplemented.new("Contributions welcome!")
@ -44,5 +41,4 @@ else
end
end
end

View file

@ -1,7 +1,8 @@
unless Fog.mocking?
module Fog
class Slicehost
module Slicehost
class Real
require 'fog/slicehost/parsers/get_slices'
# Get list of slices
#
@ -28,12 +29,8 @@ unless Fog.mocking?
end
end
end
else
module Fog
class Slicehost
class Mock
def get_slices
raise MockNotImplemented.new("Contributions welcome!")
@ -41,5 +38,4 @@ else
end
end
end

View file

@ -1,7 +1,6 @@
unless Fog.mocking?
module Fog
class Slicehost
module Slicehost
class Real
# Reboot slice
# ==== Parameters
@ -32,12 +31,8 @@ unless Fog.mocking?
end
end
end
else
module Fog
class Slicehost
class Mock
def get_slice(id)
raise MockNotImplemented.new("Contributions welcome!")
@ -45,5 +40,4 @@ else
end
end
end