class Fog::Orchestration::OpenStack::Real

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/openstack/orchestration.rb, line 134
def initialize(options={})
  initialize_identity options

  @openstack_identity_service_type = options[:openstack_identity_service_type] || 'identity'

  @openstack_service_type           = options[:openstack_service_type] || ['orchestration']
  @openstack_service_name           = options[:openstack_service_name]

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

  authenticate

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

Public Instance Methods

abandon_stack(stack) click to toggle source
# File lib/fog/openstack/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
build_info() click to toggle source
# File lib/fog/openstack/requests/orchestration/build_info.rb, line 5
def build_info
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => 'build_info'
  )
end
create_stack(arg1, arg2 = nil) click to toggle source

Create a stack.

  • options [Hash]:

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

    • :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.

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

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

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

@see developer.openstack.org/api-ref-orchestration-v1.html

# File lib/fog/openstack/requests/orchestration/create_stack.rb, line 19
def create_stack(arg1, arg2 = nil)
  if arg1.is_a?(Hash)
    # Normal use: create_stack(options)
    options = arg1
  else
    # Deprecated: create_stack(stack_name, options = {})
    Fog::Logger.deprecation("#create_stack(stack_name, options) is deprecated, use #create_stack(options) instead [light_black](#{caller.first})[/]")
    options = {
      :stack_name => arg1
    }.merge(arg2.nil? ? {} : arg2)
  end

  request(
    :expects  => 201,
    :path => 'stacks',
    :method => 'POST',
    :body => Fog::JSON.encode(options)
  )
end
delete_stack(arg1, arg2 = nil) click to toggle source

Delete a stack.

@param [Stack] Stack to be deleted

@return [Excon::Response]

@see developer.openstack.org/api-ref-orchestration-v1.html

# File lib/fog/openstack/requests/orchestration/delete_stack.rb, line 13
def delete_stack(arg1, arg2 = nil)
  if arg1.is_a?(Stack)
    # Normal use: delete_stack(stack)
    stack = arg1
    stack_name = stack.stack_name
    stack_id = stack.id
  else
    # Deprecated: delete_stack(stack_name, stack_id)
    Fog::Logger.deprecation("#delete_stack(stack_name, stack_id) is deprecated, use #delete_stack(stack) instead [light_black](#{caller.first})[/]")
    stack_name = arg1
    stack_id = arg2
  end

  request(
    :expects  => 204,
    :path => "stacks/#{stack_name}/#{stack_id}",
    :method => 'DELETE'
  )
end
get_stack_template(stack) click to toggle source
# File lib/fog/openstack/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_events(options = {}) click to toggle source
# File lib/fog/openstack/requests/orchestration/list_events.rb, line 5
def list_events(options = {})
  if !options.key?(:stack) && !(options.key?(:stack_name) && options.key?(:stack_id))
    raise(ArgumentError, "Missing required options keys: :stack or :stack_name and :stack_id, while calling "                                  " .list_events(options)")
  end

  stack        = options.delete(:stack)
  stack_name   = options.delete(:stack_name)
  stack_name ||= stack.stack_name if stack && stack.respond_to?(:stack_name)
  stack_id     = options.delete(:stack_id)
  stack_id   ||= stack.id if stack && stack.respond_to?(:id)

  resource        = options.delete(:resource)
  resource_name   = options.delete(:resource_name)
  resource_name ||= resource.resource_name if resource && resource.respond_to?(:resource_name)

  if resource_name
    path = "stacks/#{stack_name}/#{stack_id}/resources/#{resource_name}/events"
  else
    path = "stacks/#{stack_name}/#{stack_id}/events"
  end

  request(:method  => 'GET',
          :path    => path,
          :expects => 200,
          :query   => options)
end
list_resource_events(stack, resource, options = {}) click to toggle source
# File lib/fog/openstack/requests/orchestration/list_resource_events.rb, line 5
def list_resource_events(stack, resource, options = {})
  Fog::Logger.deprecation('Calling OpenStack[:orchestration].list_resource_events(stack, resource, options)'                                   ' is deprecated, call .list_events(:stack => stack, :resource => resource) or '                                   ' .list_events(:stack_name => value, :stack_id => value, :resource_name => value)'                                   ' instead')

  uri = "stacks/#{stack.stack_name}/#{stack.id}/resources/#{resource.resource_name}/events"
  request(:method => 'GET', :path => uri, :expects => 200, :query => options)
end
list_resource_types(options = {}) click to toggle source
# File lib/fog/openstack/requests/orchestration/list_resource_types.rb, line 5
def list_resource_types(options = {})
  request(
    :method  => 'GET',
    :path    => "resource_types",
    :expects => 200,
    :query   => {}
  )
end
list_resources(options = {}, options_deprecated = {}) click to toggle source
# File lib/fog/openstack/requests/orchestration/list_resources.rb, line 5
def list_resources(options = {}, options_deprecated = {})
  if options.is_a?(Hash)
    if !options.key?(:stack) && !(options.key?(:stack_name) && options.key?(:stack_id))
      raise(ArgumentError, "Missing required options keys: :stack or :stack_name and :stack_id, while calling "                                    " .list_resources(options)")
    end

    stack        = options.delete(:stack)
    stack_name   = options.delete(:stack_name)
    stack_name ||=  stack.stack_name if stack && stack.respond_to?(:stack_name)
    stack_id     = options.delete(:stack_id)
    stack_id   ||=  stack.id if stack && stack.respond_to?(:id)
    path         = "stacks/#{stack_name}/#{stack_id}/resources"
    params       = options
  else
    Fog::Logger.deprecation('Calling OpenStack[:orchestration].list_resources(stack, options) is deprecated, '                                     ' call .list_resources(:stack => stack) or '                                     ' .list_resources(:stack_name => value, :stack_id => value) instead')
    path   = "stacks/#{options.stack_name}/#{options.id}/resources"
    params = options_deprecated
  end

  request(:method  => 'GET',
          :path    => path,
          :expects => 200,
          :query   => params)
end
list_stack_data(options = {}) click to toggle source
# File lib/fog/openstack/requests/orchestration/list_stack_data.rb, line 5
def list_stack_data(options = {})
  request(
    :method  => 'GET',
    :path    => 'stacks',
    :expects => 200,
    :query   => options
  )
end
list_stack_data_detailed(options = {}) click to toggle source
# File lib/fog/openstack/requests/orchestration/list_stack_data_detailed.rb, line 5
def list_stack_data_detailed(options = {})
  request(
    :method  => 'GET',
    :path    => 'stacks/detail',
    :expects => 200,
    :query   => options
  )
end
list_stack_events(stack, options = {}) click to toggle source
# File lib/fog/openstack/requests/orchestration/list_stack_events.rb, line 5
def list_stack_events(stack, options = {})
  Fog::Logger.deprecation('Calling OpenStack[:orchestration].list_stack_events(stack, options)'                                   ' is deprecated, call .list_events(:stack => stack) or '                                   ' .list_events(:stack_name => value, :stack_id => value) instead')

  uri = "stacks/#{stack.stack_name}/#{stack.id}/events"
  request(:method => 'GET', :path => uri, :expects => 200, :query => options )
end
patch_stack(stack, options = {}) click to toggle source

patch a stack.

@param [Fog::Orchestration::OpenStack::Stack] the stack to patch. @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/patch_stack.rb, line 14
def patch_stack(stack, options = {})
  stack_name = stack.stack_name
  stack_id = stack.id

  request(
    :expects  => 202,
    :path => "stacks/#{stack_name}/#{stack_id}",
    :method => 'PATCH',
    :body => Fog::JSON.encode(options)
  )
end
preview_stack(options = {}) click to toggle source
# File lib/fog/openstack/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
request(params) click to toggle source
# File lib/fog/openstack/orchestration.rb, line 150
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}/#{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
show_event_details(stack, resource, event_id) click to toggle source
# File lib/fog/openstack/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/openstack/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/openstack/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/openstack/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/openstack/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/openstack/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(arg1, arg2 = nil, arg3 = nil) click to toggle source

Update a stack.

@param [Fog::Orchestration::OpenStack::Stack] 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 14
def update_stack(arg1, arg2 = nil, arg3 = nil)
  if arg1.is_a?(Stack)
    # Normal use, update_stack(stack, options = {})
    stack = arg1
    stack_name = stack.stack_name
    stack_id = stack.id
    params = arg2.nil? ? {} : arg2
  else
    # Deprecated, update_stack(stack_id, stack_name, options = {})
    Fog::Logger.deprecation("#update_stack(stack_id, stack_name, options) is deprecated, use #update_stack(stack, options) instead [light_black](#{caller.first})[/]")
    stack_id = arg1
    stack_name = arg2
    params = {
      :stack_name => stack_name
    }.merge(arg3.nil? ? {} : arg3)
  end

  request(
    :expects  => 202,
    :path => "stacks/#{stack_name}/#{stack_id}",
    :method => 'PUT',
    :body => Fog::JSON.encode(params)
  )
end
validate_template(options = {}) click to toggle source
# File lib/fog/openstack/requests/orchestration/validate_template.rb, line 5
def validate_template(options = {})
  request(
    :body     => Fog::JSON.encode(options),
    :expects  => [200],
    :method   => 'POST',
    :path     => 'validate'
  )
end