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

Rackspace LB: models for access lists

This commit is contained in:
Brian Hartsock 2011-07-28 13:21:26 -04:00
parent 7d75c88a73
commit c4a64d265b
6 changed files with 123 additions and 0 deletions

View file

@ -50,6 +50,8 @@ module Fog
model :node
collection :virtual_ips
model :virtual_ip
collection :access_rules
model :access_rule
request_path 'fog/rackspace/requests'
request :create_load_balancer

View file

@ -0,0 +1,39 @@
require 'fog/core/model'
module Fog
module Rackspace
class LoadBalancer
class AccessRule < Fog::Model
identity :id
attribute :address
attribute :type
def destroy
requires :identity, :load_balancer
connection.delete_access_rule(load_balancer.identity, identity)
true
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :load_balancer, :address, :type
connection.create_access_rule(load_balancer.id, address, type)
#Unfortunately, access rules creation doesn't return an ID, we require a subsequent list call and comparison
data = connection.list_access_rules(load_balancer.id).body['accessList']
.select { |ar| ar['address'] == address and ar['type'] == type }
.first
merge_attributes(data)
true
end
private
def load_balancer
collection.load_balancer
end
end
end
end
end

View file

@ -0,0 +1,28 @@
require 'fog/core/collection'
require 'fog/rackspace/models/access_rule'
module Fog
module Rackspace
class LoadBalancer
class AccessRules < Fog::Collection
model Fog::Rackspace::LoadBalancer::AccessRule
attr_accessor :load_balancer
def all
load(all_raw)
end
def get(access_rule_id)
data = all_raw.select { |access_rule| access_rule['id'] == access_rule_id }.first
data && new(data)
end
private
def all_raw
data = connection.list_access_rules(load_balancer.id).body['accessList']
end
end
end
end
end

View file

@ -25,6 +25,18 @@ module Fog
super
end
def access_rules
@access_rules ||= begin
Fog::Rackspace::LoadBalancer::AccessRules.new({
:connection => connection,
:load_balancer => self})
end
end
def access_rules=(new_access_rules=[])
access_rules.load(new_access_rules)
end
def nodes
@nodes ||= begin
Fog::Rackspace::LoadBalancer::Nodes.new({

View file

@ -0,0 +1,21 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | access_list', ['rackspace']) do
@service = Fog::Rackspace::LoadBalancer.new
@lb = @service.load_balancers.create({
:name => ('fog' + Time.now.to_i.to_s),
:protocol => 'HTTP',
:port => 80,
:virtual_ips => [{ :type => 'PUBLIC'}],
:nodes => [{ :address => '10.0.0.1', :port => 80, :condition => 'ENABLED'}]
})
@lb.wait_for { ready? }
begin
model_tests(@lb.access_rules, { :address => '10.0.0.2', :type => 'ALLOW'}, false) do
@lb.wait_for { ready? }
end
ensure
@lb.wait_for { ready? }
@lb.destroy
end
end

View file

@ -0,0 +1,21 @@
Shindo.tests('Fog::Rackspace::LoadBalancer | access_lists', ['rackspace']) do
@service = Fog::Rackspace::LoadBalancer.new
@lb = @service.load_balancers.create({
:name => ('fog' + Time.now.to_i.to_s),
:protocol => 'HTTP',
:port => 80,
:virtual_ips => [{ :type => 'PUBLIC'}],
:nodes => [{ :address => '10.0.0.1', :port => 80, :condition => 'ENABLED'}]
})
@lb.wait_for { ready? }
begin
collection_tests(@lb.access_rules, { :address => '10.0.0.2', :type => 'ALLOW'}, false) do
@lb.wait_for { ready? }
end
ensure
@lb.wait_for { ready? }
@lb.destroy
end
end