Class: VagrantPlugins::Openstack::KeystoneClient

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/vagrant-openstack-provider/client/keystone.rb

Instance Method Summary collapse

Constructor Details

#initializeKeystoneClient

Returns a new instance of KeystoneClient.



10
11
12
13
# File 'lib/vagrant-openstack-provider/client/keystone.rb', line 10

def initialize
  @logger = Log4r::Logger.new('vagrant_openstack::keystone')
  @session = VagrantPlugins::Openstack.session
end

Instance Method Details

#authenticate(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vagrant-openstack-provider/client/keystone.rb', line 15

def authenticate(env)
  @logger.debug('Authenticating on Keystone')
  config = env[:machine].provider_config
  env[:ui].info(I18n.t('vagrant_openstack.client.authentication', project: config.tenant_name, user: config.username))

  authentication = RestClient.post(
      config.openstack_auth_url,
      {
        auth:
        {
          tenantName: config.tenant_name,
          passwordCredentials:
            {
              username: config.username,
              password: config.password
            }
        }
      }.to_json,
      content_type: :json,
      accept: :json)

  access = JSON.parse(authentication)['access']

  read_endpoint_catalog(env, access['serviceCatalog'])
  override_endpoint_catalog_with_user_config(env)
  print_endpoint_catalog(env)

  response_token = access['token']
  @session.token = response_token['id']
  @session.project_id = response_token['tenant']['id']
end