Class: OpenStack::Identity::Connection
- Defined in:
- lib/openstack/identity/connection.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
- #add_user_to_tenant(options) ⇒ Object
-
#create_tenant(options) ⇒ Object
create_tenant(name: ‘tenant1’, description: ‘description’, enabled: true).
-
#create_user(options) ⇒ Object
create_user(name: ‘user1’, password: ‘password1’, email: ‘[email protected]’).
- #delete_tenant(id) ⇒ Object
- #delete_user(id) ⇒ Object
- #find_tenant_by_name(name) ⇒ Object
-
#initialize(connection) ⇒ Connection
constructor
A new instance of Connection.
- #list_roles ⇒ Object (also: #roles)
- #list_tenants ⇒ Object (also: #tenants)
- #list_users ⇒ Object (also: #users)
Constructor Details
#initialize(connection) ⇒ Connection
Returns a new instance of Connection.
6 7 8 9 |
# File 'lib/openstack/identity/connection.rb', line 6 def initialize(connection) @connection = connection OpenStack::Authentication.init(@connection) end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
4 5 6 |
# File 'lib/openstack/identity/connection.rb', line 4 def connection @connection end |
Instance Method Details
#add_user_to_tenant(options) ⇒ Object
56 57 58 59 60 |
# File 'lib/openstack/identity/connection.rb', line 56 def add_user_to_tenant() req_body = JSON.generate('role' => { 'tenantId' => [:tenant_id], 'roleId' => [:role_id] }) @connection.req('POST', "/users/#{[:user_id]}/roleRefs", data: req_body) true end |
#create_tenant(options) ⇒ Object
create_tenant(name: ‘tenant1’, description: ‘description’, enabled: true)
20 21 22 23 24 |
# File 'lib/openstack/identity/connection.rb', line 20 def create_tenant() req_body = JSON.generate('tenant' => ) response = @connection.req('POST', '/tenants', data: req_body) OpenStack::Identity::Tenant.new(JSON.parse(response.body)['tenant']) end |
#create_user(options) ⇒ Object
create_user(name: ‘user1’, password: ‘password1’, email: ‘[email protected]’)
45 46 47 48 49 |
# File 'lib/openstack/identity/connection.rb', line 45 def create_user() req_body = JSON.generate('user' => ) response = @connection.req('POST', '/users', data: req_body) OpenStack::Identity::User.new(JSON.parse(response.body)['user']) end |
#delete_tenant(id) ⇒ Object
31 32 33 34 |
# File 'lib/openstack/identity/connection.rb', line 31 def delete_tenant(id) @connection.req('DELETE', "/tenants/#{id}") true end |
#delete_user(id) ⇒ Object
51 52 53 54 |
# File 'lib/openstack/identity/connection.rb', line 51 def delete_user(id) @connection.req('DELETE', "/users/#{id}") true end |
#find_tenant_by_name(name) ⇒ Object
26 27 28 29 |
# File 'lib/openstack/identity/connection.rb', line 26 def find_tenant_by_name(name) response = @connection.req('GET', "/tenants?name=#{name}") OpenStack::Identity::Tenant.new(JSON.parse(response.body)['tenant']) end |
#list_roles ⇒ Object Also known as: roles
62 63 64 65 |
# File 'lib/openstack/identity/connection.rb', line 62 def list_roles response = @connection.req('GET', '/OS-KSADM/roles') OpenStack.symbolize_keys(JSON.parse(response.body)['roles']) end |