Module: Aviator::Openstack::Provider

Defined in:
lib/puppet/feature/aviator/openstack/provider.rb

Overview

Manages a provider (e.g. OpenStack) session.

Author

Mark Maglana (mmaglana@gmail.com)

Copyright

Copyright © 2014 Mark Maglana

License

Distributed under the MIT license

Homepage

aviator.github.io/www/

Request Options

The following options may be used in combination with each other when calling an OpenStack request class

:api_version => :v2

Forces Aviator to use the request class for the v2 API. For any other version, replace Note that this may throw an error if no such request class exists. If you want to globally specify the API version to use for a specific service, declare it in your config file under the correct environment. For example:

production:
  provider: openstack
  ...
  compute_service:
     api_version: v2

Note that the :api_version option overrides whatever is declared in the configuration.

:endpoint_type => (:public|:admin)

This allows you to be specific about the endpoint type in cases where two request classes under admin and public endpoints of the same service share the same name. This is true, for example, for the :list_tenants request of the identity service’s v2 API. Its public endpoint will return only the tenants the user is a member of whereas the admin endpoint will return all tenants in the system.

:session_data => Hash

Under normal situations, you wouldn’t need to use this as it is automatically populated by the Session object provided it is authenticated. The specific use case when you’d need to set thsi optin is when you want to use Aviator to seed your OpenStack installation. In such a scenario, you would need to use a service token since no usernames and tenants would exist yet in the environment. To use a service token with Aviator, you will need to write something similar to the following example:

openstack = Aviator::Session.new(:config => { :provider => 'openstack'})

session_data = {:base_url      => 'http://example.com',
                :service_token => 'service-token-created-at-openstack-install-time'}

openstack.request :identity, :create_tenant, :api_version => :v2, :session_data => session_data) do |params|
  params.name        = 'Tenant A'
  params.description = 'First Tenant!'
  params.enabled     = true
end

Notice how the above code skips authentication. This is because the service token is pre-validated and ready for use with any request. Also note how we’re providing a :base_url member in our session data. This is necessary since we normally get the service endpoints from Keystone when we authenticate. Now since we are not authenticating against Keystone, we don’t have that catalogue to begin with. Thus the need to hardcode it in the request.

Defined Under Namespace

Classes: MultipleServiceApisError

Class Method Summary collapse

Class Method Details

.find_request(service, name, session_data, options) ⇒ Object

:nodoc:



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/puppet/feature/aviator/openstack/provider.rb', line 101

def find_request(service, name, session_data, options)
  service = service.to_s
  endpoint_type = options[:endpoint_type]
  endpoint_types = if endpoint_type
                     [endpoint_type.to_s.camelize]
                   else
                     ['Public', 'Admin']
                   end

  namespace = Aviator.const_get('Openstack') \
                     .const_get(service.camelize) \
                     .const_get('Requests')

  if options[:api_version]
    m = options[:api_version].to_s.match(/(v\d+)\.?\d*/)
    version = m[1].to_s.camelize unless m.nil?
  end

  version ||= infer_version(session_data, name, service)

  unless version.nil?
    version = version.to_s.camelize
  end

  return nil unless version && namespace.const_defined?(version)

  namespace = namespace.const_get(version, name)

  endpoint_types.each do |endpoint_type|
    name = name.to_s.camelize

    next unless namespace.const_defined?(endpoint_type)
    next unless namespace.const_get(endpoint_type).const_defined?(name)

    return namespace.const_get(endpoint_type).const_get(name)
  end

  nil
end

.request_file_paths(service) ⇒ Object



147
148
149
150
151
152
153
154
155
156
# File 'lib/puppet/feature/aviator/openstack/provider.rb', line 147

def request_file_paths(service)
    Dir.glob(Pathname.new(__FILE__).join(
      '..',
       service.to_s,
      'requests',
      '**',
      '*.rb'
      ).expand_path
    )
end

.root_dirObject



142
143
144
# File 'lib/puppet/feature/aviator/openstack/provider.rb', line 142

def root_dir
  Pathname.new(__FILE__).join('..').expand_path
end