mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge branch 'bb_updates'
Conflicts: tests/brightbox/requests/compute/helper.rb
This commit is contained in:
commit
180426bbfd
10 changed files with 280 additions and 24 deletions
|
@ -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
|
||||
|
@ -35,6 +39,7 @@ module Fog
|
|||
request :add_nodes_load_balancer
|
||||
request :add_servers_server_group
|
||||
request :apply_to_firewall_policy
|
||||
request :remove_firewall_policy
|
||||
request :create_api_client
|
||||
request :create_cloud_ip
|
||||
request :create_firewall_policy
|
||||
|
@ -88,6 +93,7 @@ module Fog
|
|||
request :unmap_cloud_ip
|
||||
request :update_account
|
||||
request :update_api_client
|
||||
request :update_cloud_ip
|
||||
request :update_image
|
||||
request :update_load_balancer
|
||||
request :update_server
|
||||
|
|
29
lib/fog/brightbox/models/compute/firewall_policies.rb
Normal file
29
lib/fog/brightbox/models/compute/firewall_policies.rb
Normal 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
|
65
lib/fog/brightbox/models/compute/firewall_policy.rb
Normal file
65
lib/fog/brightbox/models/compute/firewall_policy.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
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 :created_at, :type => :time
|
||||
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)
|
||||
requires :identity
|
||||
options = {
|
||||
:server_group => server_group_id
|
||||
}
|
||||
data = connection.apply_to_firewall_policy(identity, options)
|
||||
merge_attributes(data)
|
||||
true
|
||||
end
|
||||
|
||||
def remove(server_group_id)
|
||||
requires :identity
|
||||
options = {
|
||||
:server_group => server_group_id
|
||||
}
|
||||
data = connection.remove_firewall_policy(identity, options)
|
||||
merge_attributes(data)
|
||||
true
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :identity
|
||||
data = connection.destroy_firewall_policy(identity)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
54
lib/fog/brightbox/models/compute/firewall_rule.rb
Normal file
54
lib/fog/brightbox/models/compute/firewall_rule.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
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 :created_at, :type => :time
|
||||
|
||||
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
|
||||
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
|
24
lib/fog/brightbox/models/compute/firewall_rules.rb
Normal file
24
lib/fog/brightbox/models/compute/firewall_rules.rb
Normal 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
|
|
@ -11,6 +11,7 @@ module Fog
|
|||
attribute :resource_type
|
||||
|
||||
attribute :name
|
||||
attribute :username
|
||||
attribute :status
|
||||
attribute :description
|
||||
|
||||
|
@ -43,6 +44,7 @@ module Fog
|
|||
:source => source,
|
||||
:arch => arch,
|
||||
:name => name,
|
||||
:username => username,
|
||||
:description => description
|
||||
}.delete_if {|k,v| v.nil? || v == "" }
|
||||
data = connection.create_image(options)
|
||||
|
|
|
@ -27,17 +27,43 @@ module Fog
|
|||
# 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
|
||||
attribute :server_groups
|
||||
attribute :zone
|
||||
attribute :server_type
|
||||
|
||||
def initialize(attributes={})
|
||||
self.image_id ||= 'img-2ab98' # Ubuntu Lucid 10.04 server (i686)
|
||||
super
|
||||
end
|
||||
|
||||
def zone_id
|
||||
if t_zone_id = attributes[:zone_id]
|
||||
t_zone_id
|
||||
elsif zone
|
||||
zone[:id] || zone['id']
|
||||
end
|
||||
end
|
||||
|
||||
def flavor_id
|
||||
if t_flavour_id = attributes[:flavor_id]
|
||||
t_flavour_id
|
||||
elsif server_type
|
||||
server_type[:id] || server_type['id']
|
||||
end
|
||||
end
|
||||
|
||||
def zone_id=(incoming_zone_id)
|
||||
attributes[:zone_id] = incoming_zone_id
|
||||
end
|
||||
|
||||
def flavor_id=(incoming_flavour_id)
|
||||
attributes[:flavor_id] = incoming_flavour_id
|
||||
end
|
||||
|
||||
def snapshot
|
||||
requires :identity
|
||||
connection.snapshot_server(identity)
|
||||
|
@ -106,7 +132,8 @@ module Fog
|
|||
:image => image_id,
|
||||
:name => name,
|
||||
:zone => zone_id,
|
||||
:user_data => user_data
|
||||
:user_data => user_data,
|
||||
:server_groups => server_groups
|
||||
}.delete_if {|k,v| v.nil? || v == "" }
|
||||
unless flavor_id.nil? || flavor_id == ""
|
||||
options.merge!(:server_type => flavor_id)
|
||||
|
|
|
@ -16,9 +16,9 @@ module Fog
|
|||
attribute :name
|
||||
attribute :description
|
||||
attribute :default
|
||||
attribute :created_at, :type => :time
|
||||
|
||||
def save
|
||||
requires :name
|
||||
options = {
|
||||
:name => name,
|
||||
:description => description
|
||||
|
@ -28,30 +28,60 @@ module Fog
|
|||
true
|
||||
end
|
||||
|
||||
# Add a server to the server group
|
||||
# Adds specified servers to this 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)
|
||||
# @param [Array] identifiers array of server identifier strings to add
|
||||
# @return [Fog::Compute::ServerGroup]
|
||||
def add_servers identifiers
|
||||
requires :identity
|
||||
server_references = server_identifiers.map {|ident| {"server" => ident} }
|
||||
options = {
|
||||
:servers => server_references
|
||||
:servers => server_references(identifiers)
|
||||
}
|
||||
data = connection.add_servers_server_group(identity, options)
|
||||
merge_attributes(data)
|
||||
data = connection.add_servers_server_group identity, options
|
||||
merge_attributes data
|
||||
end
|
||||
|
||||
# Removes specified servers from this server group
|
||||
#
|
||||
# @param [Array] identifiers array of server identifier strings to remove
|
||||
# @return [Fog::Compute::ServerGroup]
|
||||
def remove_servers identifiers
|
||||
requires :identity
|
||||
options = {
|
||||
:servers => server_references(identifiers)
|
||||
}
|
||||
data = connection.remove_servers_server_group identity, options
|
||||
merge_attributes data
|
||||
end
|
||||
|
||||
# Moves specified servers from this server group to the specified destination server group
|
||||
#
|
||||
# @param [Array] identifiers array of server identifier strings to move
|
||||
# @param [String] destination_group_id destination server group identifier
|
||||
# @return [Fog::Compute::ServerGroup]
|
||||
def move_servers identifiers, destination_group_id
|
||||
requires :identity
|
||||
options = {
|
||||
:servers => server_references(identifiers),
|
||||
:destination => destination_group_id
|
||||
}
|
||||
data = connection.move_servers_server_group identity, options
|
||||
merge_attributes data
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :identity
|
||||
connection.destroy_server_group(identity)
|
||||
true
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def server_references identifiers
|
||||
identifiers.map {|id| {"server" => id} }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
14
lib/fog/brightbox/requests/compute/remove_firewall_policy.rb
Normal file
14
lib/fog/brightbox/requests/compute/remove_firewall_policy.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Brightbox
|
||||
class Real
|
||||
|
||||
def remove_firewall_policy(identifier, options)
|
||||
return nil if identifier.nil? || identifier == ""
|
||||
request("post", "/1.0/firewall_policies/#{identifier}/remove", [202], options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -111,7 +111,7 @@ class Brightbox
|
|||
"source" => String,
|
||||
"status" => String,
|
||||
"owner" => String,
|
||||
"username" => Fog::Nullable::String,
|
||||
"username" => Fog::Nullable::String
|
||||
}
|
||||
|
||||
INTERFACE = {
|
||||
|
@ -143,7 +143,8 @@ class Brightbox
|
|||
"name" => String,
|
||||
"created_at" => String,
|
||||
"default" => Fog::Boolean,
|
||||
"description" => Fog::Nullable::String
|
||||
"description" => Fog::Nullable::String,
|
||||
"created_at" => String
|
||||
}
|
||||
|
||||
SERVER_TYPE = {
|
||||
|
@ -235,6 +236,7 @@ class Brightbox
|
|||
"source_type" => String,
|
||||
"status" => String,
|
||||
"owner" => String,
|
||||
"username" => Fog::Nullable::String,
|
||||
"public" => Fog::Boolean,
|
||||
"official" => Fog::Boolean,
|
||||
"compatibility_mode" => Fog::Boolean,
|
||||
|
@ -287,6 +289,7 @@ class Brightbox
|
|||
"name" => String,
|
||||
"description" => Fog::Nullable::String,
|
||||
"default" => Fog::Boolean,
|
||||
"created_at" => String,
|
||||
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT,
|
||||
"servers" => [Brightbox::Compute::Formats::Nested::SERVER]
|
||||
}
|
||||
|
@ -421,6 +424,7 @@ class Brightbox
|
|||
"source_type" => String,
|
||||
"status" => String,
|
||||
"owner" => String, # Account ID not object
|
||||
"username" => Fog::Nullable::String,
|
||||
"public" => Fog::Boolean,
|
||||
"official" => Fog::Boolean,
|
||||
"compatibility_mode" => Fog::Boolean,
|
||||
|
@ -489,6 +493,7 @@ class Brightbox
|
|||
"name" => String,
|
||||
"description" => Fog::Nullable::String,
|
||||
"default" => Fog::Boolean,
|
||||
"created_at" => String,
|
||||
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT,
|
||||
"servers" => [Brightbox::Compute::Formats::Nested::SERVER]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue