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

[compute|brightbox] Merge in test updates and server groups

This commit is contained in:
Paul Thornthwaite 2011-08-24 11:36:18 +01:00
commit 71b8e70947
25 changed files with 378 additions and 56 deletions

View file

@ -28,16 +28,19 @@ module Fog
request :activate_console_server
request :add_listeners_load_balancer
request :add_nodes_load_balancer
request :add_servers_server_group
request :create_api_client
request :create_cloud_ip
request :create_image
request :create_load_balancer
request :create_server
request :create_server_group
request :destroy_api_client
request :destroy_cloud_ip
request :destroy_image
request :destroy_load_balancer
request :destroy_server
request :destroy_server_group
request :get_account
request :get_api_client
request :get_cloud_ip
@ -45,6 +48,7 @@ module Fog
request :get_interface
request :get_load_balancer
request :get_server
request :get_server_group
request :get_server_type
request :get_user
request :get_zone
@ -52,13 +56,16 @@ module Fog
request :list_cloud_ips
request :list_images
request :list_load_balancers
request :list_server_groups
request :list_server_types
request :list_servers
request :list_users
request :list_zones
request :map_cloud_ip
request :move_servers_server_group
request :remove_listeners_load_balancer
request :remove_nodes_load_balancer
request :remove_servers_server_group
request :reset_ftp_password_account
request :resize_server
request :shutdown_server
@ -71,6 +78,7 @@ module Fog
request :update_image
request :update_load_balancer
request :update_server
request :update_server_group
request :update_user
class Mock

View file

@ -7,10 +7,12 @@ module Fog
class Account < Fog::Model
identity :id
attribute :resource_type
attribute :url
attribute :resource_type
attribute :name
attribute :status
attribute :address_1
attribute :address_2
attribute :city
@ -20,18 +22,28 @@ module Fog
attribute :country_name
attribute :vat_registration_number
attribute :telephone_number
attribute :telephone_verified
attribute :verified_telephone
attribute :verified_ip
attribute :ram_limit
attribute :ram_used
attribute :cloud_ips_limit
attribute :cloud_ips_used
attribute :load_balancers_limit
attribute :load_balancers_used
attribute :library_ftp_host
attribute :library_ftp_user
# This is always returned as null/nil unless performing a reset_ftp_password request
attribute :library_ftp_password
attribute :created_at, :type => :time
# Boolean flags
attribute :valid_credit_card
attribute :telephone_verified
# Times
attribute :created_at
attribute :verified_at
# Links - to be replaced
attribute :owner_id, :aliases => "owner", :squash => "id"
attribute :clients
attribute :images

View file

@ -7,19 +7,21 @@ module Fog
class CloudIp < Fog::Model
identity :id
attribute :url
attribute :resource_type
attribute :name
attribute :status
attribute :resource_type
attribute :description
attribute :reverse_dns
attribute :public_ip
# Links - to be replaced
attribute :account_id, :aliases => "account", :squash => "id"
attribute :interface_id, :aliases => "interface", :squash => "id"
attribute :server_id, :aliases => "server", :squash => "id"
attribute :load_balancer, :alias => "load_balancer", :squash => "id"
def map(interface_to_map)
requires :identity

View file

@ -7,10 +7,12 @@ module Fog
class Flavor < Fog::Model
identity :id
attribute :url
attribute :resource_type
attribute :name
attribute :status
attribute :description
attribute :handle
@ -19,9 +21,6 @@ module Fog
attribute :disk, :aliases => "disk_size"
attribute :ram
attribute :resource_type
attribute :description
def bits
0 # This is actually based on the Image type used. 32bit or 64bit Images are supported
end

View file

@ -7,31 +7,37 @@ module Fog
class Image < Fog::Model
identity :id
attribute :url
attribute :resource_type
attribute :name
attribute :status
attribute :description
attribute :source
attribute :source_type
attribute :ancestor_id, :aliases => "ancestor", :squash => "id"
attribute :owner_id, :aliases => "owner", :squash => "id"
attribute :arch
attribute :virtual_size
attribute :disk_size
attribute :resource_type
attribute :description
# Boolean flags
attribute :public
attribute :official
attribute :compatibility_mode
attribute :virtual_size
attribute :disk_size
# Times
attribute :created_at
# Links - to be replaced
attribute :ancestor_id, :aliases => "ancestor", :squash => "id"
attribute :owner_id, :aliases => "owner", :squash => "id"
def ready?
status == "available"
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :source, :arch
options = {
:source => source,

View file

@ -7,23 +7,32 @@ module Fog
class LoadBalancer < Fog::Model
identity :id
attribute :url
attribute :name
attribute :status
attribute :resource_type
attribute :nodes
attribute :name
attribute :status
attribute :policy
attribute :nodes
attribute :healthcheck
attribute :listeners
# Times
attribute :created_at
attribute :deleted_at
# Links - to be replaced
attribute :account
attribute :server
attribute :cloud_ip
def ready?
status == 'active'
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :nodes, :listeners, :healthcheck
options = {
:nodes => nodes,

View file

@ -7,23 +7,28 @@ module Fog
class Server < Fog::Compute::Server
identity :id
attribute :resource_type
attribute :url
attribute :name
attribute :state, :aliases => 'status'
attribute :hostname
attribute :created_at, :type => :time
attribute :deleted_at, :type => :time
attribute :started_at, :type => :time
attribute :user_data
attribute :console_url
attribute :console_token
attribute :resource_type
# Times
attribute :created_at
attribute :started_at
attribute :console_token_expires
attribute :deleted_at
# Links - to be replaced
attribute :account_id, :aliases => "account", :squash => "id"
attribute :image_id, :aliases => "image", :squash => "id"
attribute :flavor_id, :aliases => "server_type", :squash => "id"
attribute :zone_id, :aliases => "zone", :squash => "id"
attribute :snapshots
attribute :cloud_ips
attribute :interfaces
@ -95,6 +100,7 @@ module Fog
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :image_id
options = {
:image => image_id,

View file

@ -7,14 +7,18 @@ module Fog
class User < Fog::Model
identity :id
attribute :url
attribute :resource_type
attribute :url
attribute :name
attribute :email_address
attribute :email_verified
attribute :ssh_key
# Boolean flags
attribute :email_verified
attribute :messaging_pref
# Links - to be replaced
attribute :account_id, :aliases => "default_account", :squash => "id"
attribute :accounts

View file

@ -7,11 +7,12 @@ module Fog
class Zone < Fog::Model
identity :id
attribute :url
attribute :handle
attribute :status
attribute :resource_type
attribute :status
attribute :handle
attribute :description
end

View file

@ -0,0 +1,28 @@
module Fog
module Compute
class Brightbox
class Real
# Add a number of servers to a server group
#
# >> Compute[:brightbox].add_servers_server_group "grp-12345", :servers => [{:server => "srv-abcde"}]
#
# == Parameters:
# * identifier (String) - The identifier of the server group to add to
# * options
# * servers (Array) - An Array of Hashes containing {"server" => server_id} for each server to add
# [\[{"server" => "srv-abcde"}, {"server" => "srv-fghij"}\]]
#
# == Returns:
#
# A Ruby hash of the server response
#
def add_servers_server_group(identifier, options)
return nil if identifier.nil? || identifier == ""
request("post", "/1.0/server_groups/#{identifier}/add_servers", [202], options)
end
end
end
end
end

View file

@ -0,0 +1,13 @@
module Fog
module Compute
class Brightbox
class Real
def create_server_group(options)
request("post", "/1.0/server_groups", [202], options)
end
end
end
end
end

View file

@ -0,0 +1,14 @@
module Fog
module Compute
class Brightbox
class Real
def destroy_server_group(identifier)
return nil if identifier.nil? || identifier == ""
request("delete", "/1.0/server_groups/#{identifier}", [202])
end
end
end
end
end

View file

@ -0,0 +1,14 @@
module Fog
module Compute
class Brightbox
class Real
def get_server_group(identifier)
return nil if identifier.nil? || identifier == ""
request("get", "/1.0/server_groups/#{identifier}", [200])
end
end
end
end
end

View file

@ -0,0 +1,13 @@
module Fog
module Compute
class Brightbox
class Real
def list_server_groups
request("get", "/1.0/server_groups", [200])
end
end
end
end
end

View file

@ -0,0 +1,29 @@
module Fog
module Compute
class Brightbox
class Real
# Moves a number of servers between two server groups
#
# >> Compute[:brightbox].remove_servers_server_group "grp-12345", :destination => "grp-67890", :servers => [{:server => "srv-abcde"}]
#
# == Parameters:
# * identifier - The identifier (String) of the server group to remove from
# * options (Hash)
# * destination (String)- The identifier of the server group to move to
# * servers (Array) - Array of Hashes containing {"server" => server_id} for each server to remove
# [\[{"server" => "srv-abcde"}, {"server" => "srv-fghij"}\]]
#
# == Returns:
#
# A Ruby hash of the server response
#
def move_servers_server_group(identifier, options)
return nil if identifier.nil? || identifier == ""
request("post", "/1.0/server_groups/#{identifier}/move_servers", [202], options)
end
end
end
end
end

View file

@ -0,0 +1,27 @@
module Fog
module Compute
class Brightbox
class Real
# Remove a number of servers from a server group
#
# >> Compute[:brightbox].remove_servers_server_group "grp-12345", :servers => [{:server => "srv-abcde"}]
#
# == Parameters:
# * identifier (String) - The identifier of the server group to remove from
# * options (Array) - An Array of Hashes containing {"server" => server_id} for each server to remove
# [\[{"server" => "srv-abcde"}, {"server" => "srv-fghij"}\]]
#
# == Returns:
#
# A Ruby hash of the server response
#
def remove_servers_server_group(identifier, options)
return nil if identifier.nil? || identifier == ""
request("post", "/1.0/server_groups/#{identifier}/remove_servers", [202], options)
end
end
end
end
end

View file

@ -0,0 +1,15 @@
module Fog
module Compute
class Brightbox
class Real
def update_server_group(identifier, options)
return nil if identifier.nil? || identifier == ""
return nil if options.empty? || options.nil?
request("put", "/1.0/server_groups/#{identifier}", [202])
end
end
end
end
end

View file

@ -7,18 +7,10 @@ Shindo.tests('Fog::Compute[:brightbox] | account requests', ['brightbox']) do
Fog::Compute[:brightbox].get_account
end
unless Fog.mocking?
original_name = Fog::Compute[:brightbox].get_account["name"]
update_args = {:name => "New name from Fog test"}
end
tests("#update_account(#{update_args.inspect})").formats(Brightbox::Compute::Formats::Full::ACCOUNT) do
update_options = {:name => "Fog@#{Time.now.iso8601}"}
tests("#update_account(#{update_options.inspect})").formats(Brightbox::Compute::Formats::Full::ACCOUNT) do
pending if Fog.mocking?
Fog::Compute[:brightbox].update_account(update_args)
end
unless Fog.mocking?
Fog::Compute[:brightbox].update_account(:name => original_name)
Fog::Compute[:brightbox].update_account(update_options)
end
tests("#reset_ftp_password_account").formats(Brightbox::Compute::Formats::Full::ACCOUNT) do

View file

@ -2,7 +2,10 @@ Shindo.tests('Fog::Compute[:brightbox] | api client requests', ['brightbox']) do
tests('success') do
create_options = {:name => "Name from Fog test (#{Time.now.to_i})", :description => "Description from Fog test"}
create_options = {
:name => "Fog@#{Time.now.iso8601}",
:description => "Description from Fog test"
}
tests("#create_api_client(#{create_options.inspect})").formats(Brightbox::Compute::Formats::Full::API_CLIENT) do
pending if Fog.mocking?
@ -21,9 +24,10 @@ Shindo.tests('Fog::Compute[:brightbox] | api client requests', ['brightbox']) do
Fog::Compute[:brightbox].get_api_client(@api_client_id)
end
update_options = {:name => "Fog@#{Time.now.iso8601}"}
tests("#update_api_client('#{@api_client_id}')").formats(Brightbox::Compute::Formats::Full::API_CLIENT) do
pending if Fog.mocking?
Fog::Compute[:brightbox].update_api_client(@api_client_id, :name => "New name from Fog test")
Fog::Compute[:brightbox].update_api_client(@api_client_id, update_options)
end
tests("#destroy_api_client('#{@api_client_id}')").formats(Brightbox::Compute::Formats::Full::API_CLIENT) do

View file

@ -119,6 +119,15 @@ class Brightbox
"deleted_at" => Fog::Nullable::String
}
SERVER_GROUP = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"default" => Fog::Boolean,
"description" => Fog::Nullable::String
}
SERVER_TYPE = {
"name" => String,
"handle" => Fog::Nullable::String,
@ -199,7 +208,10 @@ class Brightbox
"name" => String,
"status" => String,
"created_at" => String,
"deleted_at" => Fog::Nullable::String
"deleted_at" => Fog::Nullable::String,
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT,
"nodes" => [Brightbox::Compute::Formats::Nested::SERVER],
"cloud_ips" => [Brightbox::Compute::Formats::Nested::CLOUD_IP]
}
SERVER = {
@ -216,11 +228,23 @@ class Brightbox
"server_type" => Brightbox::Compute::Formats::Nested::SERVER_TYPE,
"cloud_ips" => [Brightbox::Compute::Formats::Nested::CLOUD_IP],
"image" => Brightbox::Compute::Formats::Nested::IMAGE,
"server_groups" => [Brightbox::Compute::Formats::Nested::SERVER_GROUP],
"snapshots" => [Brightbox::Compute::Formats::Nested::IMAGE],
"interfaces" => [Brightbox::Compute::Formats::Nested::INTERFACE],
"zone" => Fog::Brightbox::Nullable::Zone
}
SERVER_GROUP = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"description" => Fog::Nullable::String,
"default" => Fog::Boolean,
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT,
"servers" => [Brightbox::Compute::Formats::Nested::SERVER]
}
SERVER_TYPE = {
"id" => String,
"resource_type" => String,
@ -380,10 +404,22 @@ class Brightbox
"cloud_ips" => [Brightbox::Compute::Formats::Nested::CLOUD_IP],
"image" => Brightbox::Compute::Formats::Nested::IMAGE,
"snapshots" => [Brightbox::Compute::Formats::Nested::IMAGE],
"server_groups" => [Brightbox::Compute::Formats::Nested::SERVER_GROUP],
"interfaces" => [Brightbox::Compute::Formats::Nested::INTERFACE],
"zone" => Brightbox::Compute::Formats::Nested::ZONE
}
SERVER_GROUP = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"description" => Fog::Nullable::String,
"default" => Fog::Boolean,
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT,
"servers" => [Brightbox::Compute::Formats::Nested::SERVER]
}
SERVER_TYPE = {
"id" => String,
"resource_type" => String,
@ -424,6 +460,7 @@ class Brightbox
IMAGES = [Brightbox::Compute::Formats::Collected::IMAGE]
LOAD_BALANCERS = [Brightbox::Compute::Formats::Collected::LOAD_BALANCER]
SERVERS = [Brightbox::Compute::Formats::Collected::SERVER]
SERVER_GROUPS = [Brightbox::Compute::Formats::Collected::SERVER_GROUP]
SERVER_TYPES = [Brightbox::Compute::Formats::Collected::SERVER_TYPE]
USERS = [Brightbox::Compute::Formats::Collected::USER]
ZONES = [Brightbox::Compute::Formats::Collected::ZONE]

View file

@ -16,7 +16,7 @@ Shindo.tests('Fog::Compute[:brightbox] | interface requests', ['brightbox']) do
tests('failure') do
tests("#get_interface('int-00000')").raises(Excon::Errors::Forbidden) do
tests("#get_interface('int-00000')").raises(Excon::Errors::NotFound) do
pending if Fog.mocking?
Fog::Compute[:brightbox].get_interface('int-00000')
end

View file

@ -7,7 +7,7 @@ Shindo.tests('Fog::Compute[:brightbox] | load balancer requests', ['brightbox'])
node_id = @node.id
end
creation_args = {
create_options = {
:nodes => [{
:node => node_id
}],
@ -22,9 +22,9 @@ Shindo.tests('Fog::Compute[:brightbox] | load balancer requests', ['brightbox'])
}
}
tests("#create_load_balancer(#{creation_args.inspect})").formats(Brightbox::Compute::Formats::Full::LOAD_BALANCER) do
tests("#create_load_balancer(#{create_options.inspect})").formats(Brightbox::Compute::Formats::Full::LOAD_BALANCER) do
pending if Fog.mocking?
data = Fog::Compute[:brightbox].create_load_balancer(creation_args)
data = Fog::Compute[:brightbox].create_load_balancer(create_options)
@load_balancer_id = data["id"]
data
end
@ -33,9 +33,9 @@ Shindo.tests('Fog::Compute[:brightbox] | load balancer requests', ['brightbox'])
Fog::Compute[:brightbox].load_balancers.get(@load_balancer_id).wait_for { ready? }
end
# tests("#list_load_balancers()").formats(Brightbox::Compute::Formats::Collection::LOAD_BALANCERS) do
# Fog::Compute[:brightbox].list_load_balancers
# end
tests("#list_load_balancers()").formats(Brightbox::Compute::Formats::Collection::LOAD_BALANCERS) do
Fog::Compute[:brightbox].list_load_balancers
end
tests("#get_load_balancer('#{@load_balancer_id}')").formats(Brightbox::Compute::Formats::Full::LOAD_BALANCER) do
pending if Fog.mocking?

View file

@ -0,0 +1,89 @@
Shindo.tests('Fog::Compute[:brightbox] | server group requests', ['brightbox']) do
tests('success') do
unless Fog.mocking?
@server = Fog::Compute[:brightbox].servers.create(:image_id => Brightbox::Compute::TestSupport::IMAGE_IDENTIFER)
server_id = @server.id
end
create_options = {
:name => "Fog@#{Time.now.iso8601}",
:servers => [{
:server => server_id
}]
}
tests("#create_server_group(#{create_options.inspect})").formats(Brightbox::Compute::Formats::Full::SERVER_GROUP) do
pending if Fog.mocking?
data = Fog::Compute[:brightbox].create_server_group(create_options)
@server_group_id = data["id"]
data
end
tests("#list_server_groups").formats(Brightbox::Compute::Formats::Collection::SERVER_GROUPS) do
pending if Fog.mocking?
Fog::Compute[:brightbox].list_server_groups
end
tests("#get_server_group('#{@server_group_id}')").formats(Brightbox::Compute::Formats::Full::SERVER_GROUP) do
pending if Fog.mocking?
Fog::Compute[:brightbox].get_server_group(@server_group_id)
end
update_options = {:name => "Fog@#{Time.now.iso8601}"}
tests("#update_server_group(#{update_options.inspect})").formats(Brightbox::Compute::Formats::Full::SERVER_GROUP) do
pending if Fog.mocking?
Fog::Compute[:brightbox].update_server_group(@server_group_id, update_options)
end
remove_options = {:servers => [{:server => server_id}]}
tests("#remove_servers_server_group(#{remove_options.inspect})").formats(Brightbox::Compute::Formats::Full::SERVER_GROUP) do
pending if Fog.mocking?
Fog::Compute[:brightbox].remove_servers_server_group(@server_group_id, remove_options)
end
add_options = {:servers => [{:server => server_id}]}
tests("#add_servers_server_group(#{remove_options.inspect})").formats(Brightbox::Compute::Formats::Full::SERVER_GROUP) do
pending if Fog.mocking?
Fog::Compute[:brightbox].add_servers_server_group(@server_group_id, add_options)
end
# Server Group must be empty to delete so we need to remove it again
remove_options = {:servers => [{:server => server_id}]}
tests("#remove_servers_server_group(#{remove_options.inspect})").formats(Brightbox::Compute::Formats::Full::SERVER_GROUP) do
pending if Fog.mocking?
Fog::Compute[:brightbox].remove_servers_server_group(@server_group_id, remove_options)
end
tests("#destroy_server_group('#{@server_group_id}')").formats(Brightbox::Compute::Formats::Full::SERVER_GROUP) do
pending if Fog.mocking?
Fog::Compute[:brightbox].destroy_server_group(@server_group_id)
end
unless Fog.mocking?
@server.wait_for { ready? }
@server.destroy
end
end
tests('failure') do
tests("#create_server_group").raises(ArgumentError) do
pending if Fog.mocking?
Fog::Compute[:brightbox].create_server_group
end
tests("#get_server_group('grp-00000')").raises(Excon::Errors::NotFound) do
pending if Fog.mocking?
Fog::Compute[:brightbox].get_server_group('grp-00000')
end
tests("#get_server_group").raises(ArgumentError) do
pending if Fog.mocking?
Fog::Compute[:brightbox].get_server_group
end
end
end

View file

@ -28,7 +28,7 @@ Shindo.tests('Fog::Compute[:brightbox] | server requests', ['brightbox']) do
tests("#update_server('#{server_id}')").formats(Brightbox::Compute::Formats::Full::SERVER) do
pending if Fog.mocking?
Fog::Compute[:brightbox].update_server(server_id, :name => "New name from Fog test")
Fog::Compute[:brightbox].update_server(server_id, :name => "Fog@#{Time.now.iso8601}")
end
tests("#activate_console_server('#{server_id}')").formats(Brightbox::Compute::Formats::Full::SERVER) do

View file

@ -16,7 +16,7 @@ Shindo.tests('Fog::Compute[:brightbox] | user requests', ['brightbox']) do
data
end
update_options = { :name => "New name from Fog" }
update_options = { :name => "Fog@#{Time.now.iso8601}" }
tests("#update_user('#{@user_id}', #{update_options.inspect})").formats(Brightbox::Compute::Formats::Full::USER) do
pending if Fog.mocking?