Class: Fog::Rackspace::AutoScale::Mock

Inherits:
Service
  • Object
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

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



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
# File 'lib/fog/rackspace/requests/auto_scale/create_group.rb', line 22

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

#create_policy(group_id, options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/rackspace/requests/auto_scale/create_policy.rb', line 18

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



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
# File 'lib/fog/rackspace/requests/auto_scale/create_webhook.rb', line 18

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, policy_id) ⇒ Object



15
16
17
18
# File 'lib/fog/rackspace/requests/auto_scale/delete_group.rb', line 15

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/rackspace/requests/auto_scale/delete_webhook.rb', line 15

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) ⇒ Object



15
16
17
# File 'lib/fog/rackspace/requests/auto_scale/execute_anonymous_webhook.rb', line 15

def execute_anonymous_webhook(capability_version, capability_hash)
   response(:status => 202)
end

#execute_policy(group_id, policy_id) ⇒ Object



15
16
17
# File 'lib/fog/rackspace/requests/auto_scale/execute_policy.rb', line 15

def execute_policy(group_id, policy_id)
   response(:status => 202)
end

#get_group(group_id) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/fog/rackspace/requests/auto_scale/get_group.rb', line 15

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



15
16
17
18
19
20
21
22
23
# File 'lib/fog/rackspace/requests/auto_scale/get_group_config.rb', line 15

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



15
16
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
# File 'lib/fog/rackspace/requests/auto_scale/get_group_state.rb', line 15

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



15
16
17
18
19
20
21
22
23
# File 'lib/fog/rackspace/requests/auto_scale/get_launch_config.rb', line 15

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



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/rackspace/requests/auto_scale/get_policy.rb', line 15

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) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/rackspace/requests/auto_scale/get_webhook.rb', line 15

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_groupsObject



28
29
30
# File 'lib/fog/rackspace/requests/auto_scale/list_groups.rb', line 28

def list_groups
  response(:body => {"groups" => self.data[:autoscale_groups]})
end

#list_policies(group_id) ⇒ Object



15
16
17
18
# File 'lib/fog/rackspace/requests/auto_scale/list_policies.rb', line 15

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



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/rackspace/requests/auto_scale/list_webhooks.rb', line 15

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) ⇒ Object



16
17
18
# File 'lib/fog/rackspace/requests/auto_scale/pause_group_state.rb', line 16

def pause_group_state(group_id)
   Fog::Mock.not_implemented
end

#request(params) ⇒ Object



84
85
86
# File 'lib/fog/rackspace/auto_scale.rb', line 84

def request(params)
  Fog::Mock.not_implemented
end

#resume_group_state(group_id) ⇒ Object



15
16
17
# File 'lib/fog/rackspace/requests/auto_scale/resume_group_state.rb', line 15

def resume_group_state(group_id)
   Fog::Mock.not_implemented
end

#update_group_config(group_id, options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/rackspace/requests/auto_scale/update_group_config.rb', line 18

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



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/rackspace/requests/auto_scale/update_launch_config.rb', line 18

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



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/rackspace/requests/auto_scale/update_policy.rb', line 16

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) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/rackspace/requests/auto_scale/update_webhook.rb', line 18

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