mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2120 from jamiehannaford/master
Rackspace AutoScale
This commit is contained in:
commit
71d512a79b
49 changed files with 2424 additions and 1 deletions
|
@ -3,6 +3,8 @@ class Rackspace < Fog::Bin
|
|||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :auto_scale
|
||||
Fog::Rackspace::AutoScale
|
||||
when :block_storage
|
||||
Fog::Rackspace::BlockStorage
|
||||
when :cdn
|
||||
|
@ -31,6 +33,8 @@ class Rackspace < Fog::Bin
|
|||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :auto_scale
|
||||
Fog::Rackspace::AutoScale.new
|
||||
when :cdn
|
||||
Fog::Logger.warning("Rackspace[:cdn] is not recommended, use CDN[:rackspace] for portability")
|
||||
Fog::CDN.new(:provider => 'Rackspace')
|
||||
|
|
|
@ -81,6 +81,7 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
service(:auto_scale, 'rackspace/auto_scale', 'AutoScale')
|
||||
service(:block_storage, 'rackspace/block_storage', 'BlockStorage')
|
||||
service(:cdn, 'rackspace/cdn', 'CDN')
|
||||
service(:compute, 'rackspace/compute', 'Compute')
|
||||
|
|
132
lib/fog/rackspace/auto_scale.rb
Normal file
132
lib/fog/rackspace/auto_scale.rb
Normal file
|
@ -0,0 +1,132 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rackspace'))
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale < Fog::Service
|
||||
include Fog::Rackspace::Errors
|
||||
|
||||
class ServiceError < Fog::Rackspace::Errors::ServiceError; end
|
||||
class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
|
||||
|
||||
class BadRequest < Fog::Rackspace::Errors::BadRequest
|
||||
attr_reader :validation_errors
|
||||
|
||||
def self.slurp(error, service=nil)
|
||||
if error && error.response
|
||||
status_code = error.response.status
|
||||
if error.response.body
|
||||
body = Fog::JSON.decode(error.response.body)
|
||||
message = "#{body['type']} - #{body['message']}"
|
||||
details = error.response.body['details']
|
||||
end
|
||||
end
|
||||
|
||||
new_error = new(message)
|
||||
new_error.set_backtrace(error.backtrace)
|
||||
new_error.instance_variable_set(:@validation_errors, details)
|
||||
new_error.instance_variable_set(:@status_code, status_code)
|
||||
new_error.set_transaction_id(error, service)
|
||||
new_error
|
||||
end
|
||||
end
|
||||
|
||||
requires :rackspace_username, :rackspace_api_key
|
||||
recognizes :rackspace_auth_url
|
||||
recognizes :rackspace_region
|
||||
recognizes :rackspace_auto_scale_url
|
||||
|
||||
model_path 'fog/rackspace/models/auto_scale'
|
||||
model :group
|
||||
collection :groups
|
||||
model :group_config
|
||||
model :launch_config
|
||||
|
||||
model :policy
|
||||
collection :policies
|
||||
|
||||
model :webhook
|
||||
collection :webhooks
|
||||
|
||||
request_path 'fog/rackspace/requests/auto_scale'
|
||||
request :list_groups
|
||||
request :create_group
|
||||
request :get_group
|
||||
request :delete_group
|
||||
request :get_group_state
|
||||
request :pause_group_state
|
||||
request :resume_group_state
|
||||
|
||||
request :get_group_config
|
||||
request :update_group_config
|
||||
request :get_launch_config
|
||||
request :update_launch_config
|
||||
|
||||
request :list_policies
|
||||
request :create_policy
|
||||
request :get_policy
|
||||
request :update_policy
|
||||
request :delete_policy
|
||||
request :execute_policy
|
||||
|
||||
request :execute_anonymous_webhook
|
||||
|
||||
request :get_webhook
|
||||
request :list_webhooks
|
||||
request :create_webhook
|
||||
request :update_webhook
|
||||
request :delete_webhook
|
||||
|
||||
class Mock < Fog::Rackspace::Service
|
||||
def initialize(options)
|
||||
@rackspace_api_key = options[:rackspace_api_key]
|
||||
end
|
||||
|
||||
def request(params)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Real < Fog::Rackspace::Service
|
||||
|
||||
def initialize(options = {})
|
||||
@options = options
|
||||
@options[:connection_options] ||= {}
|
||||
@options[:persistent] ||= false
|
||||
|
||||
authenticate
|
||||
|
||||
@connection = Fog::Connection.new(endpoint_uri.to_s, @options[:persistent], @options[:connection_options])
|
||||
end
|
||||
|
||||
def request(params, parse_json = true, &block)
|
||||
super(params, parse_json, &block)
|
||||
rescue Excon::Errors::NotFound => error
|
||||
raise NotFound.slurp(error, self)
|
||||
rescue Excon::Errors::BadRequest => error
|
||||
raise BadRequest.slurp(error, self)
|
||||
rescue Excon::Errors::InternalServerError => error
|
||||
raise InternalServerError.slurp(error, self)
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise ServiceError.slurp(error, self)
|
||||
end
|
||||
|
||||
def endpoint_uri(service_endpoint_url=nil)
|
||||
@uri = super(@options[:rackspace_auto_scale_url], :rackspace_auto_scale_url)
|
||||
end
|
||||
|
||||
def authenticate(options={})
|
||||
super(select_options([:rackspace_username, :rackspace_api_key, :rackspace_auth_url, :connection_options]))
|
||||
end
|
||||
|
||||
def service_name
|
||||
:autoscale
|
||||
end
|
||||
|
||||
def region
|
||||
@options[:rackspace_region]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -113,6 +113,67 @@ module Fog
|
|||
"extra_specs" => {},
|
||||
}
|
||||
|
||||
#AutoScale
|
||||
launch_config = {
|
||||
"args" => {
|
||||
"loadBalancers" => [
|
||||
{
|
||||
"port" => 8080,
|
||||
"loadBalancerId" => 9099
|
||||
}
|
||||
],
|
||||
"server" => {
|
||||
"name" => "autoscale_server",
|
||||
"imageRef" => "0d589460-f177-4b0f-81c1-8ab8903ac7d8",
|
||||
"flavorRef" => "2",
|
||||
"OS-DCF =>diskConfig" => "AUTO",
|
||||
"metadata" => {
|
||||
"build_config" => "core",
|
||||
"meta_key_1" => "meta_value_1",
|
||||
"meta_key_2" => "meta_value_2"
|
||||
},
|
||||
"networks" => [
|
||||
{
|
||||
"uuid" => "11111111-1111-1111-1111-111111111111"
|
||||
},
|
||||
{
|
||||
"uuid" => "00000000-0000-0000-0000-000000000000"
|
||||
}
|
||||
],
|
||||
"personality" => [
|
||||
{
|
||||
"path" => "/root/.csivh",
|
||||
"contents" => "VGhpcyBpcyBhIHRlc3QgZmlsZS4="
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"type" => "launch_server"
|
||||
}
|
||||
|
||||
group_config = {
|
||||
"max_entities" => 10,
|
||||
"cooldown" => 360,
|
||||
"name" => "testscalinggroup198547",
|
||||
"min_entities" => 0,
|
||||
"metadata" => {
|
||||
"gc_meta_key_2" => "gc_meta_value_2",
|
||||
"gc_meta_key_1" => "gc_meta_value_1"
|
||||
}
|
||||
}
|
||||
|
||||
policy = {
|
||||
"cooldown" => 0,
|
||||
"type" => "webhook",
|
||||
"name" => "scale up by 1",
|
||||
"change" => 1
|
||||
}
|
||||
|
||||
webhook = {
|
||||
"name" => "webhook name",
|
||||
"metadata" => {'foo' => 'bar'}
|
||||
}
|
||||
|
||||
mock_data = {
|
||||
#Compute V2
|
||||
:flavors => Hash.new { |h,k| h[k] = flavor unless [NOT_FOUND_ID, '0'].include?(k) },
|
||||
|
@ -128,6 +189,9 @@ module Fog
|
|||
:snapshots => {},
|
||||
:volume_attachments => [],
|
||||
:volume_types => {volume_type1_id => volume_type1, volume_type2_id => volume_type2},
|
||||
|
||||
#Autoscale
|
||||
:autoscale_groups => {}
|
||||
}
|
||||
|
||||
# seed with initial data
|
||||
|
|
207
lib/fog/rackspace/models/auto_scale/group.rb
Normal file
207
lib/fog/rackspace/models/auto_scale/group.rb
Normal file
|
@ -0,0 +1,207 @@
|
|||
require 'fog/core/model'
|
||||
require 'fog/rackspace/models/auto_scale/group_config'
|
||||
require 'fog/rackspace/models/auto_scale/launch_config'
|
||||
require 'fog/rackspace/models/auto_scale/policies'
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Group < Fog::Model
|
||||
|
||||
# @!attribute [r] id
|
||||
# @return [String] The autoscale group's id
|
||||
identity :id
|
||||
|
||||
# @!attribute [r] links
|
||||
# @return [Array] group links.
|
||||
attribute :links
|
||||
|
||||
# Gets the group configuration for this autoscale group. The configuration describes the
|
||||
# minimum number of entities in the group, the maximum number of entities in the group,
|
||||
# the global cooldown time for the group, and other metadata.
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::GroupConfiguration] group_config if found
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getGroupConfig_v1.0__tenantId__groups__groupId__config_Configurations.html
|
||||
def group_config
|
||||
if attributes[:group_config].nil?
|
||||
data = service.get_group_config(identity)
|
||||
attributes[:group_config] = load_model('GroupConfig', data.body['groupConfiguration'])
|
||||
end
|
||||
attributes[:group_config]
|
||||
end
|
||||
|
||||
# Sets the configuration when this object is populated.
|
||||
#
|
||||
# @param object [Hash<String, String>] Object which will stock the object
|
||||
def group_config=(object = {})
|
||||
if object.is_a?(Hash)
|
||||
attributes[:group_config] = load_model('GroupConfig', object)
|
||||
else
|
||||
attributes[:group_config] = object
|
||||
end
|
||||
end
|
||||
|
||||
# Gets the launch configuration for this autoscale group. The launch configuration describes
|
||||
# the details of how to create a server, from what image to create a server, which load balancers
|
||||
# to join the server to, which networks to add the server to, and other metadata.
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::LaunchConfiguration] group_config if found
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getLaunchConfig_v1.0__tenantId__groups__groupId__launch_Configurations.html
|
||||
def launch_config
|
||||
if attributes[:launch_config].nil?
|
||||
data = service.get_launch_config(identity)
|
||||
attributes[:launch_config] = load_model('LaunchConfig', data.body['launchConfiguration'])
|
||||
end
|
||||
attributes[:launch_config]
|
||||
end
|
||||
|
||||
# Sets the configuration when this object is populated.
|
||||
#
|
||||
# @param object [Hash<String, String>] Object which will stock the object
|
||||
def launch_config=(object={})
|
||||
if object.is_a?(Hash)
|
||||
attributes[:launch_config] = load_model('LaunchConfig', object)
|
||||
else
|
||||
attributes[:launch_config] = object
|
||||
end
|
||||
end
|
||||
|
||||
# For the specified autoscaling group, this operation returns a list of the scaling policies
|
||||
# that are available to the group. Each policy is described in terms of an ID, name, type,
|
||||
# adjustment, cooldown time, and links.
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::Policies] policies
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getPolicies_v1.0__tenantId__groups__groupId__policies_Policies.html
|
||||
def policies
|
||||
@policies ||= load_model('Policies')
|
||||
end
|
||||
|
||||
# Creates group
|
||||
# * requires attributes: :launch_config, :group_config, :policies
|
||||
#
|
||||
# @return [Boolean] returns true if group is being created
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see Groups#create
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_createGroup_v1.0__tenantId__groups_Groups.html
|
||||
def save
|
||||
requires :launch_config, :group_config, :policies
|
||||
|
||||
launch_config_hash = {
|
||||
'args' => launch_config.args,
|
||||
'type' => launch_config.type
|
||||
}
|
||||
group_config_hash = {
|
||||
'name' => group_config.name,
|
||||
'cooldown' => group_config.cooldown,
|
||||
'maxEntities' => group_config.max_entities,
|
||||
'minEntities' => group_config.min_entities
|
||||
}
|
||||
group_config_hash['metadata'] = group_config.metadata if group_config.metadata
|
||||
|
||||
data = service.create_group(launch_config_hash, group_config_hash, policies)
|
||||
merge_attributes(data.body['group'])
|
||||
true
|
||||
end
|
||||
|
||||
# Destroy the group
|
||||
#
|
||||
# @return [Boolean] returns true if group has started deleting
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/DELETE_deleteGroup_v1.0__tenantId__groups__groupId__Groups.html
|
||||
def destroy
|
||||
requires :identity
|
||||
service.delete_group(identity)
|
||||
true
|
||||
end
|
||||
|
||||
# Get the current state of the autoscale group
|
||||
#
|
||||
# @return [String] the state of the group
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getGroupState_v1.0__tenantId__groups__groupId__state_Groups.html
|
||||
def state
|
||||
requires :identity
|
||||
data = service.get_group_state(identity)
|
||||
data.body['group']
|
||||
end
|
||||
|
||||
# This operation pauses all execution of autoscaling policies.
|
||||
#
|
||||
# @note NOT IMPLEMENTED YET
|
||||
# @return [Boolean] returns true if paused
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_pauseGroup_v1.0__tenantId__groups__groupId__pause_Groups.html
|
||||
def pause
|
||||
requires :identity
|
||||
data = service.pause_group_state(identity)
|
||||
true
|
||||
end
|
||||
|
||||
# This operation resumes all execution of autoscaling policies.
|
||||
#
|
||||
# @note NOT IMPLEMENTED YET
|
||||
# @return [Boolean] returns true if resumed
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_resumeGroup_v1.0__tenantId__groups__groupId__resume_Groups.html
|
||||
def resume
|
||||
requires :identity
|
||||
data = service.resume_group_state(identity)
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_model(class_name, attrs = nil)
|
||||
# Can use either Kernel.const_get or do an eval() - first is quicker
|
||||
model = Kernel.const_get("Fog::Rackspace::AutoScale::#{class_name}").new({
|
||||
:service => @service,
|
||||
:group => self
|
||||
})
|
||||
if service && attrs
|
||||
model.merge_attributes(attrs)
|
||||
end
|
||||
model
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
60
lib/fog/rackspace/models/auto_scale/group_config.rb
Normal file
60
lib/fog/rackspace/models/auto_scale/group_config.rb
Normal file
|
@ -0,0 +1,60 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class GroupConfig < Fog::Model
|
||||
|
||||
# @!attribute [r] group
|
||||
# @return [Fog::Rackspace::AutoScale::Group] The parent group
|
||||
attribute :group
|
||||
|
||||
# @!attribute [r] name
|
||||
# @return [String] The name of the group
|
||||
attribute :name
|
||||
|
||||
# @!attribute [r] cooldown
|
||||
# @return [String] The group's cooldown
|
||||
attribute :cooldown
|
||||
|
||||
# @!attribute [r] min_entities
|
||||
# @return [Fixnum] The minimum amount of units which should exist in the group
|
||||
attribute :min_entities, :aliases => 'minEntities'
|
||||
|
||||
# @!attribute [r] max_entities
|
||||
# @return [Fixnum] The maximum amount of units which should exist in the group
|
||||
attribute :max_entities, :aliases => 'maxEntities'
|
||||
|
||||
# @!attribute [r] metadata
|
||||
# @return [Hash] The group's metadata
|
||||
attribute :metadata
|
||||
|
||||
# Update this group's configuration
|
||||
#
|
||||
# @return [Boolean] returns true if group config has been updated
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/PUT_putGroupConfig_v1.0__tenantId__groups__groupId__config_Configurations.html
|
||||
def update
|
||||
|
||||
options = {}
|
||||
|
||||
options['name'] = name unless name.nil?
|
||||
options['cooldown'] = cooldown unless cooldown.nil?
|
||||
options['minEntities'] = min_entities
|
||||
options['maxEntities'] = max_entities
|
||||
options['metadata'] = metadata unless metadata.nil?
|
||||
|
||||
data = service.update_group_config(group.id, options)
|
||||
merge_attributes(data.body)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
46
lib/fog/rackspace/models/auto_scale/groups.rb
Normal file
46
lib/fog/rackspace/models/auto_scale/groups.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/rackspace/models/auto_scale/group'
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Groups < Fog::Collection
|
||||
|
||||
model Fog::Rackspace::AutoScale::Group
|
||||
|
||||
# Returns list of autoscale grouos
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::Groups] Retrieves a list images.
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getGroups_v1.0__tenantId__groups_Groups.html
|
||||
def all
|
||||
data = service.list_groups.body['groups']
|
||||
load(data)
|
||||
end
|
||||
|
||||
# Returns an individual autoscale group
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::Group] Retrieves a list images.
|
||||
# @return nil if not found
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getGroupManifest_v1.0__tenantId__groups__groupId__Groups.html
|
||||
def get(group_id)
|
||||
data = service.get_group(group_id).body['group']
|
||||
new(data)
|
||||
rescue Fog::Rackspace::AutoScale::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
44
lib/fog/rackspace/models/auto_scale/launch_config.rb
Normal file
44
lib/fog/rackspace/models/auto_scale/launch_config.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class LaunchConfig < Fog::Model
|
||||
|
||||
# @!attribute [r] group
|
||||
# @return [Fog::Rackspace::AutoScale::Group] The parent group
|
||||
attribute :group
|
||||
|
||||
# @!attribute [r] type
|
||||
# @return [Fog::Rackspace::AutoScale::Group] The type of operation (usually "launch_server")
|
||||
attribute :type
|
||||
|
||||
# @!attribute [r] args
|
||||
# @return [Fog::Rackspace::AutoScale::Group] The arguments for the operation
|
||||
attribute :args
|
||||
|
||||
# Update this group's launch configuration
|
||||
#
|
||||
# @return [Boolean] returns true if launch config has been updated
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/PUT_putLaunchConfig_v1.0__tenantId__groups__groupId__launch_Configurations.html
|
||||
def update
|
||||
|
||||
options = {}
|
||||
options['type'] = type unless type.nil?
|
||||
options['args'] = args unless args.nil?
|
||||
|
||||
data = service.update_launch_config(group.id, options)
|
||||
merge_attributes(data.body['launchConfiguration'])
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
65
lib/fog/rackspace/models/auto_scale/policies.rb
Normal file
65
lib/fog/rackspace/models/auto_scale/policies.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/rackspace/models/auto_scale/policy'
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Policies < Fog::Collection
|
||||
|
||||
model Fog::Rackspace::AutoScale::Policy
|
||||
|
||||
attr_accessor :group
|
||||
|
||||
# Returns list of autoscale policies
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::Policies] Retrieves policies
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getPolicies_v1.0__tenantId__groups__groupId__policies_Policies.html
|
||||
def all
|
||||
data = service.list_policies(group.id).body['policies']
|
||||
load(data)
|
||||
end
|
||||
|
||||
# Returns an individual autoscale policy
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::Group] Retrieves a policy
|
||||
# @return nil if not found
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getPolicy_v1.0__tenantId__groups__groupId__policies__policyId__Policies.html
|
||||
def get(policy_id)
|
||||
data = service.get_policy(group.id, policy_id).body['policy']
|
||||
data['group_id'] = group.id
|
||||
new(data)
|
||||
rescue Fog::Rackspace::AutoScale::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
# Create an autoscale policy
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::Policy] Returns the new policy
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_createPolicies_v1.0__tenantId__groups__groupId__policies_Policies.html
|
||||
def create(attributes = {})
|
||||
attributes['group_id'] = group.id
|
||||
super(attributes)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
206
lib/fog/rackspace/models/auto_scale/policy.rb
Normal file
206
lib/fog/rackspace/models/auto_scale/policy.rb
Normal file
|
@ -0,0 +1,206 @@
|
|||
require 'fog/core/model'
|
||||
require 'fog/rackspace/models/auto_scale/webhooks'
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Policy < Fog::Model
|
||||
|
||||
# @!attribute [r] id
|
||||
# @return [String] The policy id
|
||||
identity :id
|
||||
|
||||
# @!attribute [r] group_id
|
||||
# @return [String] The autoscale group's id
|
||||
attribute :group_id
|
||||
|
||||
# @!attribute [r] links
|
||||
# @return [Array] Policy links
|
||||
attribute :links
|
||||
|
||||
# @!attribute [r] name
|
||||
# @return [String] The policy's name
|
||||
attribute :name
|
||||
|
||||
# @!attribute [r] change
|
||||
# @return [Fixnum] The fixed change to the autoscale group's number of units
|
||||
attribute :change
|
||||
|
||||
# @!attribute [r] changePercent
|
||||
# @return [Fixnum] The percentage change to the autoscale group's number of units
|
||||
attribute :change_percent, :aliases => 'changePercent'
|
||||
|
||||
# @!attribute [r] cooldown
|
||||
# @return [Fixnum] The policy's cooldown
|
||||
attribute :cooldown
|
||||
|
||||
# @!attribute [r] type
|
||||
# @note Can only be "webhook", "schedule" or "cloud_monitoring"
|
||||
# @return [String] The policy's type
|
||||
attribute :type
|
||||
|
||||
# @!attribute [r] args
|
||||
# @example See below:
|
||||
# - "cron": "23 * * * *"
|
||||
# - "at": "2013-06-05T03:12Z"
|
||||
# - "check": {
|
||||
# "label": "Website check 1",
|
||||
# "type": "remote.http",
|
||||
# "details": {
|
||||
# "url": "http://www.example.com",
|
||||
# "method": "GET"
|
||||
# },
|
||||
# "monitoring_zones_poll": [
|
||||
# "mzA"
|
||||
# ],
|
||||
# "timeout": 30,
|
||||
# "period": 100,
|
||||
# "target_alias": "default"
|
||||
# },
|
||||
# "alarm_criteria": {
|
||||
# "criteria": "if (metric[\"duration\"] >= 2) { return new AlarmStatus(OK); } return new AlarmStatus(CRITICAL);"
|
||||
# }
|
||||
#
|
||||
# @return [String] Arguments used for the policy
|
||||
attribute :args
|
||||
|
||||
# @!attribute [r] desiredCapacity
|
||||
# @return [Fixnum] The desired capacity of the group
|
||||
attribute :desired_capacity, :aliases => 'desiredCapacity'
|
||||
|
||||
# Basic sanity check to make sure attributes are valid
|
||||
#
|
||||
# @raise ArgumentError If no type is set
|
||||
# @raise ArgumentError If args attribute is missing required keys (if type == 'schedule')
|
||||
|
||||
# @return [Boolean] Returns true if the check passes
|
||||
def check_attributes
|
||||
raise ArgumentError, "This #{self.name} resource requires the #{type} argument" if type.nil?
|
||||
|
||||
if type == 'schedule'
|
||||
raise ArgumentError, "This #{self.name} resource requires the args[cron] OR args[at] argument" if args['cron'].nil? && args['at'].nil?
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
# Creates policy
|
||||
# * requires attributes: :name, :type, :cooldown
|
||||
#
|
||||
# @return [Boolean] returns true if policy is being created
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see Policies#create
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_createPolicies_v1.0__tenantId__groups__groupId__policies_Policies.html
|
||||
def save
|
||||
requires :name, :type, :cooldown
|
||||
|
||||
check_attributes
|
||||
|
||||
options = {}
|
||||
options['name'] = name unless name.nil?
|
||||
options['change'] = change unless change.nil?
|
||||
options['changePercent'] = change_percent unless change_percent.nil?
|
||||
options['cooldown'] = cooldown unless cooldown.nil?
|
||||
options['type'] = type unless type.nil?
|
||||
options['desiredCapacity'] = desired_capacity unless desired_capacity.nil?
|
||||
|
||||
if type == 'schedule'
|
||||
options['args'] = args
|
||||
end
|
||||
|
||||
data = service.create_policy(group_id, options)
|
||||
merge_attributes(data.body['policies'][0])
|
||||
true
|
||||
end
|
||||
|
||||
# Updates the policy
|
||||
#
|
||||
# @return [Boolean] returns true if policy has started updating
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/PUT_putPolicy_v1.0__tenantId__groups__groupId__policies__policyId__Policies.html
|
||||
def update
|
||||
requires :identity
|
||||
|
||||
check_attributes
|
||||
|
||||
options = {}
|
||||
options['name'] = name unless name.nil?
|
||||
options['change'] = change unless change.nil?
|
||||
options['changePercent'] = change_percent unless change_percent.nil?
|
||||
options['cooldown'] = cooldown unless cooldown.nil?
|
||||
options['type'] = type unless type.nil?
|
||||
options['desiredCapacity'] = desired_capacity unless desired_capacity.nil?
|
||||
|
||||
if type == 'schedule'
|
||||
options['args'] = args
|
||||
end
|
||||
|
||||
data = service.update_policy(group_id, identity, options)
|
||||
merge_attributes(data.body)
|
||||
true
|
||||
end
|
||||
|
||||
# Destroy the policy
|
||||
#
|
||||
# @return [Boolean] returns true if policy has started deleting
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/DELETE_deletePolicy_v1.0__tenantId__groups__groupId__policies__policyId__Policies.html
|
||||
def destroy
|
||||
requires :identity
|
||||
service.delete_policy(group_id, identity)
|
||||
true
|
||||
end
|
||||
|
||||
# Executes the scaling policy
|
||||
#
|
||||
# @return [Boolean] returns true if policy has been executed
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_executePolicy_v1.0__tenantId__groups__groupId__policies__policyId__execute_Policies.html
|
||||
def execute
|
||||
requires :identity
|
||||
service.execute_policy(group_id, identity)
|
||||
true
|
||||
end
|
||||
|
||||
# Gets the associated webhooks for this policy
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::Webhooks] returns Webhooks
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
def webhooks
|
||||
data = service.list_webhooks(group_id, self.id)
|
||||
|
||||
Fog::Rackspace::AutoScale::Webhooks.new({
|
||||
:service => service,
|
||||
:policy_id => self.id,
|
||||
:group_id => group_id
|
||||
}).merge_attributes(data.body)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
105
lib/fog/rackspace/models/auto_scale/webhook.rb
Normal file
105
lib/fog/rackspace/models/auto_scale/webhook.rb
Normal file
|
@ -0,0 +1,105 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Webhook < Fog::Model
|
||||
|
||||
# @!attribute [r] id
|
||||
# @return [String] The webhook id
|
||||
identity :id
|
||||
|
||||
# @!attribute [r] id
|
||||
# @return [String] The group id (i.e. grand-parent)
|
||||
attribute :group_id
|
||||
|
||||
# @!attribute [r] id
|
||||
# @return [String] The policy id (i.e. parent)
|
||||
attribute :policy_id
|
||||
|
||||
# @!attribute [r] name
|
||||
# @return [String] The webhook name
|
||||
attribute :name
|
||||
|
||||
# @!attribute [r] metadata
|
||||
# @return [Hash] The metadata
|
||||
attribute :metadata
|
||||
|
||||
# @!attribute [r] links
|
||||
# @return [Array] The webhook links
|
||||
attribute :links
|
||||
|
||||
# Creates webhook
|
||||
# * requires attribute: :name
|
||||
#
|
||||
# @return [Boolean] returns true if webhook is being created
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see Webhooks#create
|
||||
# @see
|
||||
def save
|
||||
requires :name
|
||||
|
||||
options = {}
|
||||
options['name'] = name if name
|
||||
options['metadata'] = metadata if metadata
|
||||
|
||||
data = service.create_webhook(group_id, policy_id, options)
|
||||
merge_attributes(data.body['webhooks'][0])
|
||||
true
|
||||
end
|
||||
|
||||
# Updates the webhook
|
||||
#
|
||||
# @return [Boolean] returns true if webhook has started updating
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/PUT_putWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__Webhooks.html
|
||||
def update
|
||||
requires :identity
|
||||
|
||||
options = {
|
||||
'name' => name,
|
||||
'metadata' => metadata
|
||||
}
|
||||
|
||||
data = service.update_webhook(group_id, policy_id, identity, options)
|
||||
merge_attributes(data.body)
|
||||
end
|
||||
|
||||
# Destroy the webhook
|
||||
#
|
||||
# @return [Boolean] returns true if webhook has started deleting
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/DELETE_deleteWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__Webhooks.html
|
||||
def destroy
|
||||
requires :identity
|
||||
service.delete_webhook(group_id, policy_id, identity)
|
||||
true
|
||||
end
|
||||
|
||||
# Retrieves the URL for anonymously executing the policy webhook
|
||||
# @return [String] the URL
|
||||
def execution_url
|
||||
requires :links
|
||||
link = links.find { |l| l['rel'] == 'capability' }
|
||||
link['href'] rescue nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
64
lib/fog/rackspace/models/auto_scale/webhooks.rb
Normal file
64
lib/fog/rackspace/models/auto_scale/webhooks.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/rackspace/models/auto_scale/webhook'
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Webhooks < Fog::Collection
|
||||
|
||||
model Fog::Rackspace::AutoScale::Webhook
|
||||
|
||||
attr_accessor :group_id
|
||||
attr_accessor :policy_id
|
||||
|
||||
# Returns list of autoscale webhooks
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::Policies] Retrieves webhooks
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
def all
|
||||
data = service.list_webhooks(group_id, policy_id).body['webhooks']
|
||||
load(data)
|
||||
end
|
||||
|
||||
# Returns an individual webhook
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::Webhook] Retrieves a webhook
|
||||
# @return nil if not found
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__Webhooks.html
|
||||
def get(webhook_id)
|
||||
data = service.get_webhook(group_id, policy_id, webhook_id).body['webhook']
|
||||
data['group_id'] = group_id
|
||||
data['policy_id'] = policy_id
|
||||
new(data)
|
||||
rescue Fog::Rackspace::AutoScale::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
# Create a webhook
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::Webhook] Returns the new webhook
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
def create(attributes = {})
|
||||
attributes['group_id'] = group_id
|
||||
attributes['policy_id'] = policy_id
|
||||
super(attributes)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
61
lib/fog/rackspace/requests/auto_scale/create_group.rb
Normal file
61
lib/fog/rackspace/requests/auto_scale/create_group.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def create_group(launch_config, group_config, policies)
|
||||
|
||||
body = {
|
||||
'launchConfiguration' => launch_config,
|
||||
'groupConfiguration' => group_config,
|
||||
'scalingPolicies' => policies
|
||||
}
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:method => 'POST',
|
||||
:path => 'groups',
|
||||
:body => Fog::JSON.encode(body)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def create_group(launch_config, group_config, policies)
|
||||
|
||||
group_id = Fog::Rackspace::MockData.uuid
|
||||
|
||||
# Construct group structure
|
||||
group = {
|
||||
'launchConfiguration' => launch_config,
|
||||
'groupConfiguration' => group_config,
|
||||
'scalingPolicies' => policies,
|
||||
'id' => group_id
|
||||
}
|
||||
|
||||
# Add links for HTTP response
|
||||
group['scalingPolicies'][0]['links'] = [
|
||||
{
|
||||
"href" => "https://ord.autoscale.api.rackspacecloud.com/v1.0/829409/groups/6791761b-821a-4d07-820d-0b2afc7dd7f6/policies/dceb14ac-b2b3-4f06-aac9-a5b6cd5d40e1/",
|
||||
"rel" => "self"
|
||||
}
|
||||
]
|
||||
|
||||
group['links'] = [
|
||||
{
|
||||
"href" => "https://ord.autoscale.api.rackspacecloud.com/v1.0/829409/groups/6791761b-821a-4d07-820d-0b2afc7dd7f6/",
|
||||
"rel" => "self"
|
||||
}
|
||||
]
|
||||
|
||||
# Save for future use
|
||||
self.data[:autoscale_groups][group_id] = group
|
||||
|
||||
# Response
|
||||
body = {'group' => group}
|
||||
response(:body => body)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
45
lib/fog/rackspace/requests/auto_scale/create_policy.rb
Normal file
45
lib/fog/rackspace/requests/auto_scale/create_policy.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
def create_policy(group_id, options)
|
||||
|
||||
data = [options]
|
||||
|
||||
request(
|
||||
:method => 'POST',
|
||||
:body => Fog::JSON.encode(data),
|
||||
:path => "groups/#{group_id}/policies",
|
||||
:expects => 201
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def create_policy(group_id, options)
|
||||
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
|
||||
if group.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
policy = {
|
||||
"id" => Fog::Rackspace::MockData.uuid,
|
||||
"name" => "set group to 5 servers",
|
||||
"desiredCapacity" => 5,
|
||||
"cooldown" => 1800,
|
||||
"type" => "webhook"
|
||||
}
|
||||
|
||||
group['scalingPolicies'] << policy
|
||||
|
||||
body = [policy]
|
||||
|
||||
response(:body => body)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
57
lib/fog/rackspace/requests/auto_scale/create_webhook.rb
Normal file
57
lib/fog/rackspace/requests/auto_scale/create_webhook.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
def create_webhook(group_id, policy_id, options)
|
||||
|
||||
body = [options]
|
||||
|
||||
request(
|
||||
:method => 'POST',
|
||||
:body => Fog::JSON.encode(body),
|
||||
:path => "groups/#{group_id}/policies/#{policy_id}/webhooks",
|
||||
:expects => 201
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def create_webhook(group_id, policy_id, options)
|
||||
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
if group.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
policy = group['scalingPolicies'].detect { |p| p["id"] == policy_id }
|
||||
if policy.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
webhook_id = Fog::Rackspace::MockData.uuid
|
||||
|
||||
webhook = {}
|
||||
webhook['id'] = webhook_id
|
||||
webhook['name'] = options['name'] || 'new webhook'
|
||||
webhook['metadata'] = options['name'] || {}
|
||||
webhook["links"] = [
|
||||
{
|
||||
"href" => "https://ord.autoscale.api.rackspacecloud.com/v1.0/829409/groups/#{group_id}/policies/#{policy_id}/webhooks/#{webhook_id}/",
|
||||
"rel" => "self"
|
||||
},
|
||||
{
|
||||
"href" => "https://ord.autoscale.api.rackspacecloud.com/v1.0/829409/execute/1/sadfadsfasdfvcjsdfsjvreaigae5",
|
||||
"rel" => "capability"
|
||||
}
|
||||
]
|
||||
|
||||
policy['webhooks'] << webhook
|
||||
|
||||
body = {'webhook' => webhook}
|
||||
response(:body => body)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/rackspace/requests/auto_scale/delete_group.rb
Normal file
23
lib/fog/rackspace/requests/auto_scale/delete_group.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def delete_group(group_id)
|
||||
request(
|
||||
:expects => [204],
|
||||
:method => 'DELETE',
|
||||
:path => "groups/#{group_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_group(group_id)
|
||||
self.data[:autoscale_groups].delete(group_id)
|
||||
response(:status => 204)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
lib/fog/rackspace/requests/auto_scale/delete_policy.rb
Normal file
31
lib/fog/rackspace/requests/auto_scale/delete_policy.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def delete_policy(group_id, policy_id)
|
||||
request(
|
||||
:expects => [204],
|
||||
:method => 'DELETE',
|
||||
:path => "groups/#{group_id}/policies/#{policy_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_group(group_id, policy_id)
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
|
||||
if group.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
group['policies'].delete_if { |p| p['id'] == policy_id }
|
||||
|
||||
response(:status => 204)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
34
lib/fog/rackspace/requests/auto_scale/delete_webhook.rb
Normal file
34
lib/fog/rackspace/requests/auto_scale/delete_webhook.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def delete_webhook(group_id, policy_id, webhook_id)
|
||||
request(
|
||||
:expects => [204],
|
||||
:method => 'DELETE',
|
||||
:path => "groups/#{group_id}/policies/#{policy_id}/webhooks/#{webhook_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_webhook(group_id, policy_id, webhook_id)
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
if group.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
policy = group['policies'].detect { |p| p["id"] == policy_id }
|
||||
if policy.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
policy['webhooks'].delete_if { |w| w['id'] == webhook_id }
|
||||
|
||||
response(:status => 204)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,22 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def execute_anonymous_webhook(capability_version, capability_hash)
|
||||
request(
|
||||
:expects => [202],
|
||||
:method => 'POST',
|
||||
:path => "execute/#{capability_version}/#{capability_hash}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def execute_anonymous_webhook(capability_version, capability_hash)
|
||||
response(:status => 202)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
22
lib/fog/rackspace/requests/auto_scale/execute_policy.rb
Normal file
22
lib/fog/rackspace/requests/auto_scale/execute_policy.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def execute_policy(group_id, policy_id)
|
||||
request(
|
||||
:expects => [202],
|
||||
:method => 'POST',
|
||||
:path => "groups/#{group_id}/policies/#{policy_id}/execute"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def execute_policy(group_id, policy_id)
|
||||
response(:status => 202)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
29
lib/fog/rackspace/requests/auto_scale/get_group.rb
Normal file
29
lib/fog/rackspace/requests/auto_scale/get_group.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
|
||||
class Real
|
||||
|
||||
def get_group(group_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "groups/#{group_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_group(group_id)
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
if server.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
else
|
||||
response(:body => {"group" => group})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
30
lib/fog/rackspace/requests/auto_scale/get_group_config.rb
Normal file
30
lib/fog/rackspace/requests/auto_scale/get_group_config.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
|
||||
class Real
|
||||
|
||||
def get_group_config(group_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "groups/#{group_id}/config"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_group_config(group_id)
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
|
||||
if group.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
response(:body => {"groupConfiguration" => group['groupConfiguration']})
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
62
lib/fog/rackspace/requests/auto_scale/get_group_state.rb
Normal file
62
lib/fog/rackspace/requests/auto_scale/get_group_state.rb
Normal file
|
@ -0,0 +1,62 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
|
||||
class Real
|
||||
|
||||
def get_group_state(group_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "groups/#{group_id}/state"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_group_state(group_id)
|
||||
|
||||
instance_id_1 = Fog::Rackspace::AutoScale::MockData.uuid
|
||||
instance_id_2 = Fog::Rackspace::AutoScale::MockData.uuid
|
||||
|
||||
state = {
|
||||
"id" => group_id,
|
||||
"links" => [
|
||||
{
|
||||
"href" => "https://dfw.autoscale.api.rackspacecloud.com/v1.0/010101/groups/#{group_id}",
|
||||
"rel" => "self"
|
||||
}
|
||||
],
|
||||
"active" => [
|
||||
{
|
||||
"id" => "#{instance_id_1}",
|
||||
"links" => [
|
||||
{
|
||||
"href" => "https://dfw.servers.api.rackspacecloud.com/v2/010101/servers/#{instance_id_1}",
|
||||
"rel" => "self"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id" => "#{instance_id_2}",
|
||||
"links" => [
|
||||
{
|
||||
"href" => "https://dfw.servers.api.rackspacecloud.com/v2/010101/servers/#{instance_id_2}",
|
||||
"rel" => "self"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"activeCapacity" => 2,
|
||||
"pendingCapacity" => 2,
|
||||
"desiredCapacity" => 4,
|
||||
"paused" => false
|
||||
}
|
||||
|
||||
response(:body => {'group' => state})
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
30
lib/fog/rackspace/requests/auto_scale/get_launch_config.rb
Normal file
30
lib/fog/rackspace/requests/auto_scale/get_launch_config.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
|
||||
class Real
|
||||
|
||||
def get_launch_config(group_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "groups/#{group_id}/launch"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_launch_config(group_id)
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
|
||||
if group.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
response(:body => {"launchConfiguration" => group['launchConfiguration']})
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
35
lib/fog/rackspace/requests/auto_scale/get_policy.rb
Normal file
35
lib/fog/rackspace/requests/auto_scale/get_policy.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
|
||||
class Real
|
||||
|
||||
def get_policy(group_id, policy_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "groups/#{group_id}/policies/#{policy_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_policy(group_id, policy_id)
|
||||
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
if group.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
policy = group['scalingPolicies'].detect { |p| p["id"] == policy_id }
|
||||
if policy.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
response(:body => {'policy' => policy})
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
39
lib/fog/rackspace/requests/auto_scale/get_webhook.rb
Normal file
39
lib/fog/rackspace/requests/auto_scale/get_webhook.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
|
||||
class Real
|
||||
|
||||
def get_webhook(group_id, policy_id, webhook_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "groups/#{group_id}/policies/#{policy_id}/webhooks/#{webhook_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_webhook(group_id, policy_id, webhook_id)
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
if group.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
policy = group['scalingPolicies'].detect { |p| p["id"] == policy_id }
|
||||
if policy.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
webhook = policy['webhooks'].detect { |w| w['id'] == webhook_id }
|
||||
if webhook.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
response(:body => {'webhook' => webhook})
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
35
lib/fog/rackspace/requests/auto_scale/list_groups.rb
Normal file
35
lib/fog/rackspace/requests/auto_scale/list_groups.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
# Retrieves a list of images
|
||||
# @return [Excon::Response] response:
|
||||
# * body [Hash]:
|
||||
# * images [Array]:
|
||||
# * [Hash]:
|
||||
# * id [String] - flavor id
|
||||
# * links [Array] - image links
|
||||
# * name [String] - image name
|
||||
# @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404
|
||||
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Flavors-d1e4188.html
|
||||
def list_groups
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => 'groups'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_groups
|
||||
response(:body => {"groups" => self.data[:autoscale_groups]})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/rackspace/requests/auto_scale/list_policies.rb
Normal file
23
lib/fog/rackspace/requests/auto_scale/list_policies.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def list_policies(group_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "groups/#{group_id}/policies"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_policies(group_id)
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
response(:body => {'policies' => group['scalingPolicies']})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
33
lib/fog/rackspace/requests/auto_scale/list_webhooks.rb
Normal file
33
lib/fog/rackspace/requests/auto_scale/list_webhooks.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def list_webhooks(group_id, policy_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "groups/#{group_id}/policies/#{policy_id}/webhooks"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_webhooks(group_id, policy_id)
|
||||
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
if group.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
policy = group['scalingPolicies'].detect { |p| p["id"] == policy_id }
|
||||
if policy.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
response(:body => {'webhooks' => policy['webhooks']})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/rackspace/requests/auto_scale/pause_group_state.rb
Normal file
23
lib/fog/rackspace/requests/auto_scale/pause_group_state.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def pause_group_state(group_id)
|
||||
Fog::Real.not_implemented
|
||||
# request(
|
||||
# :expects => [204],
|
||||
# :method => 'POST',
|
||||
# :path => 'groups/#{group_id}/pause'
|
||||
# )
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def pause_group_state(group_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/rackspace/requests/auto_scale/resume_group_state.rb
Normal file
23
lib/fog/rackspace/requests/auto_scale/resume_group_state.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def resume_group_state(group_id)
|
||||
Fog::Real.not_implemented
|
||||
# request(
|
||||
# :expects => [204],
|
||||
# :method => 'POST',
|
||||
# :path => 'groups/#{group_id}/resume'
|
||||
# )
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def resume_group_state(group_id)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
39
lib/fog/rackspace/requests/auto_scale/update_group_config.rb
Normal file
39
lib/fog/rackspace/requests/auto_scale/update_group_config.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def update_group_config(group_id, options)
|
||||
|
||||
body = options
|
||||
|
||||
request(
|
||||
:expects => [204],
|
||||
:method => 'PUT',
|
||||
:path => "groups/#{group_id}/config",
|
||||
:body => Fog::JSON.encode(body)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def update_group_config(group_id, options)
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
if group.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
config = group['groupConfiguration']
|
||||
|
||||
config['name'] = options['name'] if options['name']
|
||||
config['cooldown'] = options['cooldown'] if options['cooldown']
|
||||
config['minEntities'] = options['minEntities'] if options['minEntities']
|
||||
config['maxEntities'] = options['maxEntities'] if options['maxEntities']
|
||||
config['metadata'] = options['metadata'] if options['metadata']
|
||||
|
||||
request(:body => config)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,36 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def update_launch_config(group_id, options)
|
||||
|
||||
body = options
|
||||
|
||||
request(
|
||||
:expects => [204],
|
||||
:method => 'PUT',
|
||||
:path => "groups/#{group_id}/launch",
|
||||
:body => Fog::JSON.encode(body)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def update_launch_config(group_id, options)
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
if group.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
config = group['launchConfiguration']
|
||||
|
||||
config['args'] = options['args'] if options['args']
|
||||
config['type'] = options['type'] if options['type']
|
||||
|
||||
request(:body => config)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
33
lib/fog/rackspace/requests/auto_scale/update_policy.rb
Normal file
33
lib/fog/rackspace/requests/auto_scale/update_policy.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def update_policy(group_id, policy_id, options)
|
||||
|
||||
request(
|
||||
:expects => [204],
|
||||
:method => 'PUT',
|
||||
:path => "groups/#{group_id}/policies/#{policy_id}",
|
||||
:body => Fog::JSON.encode(options)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def update_policy(group_id, policy_id, options)
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
if group.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
policy = group['scalingPolicies'].detect { |p| p["id"] == policy_id }
|
||||
|
||||
policy.merge(options)
|
||||
|
||||
request(:body => policy)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
44
lib/fog/rackspace/requests/auto_scale/update_webhook.rb
Normal file
44
lib/fog/rackspace/requests/auto_scale/update_webhook.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class AutoScale
|
||||
class Real
|
||||
|
||||
def update_webhook(group_id, policy_id, webhook_id, options)
|
||||
|
||||
body = options
|
||||
|
||||
request(
|
||||
:expects => [204],
|
||||
:method => 'PUT',
|
||||
:path => "groups/#{group_id}/policies/#{policy_id}/webhooks/#{webhook_id}",
|
||||
:body => Fog::JSON.encode(body)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def update_webhook(group_id, policy_id, webhook_id, options)
|
||||
group = self.data[:autoscale_groups][group_id]
|
||||
if group.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
policy = group['scalingPolicies'].detect { |p| p["id"] == policy_id }
|
||||
if policy.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
webhook = policy['webhooks'].detect { |w| w['id'] == webhook_id }
|
||||
if webhook.nil?
|
||||
raise Fog::Rackspace::AutoScale::NotFound
|
||||
end
|
||||
|
||||
webhook.merge(options)
|
||||
|
||||
response(:body => webhook)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -126,6 +126,11 @@ module Fog
|
|||
@auth_token || @identity_service.auth_token
|
||||
end
|
||||
|
||||
def select_options(keys)
|
||||
return nil unless @options && keys
|
||||
@options.select {|k,v| keys.include?(k)}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
84
tests/rackspace/auto_scale_tests.rb
Normal file
84
tests/rackspace/auto_scale_tests.rb
Normal file
|
@ -0,0 +1,84 @@
|
|||
Shindo.tests('Fog::Rackspace::AutoScale', ['rackspace']) do
|
||||
|
||||
def assert_method(url, method)
|
||||
@service.instance_variable_set "@rackspace_auth_url", url
|
||||
returns(method) { @service.send :authentication_method }
|
||||
end
|
||||
|
||||
tests('#authentication_method') do
|
||||
@service = Fog::Rackspace::AutoScale.new :rackspace_region => :dfw
|
||||
|
||||
assert_method nil, :authenticate_v2
|
||||
|
||||
assert_method 'auth.api.rackspacecloud.com', :authenticate_v1 # chef's default auth endpoint
|
||||
|
||||
assert_method 'https://identity.api.rackspacecloud.com', :authenticate_v1
|
||||
assert_method 'https://identity.api.rackspacecloud.com/v1', :authenticate_v1
|
||||
assert_method 'https://identity.api.rackspacecloud.com/v1.1', :authenticate_v1
|
||||
assert_method 'https://identity.api.rackspacecloud.com/v2.0', :authenticate_v2
|
||||
|
||||
assert_method 'https://lon.identity.api.rackspacecloud.com', :authenticate_v1
|
||||
assert_method 'https://lon.identity.api.rackspacecloud.com/v1', :authenticate_v1
|
||||
assert_method 'https://lon.identity.api.rackspacecloud.com/v1.1', :authenticate_v1
|
||||
assert_method 'https://lon.identity.api.rackspacecloud.com/v2.0', :authenticate_v2
|
||||
end
|
||||
|
||||
|
||||
tests('current authentation') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
tests('variables populated').succeeds do
|
||||
@service = Fog::Rackspace::AutoScale.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :connection_options => {:ssl_verify_peer => true}, :rackspace_region => :dfw
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(false, "path populated") { @service.instance_variable_get("@uri").host.nil? }
|
||||
identity_service = @service.instance_variable_get("@identity_service")
|
||||
returns(false, "identity service was used") { identity_service.nil? }
|
||||
returns(true, "connection_options are passed") { identity_service.instance_variable_get("@connection_options").has_key?(:ssl_verify_peer) }
|
||||
@service.list_groups
|
||||
end
|
||||
tests('dfw region').succeeds do
|
||||
@service = Fog::Rackspace::AutoScale.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :dfw
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw/) != nil }
|
||||
@service.list_groups
|
||||
end
|
||||
tests('ord region').succeeds do
|
||||
@service = Fog::Rackspace::AutoScale.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :ord
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/) != nil }
|
||||
@service.list_groups
|
||||
end
|
||||
tests('custom endpoint') do
|
||||
@service = Fog::Rackspace::AutoScale.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
|
||||
:rackspace_auto_scale_url => 'https://my-custom-endpoint.com'
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
|
||||
end
|
||||
end
|
||||
|
||||
tests('default auth') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
tests('specify region').succeeds do
|
||||
@service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/ ) != nil }
|
||||
@service.list_groups
|
||||
end
|
||||
tests('custom endpoint') do
|
||||
@service = Fog::Rackspace::AutoScale.new :rackspace_auto_scale_url => 'https://my-custom-endpoint.com'
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
|
||||
end
|
||||
end
|
||||
|
||||
tests('reauthentication') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
@service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
@service.instance_variable_set("@auth_token", "bad_token")
|
||||
returns(true) { [200, 203].include? @service.list_groups.status }
|
||||
end
|
||||
|
||||
end
|
19
tests/rackspace/models/auto_scale/group.rb
Normal file
19
tests/rackspace/models/auto_scale/group.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
Shindo.tests('Fog::Rackspace::AutoScale | group', ['rackspace', 'rackspace_autoscale']) do
|
||||
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
options = {
|
||||
:name => "fog_#{Time.now.to_i.to_s}",
|
||||
:policies => POLICIES_OPTIONS,
|
||||
:launch_config => LAUNCH_CONFIG_OPTIONS,
|
||||
:group_config => GROUP_CONFIG_OPTIONS
|
||||
}
|
||||
|
||||
|
||||
model_tests(service.groups, options, false) do
|
||||
tests('#policies').succeeds do
|
||||
@instance.policies
|
||||
end
|
||||
end
|
||||
|
||||
end
|
13
tests/rackspace/models/auto_scale/groups.rb
Normal file
13
tests/rackspace/models/auto_scale/groups.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
Shindo.tests('Fog::Rackspace::AutoScale | groups', ['rackspace', 'rackspace_autoscale']) do
|
||||
pending if Fog.mocking?
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
options = {
|
||||
:policies => POLICIES_OPTIONS,
|
||||
:group_config => GROUP_CONFIG_OPTIONS,
|
||||
:launch_config => LAUNCH_CONFIG_OPTIONS
|
||||
}
|
||||
|
||||
collection_tests(service.groups, options, false)
|
||||
|
||||
end
|
23
tests/rackspace/models/auto_scale/policies.rb
Normal file
23
tests/rackspace/models/auto_scale/policies.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
Shindo.tests('Fog::Rackspace::AutoScale | policies', ['rackspace', 'rackspace_autoscale']) do
|
||||
pending if Fog.mocking?
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
group = service.groups.create({
|
||||
:policies => POLICIES_OPTIONS,
|
||||
:group_config => GROUP_CONFIG_OPTIONS,
|
||||
:launch_config => LAUNCH_CONFIG_OPTIONS
|
||||
})
|
||||
|
||||
options = {
|
||||
:name => "policy 2",
|
||||
:change => 5,
|
||||
:cooldown => 100,
|
||||
:type => 'webhook'
|
||||
}
|
||||
|
||||
begin
|
||||
collection_tests(group.policies, options, false)
|
||||
ensure
|
||||
group.destroy
|
||||
end
|
||||
end
|
29
tests/rackspace/models/auto_scale/policy.rb
Normal file
29
tests/rackspace/models/auto_scale/policy.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
Shindo.tests('Fog::Rackspace::AutoScale | policy', ['rackspace', 'rackspace_autoscale']) do
|
||||
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
group = service.groups.create({
|
||||
:policies => POLICIES_OPTIONS,
|
||||
:group_config => GROUP_CONFIG_OPTIONS,
|
||||
:launch_config => LAUNCH_CONFIG_OPTIONS
|
||||
})
|
||||
|
||||
options = {
|
||||
:name => "policy 2",
|
||||
:change => 5,
|
||||
:cooldown => 100,
|
||||
:type => 'webhook',
|
||||
:group_id => group.id
|
||||
}
|
||||
|
||||
begin
|
||||
model_tests(group.policies, options, false) do
|
||||
tests('#webhooks').succeeds do
|
||||
@instance.webhooks
|
||||
end
|
||||
end
|
||||
ensure
|
||||
group.destroy
|
||||
end
|
||||
|
||||
end
|
35
tests/rackspace/models/auto_scale/webhook.rb
Normal file
35
tests/rackspace/models/auto_scale/webhook.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
Shindo.tests('Fog::Rackspace::AutoScale | webhook', ['rackspace', 'rackspace_autoscale']) do
|
||||
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
group = service.groups.create({
|
||||
:policies => POLICIES_OPTIONS,
|
||||
:group_config => GROUP_CONFIG_OPTIONS,
|
||||
:launch_config => LAUNCH_CONFIG_OPTIONS
|
||||
})
|
||||
|
||||
policy = group.policies.create({
|
||||
:name => "set group to 5 servers",
|
||||
:desired_capacity => 5,
|
||||
:cooldown => 1800,
|
||||
:type => "webhook",
|
||||
:group_id => group.id
|
||||
})
|
||||
|
||||
options = {
|
||||
:name => 'webhook name',
|
||||
:metadata => {
|
||||
'owner' => 'me'
|
||||
},
|
||||
:group_id => group.id,
|
||||
:policy_id => policy.id
|
||||
}
|
||||
|
||||
begin
|
||||
model_tests(policy.webhooks, options, false)
|
||||
ensure
|
||||
policy.destroy
|
||||
group.destroy
|
||||
end
|
||||
|
||||
end
|
28
tests/rackspace/models/auto_scale/webhooks.rb
Normal file
28
tests/rackspace/models/auto_scale/webhooks.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
Shindo.tests('Fog::Rackspace::AutoScale | webhooks', ['rackspace', 'rackspace_autoscale']) do
|
||||
pending if Fog.mocking?
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
group = service.groups.create({
|
||||
:policies => POLICIES_OPTIONS,
|
||||
:group_config => GROUP_CONFIG_OPTIONS,
|
||||
:launch_config => LAUNCH_CONFIG_OPTIONS
|
||||
})
|
||||
|
||||
policy = group.policies.create({
|
||||
:name => "policy 2",
|
||||
:change => 5,
|
||||
:cooldown => 100,
|
||||
:type => 'webhook',
|
||||
:group_id => group.id
|
||||
})
|
||||
|
||||
options = {:name => 'New webhook', :group_id => group.id, :policy_id => policy.id}
|
||||
|
||||
begin
|
||||
collection_tests(policy.webhooks, options, false)
|
||||
ensure
|
||||
policy.destroy
|
||||
group.destroy
|
||||
end
|
||||
|
||||
end
|
51
tests/rackspace/requests/auto_scale/config_tests.rb
Normal file
51
tests/rackspace/requests/auto_scale/config_tests.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
Shindo.tests('Fog::Rackspace::AutoScale | config_tests', ['rackspace', 'rackspace_autoscale']) do
|
||||
|
||||
pending if Fog.mocking?
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
@group = service.create_group(LAUNCH_CONFIG_OPTIONS, GROUP_CONFIG_OPTIONS, POLICIES_OPTIONS).body['group']
|
||||
@group_id = @group['id']
|
||||
|
||||
tests('success') do
|
||||
tests('#get group config').formats({"groupConfiguration" => GROUP_CONFIG_FORMAT}) do
|
||||
service.get_group_config(@group_id).body
|
||||
end
|
||||
tests('#update group config').formats(204) do
|
||||
data = service.update_group_config(@group_id, {
|
||||
'maxEntities' => 7,
|
||||
'minEntities' => 1,
|
||||
'metadata' => {},
|
||||
'name' => 'foo',
|
||||
'cooldown' => 20}).data
|
||||
data[:status]
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
tests('#update group config').raises(Fog::Rackspace::AutoScale::BadRequest) do
|
||||
service.update_group_config(@group_id, {})
|
||||
end
|
||||
tests('#delete group config').raises(NoMethodError) do
|
||||
service.delete_group_config(123)
|
||||
end
|
||||
tests('#create group config').raises(NoMethodError) do
|
||||
service.create_group_config({})
|
||||
end
|
||||
tests('#update launch config').raises(Fog::Rackspace::AutoScale::BadRequest) do
|
||||
service.update_launch_config(@group_id, {})
|
||||
end
|
||||
tests('#delete launch config').raises(NoMethodError) do
|
||||
service.delete_launch_config(123)
|
||||
end
|
||||
tests('#create launch config').raises(NoMethodError) do
|
||||
service.create_launch_config({})
|
||||
end
|
||||
end
|
||||
|
||||
# @group['scalingPolicies'].each do |p|
|
||||
# service.delete_policy(@group_id, p['id'])
|
||||
# end
|
||||
|
||||
# service.delete_group(@group_id)
|
||||
|
||||
end
|
38
tests/rackspace/requests/auto_scale/group_tests.rb
Normal file
38
tests/rackspace/requests/auto_scale/group_tests.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
Shindo.tests('Fog::Rackspace::AutoScale | group_tests', ['rackspace', 'rackspace_autoscale']) do
|
||||
|
||||
pending if Fog.mocking?
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
tests('success') do
|
||||
tests('#create new group').formats(GROUP_FORMAT) do
|
||||
response = service.create_group(LAUNCH_CONFIG_OPTIONS, GROUP_CONFIG_OPTIONS, POLICIES_OPTIONS).body
|
||||
@group_id = response['group']['id']
|
||||
response
|
||||
end
|
||||
tests('#get group').formats(GET_GROUP_HEADERS_FORMAT) do
|
||||
service.get_group(@group_id).data[:headers]
|
||||
end
|
||||
tests('#get group - body').formats(GROUP_FORMAT) do
|
||||
service.get_group(@group_id).body
|
||||
end
|
||||
tests('#delete group').formats(GROUP_DELETE_DATA_FORMAT) do
|
||||
service.delete_group(@group_id).data
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
tests('#fail to create group(-1)').raises(Fog::Rackspace::AutoScale::BadRequest) do
|
||||
service.create_group(@launch_config, @group_config, {})
|
||||
end
|
||||
tests('#fail to get group(-1)').raises(Fog::Rackspace::AutoScale::NotFound) do
|
||||
service.get_group(-1)
|
||||
end
|
||||
tests('#update group').raises(NoMethodError) do
|
||||
service.update_group
|
||||
end
|
||||
tests('#fail to delete group(-1)').raises(Fog::Rackspace::AutoScale::NotFound) do
|
||||
service.delete_group(-1)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
181
tests/rackspace/requests/auto_scale/helper.rb
Normal file
181
tests/rackspace/requests/auto_scale/helper.rb
Normal file
|
@ -0,0 +1,181 @@
|
|||
### FORMATS
|
||||
|
||||
GET_GROUP_HEADERS_FORMAT = {
|
||||
"Content-Type"=>String,
|
||||
"Via"=>String,
|
||||
"x-response-id"=>String,
|
||||
"Date"=>String,
|
||||
"Transfer-Encoding"=>String,
|
||||
"Server"=>String
|
||||
}
|
||||
|
||||
GROUP_DELETE_DATA_FORMAT = {
|
||||
:body=>Hash,
|
||||
:headers=> {
|
||||
"Content-Type"=>String,
|
||||
"Via"=>String,
|
||||
"x-response-id"=>String,
|
||||
"Date"=>String,
|
||||
"Server"=>String
|
||||
},
|
||||
:status=>Integer,
|
||||
:remote_ip=>String
|
||||
}
|
||||
|
||||
LAUNCH_CONFIG_FORMAT = {
|
||||
"args" => {
|
||||
"loadBalancers" => [
|
||||
{
|
||||
"port" => Integer,
|
||||
"loadBalancerId" => Integer
|
||||
}
|
||||
],
|
||||
"server" => {
|
||||
"name" => String,
|
||||
"imageRef" => String,
|
||||
"flavorRef" => String,
|
||||
"OS-DCF =>diskConfig" => String,
|
||||
"metadata" => {
|
||||
"build_config" => String,
|
||||
"meta_key_1" => String,
|
||||
"meta_key_2" => String
|
||||
},
|
||||
"networks" => [
|
||||
{
|
||||
"uuid" => String
|
||||
},
|
||||
{
|
||||
"uuid" => String
|
||||
}
|
||||
],
|
||||
"personality" => [
|
||||
{
|
||||
"path" => String,
|
||||
"contents" => String
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"type" => String
|
||||
}
|
||||
|
||||
GROUP_CONFIG_FORMAT = {
|
||||
"maxEntities" => Integer,
|
||||
"cooldown" => Integer,
|
||||
"name" => String,
|
||||
"minEntities" => Integer,
|
||||
"metadata" => {
|
||||
"gc_meta_key_2" => String,
|
||||
"gc_meta_key_1" => String
|
||||
}
|
||||
}
|
||||
|
||||
POLICY_FORMAT = {
|
||||
"name"=> String,
|
||||
"links"=> Array,
|
||||
"cooldown"=>Integer,
|
||||
"type"=>String,
|
||||
"id"=>String,
|
||||
"change"=>Integer
|
||||
}
|
||||
|
||||
POLICIES_FORMAT = [POLICY_FORMAT]
|
||||
|
||||
GROUP_FORMAT = {
|
||||
"group" => {
|
||||
"launchConfiguration" => LAUNCH_CONFIG_FORMAT,
|
||||
"groupConfiguration" => GROUP_CONFIG_FORMAT,
|
||||
"scalingPolicies" => POLICIES_FORMAT,
|
||||
"links" => [
|
||||
{
|
||||
"href" => String,
|
||||
"rel" => String
|
||||
}
|
||||
],
|
||||
"id" => String
|
||||
}
|
||||
}
|
||||
|
||||
WEBHOOK_FORMAT = {
|
||||
"id" => String,
|
||||
"name" => String,
|
||||
"metadata" => Hash,
|
||||
"links" => Array
|
||||
}
|
||||
|
||||
### OPTIONS
|
||||
|
||||
LAUNCH_CONFIG_OPTIONS = {
|
||||
"args" => {
|
||||
"loadBalancers" => [
|
||||
{
|
||||
"port" => 8080,
|
||||
"loadBalancerId" => 9099
|
||||
}
|
||||
],
|
||||
"server" => {
|
||||
"name" => "autoscale_server",
|
||||
"imageRef" => "0d589460-f177-4b0f-81c1-8ab8903ac7d8",
|
||||
"flavorRef" => "2",
|
||||
"OS-DCF =>diskConfig" => "AUTO",
|
||||
"metadata" => {
|
||||
"build_config" => "core",
|
||||
"meta_key_1" => "meta_value_1",
|
||||
"meta_key_2" => "meta_value_2"
|
||||
},
|
||||
"networks" => [
|
||||
{
|
||||
"uuid" => "11111111-1111-1111-1111-111111111111"
|
||||
},
|
||||
{
|
||||
"uuid" => "00000000-0000-0000-0000-000000000000"
|
||||
}
|
||||
],
|
||||
"personality" => [
|
||||
{
|
||||
"path" => "/root/.csivh",
|
||||
"contents" => "VGhpcyBpcyBhIHRlc3QgZmlsZS4="
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"type" => "launch_server"
|
||||
}
|
||||
|
||||
GROUP_CONFIG_OPTIONS = {
|
||||
"maxEntities" => 10,
|
||||
"cooldown" => 360,
|
||||
"name" => "testscalinggroup198547",
|
||||
"minEntities" => 0,
|
||||
"metadata" => {
|
||||
"gc_meta_key_2" => "gc_meta_value_2",
|
||||
"gc_meta_key_1" => "gc_meta_value_1"
|
||||
}
|
||||
}
|
||||
|
||||
POLICIES_OPTIONS = [
|
||||
{
|
||||
"cooldown" => 0,
|
||||
"type" => "webhook",
|
||||
"name" => "scale up by 1",
|
||||
"change" => 1
|
||||
}
|
||||
]
|
||||
|
||||
POLICY_OPTIONS = {
|
||||
"cooldown" => 0,
|
||||
"type" => "webhook",
|
||||
"name" => "FOOBAR",
|
||||
"change" => 1
|
||||
}
|
||||
|
||||
GROUP_OPTIONS = {
|
||||
"launchConfiguration" => LAUNCH_CONFIG_OPTIONS,
|
||||
"groupConfiguration" => GROUP_CONFIG_OPTIONS,
|
||||
"scalingPolicies" => POLICIES_OPTIONS
|
||||
}
|
||||
|
||||
WEBHOOK_OPTIONS = {
|
||||
"name" => "webhook name",
|
||||
"metadata" => {'foo' => 'bar'}
|
||||
}
|
61
tests/rackspace/requests/auto_scale/policy_tests.rb
Normal file
61
tests/rackspace/requests/auto_scale/policy_tests.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
Shindo.tests('Fog::Rackspace::AutoScale | policy_tests', ['rackspace', 'rackspace_autoscale']) do
|
||||
|
||||
pending if Fog.mocking?
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
@group_id = service.create_group(LAUNCH_CONFIG_OPTIONS, GROUP_CONFIG_OPTIONS, POLICIES_OPTIONS).body['group']['id']
|
||||
|
||||
tests('success') do
|
||||
tests('#list policies').formats(POLICIES_FORMAT) do
|
||||
service.list_policies(@group_id).body['policies']
|
||||
end
|
||||
tests('#create policy').formats(201) do
|
||||
response = service.create_policy(@group_id, POLICY_OPTIONS)
|
||||
@policy_id = response.body['policies'][0]['id']
|
||||
response.data[:status]
|
||||
end
|
||||
|
||||
tests('#get policy').formats(POLICY_FORMAT) do
|
||||
response = service.get_policy(@group_id, @policy_id)
|
||||
response.body['policy']
|
||||
end
|
||||
|
||||
tests('#update policy').formats(204) do
|
||||
response = service.update_policy(@group_id, @policy_id, {
|
||||
'name' => 'foo',
|
||||
'changePercent' => 1,
|
||||
'type' => 'webhook',
|
||||
'cooldown' => 100
|
||||
})
|
||||
response.data[:status]
|
||||
end
|
||||
|
||||
tests('#delete policy').formats(204) do
|
||||
response = service.delete_policy(@group_id, @policy_id)
|
||||
response.data[:status]
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
tests('#create policy').raises(Fog::Rackspace::AutoScale::BadRequest) do
|
||||
service.create_policy(@group_id, {})
|
||||
end
|
||||
|
||||
tests('#get policy').raises(Fog::Rackspace::AutoScale::NotFound) do
|
||||
service.get_policy(@group_id, 123)
|
||||
end
|
||||
|
||||
tests('#update policy').raises(Fog::Rackspace::AutoScale::BadRequest) do
|
||||
service.update_policy(@group_id, 123, {})
|
||||
end
|
||||
|
||||
tests('#execute policy').raises(Fog::Rackspace::AutoScale::NotFound) do
|
||||
service.execute_policy(@group_id, 123)
|
||||
end
|
||||
|
||||
tests('#delete policy').raises(Fog::Rackspace::AutoScale::NotFound) do
|
||||
service.delete_policy(@group_id, 123)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
49
tests/rackspace/requests/auto_scale/webhook_tests.rb
Normal file
49
tests/rackspace/requests/auto_scale/webhook_tests.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
Shindo.tests('Fog::Rackspace::AutoScale | webhook_tests', ['rackspace', 'rackspace_autoscale']) do
|
||||
pending if Fog.mocking?
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
@group_id = service.create_group(LAUNCH_CONFIG_OPTIONS, GROUP_CONFIG_OPTIONS, POLICIES_OPTIONS).body['group']['id']
|
||||
@policy_id = service.create_policy(@group_id, POLICY_OPTIONS).body['policies'][0]['id']
|
||||
|
||||
tests('success') do
|
||||
tests('#create webhook').formats(201) do
|
||||
response = service.create_webhook(@group_id, @policy_id, WEBHOOK_OPTIONS)
|
||||
@webhook_id = response.body['webhooks'][0]['id']
|
||||
response.data[:status]
|
||||
end
|
||||
|
||||
tests('#view webhook').formats(WEBHOOK_FORMAT) do
|
||||
response = service.get_webhook(@group_id, @policy_id, @webhook_id)
|
||||
response.body['webhook']
|
||||
end
|
||||
|
||||
tests('#update webhook').formats(204) do
|
||||
response = service.update_webhook(@group_id, @policy_id, @webhook_id, {'name' => 'new', 'metadata' => {}} )
|
||||
response.data[:status]
|
||||
end
|
||||
|
||||
tests('#delete webhook').formats(204) do
|
||||
response = service.delete_webhook(@group_id, @policy_id, @webhook_id)
|
||||
response.data[:status]
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
tests('#create webhook').raises(Fog::Rackspace::AutoScale::BadRequest) do
|
||||
service.create_webhook(@group_id, @policy_id, {})
|
||||
end
|
||||
|
||||
tests('#view webhook').raises(Fog::Rackspace::AutoScale::NotFound) do
|
||||
service.get_webhook(@group_id, @policy_id, 123)
|
||||
end
|
||||
|
||||
tests('#update webhook').raises(Fog::Rackspace::AutoScale::BadRequest) do
|
||||
service.update_webhook(@group_id, @policy_id, @webhook_id, {})
|
||||
end
|
||||
|
||||
tests('#delete webhook').raises(Fog::Rackspace::AutoScale::NotFound) do
|
||||
service.delete_webhook(@group_id, @policy_id, 123)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -14,7 +14,7 @@ Shindo.tests('Fog::Compute::RackspaceV2 | address requests', ['rackspace']) do
|
|||
address_format = { "addresses"=> {
|
||||
"private" => [{"addr" => String, "version" => Integer}],
|
||||
"public" => [{"addr" => String, "version" => Integer }, {"addr"=> String, "version" => Integer}]}
|
||||
}
|
||||
}
|
||||
|
||||
begin
|
||||
tests("#list_addresses(#{@server_id})").formats(address_format) do
|
||||
|
|
Loading…
Add table
Reference in a new issue