Class: Fog::Rackspace::AutoScale::Mock
- Inherits:
-
Service
- Object
- Service
- Fog::Rackspace::AutoScale::Mock
show all
- Defined in:
- lib/fog/rackspace/auto_scale.rb,
lib/fog/rackspace/requests/auto_scale/get_group.rb,
lib/fog/rackspace/requests/auto_scale/get_policy.rb,
lib/fog/rackspace/requests/auto_scale/get_webhook.rb,
lib/fog/rackspace/requests/auto_scale/list_groups.rb,
lib/fog/rackspace/requests/auto_scale/create_group.rb,
lib/fog/rackspace/requests/auto_scale/delete_group.rb,
lib/fog/rackspace/requests/auto_scale/create_policy.rb,
lib/fog/rackspace/requests/auto_scale/delete_policy.rb,
lib/fog/rackspace/requests/auto_scale/list_policies.rb,
lib/fog/rackspace/requests/auto_scale/list_webhooks.rb,
lib/fog/rackspace/requests/auto_scale/update_policy.rb,
lib/fog/rackspace/requests/auto_scale/create_webhook.rb,
lib/fog/rackspace/requests/auto_scale/delete_webhook.rb,
lib/fog/rackspace/requests/auto_scale/execute_policy.rb,
lib/fog/rackspace/requests/auto_scale/update_webhook.rb,
lib/fog/rackspace/requests/auto_scale/get_group_state.rb,
lib/fog/rackspace/requests/auto_scale/get_group_config.rb,
lib/fog/rackspace/requests/auto_scale/get_launch_config.rb,
lib/fog/rackspace/requests/auto_scale/pause_group_state.rb,
lib/fog/rackspace/requests/auto_scale/resume_group_state.rb,
lib/fog/rackspace/requests/auto_scale/update_group_config.rb,
lib/fog/rackspace/requests/auto_scale/update_launch_config.rb,
lib/fog/rackspace/requests/auto_scale/execute_anonymous_webhook.rb
Instance Method Summary
collapse
-
#create_group(launch_config, group_config, policies) ⇒ Object
-
#create_policy(group_id, options) ⇒ Object
-
#create_webhook(group_id, policy_id, options) ⇒ Object
-
#delete_group(group_id, policy_id) ⇒ Object
-
#delete_webhook(group_id, policy_id, webhook_id) ⇒ Object
-
#execute_anonymous_webhook(capability_version, capability_hash) ⇒ Object
-
#execute_policy(group_id, policy_id) ⇒ Object
-
#get_group(group_id) ⇒ Object
-
#get_group_config(group_id) ⇒ Object
-
#get_group_state(group_id) ⇒ Object
-
#get_launch_config(group_id) ⇒ Object
-
#get_policy(group_id, policy_id) ⇒ Object
-
#get_webhook(group_id, policy_id, webhook_id) ⇒ Object
-
#initialize(options) ⇒ Mock
constructor
-
#list_groups ⇒ Object
-
#list_policies(group_id) ⇒ Object
-
#list_webhooks(group_id, policy_id) ⇒ Object
-
#pause_group_state(group_id) ⇒ Object
-
#request(params) ⇒ Object
-
#resume_group_state(group_id) ⇒ Object
-
#update_group_config(group_id, options) ⇒ Object
-
#update_launch_config(group_id, options) ⇒ Object
-
#update_policy(group_id, policy_id, options) ⇒ Object
-
#update_webhook(group_id, policy_id, webhook_id, options) ⇒ Object
Methods inherited from Service
#authenticate, #endpoint_uri, #region, #request_without_retry, #service_name, #service_net?
Constructor Details
#initialize(options) ⇒ Mock
Returns a new instance of Mock.
80
81
82
|
# File 'lib/fog/rackspace/auto_scale.rb', line 80
def initialize(options)
@rackspace_api_key = options[:rackspace_api_key]
end
|
Instance Method Details
#create_group(launch_config, group_config, policies) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/fog/rackspace/requests/auto_scale/create_group.rb', line 24
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) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/fog/rackspace/requests/auto_scale/create_policy.rb', line 19
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) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/fog/rackspace/requests/auto_scale/create_webhook.rb', line 19
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
|
#delete_group(group_id, policy_id) ⇒ Object
16
17
18
19
|
# File 'lib/fog/rackspace/requests/auto_scale/delete_group.rb', line 16
def delete_group(group_id)
self.data[:autoscale_groups].delete(group_id)
response(:status => 204)
end
|
#delete_webhook(group_id, policy_id, webhook_id) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/fog/rackspace/requests/auto_scale/delete_webhook.rb', line 16
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
|
#execute_anonymous_webhook(capability_version, capability_hash) ⇒ Object
16
17
18
|
# File 'lib/fog/rackspace/requests/auto_scale/execute_anonymous_webhook.rb', line 16
def execute_anonymous_webhook(capability_version, capability_hash)
response(:status => 202)
end
|
#execute_policy(group_id, policy_id) ⇒ Object
16
17
18
|
# File 'lib/fog/rackspace/requests/auto_scale/execute_policy.rb', line 16
def execute_policy(group_id, policy_id)
response(:status => 202)
end
|
#get_group(group_id) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/fog/rackspace/requests/auto_scale/get_group.rb', line 17
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) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/fog/rackspace/requests/auto_scale/get_group_config.rb', line 17
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) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/fog/rackspace/requests/auto_scale/get_group_state.rb', line 17
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) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/fog/rackspace/requests/auto_scale/get_launch_config.rb', line 17
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) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/fog/rackspace/requests/auto_scale/get_policy.rb', line 17
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
|
#get_webhook(group_id, policy_id, webhook_id) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/fog/rackspace/requests/auto_scale/get_webhook.rb', line 17
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
|
#list_groups ⇒ Object
29
30
31
|
# File 'lib/fog/rackspace/requests/auto_scale/list_groups.rb', line 29
def list_groups
response(:body => {"groups" => self.data[:autoscale_groups]})
end
|
#list_policies(group_id) ⇒ Object
16
17
18
19
|
# File 'lib/fog/rackspace/requests/auto_scale/list_policies.rb', line 16
def list_policies(group_id)
group = self.data[:autoscale_groups][group_id]
response(:body => {'policies' => group['scalingPolicies']})
end
|
#list_webhooks(group_id, policy_id) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/fog/rackspace/requests/auto_scale/list_webhooks.rb', line 16
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
|
#pause_group_state(group_id) ⇒ Object
17
18
19
|
# File 'lib/fog/rackspace/requests/auto_scale/pause_group_state.rb', line 17
def pause_group_state(group_id)
Fog::Mock.not_implemented
end
|
#request(params) ⇒ Object
#resume_group_state(group_id) ⇒ Object
16
17
18
|
# File 'lib/fog/rackspace/requests/auto_scale/resume_group_state.rb', line 16
def resume_group_state(group_id)
Fog::Mock.not_implemented
end
|
#update_group_config(group_id, options) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/fog/rackspace/requests/auto_scale/update_group_config.rb', line 20
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) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/fog/rackspace/requests/auto_scale/update_launch_config.rb', line 20
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) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/fog/rackspace/requests/auto_scale/update_policy.rb', line 18
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
|
#update_webhook(group_id, policy_id, webhook_id, options) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/fog/rackspace/requests/auto_scale/update_webhook.rb', line 20
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
|