Merge branch 'master' of github.com:geemus/fog

This commit is contained in:
Patrick Debois 2011-09-21 14:34:30 +02:00
commit ff7fccfa6f
22 changed files with 325 additions and 15 deletions

View File

@ -160,7 +160,11 @@ module Fog
instance_set.each do |instance|
case instance['instanceState']['name']
when 'pending'
if Time.now - instance['launchTime'] >= Fog::Mock.delay
if Time.now - instance['launchTime'] < Fog::Mock.delay * 2
raise Fog::Compute::AWS::NotFound.new("The instance ID '#{instance['instanceId']}' does not exist")
end
if Time.now - instance['launchTime'] >= Fog::Mock.delay * 2
instance['ipAddress'] = Fog::AWS::Mock.ip_address
instance['originalIpAddress'] = instance['ipAddress']
instance['dnsName'] = Fog::AWS::Mock.dns_name_for(instance['ipAddress'])

View File

@ -8,12 +8,14 @@ module Fog
API_URL = "https://api.gb1.brightbox.com/"
requires :brightbox_client_id, :brightbox_secret
recognizes :brightbox_auth_url, :brightbox_api_url
recognizes :brightbox_auth_url, :brightbox_api_url, :persistent
model_path 'fog/brightbox/models/compute'
model :account # Singular resource, no collection
collection :servers
model :server
collection :server_groups
model :server_group
collection :flavors
model :flavor
collection :images
@ -32,14 +34,19 @@ module Fog
request :add_listeners_load_balancer
request :add_nodes_load_balancer
request :add_servers_server_group
request :apply_to_firewall_policy
request :create_api_client
request :create_cloud_ip
request :create_firewall_policy
request :create_firewall_rule
request :create_image
request :create_load_balancer
request :create_server
request :create_server_group
request :destroy_api_client
request :destroy_cloud_ip
request :destroy_firewall_policy
request :destroy_firewall_rule
request :destroy_image
request :destroy_load_balancer
request :destroy_server
@ -47,6 +54,8 @@ module Fog
request :get_account
request :get_api_client
request :get_cloud_ip
request :get_firewall_policy
request :get_firewall_rule
request :get_image
request :get_interface
request :get_load_balancer
@ -57,6 +66,7 @@ module Fog
request :get_zone
request :list_api_clients
request :list_cloud_ips
request :list_firewall_policies
request :list_images
request :list_load_balancers
request :list_server_groups
@ -106,7 +116,7 @@ module Fog
@connection_options = options[:connection_options] || {}
@brightbox_client_id = options[:brightbox_client_id] || Fog.credentials[:brightbox_client_id]
@brightbox_secret = options[:brightbox_secret] || Fog.credentials[:brightbox_secret]
@persistent = options[:peristent] || false
@persistent = options[:persistent] || false
@connection = Fog::Connection.new(@api_url, @persistent, @connection_options)
end

View File

@ -0,0 +1,57 @@
require 'fog/core/model'
module Fog
module Compute
class Brightbox
# A server group is a collection of servers
#
# Certain actions can accept a server group and affect all members
class ServerGroup < Fog::Model
identity :id
attribute :url
attribute :resource_type
attribute :name
attribute :description
attribute :default
def save
requires :name
options = {
:name => name,
:description => description
}.delete_if {|k,v| v.nil? || v == "" }
data = connection.create_server_group(options)
merge_attributes(data)
true
end
# Add a server to the server group
#
# == Parameters:
# identifiers::
# An array of identifiers for the servers to add to the group
#
# == Returns:
#
# An excon response object representing the result
#
# <Excon::Response: ...
#
def add_servers(server_identifiers)
requires :identity
server_references = server_identifiers.map {|ident| {"server" => ident} }
options = {
:servers => server_references
}
data = connection.add_servers_server_group(identity, options)
merge_attributes(data)
end
end
end
end
end

View File

@ -0,0 +1,29 @@
require 'fog/core/collection'
require 'fog/brightbox/models/compute/server_group'
module Fog
module Compute
class Brightbox
class ServerGroups < Fog::Collection
model Fog::Compute::Brightbox::ServerGroup
def all
data = connection.list_server_groups
load(data)
end
def get(identifier)
return nil if identifier.nil? || identifier == ""
data = connection.get_server_group(identifier)
new(data)
rescue Excon::Errors::NotFound
nil
end
end
end
end
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ module Fog
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])
request("put", "/1.0/server_groups/#{identifier}", [202], options)
end
end

View File

@ -50,15 +50,15 @@ module Fog
requires :hostname, :rootpw
options = {
:datacenter => "Falkenberg" || datacenter,
:platform => "Xen" || platform,
:datacenter => datacenter || "Falkenberg",
:platform => platform || "Xen",
:hostname => hostname,
:template => "Debian-6 x64" || template,
:disksize => "10" || disksize,
:memorysize => "512" || memorysize,
:cpucores => "1" || cpucores,
:template => template || "Debian-6 x64",
:disksize => disksize || "10",
:memorysize => memorysize || "512",
:cpucores => cpucores || "1",
:rootpw => rootpw,
:transfer => "500" || transfer,
:transfer => transfer || "500",
}
data = connection.create(options)
merge_attributes(data.body['response']['server'])

View File

@ -67,7 +67,7 @@ module Fog
def get_url(key)
requires :directory
if self.directory.public_url
"#{self.directory.public_url}/#{key}"
"#{self.directory.public_url}/#{Fog::Rackspace.escape(key, '/')}"
end
end

View File

@ -79,6 +79,27 @@ class Brightbox
"reverse_dns" => String
}
FIREWALL_POLICY = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"default" => Fog::Boolean
}
FIREWALL_RULE = {
"id" => String,
"resource_type" => String,
"url" => String,
"source" => Fog::Nullable::String,
"source_port" => Fog::Nullable::String,
"destination" => Fog::Nullable::String,
"destination_port" => Fog::Nullable::String,
"protocol" => String,
"icmp_type_name" => Fog::Nullable::String,
"description" => Fog::Nullable::String
}
IMAGE = {
"name" => String,
"created_at" => String,
@ -174,6 +195,31 @@ class Brightbox
"server" => Fog::Brightbox::Nullable::Server
}
FIREWALL_POLICY = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"description" => Fog::Nullable::String,
"default" => Fog::Boolean,
"server_group" => Brightbox::Compute::Formats::Nested::SERVER_GROUP,
"rules" => [Brightbox::Compute::Formats::Nested::FIREWALL_RULE]
}
FIREWALL_RULE = {
"id" => String,
"resource_type" => String,
"url" => String,
"source" => String,
"source_port" => String,
"destination" => String,
"destination_port" => String,
"protocol" => String,
"icmp_type_name" => String,
"description" => Fog::Nullable::String,
"firewall_policy" => Brightbox::Compute::Formats::Nested::FIREWALL_POLICY
}
IMAGE = {
"name" => String,
"created_at" => String,
@ -333,6 +379,30 @@ class Brightbox
"server" => Fog::Brightbox::Nullable::Server
}
FIREWALL_POLICY = {
"id" => String,
"resource_type" => String,
"url" => String,
"name" => String,
"description" => Fog::Nullable::String,
"default" => Fog::Boolean,
"server_group" => Brightbox::Compute::Formats::Nested::SERVER_GROUP,
"rules" => [Brightbox::Compute::Formats::Nested::FIREWALL_RULE]
}
FIREWALL_RULE = {
"id" => String,
"resource_type" => String,
"url" => String,
"source" => String,
"source_port" => String,
"destination" => String,
"destination_port" => String,
"protocol" => String,
"icmp_type_name" => String,
"description" => Fog::Nullable::String
}
IMAGE = {
"name" => String,
"created_at" => String,
@ -452,6 +522,8 @@ class Brightbox
API_CLIENTS = [Brightbox::Compute::Formats::Collected::API_CLIENT]
CLOUD_IPS = [Brightbox::Compute::Formats::Collected::CLOUD_IP]
IMAGES = [Brightbox::Compute::Formats::Collected::IMAGE]
FIREWALL_POLICIES = [Brightbox::Compute::Formats::Collected::FIREWALL_POLICY]
FIREWALL_RULES = [Brightbox::Compute::Formats::Collected::FIREWALL_RULE]
LOAD_BALANCERS = [Brightbox::Compute::Formats::Collected::LOAD_BALANCER]
SERVERS = [Brightbox::Compute::Formats::Collected::SERVER]
SERVER_GROUPS = [Brightbox::Compute::Formats::Collected::SERVER_GROUP]

View File

@ -8,7 +8,7 @@ for provider, config in storage_providers
:key => 'fogdirectorytests'
}.merge!(config[:directory_attributes] || {})
model_tests(Fog::Storage[provider].directory, directory_attributes, config[:mocked]) do
model_tests(Fog::Storage[provider].directories, directory_attributes, config[:mocked]) do
tests("#public=(true)").succeeds do
pending if Fog.mocking? && !config[:mocked]
@ -17,7 +17,7 @@ for provider, config in storage_providers
tests('responds_to(:public_url)') do
pending if Fog.mocking? && !config[:mocked]
@instance.responds_to(:public_url)
responds_to(:public_url)
end
end