create_group(launch_config, group_config, policies)
click to toggle source
def create_group(launch_config, group_config, policies)
group_id = Fog::Rackspace::MockData.uuid
group = {
'launchConfiguration' => launch_config,
'groupConfiguration' => group_config,
'scalingPolicies' => policies,
'id' => group_id
}
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"
}
]
self.data[:autoscale_groups][group_id] = group
body = {'group' => group}
response(:body => body)
end
create_policy(group_id, options)
click to toggle source
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
create_webhook(group_id, policy_id, options)
click to toggle source
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'].find { |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
delete_group(group_id)
click to toggle source
def delete_group(group_id)
self.data[:autoscale_groups].delete(group_id)
response(:status => 204)
end
delete_webhook(group_id, policy_id, webhook_id)
click to toggle source
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'].find { |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
execute_anonymous_webhook(capability_version, capability_hash)
click to toggle source
def execute_anonymous_webhook(capability_version, capability_hash)
response(:status => 202)
end
execute_policy(group_id, policy_id)
click to toggle source
def execute_policy(group_id, policy_id)
response(:status => 202)
end
get_group(group_id)
click to toggle source
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
get_group_config(group_id)
click to toggle source
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
get_group_state(group_id)
click to toggle source
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
get_launch_config(group_id)
click to toggle source
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
get_policy(group_id, policy_id)
click to toggle source
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'].find { |p| p["id"] == policy_id }
if policy.nil?
raise Fog::Rackspace::AutoScale::NotFound
end
response(:body => {'policy' => policy})
end
get_webhook(group_id, policy_id, webhook_id)
click to toggle source
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'].find { |p| p["id"] == policy_id }
if policy.nil?
raise Fog::Rackspace::AutoScale::NotFound
end
webhook = policy['webhooks'].find { |w| w['id'] == webhook_id }
if webhook.nil?
raise Fog::Rackspace::AutoScale::NotFound
end
response(:body => {'webhook' => webhook})
end
list_groups()
click to toggle source
def list_groups
response(:body => {"groups" => self.data[:autoscale_groups]})
end
list_policies(group_id)
click to toggle source
def list_policies(group_id)
group = self.data[:autoscale_groups][group_id]
response(:body => {'policies' => group['scalingPolicies']})
end
list_webhooks(group_id, policy_id)
click to toggle source
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'].find { |p| p["id"] == policy_id }
if policy.nil?
raise Fog::Rackspace::AutoScale::NotFound
end
response(:body => {'webhooks' => policy['webhooks']})
end
pause_group_state(group_id)
click to toggle source
def pause_group_state(group_id)
Fog::Mock.not_implemented
end
request(params)
click to toggle source
def request(params)
Fog::Mock.not_implemented
end
resume_group_state(group_id)
click to toggle source
def resume_group_state(group_id)
Fog::Mock.not_implemented
end
update_group_config(group_id, options)
click to toggle source
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
update_launch_config(group_id, options)
click to toggle source
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
update_policy(group_id, policy_id, options)
click to toggle source
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'].find { |p| p["id"] == policy_id }
policy.merge(options)
request(:body => policy)
end
update_webhook(group_id, policy_id, webhook_id, options)
click to toggle source
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'].find { |p| p["id"] == policy_id }
if policy.nil?
raise Fog::Rackspace::AutoScale::NotFound
end
webhook = policy['webhooks'].find { |w| w['id'] == webhook_id }
if webhook.nil?
raise Fog::Rackspace::AutoScale::NotFound
end
webhook.merge(options)
response(:body => webhook)
end