2011-08-18 12:16:58 -04:00
|
|
|
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
|
2011-10-27 05:57:27 -04:00
|
|
|
attribute :created_at, :type => :time
|
2011-08-18 12:16:58 -04:00
|
|
|
|
|
|
|
def save
|
|
|
|
options = {
|
|
|
|
:name => name,
|
|
|
|
:description => description
|
|
|
|
}.delete_if {|k,v| v.nil? || v == "" }
|
|
|
|
data = connection.create_server_group(options)
|
|
|
|
merge_attributes(data)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2011-09-21 14:16:08 -04:00
|
|
|
# Adds specified servers to this server group
|
2011-08-18 12:16:58 -04:00
|
|
|
#
|
2011-09-21 14:16:08 -04:00
|
|
|
# @param [Array] identifiers array of server identifier strings to add
|
|
|
|
# @return [Fog::Compute::ServerGroup]
|
|
|
|
def add_servers identifiers
|
|
|
|
requires :identity
|
|
|
|
options = {
|
|
|
|
:servers => server_references(identifiers)
|
|
|
|
}
|
|
|
|
data = connection.add_servers_server_group identity, options
|
|
|
|
merge_attributes data
|
|
|
|
end
|
|
|
|
|
|
|
|
# Removes specified servers from this server group
|
2011-08-18 12:16:58 -04:00
|
|
|
#
|
2011-09-21 14:16:08 -04:00
|
|
|
# @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
|
2011-08-18 12:16:58 -04:00
|
|
|
#
|
2011-09-21 14:16:08 -04:00
|
|
|
# @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
|
2011-08-18 12:16:58 -04:00
|
|
|
requires :identity
|
|
|
|
options = {
|
2011-09-21 14:16:08 -04:00
|
|
|
:servers => server_references(identifiers),
|
|
|
|
:destination => destination_group_id
|
2011-08-18 12:16:58 -04:00
|
|
|
}
|
2011-09-21 14:16:08 -04:00
|
|
|
data = connection.move_servers_server_group identity, options
|
|
|
|
merge_attributes data
|
2011-08-18 12:16:58 -04:00
|
|
|
end
|
|
|
|
|
2011-09-21 14:16:08 -04:00
|
|
|
def destroy
|
|
|
|
requires :identity
|
|
|
|
connection.destroy_server_group(identity)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
2011-08-18 12:16:58 -04:00
|
|
|
|
2011-09-21 14:16:08 -04:00
|
|
|
def server_references identifiers
|
|
|
|
identifiers.map {|id| {"server" => id} }
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2011-08-18 12:16:58 -04:00
|
|
|
end
|
|
|
|
end
|
2011-09-21 14:16:08 -04:00
|
|
|
end
|