Class: Keystone::V2_0::Client

Inherits:
Openstack::Client show all
Defined in:
lib/keystone/v2_0/client.rb

Instance Attribute Summary collapse

Attributes inherited from Openstack::Client

#auth_token, #management_url

Instance Method Summary collapse

Methods inherited from Openstack::Client

#delete, #execute, #get, #post, #put

Constructor Details

#initialize(options = {}) ⇒ Client

Creates a new Keystone::V2_0::Client object.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :username (String)

    Your Openstack username (optional)

  • :password (String)

    Your Openstack password (optional)

  • :tenant_id (String)

    Your Openstack tenantId (optional)

  • :tenant_name (String)

    Your Openstack tenantName (optional)

  • :auth_url (String)

    Keystone service endpoint for authorization.

  • :region_name (String)

    The specific service region to use. Defaults to first returned region.

  • :token (String)

    Whether to retry if your auth token expires (defaults to true)

  • :endpoint (String)

    A user-supplied endpoint URL for the keystone service. Lazy-authentication is possible for API service calls if endpoint is set at instantiation.(optional)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/keystone/v2_0/client.rb', line 46

def initialize options={}
  self.username     = options[:username]
  self.tenant_id    = options[:tenant_id]
  self.tenant_name  = options[:tenant_name]
  self.password     = options[:password]
  self.auth_url     = options[:auth_url].chomp('/') if options[:auth_url]
  self.version      = 'v2.0'
  self.region_name  = options[:region_name]
  self.auth_token   = options[:token]

  # self.roles = roles.RoleManager(self)
  # self.services = services.ServiceManager(self)
  self.tenants = Keystone::V2_0::TenantManager.new(self)
  self.tokens = Keystone::V2_0::TokenManager.new(self)
  # self.users = users.UserManager(self)

  # extensions
  self.ec2 = Keystone::V2_0::EC2CredentialsManager.new(self)

  unless options[:endpoint]
    authenticate
  else
    self.management_url = options[:endpoint]
  end
end

Instance Attribute Details

#auth_urlObject

Returns the value of attribute auth_url.



17
18
19
# File 'lib/keystone/v2_0/client.rb', line 17

def auth_url
  @auth_url
end

#ec2Object

Returns the value of attribute ec2.



30
31
32
# File 'lib/keystone/v2_0/client.rb', line 30

def ec2
  @ec2
end

#passwordObject

Returns the value of attribute password.



16
17
18
# File 'lib/keystone/v2_0/client.rb', line 16

def password
  @password
end

#region_nameObject

Returns the value of attribute region_name.



19
20
21
# File 'lib/keystone/v2_0/client.rb', line 19

def region_name
  @region_name
end

#rolesObject

Returns the value of attribute roles.



21
22
23
# File 'lib/keystone/v2_0/client.rb', line 21

def roles
  @roles
end

#service_catalogObject

Returns the value of attribute service_catalog.



26
27
28
# File 'lib/keystone/v2_0/client.rb', line 26

def service_catalog
  @service_catalog
end

#servicesObject

Returns the value of attribute services.



22
23
24
# File 'lib/keystone/v2_0/client.rb', line 22

def services
  @services
end

#tenant_idObject

Returns the value of attribute tenant_id.



14
15
16
# File 'lib/keystone/v2_0/client.rb', line 14

def tenant_id
  @tenant_id
end

#tenant_nameObject

Returns the value of attribute tenant_name.



15
16
17
# File 'lib/keystone/v2_0/client.rb', line 15

def tenant_name
  @tenant_name
end

#tenantsObject

Returns the value of attribute tenants.



23
24
25
# File 'lib/keystone/v2_0/client.rb', line 23

def tenants
  @tenants
end

#tokensObject

Returns the value of attribute tokens.



24
25
26
# File 'lib/keystone/v2_0/client.rb', line 24

def tokens
  @tokens
end

#userObject

Returns the value of attribute user.



28
29
30
# File 'lib/keystone/v2_0/client.rb', line 28

def user
  @user
end

#usernameObject

Returns the value of attribute username.



13
14
15
# File 'lib/keystone/v2_0/client.rb', line 13

def username
  @username
end

#usersObject

Returns the value of attribute users.



25
26
27
# File 'lib/keystone/v2_0/client.rb', line 25

def users
  @users
end

#versionObject

Returns the value of attribute version.



18
19
20
# File 'lib/keystone/v2_0/client.rb', line 18

def version
  @version
end

Instance Method Details

#_extract_service_catalog(url, body) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/keystone/v2_0/client.rb', line 96

def _extract_service_catalog url, body
  self.service_catalog  = Openstack::Client::ServiceCatalog.new(body)
  self.auth_token       = self.service_catalog.token['id']
  begin
    self.management_url   = self.service_catalog.url_for(
                                                  attribute: 'region',
                                                  filter_value: self.region_name,
                                                  endpoint_type: 'adminURL'
                                                )
  rescue
    # logger.info 'identity endpoint Not Found'
  end
end

#authenticateboolean

Authenticate against the Keystone API.

Uses the data provided at instantiation to authenticate against the Keystone server. This may use either a username and password or token for authentication. If a tenant id was provided then the resulting authenticated client will be scoped to that tenant and contain a service catalog of available endpoints.

Returns:

  • (boolean)

    if authentication was successful returns true.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/keystone/v2_0/client.rb', line 81

def authenticate
  self.management_url = self.auth_url
  raw_token = self.tokens.authenticate(
    username: username,
    tenant_id: tenant_id,
    tenant_name: tenant_name,
    password: password,
    token: auth_token,
    return_raw: true
  )
  self._extract_service_catalog(self.auth_url, raw_token)
  self.user = raw_token['user']
  return true
end