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

[brightbox] Firewall models

This commit is contained in:
Paul Thornthwaite 2011-09-23 16:15:01 +01:00
parent 863f456ce6
commit 298d1a9192
5 changed files with 163 additions and 0 deletions

View file

@ -16,6 +16,10 @@ module Fog
model :server
collection :server_groups
model :server_group
collection :firewall_policies
model :firewall_policy
collection :firewall_rules
model :firewall_rule
collection :flavors
model :flavor
collection :images

View file

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

View file

@ -0,0 +1,53 @@
require 'fog/core/model'
module Fog
module Compute
class Brightbox
class FirewallPolicy < Fog::Model
identity :id
attribute :url
attribute :resource_type
attribute :name
attribute :description
attribute :default
attribute :server_group_id, :aliases => "server_group", :squash => "id"
attribute :rules
# Sticking with existing Fog behaviour, save does not update but creates a new resource
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
options = {
:server_group => server_group_id,
:name => name,
:description => description
}.delete_if {|k,v| v.nil? || v == "" }
data = connection.create_firewall_policy(options)
merge_attributes(data)
true
end
def apply_to(server_group_id)
options = {
:server_group => server_group_id
}
data = connection.apply_to_firewall_policy(options)
merge_attributes(data)
true
end
def destroy
requires :identity
data = connection.destroy_firewall_policy(identity)
true
end
end
end
end
end

View file

@ -0,0 +1,53 @@
require 'fog/core/model'
module Fog
module Compute
class Brightbox
class FirewallRule < Fog::Model
identity :id
attribute :url
attribute :resource_type
attribute :description
attribute :source
attribute :source_port
attribute :destination
attribute :destination_port
attribute :protocol
attribute :icmp_type_name
attribute :firewall_policy_id, :aliases => "firewall_policy", :squash => "id"
# Sticking with existing Fog behaviour, save does not update but creates a new resource
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :firewall_policy_id, :protocol
options = {
:firewall_policy => firewall_policy_id,
:protocol => protocol,
:description => description,
:source => source,
:source_port => source_port,
:destination => destination,
:destination_port => destination_port,
:icmp_type_name => icmp_type_name
}.delete_if {|k,v| v.nil? || v == "" }
data = connection.create_firewall_rule(options)
merge_attributes(data)
true
end
def destroy
requires :identity
connection.destroy_firewall_rule(identity)
true
end
end
end
end
end

View file

@ -0,0 +1,24 @@
require 'fog/core/collection'
require 'fog/brightbox/models/compute/firewall_rule'
module Fog
module Compute
class Brightbox
class FirewallRules < Fog::Collection
model Fog::Compute::Brightbox::FirewallRule
def get(identifier)
return nil if identifier.nil? || identifier == ""
data = connection.get_firewall_rule(identifier)
new(data)
rescue Excon::Errors::NotFound
nil
end
end
end
end
end