class Fog::Openstack::Planning::Real

Public Class Methods

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

  @openstack_service_type           = options[:openstack_service_type] || ['management'] # currently Tuskar is configured as 'management' service in Keystone
  @openstack_service_name           = options[:openstack_service_name]
  @openstack_endpoint_type          = options[:openstack_endpoint_type] || 'adminURL'

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

  authenticate

  unless @path.match(SUPPORTED_VERSIONS)
    @path = "/v2"
  end

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

Public Instance Methods

add_role_to_plan(plan_uuid, role_uuid) click to toggle source
# File lib/fog/openstack/requests/planning/add_role_to_plan.rb, line 5
def add_role_to_plan(plan_uuid, role_uuid)
  request(
    :expects => [201],
    :method  => 'POST',
    :path    => "plans/#{plan_uuid}/roles",
    :body => Fog::JSON.encode({'uuid' => role_uuid})
  )
end
create_plan(parameters) click to toggle source
# File lib/fog/openstack/requests/planning/create_plan.rb, line 5
def create_plan(parameters)
  request(
    :expects => [201],
    :method  => 'POST',
    :path    => "plans",
    :body => Fog::JSON.encode(parameters)
  )
end
delete_plan(plan_uuid) click to toggle source
# File lib/fog/openstack/requests/planning/delete_plan.rb, line 5
def delete_plan(plan_uuid)
  request(
    :expects => [204],
    :method  => 'DELETE',
    :path    => "plans/#{plan_uuid}"
  )
end
get_plan(plan_uuid) click to toggle source
# File lib/fog/openstack/requests/planning/get_plan.rb, line 5
def get_plan(plan_uuid)
  request(
    :expects => [200, 204],
    :method  => 'GET',
    :path    => "plans/#{plan_uuid}"
  )
end
get_plan_templates(plan_uuid) click to toggle source
# File lib/fog/openstack/requests/planning/get_plan_templates.rb, line 5
def get_plan_templates(plan_uuid)
  request(
    :expects => [200, 204],
    :method  => 'GET',
    :path    => "plans/#{plan_uuid}/templates"
  )
end
list_plans(options = {}) click to toggle source
# File lib/fog/openstack/requests/planning/list_plans.rb, line 5
def list_plans(options = {})
  request(
    :expects => [200, 204],
    :method  => 'GET',
    :path    => 'plans',
    :query   => options
  )
end
list_roles(options = {}) click to toggle source
# File lib/fog/openstack/requests/planning/list_roles.rb, line 5
def list_roles(options = {})
  request(
    :expects => [200, 204],
    :method  => 'GET',
    :path    => 'roles',
    :query   => options
  )
end
patch_plan(plan_uuid, parameters) click to toggle source
# File lib/fog/openstack/requests/planning/patch_plan.rb, line 5
def patch_plan(plan_uuid, parameters)
  request(
    :expects => [201],
    :method  => 'PATCH',
    :path    => "plans/#{plan_uuid}",
    :body => Fog::JSON.encode(parameters)
  )
end
remove_role_from_plan(plan_uuid, role_uuid) click to toggle source
# File lib/fog/openstack/requests/planning/remove_role_from_plan.rb, line 5
def remove_role_from_plan(plan_uuid, role_uuid)
  request(
    :expects => [200],
    :method  => 'DELETE',
    :path    => "plans/#{plan_uuid}/roles/#{role_uuid}"
  )
end
request(params) click to toggle source
# File lib/fog/openstack/planning.rb, line 119
def request(params)
  begin
    response = @connection.request(params.merge({
      :headers  => {
        'Content-Type' => 'application/json',
        'X-Auth-Token' => @auth_token
      }.merge!(params[:headers] || {}),
      :path     => "#{@path}/#{params[:path]}"#,
    }))
  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
  unless response.body.empty?
    response.body = Fog::JSON.decode(response.body)
  end
  response
end