mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace|auto_scale] fixing formatting and documentation; updated collections to pass along dependent parent models
This commit is contained in:
parent
041e2dce4c
commit
df971524d4
11 changed files with 90 additions and 96 deletions
|
@ -9,7 +9,7 @@ module Fog
|
|||
class Group < Fog::Model
|
||||
|
||||
# @!attribute [r] id
|
||||
# @return [String] The autoscale group's id
|
||||
# @return [String] The autoscale group's id
|
||||
identity :id
|
||||
|
||||
# @!attribute [r] links
|
||||
|
|
|
@ -42,7 +42,6 @@ module Fog
|
|||
def update
|
||||
|
||||
options = {}
|
||||
|
||||
options['name'] = name unless name.nil?
|
||||
options['cooldown'] = cooldown unless cooldown.nil?
|
||||
options['minEntities'] = min_entities
|
||||
|
|
|
@ -8,9 +8,9 @@ module Fog
|
|||
|
||||
model Fog::Rackspace::AutoScale::Group
|
||||
|
||||
# Returns list of autoscale grouos
|
||||
# Returns list of autoscale groups
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::Groups] Retrieves a list images.
|
||||
# @return [Fog::Rackspace::AutoScale::Groups] Retrieves a list groups.
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
|
||||
|
@ -25,7 +25,7 @@ module Fog
|
|||
|
||||
# Returns an individual autoscale group
|
||||
#
|
||||
# @return [Fog::Rackspace::AutoScale::Group] Retrieves a list images.
|
||||
# @return [Fog::Rackspace::AutoScale::Group] Retrieves a list groups.
|
||||
# @return nil if not found
|
||||
#
|
||||
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
|
||||
|
|
|
@ -22,9 +22,7 @@ module Fog
|
|||
# @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']
|
||||
policies = load(data)
|
||||
policies.each {|p| p.group = group }
|
||||
policies
|
||||
load(data)
|
||||
end
|
||||
|
||||
# Returns an individual autoscale policy
|
||||
|
@ -40,9 +38,7 @@ module Fog
|
|||
# @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']
|
||||
policy = new(data)
|
||||
policy.group = group
|
||||
policy
|
||||
new(data)
|
||||
rescue Fog::Rackspace::AutoScale::NotFound
|
||||
nil
|
||||
end
|
||||
|
@ -58,10 +54,13 @@ module Fog
|
|||
#
|
||||
# @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 = {})
|
||||
attribute[:group] = group
|
||||
super(attributes)
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
super({:group => group}.merge(attributes))
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -100,7 +100,7 @@ module Fog
|
|||
#
|
||||
# @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
|
||||
def create
|
||||
requires :name, :type, :cooldown
|
||||
|
||||
check_attributes
|
||||
|
@ -209,13 +209,11 @@ module Fog
|
|||
def webhooks
|
||||
requires :identity
|
||||
|
||||
data = service.list_webhooks(group.id, identity)
|
||||
|
||||
Fog::Rackspace::AutoScale::Webhooks.new({
|
||||
@webhooks ||= Fog::Rackspace::AutoScale::Webhooks.new({
|
||||
:service => service,
|
||||
:policy_id => identity,
|
||||
:group_id => group.id
|
||||
}).merge_attributes(data.body)
|
||||
:policy => self,
|
||||
:group => group
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -9,13 +9,13 @@ module Fog
|
|||
# @return [String] The webhook id
|
||||
identity :id
|
||||
|
||||
# @!attribute [r] id
|
||||
# @return [String] The group id (i.e. grand-parent)
|
||||
attribute :group_id
|
||||
# @!attribute [r] group
|
||||
# @return [String] The associated group
|
||||
attribute :group
|
||||
|
||||
# @!attribute [r] id
|
||||
# @return [String] The policy id (i.e. parent)
|
||||
attribute :policy_id
|
||||
# @!attribute [r] policy
|
||||
# @return [String] The associated policy
|
||||
attribute :policy
|
||||
|
||||
# @!attribute [r] name
|
||||
# @return [String] The webhook name
|
||||
|
@ -48,7 +48,7 @@ module Fog
|
|||
options['name'] = name if name
|
||||
options['metadata'] = metadata if metadata
|
||||
|
||||
data = service.create_webhook(group_id, policy_id, options)
|
||||
data = service.create_webhook(group.id, policy.id, options)
|
||||
merge_attributes(data.body['webhooks'][0])
|
||||
true
|
||||
end
|
||||
|
@ -71,8 +71,9 @@ module Fog
|
|||
'metadata' => metadata
|
||||
}
|
||||
|
||||
data = service.update_webhook(group_id, policy_id, identity, options)
|
||||
data = service.update_webhook(group.id, policy.id, identity, options)
|
||||
merge_attributes(data.body)
|
||||
true
|
||||
end
|
||||
|
||||
# Saves the webhook
|
||||
|
@ -99,7 +100,7 @@ module Fog
|
|||
# @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)
|
||||
service.delete_webhook(group.id, policy.id, identity)
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ module Fog
|
|||
|
||||
model Fog::Rackspace::AutoScale::Webhook
|
||||
|
||||
attr_accessor :group_id
|
||||
attr_accessor :policy_id
|
||||
attr_accessor :group
|
||||
attr_accessor :policy
|
||||
|
||||
# Returns list of autoscale webhooks
|
||||
#
|
||||
|
@ -20,7 +20,7 @@ module Fog
|
|||
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
|
||||
def all
|
||||
data = service.list_webhooks(group_id, policy_id).body['webhooks']
|
||||
data = service.list_webhooks(group.id, policy.id).body['webhooks']
|
||||
load(data)
|
||||
end
|
||||
|
||||
|
@ -35,10 +35,8 @@ module Fog
|
|||
# @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
|
||||
def get(webhook_id)
|
||||
data = service.get_webhook(group.id, policy.id, webhook_id).body['webhook']
|
||||
new(data)
|
||||
rescue Fog::Rackspace::AutoScale::NotFound
|
||||
nil
|
||||
|
@ -53,11 +51,12 @@ module Fog
|
|||
# @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
|
||||
|
||||
def new(attributes = {})
|
||||
super({:group => group, :policy => policy}.merge(attributes))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,28 +4,28 @@ Shindo.tests('Fog::Rackspace::AutoScale | policy', ['rackspace', 'rackspace_auto
|
|||
|
||||
pending if Fog.mocking?
|
||||
|
||||
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
|
||||
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 => group
|
||||
}
|
||||
|
||||
model_tests(group.policies, options, false) do
|
||||
tests('#webhooks').succeeds do
|
||||
@instance.webhooks
|
||||
end
|
||||
end
|
||||
ensure
|
||||
group.destroy
|
||||
group.destroy if group
|
||||
end
|
||||
|
||||
end
|
|
@ -4,34 +4,34 @@ Shindo.tests('Fog::Rackspace::AutoScale | webhook', ['rackspace', 'rackspace_aut
|
|||
|
||||
pending if Fog.mocking?
|
||||
|
||||
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
|
||||
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 => group
|
||||
})
|
||||
|
||||
options = {
|
||||
:name => 'webhook name',
|
||||
:metadata => {
|
||||
'owner' => 'me'
|
||||
},
|
||||
:group => group,
|
||||
:policy => policy
|
||||
}
|
||||
|
||||
model_tests(policy.webhooks, options, false)
|
||||
ensure
|
||||
policy.destroy
|
||||
group.destroy
|
||||
policy.destroy if policy
|
||||
group.destroy if group
|
||||
end
|
||||
|
||||
end
|
|
@ -2,27 +2,26 @@ Shindo.tests('Fog::Rackspace::AutoScale | webhooks', ['rackspace', 'rackspace_au
|
|||
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
|
||||
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 => group
|
||||
})
|
||||
|
||||
options = {:name => 'New webhook', :group => group, :policy => policy }
|
||||
collection_tests(policy.webhooks, options, false)
|
||||
ensure
|
||||
policy.destroy
|
||||
group.destroy
|
||||
policy.destroy if policy
|
||||
group.destroy if group
|
||||
end
|
||||
|
||||
end
|
|
@ -10,7 +10,6 @@ GET_GROUP_HEADERS_FORMAT = {
|
|||
}
|
||||
|
||||
GROUP_DELETE_DATA_FORMAT = {
|
||||
:body=>Hash,
|
||||
:headers=> {
|
||||
"Content-Type"=>String,
|
||||
"Via"=>String,
|
||||
|
|
Loading…
Reference in a new issue