Module: OpenStack::Identity::ConnectionV3

Defined in:
lib/openstack/identity/connection_v3.rb

Instance Method Summary collapse

Instance Method Details

#add_user_to_tenant(options) ⇒ Object



46
47
48
49
# File 'lib/openstack/identity/connection_v3.rb', line 46

def add_user_to_tenant(options)
  @connection.req('PUT', "/projects/#{options[:tenant_id]}/users/#{options[:user_id]}/roles/#{options[:role_id]}")
  true
end

#create_tenant(options) ⇒ Object

create_tenant(name: ‘tenant1’, description: ‘description’, enabled: true)



13
14
15
16
17
18
# File 'lib/openstack/identity/connection_v3.rb', line 13

def create_tenant(options)
  options.merge!(domain_id: @connection.domain_id)
  req_body = JSON.generate('project' => options)
  response = @connection.req('POST', '/projects', data: req_body)
  OpenStack::Identity::Tenant.new(JSON.parse(response.body)['project'])
end

#create_user(options) ⇒ Object

create_user(name: ‘user1’, password: ‘password1’, email: ‘[email protected]’)



32
33
34
35
36
37
# File 'lib/openstack/identity/connection_v3.rb', line 32

def create_user(options)
  options.merge!(domain_id: @connection.domain_id)
  req_body = JSON.generate('user' => options)
  response = @connection.req('POST', '/users', data: req_body)
  OpenStack::Identity::User.new(JSON.parse(response.body)['user'])
end

#delete_tenant(id) ⇒ Object



25
26
27
28
# File 'lib/openstack/identity/connection_v3.rb', line 25

def delete_tenant(id)
  @connection.req('DELETE', "/projects/#{id}")
  true
end

#find_tenant_by_name(name) ⇒ Object



20
21
22
23
# File 'lib/openstack/identity/connection_v3.rb', line 20

def find_tenant_by_name(name)
  response = @connection.req('GET', "/projects?name=#{name}")
  OpenStack::Identity::Tenant.new(JSON.parse(response.body)['project'])
end

#list_rolesObject Also known as: roles



51
52
53
54
# File 'lib/openstack/identity/connection_v3.rb', line 51

def list_roles
  response = @connection.req('GET', '/roles')
  OpenStack.symbolize_keys(JSON.parse(response.body)['roles'])
end

#list_tenantsObject Also known as: tenants



4
5
6
7
8
# File 'lib/openstack/identity/connection_v3.rb', line 4

def list_tenants
  response = @connection.req('GET', '/projects')
  tenants_hash = JSON.parse(response.body)['projects']
  tenants_hash.map { |res| OpenStack::Identity::Tenant.new(res) }
end

#update_user(user_id, options) ⇒ Object

update_user(1, ‘user1’, password: ‘password1’, email: ‘[email protected]’)



40
41
42
43
44
# File 'lib/openstack/identity/connection_v3.rb', line 40

def update_user(user_id, options)
  req_body = JSON.generate('user' => options)
  response = @connection.req('PATCH', "/users/#{user_id}", data: req_body)
  OpenStack::Identity::User.new(JSON.parse(response.body)['user'])
end