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

[stormondemand] Adjustments per pull request276, modified tests

This commit is contained in:
seeingidog 2011-04-30 15:29:05 -04:00
parent 0cb8b18379
commit fcf04f4c87
35 changed files with 71 additions and 116 deletions

View file

@ -1,10 +1,10 @@
class Stormondemand < Fog::Bin
class StormOnDemand < Fog::Bin
class << self
def class_for(key)
case key
when :compute
Fog::Stormondemand::Compute
Fog::StormOnDemand::Compute
else
raise ArgumentError, "Unsupported #{self} service: #{key}"
end
@ -14,7 +14,7 @@ class Stormondemand < Fog::Bin
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Fog::Compute.new(:provider => 'Stormondemand')
Fog::Compute.new(:provider => 'StormOnDemand')
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
end
@ -23,7 +23,7 @@ class Stormondemand < Fog::Bin
end
def services
Fog::Stormondemand.services
Fog::StormOnDemand.services
end
end

View file

@ -31,9 +31,9 @@ module Fog
when 'Slicehost'
require 'fog/compute/slicehost'
Fog::Slicehost::Compute.new(attributes)
when 'Stormondemand'
when 'StormOnDemand'
require 'fog/compute/stormondemand'
Fog::Stormondemand::Compute.new(attributes)
Fog::StormOnDemand::Compute.new(attributes)
when 'VirtualBox'
require 'fog/compute/virtual_box'
Fog::VirtualBox::Compute.new(attributes)

View file

@ -1,7 +1,7 @@
require 'fog/core/model'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Balancer < Fog::Model

View file

@ -2,12 +2,12 @@ require 'fog/core/collection'
require 'fog/compute/models/stormondemand/balancer'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Balancers < Fog::Collection
model Fog::Stormondemand::Compute::Balancer
model Fog::StormOnDemand::Compute::Balancer
def all
data = connection.list_balancers.body['loadbalancers']

View file

@ -1,7 +1,7 @@
require 'fog/core/model'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Config < Fog::Model

View file

@ -2,12 +2,12 @@ require 'fog/core/collection'
require 'fog/compute/models/stormondemand/config'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Configs < Fog::Collection
model Fog::Stormondemand::Compute::Config
model Fog::StormOnDemand::Compute::Config
def all
data = connection.list_configs.body['configs']

View file

@ -1,5 +1,5 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real

View file

@ -1,7 +1,7 @@
require 'fog/core/model'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Image < Fog::Model

View file

@ -2,12 +2,12 @@ require 'fog/core/collection'
require 'fog/compute/models/stormondemand/image'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Images < Fog::Collection
model Fog::Stormondemand::Compute::Image
model Fog::StormOnDemand::Compute::Image
def all
data = connection.list_images.body['images']

View file

@ -1,7 +1,7 @@
require 'fog/core/model'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class PrivateIp < Fog::Model

View file

@ -2,12 +2,12 @@ require 'fog/core/collection'
require 'fog/compute/models/stormondemand/private_ip'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class PrivateIps < Fog::Collection
model Fog::Stormondemand::Compute::PrivateIp
model Fog::StormOnDemand::Compute::PrivateIp
def all
data = connection.list_private_ips.body['networks']

View file

@ -1,7 +1,7 @@
require 'fog/core/model'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Server < Fog::Model

View file

@ -2,12 +2,12 @@ require 'fog/core/collection'
require 'fog/compute/models/stormondemand/server'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Servers < Fog::Collection
model Fog::Stormondemand::Compute::Server
model Fog::StormOnDemand::Compute::Server
def all
data = connection.list_servers.body['servers']

View file

@ -1,7 +1,7 @@
require 'fog/core/model'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Stat < Fog::Model

View file

@ -2,11 +2,11 @@ require 'fog/core/collection'
require 'fog/compute/models/stormondemand/stat'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Stats < Fog::Collection
model Fog::Stormondemand::Compute::Stat
model Fog::StormOnDemand::Compute::Stat
def get(options)
data = connection.get_stats(options).body

View file

@ -1,7 +1,7 @@
require 'fog/core/model'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Template < Fog::Model

View file

@ -2,12 +2,12 @@ require 'fog/core/collection'
require 'fog/compute/models/stormondemand/template'
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Templates < Fog::Collection
model Fog::Stormondemand::Compute::Template
model Fog::StormOnDemand::Compute::Template
def all
data = connection.list_templates.body['templates']

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def add_balancer_node(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/network/loadbalancer/addnode",
:headers => {"Content-Type" => "application/json"},
:body => {:params => options}.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def clone_server(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/storm/server/clone",
:headers => {"Content-Type" => "application/json"},
:body => {:params => options}.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def create_server(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/storm/server/create",
:headers => {"Content-Type" => "application/json"},
:body => {:params => options}.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def delete_server(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/storm/server/destroy",
:headers => {"Content-Type" => "application/json"},
:body => {:params => options}.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def get_server(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/storm/server/details",
:headers => {"Content-Type" => "application/json"},
:body => {:params => options}.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def get_stats(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/monitoring/load/stats",
:headers => {"Content-Type" => "application/json"},
:body => {:params => options}.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def list_balancers(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/network/loadbalancer/list",
:headers => {"Content-Type" => "application/json"},
:body => options.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def list_configs(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/storm/config/list",
:headers => {"Content-Type" => "application/json"},
:body => options.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def list_images(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/server/image/list",
:headers => {"Content-Type" => "application/json"},
:body => options.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def list_private_ips(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/network/private/get",
:headers => {"Content-Type" => "application/json"},
:body => options.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def list_servers(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/storm/server/list",
:headers => {"Content-Type" => "application/json"},
:body => options.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def list_templates(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/server/template/list",
:headers => {"Content-Type" => "application/json"},
:body => options.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def reboot_server(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/storm/server/reboot",
:headers => {"Content-Type" => "application/json"},
:body => {:params => options}.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def remove_balancer_node(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/network/loadbalancer/removenode",
:headers => {"Content-Type" => "application/json"},
:body => {:params => options}.to_json
)
end

View file

@ -1,14 +1,11 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute
class Real
def resize_server(options = {})
request(
:expects => [200],
:method => 'GET',
:path => "/storm/server/resize",
:headers => {"Content-Type" => "application/json"},
:body => {:params => options}.to_json
)
end

View file

@ -1,5 +1,5 @@
module Fog
module Stormondemand
module StormOnDemand
class Compute < Fog::Service
API_URL = 'https://api.stormondemand.com'
@ -38,11 +38,7 @@ module Fog
request :list_configs
request :list_templates
request :list_images
# possibly broken, needs testing with monitored instance
request :get_stats
# broken:
request :list_private_ips
class Mock
@ -99,7 +95,9 @@ module Fog
'Authorization' => "Basic " + Base64.encode64("#{@stormondemand_username}:#{@stormondemand_password}").chomp
}.merge!(params[:headers] || {}),
:host => @host,
:path => "#{@path}/#{params[:path]}"
:path => "#{@path}/#{params[:path]}",
:expects => 200,
:method => :post
}))
rescue Excon::Errors::HTTPStatusError => error
raise case error
@ -113,7 +111,7 @@ module Fog
response.body = JSON.parse(response.body)
end
if response.body.keys[0] == 'error_class'
raise Fog::Stormondemand::Compute::Error, response.body.inspect
raise Fog::StormOnDemand::Compute::Error, response.body.inspect
end
response
end

View file

@ -1,7 +1,7 @@
require 'fog/core'
module Fog
module Stormondemand
module StormOnDemand
extend Fog::Provider

View file

@ -1,10 +1,9 @@
Shindo.tests('Stormondemand::Compute | server requests', ['stormondemand']) do
Shindo.tests('StormOnDemand::Compute | server requests', ['stormondemand']) do
@servers_format = {
'servers' => [{
@server_format = {
'uniq_id' => String,
'accnt' => String,
'backup_enabled' => String, #boolean?
'backup_enabled' => String,
'backup_plan' => String,
'backup_size' => String,
'backup_quota' => String,
@ -15,47 +14,50 @@ Shindo.tests('Stormondemand::Compute | server requests', ['stormondemand']) do
'ip' => String,
'ip_count' => String,
'subaccnt' => String,
'template' => String,
'template' => NilClass,
'template_description' => String,
'manage_level' => String,
'manage_level' => NilClass,
'zone' => Hash,
'active' => Integer,
'create_date' => String
}]
}
@servers_format = {
'servers' => [@server_format]
}
tests('success') do
@uniq_id = nil
@name = "fog-test#{Time.now.to_i}.com"
tests("#create_server(:backup_enabled => 0, :config_id => 114, :domain => '#{@name}', :template => 'CENTOSUNMANAGED', :ip_count => 1, :password => 'B92bxfijsdK3!')").formats(@servers_format) do
tests("#create_server(:backup_enabled => 0, :config_id => 114, :domain => '#{@name}', :template => 'CENTOSUNMANAGED', :ip_count => 1, :password => 'B92bxfijsdK3!')").formats(@server_format) do
pending if Fog.mocking?
data = Stormondemand[:compute].create_server(:backup_enabled => 0, :config_id => 114, :domain => @name, :template => 'CENTOSUNMANAGED', :ip_count => 1, :password => 'B92bxfijsdK3!').body
data = StormOnDemand[:compute].create_server(:backup_enabled => 0, :config_id => 114, :domain => @name, :template => 'CENTOSUNMANAGED', :ip_count => 1, :password => 'B92bxfijsdK3!').body
@uniq_id = data['uniq_id']
data
end
tests('#list_servers').formats(@servers_format) do
pending if Fog.mocking?
StormOnDemand[:compute].list_servers.body
end
unless Fog.mocking?
Stormondemand[:compute].servers.get(@server_id).wait_for { ready? }
StormOnDemand[:compute].servers.get(:uniq_id => @uniq_id).wait_for { ready? }
end
tests("#delete_server(#{@uniq_id})").succeeds do
tests("#delete_server(:uniq_id => #{@uniq_id})").succeeds do
pending if Fog.mocking?
Stormondemand[:compute].delete_server(@uniq_id)
end
tests('#list_servers').formats(@server_format) do
pending if Fog.mocking?
Stormondemand[:compute].list_servers.body
StormOnDemand[:compute].delete_server(@uniq_id)
end
end
tests('failure') do
tests('#delete_server(0)').raises(Fog::Stormondemand::Compute::Error) do
tests('#delete_server(0)').raises(Fog::StormOnDemand::Compute::Error) do
pending if Fog.mocking?
Stormondemand[:compute].delete_server(0)
StormOnDemand[:compute].delete_server(0)
end
end