Class: Fog::Rackspace::AutoScale::Real

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

#request_without_retry, #service_net?

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



90
91
92
93
94
95
96
97
98
# File 'lib/fog/rackspace/auto_scale.rb', line 90

def initialize(options = {})
  @options = options
  @options[:connection_options] ||= {}
  @options[:persistent] ||= false

  authenticate

  @connection = Fog::Core::Connection.new(endpoint_uri.to_s, @options[:persistent], @options[:connection_options])
end

Instance Method Details

#authenticate(options = {}) ⇒ Object



116
117
118
# File 'lib/fog/rackspace/auto_scale.rb', line 116

def authenticate(options={})
  super(select_options([:rackspace_username, :rackspace_api_key, :rackspace_auth_url, :connection_options]))
end

#create_group(launch_config, group_config, policies) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fog/rackspace/requests/auto_scale/create_group.rb', line 5

def create_group(launch_config, group_config, policies)
  body = {
    'launchConfiguration' => launch_config,
    'groupConfiguration' => group_config,
    'scalingPolicies' => policies
  }

  request(
    :expects => [201],
    :method => 'POST',
    :path => 'groups',
    :body => Fog::JSON.encode(body)
  )
end

#create_policy(group_id, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/fog/rackspace/requests/auto_scale/create_policy.rb', line 5

def create_policy(group_id, options)
  data = [options]

  request(
    :method => 'POST',
    :body => Fog::JSON.encode(data),
    :path => "groups/#{group_id}/policies",
    :expects => 201
  )
end

#create_webhook(group_id, policy_id, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/fog/rackspace/requests/auto_scale/create_webhook.rb', line 5

def create_webhook(group_id, policy_id, options)
  body = [options]

  request(
    :method => 'POST',
    :body => Fog::JSON.encode(body),
    :path => "groups/#{group_id}/policies/#{policy_id}/webhooks",
    :expects => 201
  )
end

#delete_group(group_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/delete_group.rb', line 5

def delete_group(group_id)
  request(
  :expects => [204],
  :method => 'DELETE',
  :path => "groups/#{group_id}"
  )
end

#delete_policy(group_id, policy_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/delete_policy.rb', line 5

def delete_policy(group_id, policy_id)
  request(
    :expects => [204],
    :method => 'DELETE',
    :path => "groups/#{group_id}/policies/#{policy_id}"
  )
end

#delete_webhook(group_id, policy_id, webhook_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/delete_webhook.rb', line 5

def delete_webhook(group_id, policy_id, webhook_id)
  request(
    :expects => [204],
    :method => 'DELETE',
    :path => "groups/#{group_id}/policies/#{policy_id}/webhooks/#{webhook_id}"
  )
end

#endpoint_uri(service_endpoint_url = nil) ⇒ Object



112
113
114
# File 'lib/fog/rackspace/auto_scale.rb', line 112

def endpoint_uri(service_endpoint_url=nil)
  @uri = super(@options[:rackspace_auto_scale_url], :rackspace_auto_scale_url)
end

#execute_anonymous_webhook(capability_version, capability_hash) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/execute_anonymous_webhook.rb', line 5

def execute_anonymous_webhook(capability_version, capability_hash)
  request(
    :expects => [202],
    :method => 'POST',
    :path => "execute/#{capability_version}/#{capability_hash}"
  )
end

#execute_policy(group_id, policy_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/execute_policy.rb', line 5

def execute_policy(group_id, policy_id)
  request(
    :expects => [202],
    :method => 'POST',
    :path => "groups/#{group_id}/policies/#{policy_id}/execute"
  )
end

#get_group(group_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/get_group.rb', line 5

def get_group(group_id)
  request(
    :expects => [200],
    :method => 'GET',
    :path => "groups/#{group_id}"
  )
end

#get_group_config(group_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/get_group_config.rb', line 5

def get_group_config(group_id)
  request(
    :expects => [200],
    :method => 'GET',
    :path => "groups/#{group_id}/config"
  )
end

#get_group_state(group_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/get_group_state.rb', line 5

def get_group_state(group_id)
  request(
    :expects => [200],
    :method => 'GET',
    :path => "groups/#{group_id}/state"
  )
end

#get_launch_config(group_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/get_launch_config.rb', line 5

def get_launch_config(group_id)
  request(
    :expects => [200],
    :method => 'GET',
    :path => "groups/#{group_id}/launch"
  )
end

#get_policy(group_id, policy_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/get_policy.rb', line 5

def get_policy(group_id, policy_id)
  request(
    :expects => [200],
    :method => 'GET',
    :path => "groups/#{group_id}/policies/#{policy_id}"
  )
end

#get_webhook(group_id, policy_id, webhook_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/get_webhook.rb', line 5

def get_webhook(group_id, policy_id, webhook_id)
  request(
    :expects => [200],
    :method => 'GET',
    :path => "groups/#{group_id}/policies/#{policy_id}/webhooks/#{webhook_id}"
  )
end

#list_groupsExcon::Response

Retrieves a list of images

Returns:

  • (Excon::Response)

    response:

    • body [Hash]:

      • images [Array]:

        • [Hash]:

          • id [String] - flavor id

          • links [Array] - image links

          • name [String] - image name

Raises:

See Also:



18
19
20
21
22
23
24
# File 'lib/fog/rackspace/requests/auto_scale/list_groups.rb', line 18

def list_groups
  request(
    :expects => [200],
    :method => 'GET',
    :path => 'groups'
  )
end

#list_policies(group_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/list_policies.rb', line 5

def list_policies(group_id)
  request(
    :expects => [200],
    :method => 'GET',
    :path => "groups/#{group_id}/policies"
  )
end

#list_webhooks(group_id, policy_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/list_webhooks.rb', line 5

def list_webhooks(group_id, policy_id)
  request(
    :expects => [200],
    :method => 'GET',
    :path => "groups/#{group_id}/policies/#{policy_id}/webhooks"
  )
end

#pause_group_state(group_id) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/rackspace/requests/auto_scale/pause_group_state.rb', line 5

def pause_group_state(group_id)
  Fog::Real.not_implemented
  # request(
  #   :expects => [204],
  #   :method => 'POST',
  #   :path => 'groups/#{group_id}/pause'
  # )
end

#regionObject



128
129
130
# File 'lib/fog/rackspace/auto_scale.rb', line 128

def region
  @options[:rackspace_region]
end

#request(params, parse_json = true, &block) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fog/rackspace/auto_scale.rb', line 100

def request(params, parse_json = true, &block)
  super(params, parse_json, &block)
rescue Excon::Errors::NotFound => error
  raise NotFound.slurp(error, self)
rescue Excon::Errors::BadRequest => error
  raise BadRequest.slurp(error, self)
rescue Excon::Errors::InternalServerError => error
  raise InternalServerError.slurp(error, self)
rescue Excon::Errors::HTTPStatusError => error
  raise ServiceError.slurp(error, self)
end

#request_id_headerObject



124
125
126
# File 'lib/fog/rackspace/auto_scale.rb', line 124

def request_id_header
  "x-response-id"
end

#resume_group_state(group_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/auto_scale/resume_group_state.rb', line 5

def resume_group_state(group_id)
  request(
    :expects => [204],
    :method => 'POST',
    :path => "groups/#{group_id}/resume"
  )
end

#service_nameObject



120
121
122
# File 'lib/fog/rackspace/auto_scale.rb', line 120

def service_name
  :autoscale
end

#update_group_config(group_id, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/fog/rackspace/requests/auto_scale/update_group_config.rb', line 5

def update_group_config(group_id, options)
  body = options

  request(
    :expects => [204],
    :method => 'PUT',
    :path => "groups/#{group_id}/config",
    :body => Fog::JSON.encode(body)
  )
end

#update_launch_config(group_id, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/fog/rackspace/requests/auto_scale/update_launch_config.rb', line 5

def update_launch_config(group_id, options)
  body = options

  request(
    :expects => [204],
    :method => 'PUT',
    :path => "groups/#{group_id}/launch",
    :body => Fog::JSON.encode(body)
  )
end

#update_policy(group_id, policy_id, options) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/rackspace/requests/auto_scale/update_policy.rb', line 5

def update_policy(group_id, policy_id, options)
  request(
    :expects => [204],
    :method => 'PUT',
    :path => "groups/#{group_id}/policies/#{policy_id}",
    :body => Fog::JSON.encode(options)
  )
end

#update_webhook(group_id, policy_id, webhook_id, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/fog/rackspace/requests/auto_scale/update_webhook.rb', line 5

def update_webhook(group_id, policy_id, webhook_id, options)
  body = options

  request(
    :expects => [204],
    :method => 'PUT',
    :path => "groups/#{group_id}/policies/#{policy_id}/webhooks/#{webhook_id}",
    :body => Fog::JSON.encode(body)
  )
end