mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Adding a few more ensure blocks for resource deletion
This commit is contained in:
parent
91cb2fa01d
commit
373b440c6a
21 changed files with 125 additions and 204 deletions
|
@ -8,20 +8,10 @@ module Fog
|
|||
class ServiceError < Fog::Rackspace::Errors::ServiceError; end
|
||||
class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
|
||||
|
||||
class MissingArgumentException
|
||||
def initialize(resource, argument)
|
||||
@resource = resource
|
||||
@argument = argument
|
||||
end
|
||||
def to_s
|
||||
"This #{resource} resource requires the #{argument} argument"
|
||||
end
|
||||
end
|
||||
|
||||
class BadRequest < Fog::Rackspace::Errors::BadRequest
|
||||
attr_reader :validation_errors
|
||||
|
||||
def self.slurp(error)
|
||||
def self.slurp(error, service=nil)
|
||||
if error && error.response
|
||||
status_code = error.response.status
|
||||
if error.response.body
|
||||
|
@ -35,7 +25,7 @@ module Fog
|
|||
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
|
||||
|
@ -112,13 +102,13 @@ module Fog
|
|||
def request(params, parse_json = true, &block)
|
||||
super(params, parse_json, &block)
|
||||
rescue Excon::Errors::NotFound => error
|
||||
raise NotFound.slurp(error, region)
|
||||
raise NotFound.slurp(error, self)
|
||||
rescue Excon::Errors::BadRequest => error
|
||||
raise BadRequest.slurp error
|
||||
raise BadRequest.slurp(error, self)
|
||||
rescue Excon::Errors::InternalServerError => error
|
||||
raise InternalServerError.slurp error
|
||||
raise InternalServerError.slurp(error, self)
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise ServiceError.slurp error
|
||||
raise ServiceError.slurp(error, self)
|
||||
end
|
||||
|
||||
def endpoint_uri(service_endpoint_url=nil)
|
||||
|
|
|
@ -16,11 +16,6 @@ module Fog
|
|||
# @return [Array] group links.
|
||||
attribute :links
|
||||
|
||||
def initialize(attributes={})
|
||||
@service = attributes[:service]
|
||||
super
|
||||
end
|
||||
|
||||
# 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.
|
||||
|
@ -32,16 +27,11 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getGroupConfig_v1.0__tenantId__groups__groupId__config_Configurations.html
|
||||
# @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] = begin
|
||||
Fog::Rackspace::AutoScale::GroupConfig.new({
|
||||
:service => @service,
|
||||
:group => self
|
||||
}).merge_attributes(data.body['groupConfiguration'])
|
||||
end
|
||||
attributes[:group_config] = load_model('GroupConfig', data.body['groupConfiguration'])
|
||||
end
|
||||
attributes[:group_config]
|
||||
end
|
||||
|
@ -51,12 +41,7 @@ module Fog
|
|||
# @param object [Hash<String, String>] Object which will stock the object
|
||||
def group_config=(object = {})
|
||||
if object.is_a?(Hash)
|
||||
attributes[:group_config] = begin
|
||||
Fog::Rackspace::AutoScale::GroupConfig.new({
|
||||
:service => @service,
|
||||
:group => self
|
||||
}).merge_attributes(object)
|
||||
end
|
||||
attributes[:group_config] = load_model('GroupConfig', object)
|
||||
else
|
||||
attributes[:group_config] = object
|
||||
end
|
||||
|
@ -73,16 +58,11 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getLaunchConfig_v1.0__tenantId__groups__groupId__launch_Configurations.html
|
||||
# @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] = begin
|
||||
Fog::Rackspace::AutoScale::LaunchConfig.new({
|
||||
:service => @service,
|
||||
:group => self
|
||||
}).merge_attributes(data.body['launchConfiguration'])
|
||||
end
|
||||
attributes[:launch_config] = load_model('LaunchConfig', data.body['launchConfiguration'])
|
||||
end
|
||||
attributes[:launch_config]
|
||||
end
|
||||
|
@ -92,12 +72,7 @@ module Fog
|
|||
# @param object [Hash<String, String>] Object which will stock the object
|
||||
def launch_config=(object={})
|
||||
if object.is_a?(Hash)
|
||||
attributes[:launch_config] = begin
|
||||
Fog::Rackspace::AutoScale::LaunchConfig.new({
|
||||
:service => @service,
|
||||
:group => self
|
||||
}).merge_attributes(object)
|
||||
end
|
||||
attributes[:launch_config] = load_model('LaunchConfig', object)
|
||||
else
|
||||
attributes[:launch_config] = object
|
||||
end
|
||||
|
@ -109,14 +84,9 @@ module Fog
|
|||
#
|
||||
# @return [Fog::Rackspace::AutoScale::Policies] policies
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getPolicies_v1.0__tenantId__groups__groupId__policies_Policies.html
|
||||
# @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 ||= begin
|
||||
Fog::Rackspace::AutoScale::Policies.new({
|
||||
:service => service,
|
||||
:group => self
|
||||
})
|
||||
end
|
||||
@policies ||= load_model('Policies')
|
||||
end
|
||||
|
||||
# Creates group
|
||||
|
@ -130,11 +100,23 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see Groups#create
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_createGroup_v1.0__tenantId__groups_Groups.html
|
||||
# @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
|
||||
|
||||
data = service.create_group(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
|
||||
|
@ -148,7 +130,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/DELETE_deleteGroup_v1.0__tenantId__groups__groupId__Groups.html
|
||||
# @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)
|
||||
|
@ -164,7 +146,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getGroupState_v1.0__tenantId__groups__groupId__state_Groups.html
|
||||
# @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)
|
||||
|
@ -181,7 +163,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_pauseGroup_v1.0__tenantId__groups__groupId__pause_Groups.html
|
||||
# @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)
|
||||
|
@ -198,13 +180,27 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_resumeGroup_v1.0__tenantId__groups__groupId__resume_Groups.html
|
||||
# @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
|
||||
|
|
|
@ -26,7 +26,7 @@ module Fog
|
|||
attribute :max_entities, :aliases => 'maxEntities'
|
||||
|
||||
# @!attribute [r] metadata
|
||||
# @return [Array] The group's metadata
|
||||
# @return [Hash] The group's metadata
|
||||
attribute :metadata
|
||||
|
||||
# Update this group's configuration
|
||||
|
@ -38,7 +38,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/PUT_putGroupConfig_v1.0__tenantId__groups__groupId__config_Configurations.html
|
||||
# @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 = {}
|
||||
|
|
|
@ -17,7 +17,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getGroups_v1.0__tenantId__groups_Groups.html
|
||||
# @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)
|
||||
|
@ -33,7 +33,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getGroupManifest_v1.0__tenantId__groups__groupId__Groups.html
|
||||
# @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)
|
||||
|
|
|
@ -26,7 +26,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/PUT_putLaunchConfig_v1.0__tenantId__groups__groupId__launch_Configurations.html
|
||||
# @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 = {}
|
||||
|
|
|
@ -19,7 +19,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getPolicies_v1.0__tenantId__groups__groupId__policies_Policies.html
|
||||
# @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)
|
||||
|
@ -35,7 +35,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getPolicy_v1.0__tenantId__groups__groupId__policies__policyId__Policies.html
|
||||
# @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
|
||||
|
@ -53,7 +53,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_createPolicies_v1.0__tenantId__groups__groupId__policies_Policies.html
|
||||
# @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)
|
||||
|
|
|
@ -28,7 +28,7 @@ module Fog
|
|||
|
||||
# @!attribute [r] changePercent
|
||||
# @return [Fixnum] The percentage change to the autoscale group's number of units
|
||||
attribute :changePercent
|
||||
attribute :change_percent, :aliases => 'changePercent'
|
||||
|
||||
# @!attribute [r] cooldown
|
||||
# @return [Fixnum] The policy's cooldown
|
||||
|
@ -41,7 +41,7 @@ module Fog
|
|||
|
||||
# @!attribute [r] args
|
||||
# @note An example might be:
|
||||
#
|
||||
# @example See below:
|
||||
# - "cron": "23 * * * *"
|
||||
# - "at": "2013-06-05T03:12Z"
|
||||
# - "check": {
|
||||
|
@ -67,19 +67,19 @@ module Fog
|
|||
|
||||
# @!attribute [r] desiredCapacity
|
||||
# @return [Fixnum] The desired capacity of the group
|
||||
attribute :desiredCapacity
|
||||
attribute :desired_capacity, :aliases => 'desiredCapacity'
|
||||
|
||||
# Basic sanity check to make sure attributes are valid
|
||||
#
|
||||
# @raise MissingArgumentException If no type is set
|
||||
# @raise MissingArgumentException If args attribute is missing required keys (if type == 'schedule')
|
||||
# @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 MissingArgumentException(self.name, type) if type.nil?
|
||||
raise ArgumentError, "This #{self.name} resource requires the #{type} argument" if type.nil?
|
||||
|
||||
if type == 'schedule'
|
||||
raise MissingArgumentException(self.name, "args[cron] OR args[at]") if args['cron'].nil? && args['at'].nil?
|
||||
raise ArgumentError, "This #{self.name} resource requires the args[cron] OR args[at] argument" if args['cron'].nil? && args['at'].nil?
|
||||
end
|
||||
|
||||
true
|
||||
|
@ -96,7 +96,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see Policies#create
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_createPolicies_v1.0__tenantId__groups__groupId__policies_Policies.html
|
||||
# @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
|
||||
|
||||
|
@ -105,10 +105,10 @@ module Fog
|
|||
options = {}
|
||||
options['name'] = name unless name.nil?
|
||||
options['change'] = change unless change.nil?
|
||||
options['changePercent'] = changePercent unless changePercent.nil?
|
||||
options['changePercent'] = change_percent unless change_percent.nil?
|
||||
options['cooldown'] = cooldown unless cooldown.nil?
|
||||
options['type'] = type unless type.nil?
|
||||
options['desiredCapacity'] = desiredCapacity unless desiredCapacity.nil?
|
||||
options['desiredCapacity'] = desired_capacity unless desired_capacity.nil?
|
||||
|
||||
if type == 'schedule'
|
||||
options['args'] = args
|
||||
|
@ -128,7 +128,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/PUT_putPolicy_v1.0__tenantId__groups__groupId__policies__policyId__Policies.html
|
||||
# @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
|
||||
|
||||
|
@ -137,10 +137,10 @@ module Fog
|
|||
options = {}
|
||||
options['name'] = name unless name.nil?
|
||||
options['change'] = change unless change.nil?
|
||||
options['changePercent'] = changePercent unless changePercent.nil?
|
||||
options['changePercent'] = change_percent unless change_percent.nil?
|
||||
options['cooldown'] = cooldown unless cooldown.nil?
|
||||
options['type'] = type unless type.nil?
|
||||
options['desiredCapacity'] = desiredCapacity unless desiredCapacity.nil?
|
||||
options['desiredCapacity'] = desired_capacity unless desired_capacity.nil?
|
||||
|
||||
if type == 'schedule'
|
||||
options['args'] = args
|
||||
|
@ -160,7 +160,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/DELETE_deletePolicy_v1.0__tenantId__groups__groupId__policies__policyId__Policies.html
|
||||
# @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)
|
||||
|
@ -176,7 +176,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/POST_executePolicy_v1.0__tenantId__groups__groupId__policies__policyId__execute_Policies.html
|
||||
# @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)
|
||||
|
|
|
@ -22,7 +22,7 @@ module Fog
|
|||
attribute :name
|
||||
|
||||
# @!attribute [r] metadata
|
||||
# @return [Array] The metadata
|
||||
# @return [Hash] The metadata
|
||||
attribute :metadata
|
||||
|
||||
# @!attribute [r] links
|
||||
|
@ -62,7 +62,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/PUT_putWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__Webhooks.html
|
||||
# @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
|
||||
|
||||
|
@ -84,7 +84,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/DELETE_deleteWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__Webhooks.html
|
||||
# @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)
|
||||
|
@ -95,8 +95,8 @@ module Fog
|
|||
# @return [String] the URL
|
||||
def execution_url
|
||||
requires :links
|
||||
link = links.select { |l| l['rel'] == 'capability' }
|
||||
link[0]['href']
|
||||
link = links.find { |l| l['rel'] == 'capability' }
|
||||
link['href'] rescue nil
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -34,7 +34,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
#
|
||||
# @see http://docs-internal.rackspace.com/cas/api/v1.0/autoscale-devguide/content/GET_getWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__Webhooks.html
|
||||
# @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
|
||||
|
|
|
@ -5,30 +5,12 @@ module Fog
|
|||
|
||||
def create_group(launch_config, group_config, policies)
|
||||
|
||||
if !launch_config.is_a?(LaunchConfig)
|
||||
raise ArgumentError, 'launch_config needs to be an instance of Fog::Rackspace::AutoScale::LaunchConfig'
|
||||
end
|
||||
|
||||
if !group_config.is_a?(GroupConfig)
|
||||
raise ArgumentError, 'group_config needs to be an instance of Fog::Rackspace::AutoScale::GroupConfig'
|
||||
end
|
||||
|
||||
body = {
|
||||
'launchConfiguration' => {
|
||||
'args' => launch_config.args,
|
||||
'type' => launch_config.type
|
||||
},
|
||||
'groupConfiguration' => {
|
||||
'name' => group_config.name,
|
||||
'cooldown' => group_config.cooldown,
|
||||
'maxEntities' => group_config.max_entities,
|
||||
'minEntities' => group_config.min_entities
|
||||
},
|
||||
'launchConfiguration' => launch_config,
|
||||
'groupConfiguration' => group_config,
|
||||
'scalingPolicies' => policies
|
||||
}
|
||||
|
||||
body['groupConfiguration']['metadata'] = group_config.metadata unless group_config.metadata.nil?
|
||||
|
||||
request(
|
||||
:expects => [201],
|
||||
:method => 'POST',
|
||||
|
|
|
@ -9,12 +9,11 @@ Shindo.tests('Fog::Rackspace::AutoScale | group', ['rackspace', 'rackspace_autos
|
|||
:group_config => GROUP_CONFIG_OPTIONS
|
||||
}
|
||||
|
||||
model_tests(service.groups, options, false) do
|
||||
|
||||
model_tests(service.groups, options, false) do
|
||||
tests('#policies').succeeds do
|
||||
@instance.policies
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -2,19 +2,12 @@ Shindo.tests('Fog::Rackspace::AutoScale | groups', ['rackspace', 'rackspace_auto
|
|||
pending if Fog.mocking?
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
tests("success") do
|
||||
tests("#all").succeeds do
|
||||
groups = service.groups.all
|
||||
@group_id = groups.first.id
|
||||
end
|
||||
options = {
|
||||
:policies => POLICIES_OPTIONS,
|
||||
:group_config => GROUP_CONFIG_OPTIONS,
|
||||
:launch_config => LAUNCH_CONFIG_OPTIONS
|
||||
}
|
||||
|
||||
tests("#get").succeeds do
|
||||
service.groups.get(@group_id)
|
||||
end
|
||||
end
|
||||
|
||||
tests("failure").returns(nil) do
|
||||
service.groups.get(123)
|
||||
end
|
||||
collection_tests(service.groups, options, false)
|
||||
|
||||
end
|
|
@ -15,7 +15,9 @@ Shindo.tests('Fog::Rackspace::AutoScale | policies', ['rackspace', 'rackspace_au
|
|||
:type => 'webhook'
|
||||
}
|
||||
|
||||
collection_tests(group.policies, options, false)
|
||||
|
||||
group.destroy
|
||||
begin
|
||||
collection_tests(group.policies, options, false)
|
||||
ensure
|
||||
group.destroy
|
||||
end
|
||||
end
|
|
@ -16,12 +16,14 @@ Shindo.tests('Fog::Rackspace::AutoScale | policy', ['rackspace', 'rackspace_auto
|
|||
:group_id => group.id
|
||||
}
|
||||
|
||||
model_tests(group.policies, options, false) do
|
||||
|
||||
tests('#webhooks').succeeds do
|
||||
@instance.webhooks
|
||||
begin
|
||||
model_tests(group.policies, options, false) do
|
||||
tests('#webhooks').succeeds do
|
||||
@instance.webhooks
|
||||
end
|
||||
end
|
||||
|
||||
ensure
|
||||
group.destroy
|
||||
end
|
||||
|
||||
end
|
|
@ -10,7 +10,7 @@ Shindo.tests('Fog::Rackspace::AutoScale | webhook', ['rackspace', 'rackspace_aut
|
|||
|
||||
policy = group.policies.create({
|
||||
:name => "set group to 5 servers",
|
||||
:desiredCapacity => 5,
|
||||
:desired_capacity => 5,
|
||||
:cooldown => 1800,
|
||||
:type => "webhook",
|
||||
:group_id => group.id
|
||||
|
@ -25,6 +25,11 @@ Shindo.tests('Fog::Rackspace::AutoScale | webhook', ['rackspace', 'rackspace_aut
|
|||
:policy_id => policy.id
|
||||
}
|
||||
|
||||
model_tests(policy.webhooks, options, false)
|
||||
begin
|
||||
model_tests(policy.webhooks, options, false)
|
||||
ensure
|
||||
policy.destroy
|
||||
group.destroy
|
||||
end
|
||||
|
||||
end
|
|
@ -18,9 +18,11 @@ Shindo.tests('Fog::Rackspace::AutoScale | webhooks', ['rackspace', 'rackspace_au
|
|||
|
||||
options = {:name => 'New webhook', :group_id => group.id, :policy_id => policy.id}
|
||||
|
||||
collection_tests(policy.webhooks, options, false)
|
||||
|
||||
policy.destroy
|
||||
group.destroy
|
||||
begin
|
||||
collection_tests(policy.webhooks, options, false)
|
||||
ensure
|
||||
policy.destroy
|
||||
group.destroy
|
||||
end
|
||||
|
||||
end
|
|
@ -3,21 +3,8 @@ Shindo.tests('Fog::Rackspace::AutoScale | config_tests', ['rackspace', 'rackspac
|
|||
pending if Fog.mocking?
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
@launch_config = begin
|
||||
Fog::Rackspace::AutoScale::LaunchConfig.new({
|
||||
:service => @service,
|
||||
:group => self
|
||||
}).merge_attributes(LAUNCH_CONFIG_OPTIONS)
|
||||
end
|
||||
|
||||
@group_config = begin
|
||||
Fog::Rackspace::AutoScale::GroupConfig.new({
|
||||
:service => @service,
|
||||
:group => self
|
||||
}).merge_attributes(GROUP_CONFIG_OPTIONS)
|
||||
end
|
||||
|
||||
@group_id = service.create_group(@launch_config, @group_config, POLICIES_OPTIONS).body['group']['id']
|
||||
@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
|
||||
|
@ -55,7 +42,10 @@ Shindo.tests('Fog::Rackspace::AutoScale | config_tests', ['rackspace', 'rackspac
|
|||
end
|
||||
end
|
||||
|
||||
# If you execute a DELETE, it returns a 403 and says there are "entities" attached to the group. What?
|
||||
#service.delete_group(@group_id)
|
||||
# @group['scalingPolicies'].each do |p|
|
||||
# service.delete_policy(@group_id, p['id'])
|
||||
# end
|
||||
|
||||
# service.delete_group(@group_id)
|
||||
|
||||
end
|
|
@ -3,29 +3,18 @@ Shindo.tests('Fog::Rackspace::AutoScale | group_tests', ['rackspace', 'rackspace
|
|||
pending if Fog.mocking?
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
@launch_config = begin
|
||||
Fog::Rackspace::AutoScale::LaunchConfig.new({
|
||||
:service => @service,
|
||||
:group => self
|
||||
}).merge_attributes(LAUNCH_CONFIG_OPTIONS)
|
||||
end
|
||||
|
||||
@group_config = begin
|
||||
Fog::Rackspace::AutoScale::GroupConfig.new({
|
||||
:service => @service,
|
||||
:group => self
|
||||
}).merge_attributes(GROUP_CONFIG_OPTIONS)
|
||||
end
|
||||
|
||||
tests('success') do
|
||||
tests('#create new group').formats(GROUP_FORMAT) do
|
||||
response = service.create_group(@launch_config, @group_config, POLICIES_OPTIONS).body
|
||||
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
|
||||
|
|
|
@ -10,7 +10,7 @@ GET_GROUP_HEADERS_FORMAT = {
|
|||
}
|
||||
|
||||
GROUP_DELETE_DATA_FORMAT = {
|
||||
:body=>nil,
|
||||
:body=>Hash,
|
||||
:headers=> {
|
||||
"Content-Type"=>String,
|
||||
"Via"=>String,
|
||||
|
@ -143,10 +143,10 @@ LAUNCH_CONFIG_OPTIONS = {
|
|||
}
|
||||
|
||||
GROUP_CONFIG_OPTIONS = {
|
||||
"max_entities" => 10,
|
||||
"maxEntities" => 10,
|
||||
"cooldown" => 360,
|
||||
"name" => "testscalinggroup198547",
|
||||
"min_entities" => 0,
|
||||
"minEntities" => 0,
|
||||
"metadata" => {
|
||||
"gc_meta_key_2" => "gc_meta_value_2",
|
||||
"gc_meta_key_1" => "gc_meta_value_1"
|
||||
|
|
|
@ -3,21 +3,7 @@ Shindo.tests('Fog::Rackspace::AutoScale | policy_tests', ['rackspace', 'rackspac
|
|||
pending if Fog.mocking?
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
@launch_config = begin
|
||||
Fog::Rackspace::AutoScale::LaunchConfig.new({
|
||||
:service => @service,
|
||||
:group => self
|
||||
}).merge_attributes(LAUNCH_CONFIG_OPTIONS)
|
||||
end
|
||||
|
||||
@group_config = begin
|
||||
Fog::Rackspace::AutoScale::GroupConfig.new({
|
||||
:service => @service,
|
||||
:group => self
|
||||
}).merge_attributes(GROUP_CONFIG_OPTIONS)
|
||||
end
|
||||
|
||||
@group_id = service.create_group(@launch_config, @group_config, POLICIES_OPTIONS).body['group']['id']
|
||||
@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
|
||||
|
|
|
@ -2,22 +2,7 @@ Shindo.tests('Fog::Rackspace::AutoScale | webhook_tests', ['rackspace', 'rackspa
|
|||
pending if Fog.mocking?
|
||||
service = Fog::Rackspace::AutoScale.new :rackspace_region => :ord
|
||||
|
||||
@launch_config = begin
|
||||
Fog::Rackspace::AutoScale::LaunchConfig.new({
|
||||
:service => @service,
|
||||
:group => self
|
||||
}).merge_attributes(LAUNCH_CONFIG_OPTIONS)
|
||||
end
|
||||
|
||||
@group_config = begin
|
||||
Fog::Rackspace::AutoScale::GroupConfig.new({
|
||||
:service => @service,
|
||||
:group => self
|
||||
}).merge_attributes(GROUP_CONFIG_OPTIONS)
|
||||
end
|
||||
|
||||
@group_id = service.create_group(@launch_config, @group_config, POLICIES_OPTIONS).body['group']['id']
|
||||
|
||||
@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
|
||||
|
|
Loading…
Add table
Reference in a new issue