Parent

Class/Module Index [+]

Quicksearch

Fog::Orchestration::OpenStack::Real

Attributes

auth_token[R]
auth_token_expiration[R]
current_tenant[R]
current_user[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/openstack/orchestration.rb, line 84
def initialize(options={})
  @openstack_auth_token = options[:openstack_auth_token]
  @auth_token        = options[:openstack_auth_token]
  @openstack_identity_public_endpoint = options[:openstack_identity_endpoint]

  unless @auth_token
    missing_credentials = Array.new
    @openstack_api_key  = options[:openstack_api_key]
    @openstack_username = options[:openstack_username]

    missing_credentials << :openstack_api_key  unless @openstack_api_key
    missing_credentials << :openstack_username unless @openstack_username
    raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty?
  end

  @openstack_tenant     = options[:openstack_tenant]
  @openstack_auth_uri   = URI.parse(options[:openstack_auth_url])
  @openstack_management_url       = options[:openstack_management_url]
  @openstack_must_reauthenticate  = false
  @openstack_service_type = options[:openstack_service_type] || ['orchestration']
  @openstack_service_name = options[:openstack_service_name]
  @openstack_identity_service_type = options[:openstack_identity_service_type] || 'identity'
  @openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL'
  @openstack_region      = options[:openstack_region]

  @connection_options = options[:connection_options] || {}

  @current_user = options[:current_user]
  @current_tenant = options[:current_tenant]

  authenticate

  @persistent = options[:persistent] || false
  @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Public Instance Methods

create_stack(stack_name, options = {}) click to toggle source

Create a stack.

  • stack_name [String] Name of the stack to create.

  • options [Hash]:

    • :template_body [String] Structure containing the template body.

    or (one of the two Template parameters is required)

    • :template_url [String] URL of file containing the template body.

    • :disable_rollback [Boolean] Controls rollback on stack creation failure, defaults to false.

    • :parameters [Hash] Hash of providers to supply to template

    • :timeout_in_minutes [Integer] Minutes to wait before status is set to CREATE_FAILED

@see docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_CreateStack.html

# File lib/fog/openstack/requests/orchestration/create_stack.rb, line 18
def create_stack(stack_name, options = {})
  params = {
    :stack_name => stack_name
  }.merge(options)

  request(
    :expects  => 201,
    :path => 'stacks',
    :method => 'POST',
    :body => Fog::JSON.encode(params)
  )
end
credentials() click to toggle source
# File lib/fog/openstack/orchestration.rb, line 120
def credentials
  { :provider                 => 'openstack',
    :openstack_auth_url       => @openstack_auth_uri.to_s,
    :openstack_auth_token     => @auth_token,
    :openstack_management_url => @openstack_management_url,
    :openstack_identity_endpoint => @openstack_identity_public_endpoint,
    :openstack_region         => @openstack_region,
    :current_user             => @current_user,
    :current_tenant           => @current_tenant }
end
delete_stack(stack_name, stack_id) click to toggle source

Delete a stack.

@param stack_name [String] Name of the stack to delete. @param stack_id [String] ID of the stack to delete.

@return [Excon::Response]

@see docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_DeleteStack.html

# File lib/fog/openstack/requests/orchestration/delete_stack.rb, line 14
def delete_stack(stack_name, stack_id)
  request(
    :expects  => 204,
    :path => "stacks/#{stack_name}/#{stack_id}",
    :method => 'DELETE'
  )
end
list_stacks(options = {}) click to toggle source

List stacks.

@param options [Hash]

@return [Excon::Response]

* body [Hash]:
  * stacks [Array] - Matching stacks
    * stack [Hash]:
      * id [String] -
      * stack_name [String] -
      * description [String]
      * links [Array]
      * stack_status [String] -
      * stack_status_reason [String]
      * creation_time [Time] -
      * updated_time [Time] -

@see docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_ListStacks.html

# File lib/fog/openstack/requests/orchestration/list_stacks.rb, line 25
def list_stacks(options = {})
  request(
    :expects  => 200,
    :path => 'stacks',
    :method => 'GET',
    :query => options
  )
end
reload() click to toggle source
# File lib/fog/openstack/orchestration.rb, line 131
def reload
  @connection.reset
end
request(params) click to toggle source
# File lib/fog/openstack/orchestration.rb, line 135
def request(params)
  begin
    response = @connection.request(params.merge({
      :headers  => {
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
        'X-Auth-Token' => @auth_token,
        'X-Auth-User'  => @openstack_username,
        'X-Auth-Key'   => @openstack_api_key
      }.merge!(params[:headers] || {}),
      :path     => "#{@path}/#{@tenant_id}/#{params[:path]}",
      :query    => params[:query]
    }))
  rescue Excon::Errors::Unauthorized => error
    if error.response.body != 'Bad username or password' # token expiration
      @openstack_must_reauthenticate = true
      authenticate
      retry
    else # Bad Credentials
      raise error
    end
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
      when Excon::Errors::NotFound
        Fog::Compute::OpenStack::NotFound.slurp(error)
      else
        error
      end
  end

  if !response.body.empty? and response.get_header('Content-Type') =~ /application\/json/ then
    response.body = Fog::JSON.decode(response.body)
  end

  response
end
update_stack(stack_id, stack_name, options = {}) click to toggle source

Update a stack.

@param [String] stack_id ID of the stack to update. @param [String] stack_name Name of the stack to update. @param [Hash] options

* :template [String] Structure containing the template body.
or (one of the two Template parameters is required)
* :template_url [String] URL of file containing the template body.
* :parameters [Hash] Hash of providers to supply to template.
# File lib/fog/openstack/requests/orchestration/update_stack.rb, line 15
def update_stack(stack_id, stack_name, options = {})
  params = {
    :stack_name => stack_name
  }.merge(options)

  request(
    :expects  => 202,
    :path => "stacks/#{stack_name}/#{stack_id}",
    :method => 'PUT',
    :body => Fog::JSON.encode(params)
  )
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.