class Fog::Rackspace::Orchestration::Real

Public Class Methods

new(options = {}) click to toggle source
# File lib/fog/rackspace/orchestration.rb, line 114
def initialize(options = {})
  @rackspace_api_key = options[:rackspace_api_key]
  @rackspace_username = options[:rackspace_username]
  @rackspace_auth_url = options[:rackspace_auth_url]
  setup_custom_endpoint(options)
  @rackspace_must_reauthenticate = false
  @connection_options = options[:connection_options] || {}

  authenticate

  deprecation_warnings(options)

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

Public Instance Methods

abandon_stack(stack) click to toggle source
# File lib/fog/rackspace/requests/orchestration/abandon_stack.rb, line 5
def abandon_stack(stack)
  request(
    :expects => [200],
    :method  => 'DELETE',
    :path    => "stacks/#{stack.stack_name}/#{stack.id}/abandon"
  )
end
authenticate(options={}) click to toggle source
Calls superclass method Fog::Rackspace::Service#authenticate
# File lib/fog/rackspace/orchestration.rb, line 142
def authenticate(options={})
  super({
    :rackspace_api_key => @rackspace_api_key,
    :rackspace_username => @rackspace_username,
    :rackspace_auth_url => @rackspace_auth_url,
    :connection_options => @connection_options
  })
end
build_info() click to toggle source
# File lib/fog/rackspace/requests/orchestration/build_info.rb, line 5
def build_info
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => 'build_info'
  )
end
create_stack(options={}) click to toggle source
# File lib/fog/rackspace/requests/orchestration/create_stack.rb, line 5
def create_stack(options={})
  request(
    :body     => Fog::JSON.encode(options),
    :expects  => [201],
    :method   => 'POST',
    :path     => "stacks"
  )
end
delete_stack(stack) click to toggle source
# File lib/fog/rackspace/requests/orchestration/delete_stack.rb, line 5
def delete_stack(stack)
  request(
    :expects => [204],
    :method  => 'DELETE',
    :path    => "stacks/#{stack.stack_name}/#{stack.id}"
  )
end
endpoint_uri(service_endpoint_url=nil) click to toggle source
Calls superclass method Fog::Rackspace::Service#endpoint_uri
# File lib/fog/rackspace/orchestration.rb, line 163
def endpoint_uri(service_endpoint_url=nil)
  @uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_orchestration_url)
end
get_stack_template(stack) click to toggle source
# File lib/fog/rackspace/requests/orchestration/get_stack_template.rb, line 5
def get_stack_template(stack)
  request(
    :method  => 'GET',
    :path    => "stacks/#{stack.stack_name}/#{stack.id}/template",
    :expects => 200
  )
end
list_resource_events(stack, resource, options={}) click to toggle source
# File lib/fog/rackspace/requests/orchestration/list_resource_events.rb, line 5
def list_resource_events(stack, resource, options={})
  uri = request_uri("stacks/#{stack.stack_name}/#{stack.id}/resources/#{resource.resource_name}/events", options)
  request(:method => 'GET', :path => uri, :expects => 200)
end
list_resource_types() click to toggle source
# File lib/fog/rackspace/requests/orchestration/list_resource_types.rb, line 5
def list_resource_types
  request(
    :method  => 'GET',
    :path    => "resource_types",
    :expects => 200
  )
end
list_resources(stack, options={}) click to toggle source
# File lib/fog/rackspace/requests/orchestration/list_resources.rb, line 5
def list_resources(stack, options={})
  uri = request_uri("stacks/#{stack.stack_name}/#{stack.id}/resources", options)
  request(:method => 'GET', :path => uri, :expects => 200)
end
list_stack_data(options={}) click to toggle source
# File lib/fog/rackspace/requests/orchestration/list_stack_data.rb, line 5
def list_stack_data(options={})
  request(
    :method  => 'GET',
    :path    => request_uri("stacks", options),
    :expects => 200
  )
end
list_stack_events(stack, options={}) click to toggle source
# File lib/fog/rackspace/requests/orchestration/list_stack_events.rb, line 5
def list_stack_events(stack, options={})
  uri = request_uri("stacks/#{stack.stack_name}/#{stack.id}/events", options)
  request(:method => 'GET', :path => uri, :expects => 200)
end
preview_stack(options = {}) click to toggle source
# File lib/fog/rackspace/requests/orchestration/preview_stack.rb, line 5
def preview_stack(options = {})
  request(
    :body     => Fog::JSON.encode(options),
    :expects  => [200],
    :method   => 'POST',
    :path     => 'stacks/preview'
  )
end
region() click to toggle source
# File lib/fog/rackspace/orchestration.rb, line 159
def region
  @rackspace_region
end
request(params, parse_json = true) click to toggle source
Calls superclass method Fog::Rackspace::Service#request
# File lib/fog/rackspace/orchestration.rb, line 130
def request(params, parse_json = true)
  super
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_header() click to toggle source
# File lib/fog/rackspace/orchestration.rb, line 155
def request_id_header
  "x-orchestration-request-id"
end
request_uri(path, options={}) click to toggle source
# File lib/fog/rackspace/orchestration.rb, line 167
def request_uri(path, options={})
  return path if options == {}
  require "addressable/uri"
  Addressable::URI.new({:path=>path, :query_values=>options}).request_uri
end
service_name() click to toggle source
# File lib/fog/rackspace/orchestration.rb, line 151
def service_name
  :cloudOrchestration
end
show_event_details(stack, resource, event_id) click to toggle source
# File lib/fog/rackspace/requests/orchestration/show_event_details.rb, line 5
def show_event_details(stack, resource, event_id)
  request(
    :method  => 'GET',
    :path    => "stacks/#{stack.stack_name}/#{stack.id}/resources/#{resource.resource_name}/events/#{event_id}",
    :expects => 200
  )
end
show_resource_data(stack_name, stack_id, resource_name) click to toggle source
# File lib/fog/rackspace/requests/orchestration/show_resource_data.rb, line 5
def show_resource_data(stack_name, stack_id, resource_name)
  request(
    :method  => 'GET',
    :path    => "stacks/#{stack_name}/#{stack_id}/resources/#{resource_name}",
    :expects => 200
  )
end
show_resource_metadata(stack, resource_name) click to toggle source
# File lib/fog/rackspace/requests/orchestration/show_resource_metadata.rb, line 5
def show_resource_metadata(stack, resource_name)
  request(
    :method  => 'GET',
    :path    => "stacks/#{stack.stack_name}/#{stack.id}/resources/#{resource_name}/metadata",
    :expects => 200
  )
end
show_resource_schema(name) click to toggle source
# File lib/fog/rackspace/requests/orchestration/show_resource_schema.rb, line 5
def show_resource_schema(name)
  request(
    :method  => 'GET',
    :path    => "resource_types/#{name}",
    :expects => 200
  )
end
show_resource_template(name) click to toggle source
# File lib/fog/rackspace/requests/orchestration/show_resource_template.rb, line 5
def show_resource_template(name)
  request(
    :method  => 'GET',
    :path    => "resource_types/#{name}/template",
    :expects => 200
  )
end
show_stack_details(name, id) click to toggle source
# File lib/fog/rackspace/requests/orchestration/show_stack_details.rb, line 5
def show_stack_details(name, id)
  request(
    :method  => 'GET',
    :path    => "stacks/#{name}/#{id}",
    :expects => 200
  )
end
update_stack(stack, options = {}) click to toggle source
# File lib/fog/rackspace/requests/orchestration/update_stack.rb, line 5
def update_stack(stack, options = {})
  request(
    :body     => Fog::JSON.encode(options),
    :expects  => [202],
    :method   => 'PUT',
    :path     => "stacks/#{stack.stack_name}/#{stack.id}"
  )
end
validate_template(options = {}) click to toggle source
# File lib/fog/rackspace/requests/orchestration/validate_template.rb, line 5
def validate_template(options = {})
  request(
    :body     => Fog::JSON.encode(options),
    :expects  => [200],
    :method   => 'POST',
    :path     => 'validate'
  )
end

Private Instance Methods

append_tenant_v1(credentials) click to toggle source
# File lib/fog/rackspace/orchestration.rb, line 211
def append_tenant_v1(credentials)
  account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]

  endpoint = @rackspace_endpoint || credentials['X-Server-Management-Url'] || ORCHESTRATION_DFW_URL
  @uri = URI.parse(endpoint)
  @uri.path = "#{@uri.path}/#{account_id}"
end
authenticate_v1(options) click to toggle source
# File lib/fog/rackspace/orchestration.rb, line 219
def authenticate_v1(options)
  credentials = Fog::Rackspace.authenticate(options, @connection_options)
  append_tenant_v1 credentials
  @auth_token = credentials['X-Auth-Token']
end
deprecation_warnings(options) click to toggle source
# File lib/fog/rackspace/orchestration.rb, line 202
def deprecation_warnings(options)
  Fog::Logger.deprecation("The :rackspace_endpoint option is deprecated. Please use :rackspace_orchestration_url for custom endpoints") if options[:rackspace_endpoint]

  if [ORCHESTRATION_DFW_URL, ORCHESTRATION_ORD_URL, ORCHESTRATION_IAD_URL, ORCHESTRATION_LON_URL].include?(@rackspace_endpoint) && v2_authentication?
    regions = @identity_service.service_catalog.display_service_regions(service_name)
    Fog::Logger.deprecation("Please specify region using :rackspace_region rather than :rackspace_endpoint. Valid regions for :rackspace_region are #{regions}.")
  end
end
setup_custom_endpoint(options) click to toggle source
# File lib/fog/rackspace/orchestration.rb, line 175
def setup_custom_endpoint(options)
  @rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_orchestration_url] || options[:rackspace_endpoint])

  if v2_authentication?
    case @rackspace_endpoint
      when ORCHESTRATION_DFW_URL
        @rackspace_endpoint = nil
        @rackspace_region = :dfw
      when ORCHESTRATION_ORD_URL
        @rackspace_endpoint = nil
        @rackspace_region = :ord
      when ORCHESTRATION_IAD_URL
        @rackspace_endpoint = nil
        @rackspace_region = :iad
      when ORCHESTRATION_LON_URL
        @rackspace_endpoint = nil
        @rackspace_region = :lon
      else
        # we are actually using a custom endpoint
        @rackspace_region = options[:rackspace_region]
    end
  else
    #if we are using auth1 and the endpoint is not set, default to DFW_URL for historical reasons
    @rackspace_endpoint ||= ORCHESTRATION_DFW_URL
  end
end